Documentation
¶
Index ¶
- Constants
- func CopyHandlers[T any](mu *sync.RWMutex, handlers []T) []T
- func FindCutPoint(content string, maxLen int) int
- func FormatThreadMessage(botID, botUsername, mentionUserID, message, greetingPrefix string) string
- func HasCommandPrefix(content string) bool
- func RegisterHandler[T any](mu *sync.RWMutex, handlers *[]T, handler T)
- func ReplaceTextMention(content, username, mention string) string
- func SplitMessage(content string, maxLen int) []string
- func StripMention(content, botUserID string) string
- func StripPrefix(content string) string
- type ChannelDeleteHandler
- type ChannelJoinHandler
- type IncomingMessage
- type Interaction
- type InteractionHandler
- type MessageHandler
- type OutgoingMessage
Constants ¶
const CommandPrefix = "!loop"
CommandPrefix is the text prefix used to trigger bot commands.
Variables ¶
This section is empty.
Functions ¶
func CopyHandlers ¶ added in v0.1.46
CopyHandlers returns a snapshot of the handler slice under a read lock.
func FindCutPoint ¶
FindCutPoint returns the best position to split content at, given a maximum length. It prefers cutting at a newline, then a space, then does a hard cut.
func FormatThreadMessage ¶ added in v0.1.57
FormatThreadMessage builds the initial message for a new thread. When message is non-empty it strips existing bot mentions, prepends a bot mention, and optionally appends a user mention. When message is empty, it returns a greeting (optionally mentioning the user) prefixed by greetingPrefix (e.g. Slack uses "*threadName*\n").
func HasCommandPrefix ¶
HasCommandPrefix reports whether content starts with the command prefix (case-insensitive).
func RegisterHandler ¶ added in v0.1.46
RegisterHandler appends a handler to the slice under the given mutex.
func ReplaceTextMention ¶
ReplaceTextMention replaces a case-insensitive @username with the given mention string.
func SplitMessage ¶
SplitMessage splits a message into chunks of at most maxLen characters, breaking on newlines when possible.
func StripMention ¶
StripMention removes both <@botUserID> and <@!botUserID> forms from content and trims surrounding whitespace.
func StripPrefix ¶
StripPrefix removes the command prefix from content and trims surrounding whitespace.
Types ¶
type ChannelDeleteHandler ¶
ChannelDeleteHandler is a callback for channel/thread deletion events.
type ChannelJoinHandler ¶
ChannelJoinHandler is a callback for when the bot joins a channel.
type IncomingMessage ¶
type IncomingMessage struct {
ChannelID string
GuildID string
AuthorID string
AuthorName string
Content string
MessageID string
IsBotMention bool
IsReplyToBot bool
HasPrefix bool
IsDM bool
Timestamp time.Time
AuthorRoles []string // role IDs for permission checking (Discord only)
}
IncomingMessage from the chat platform.
type Interaction ¶ added in v0.1.58
type Interaction struct {
ChannelID string
GuildID string
CommandName string
Options map[string]string
AuthorID string // user who invoked the command
AuthorRoles []string // role IDs (Discord only)
}
Interaction represents a slash command interaction.
type InteractionHandler ¶
type InteractionHandler = func(ctx context.Context, i *Interaction)
InteractionHandler is a callback for slash command interactions.
type MessageHandler ¶
type MessageHandler = func(ctx context.Context, msg *IncomingMessage)
MessageHandler is a callback for incoming messages.
type OutgoingMessage ¶
OutgoingMessage to the chat platform.