bot

package
v0.1.65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const CommandPrefix = "!loop"

CommandPrefix is the text prefix used to trigger bot commands.

Variables

View Source
var RemoveMCPConfig = removeMCPConfig

RemoveMCPConfig removes the per-channel MCP config file for the given channel. It silently ignores os.ErrNotExist (the file may not exist if the agent never ran). This is a variable so external packages can override it in tests.

Functions

func CopyHandlers added in v0.1.46

func CopyHandlers[T any](mu *sync.RWMutex, handlers []T) []T

CopyHandlers returns a snapshot of the handler slice under a read lock.

func FindCutPoint

func FindCutPoint(content string, maxLen int) int

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

func FormatThreadMessage(botID, botUsername, mentionUserID, message string) string

FormatThreadMessage builds the initial message for a new thread. It always includes a <@botID> mention so that the bot's event handler recognises the message as a self-mention trigger and starts a new agent run inside the thread. Existing bot mentions (both <@botID> and @username forms) are stripped from message before prepending a canonical <@botID>. If mentionUserID is non-empty the user is appended as a mention.

func HasCommandPrefix

func HasCommandPrefix(content string) bool

HasCommandPrefix reports whether content starts with the command prefix (case-insensitive).

func RegisterHandler added in v0.1.46

func RegisterHandler[T any](mu *sync.RWMutex, handlers *[]T, handler T)

RegisterHandler appends a handler to the slice under the given mutex.

func ReplaceTextMention

func ReplaceTextMention(content, username, mention string) string

ReplaceTextMention replaces a case-insensitive @username with the given mention string.

func SplitMessage

func SplitMessage(content string, maxLen int) []string

SplitMessage splits a message into chunks of at most maxLen characters, breaking on newlines when possible.

func StripMention

func StripMention(content, botUserID string) string

StripMention removes both <@botUserID> and <@!botUserID> forms from content and trims surrounding whitespace.

func StripPrefix

func StripPrefix(content string) string

StripPrefix removes the command prefix from content and trims surrounding whitespace.

Types

type ChannelDeleteHandler

type ChannelDeleteHandler = func(ctx context.Context, channelID string, isThread bool)

ChannelDeleteHandler is a callback for channel/thread deletion events.

type ChannelJoinHandler

type ChannelJoinHandler = func(ctx context.Context, channelID string)

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

type OutgoingMessage struct {
	ChannelID        string
	Content          string
	ReplyToMessageID string
}

OutgoingMessage to the chat platform.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL