Documentation
¶
Overview ¶
Package discord provides Discord API client functionality.
Index ¶
- type BotInfo
- type BotStatus
- type ChannelMapGetter
- type ChannelMappings
- type Client
- func (c *Client) ArchiveThread(ctx context.Context, threadID string) error
- func (c *Client) BotInfo(ctx context.Context) (BotInfo, error)
- func (c *Client) ChannelMessages(ctx context.Context, channelID string, limit int) ([]*discordgo.Message, error)
- func (c *Client) ChannelType(ctx context.Context, channelID string) (discordgo.ChannelType, error)
- func (c *Client) Close() error
- func (c *Client) FindChannelMessage(ctx context.Context, channelID, prURL string) (messageID string, found bool)
- func (c *Client) FindDMForPR(ctx context.Context, userID, prURL string) (channelID, messageID string, found bool)
- func (c *Client) FindForumThread(ctx context.Context, forumID, prURL string) (threadID, messageID string, found bool)
- func (c *Client) GuildID() string
- func (c *Client) GuildInfo(ctx context.Context) (GuildInfo, error)
- func (c *Client) IsBotInChannel(ctx context.Context, channelID string) bool
- func (c *Client) IsForumChannel(ctx context.Context, channelID string) bool
- func (c *Client) IsUserActive(ctx context.Context, userID string) bool
- func (c *Client) IsUserInGuild(ctx context.Context, userID string) bool
- func (c *Client) LookupUserByUsername(ctx context.Context, username string) string
- func (c *Client) MessageContent(ctx context.Context, channelID, messageID string) (string, error)
- func (c *Client) Open() error
- func (c *Client) PostForumThread(ctx context.Context, channelID, title, content string) (threadID, messageID string, err error)
- func (c *Client) PostMessage(ctx context.Context, channelID, text string) (string, error)
- func (c *Client) ResolveChannelID(ctx context.Context, channelName string) string
- func (c *Client) SendDM(ctx context.Context, userID, text string) (channelID, messageID string, err error)
- func (c *Client) Session() *discordgo.Session
- func (c *Client) SetGuildID(guildID string)
- func (c *Client) UpdateDM(ctx context.Context, channelID, messageID, newText string) error
- func (c *Client) UpdateForumPost(ctx context.Context, threadID, messageID, newTitle, newContent string) error
- func (c *Client) UpdateMessage(ctx context.Context, channelID, messageID, newText string) error
- type DailyReportDebug
- type DailyReportGetter
- type GuildInfo
- type GuildManager
- func (m *GuildManager) Client(guildID string) (*Client, bool)
- func (m *GuildManager) ClientFromToken(ctx context.Context, guildID, token string) (*Client, error)
- func (m *GuildManager) Close() error
- func (m *GuildManager) ForEach(fn func(guildID string, client *Client))
- func (m *GuildManager) GuildIDs() []string
- func (m *GuildManager) RegisterClient(guildID string, client *Client)
- func (m *GuildManager) RemoveClient(guildID string)
- type PRReport
- type PRSummary
- type RepoChannelMapping
- type ReportGetter
- type SlashCommandHandler
- func (h *SlashCommandHandler) RegisterCommands(guildID string) error
- func (h *SlashCommandHandler) RemoveCommands(guildID string) error
- func (h *SlashCommandHandler) SetChannelMapGetter(getter ChannelMapGetter)
- func (h *SlashCommandHandler) SetDailyReportGetter(getter DailyReportGetter)
- func (h *SlashCommandHandler) SetDashboardURL(url string)
- func (h *SlashCommandHandler) SetReportGetter(getter ReportGetter)
- func (h *SlashCommandHandler) SetStatusGetter(getter StatusGetter)
- func (h *SlashCommandHandler) SetStore(store state.Store)
- func (h *SlashCommandHandler) SetUserMapGetter(getter UserMapGetter)
- func (h *SlashCommandHandler) SetupHandler()
- type StatusGetter
- type UserMapGetter
- type UserMapping
- type UserMappings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BotStatus ¶
type BotStatus struct {
LastEventTime string
ConfiguredRepos []string
ConnectedOrgs []string
WatchedChannels []string
PendingDMs int
UptimeSeconds int64
ActivePRs int
SprinklerConnections int
UsersCached int
DMsSent int64
DailyReportsSent int64
ChannelMessagesSent int64
Connected bool
}
BotStatus contains bot status information.
type ChannelMapGetter ¶
type ChannelMapGetter interface {
// ChannelMappings returns all repo to channel mappings for a guild.
ChannelMappings(ctx context.Context, guildID string) (*ChannelMappings, error)
}
ChannelMapGetter provides channel mapping information.
type ChannelMappings ¶
type ChannelMappings struct {
RepoMappings []RepoChannelMapping
TotalRepos int
}
ChannelMappings contains all channel mapping information.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps discordgo.Session with a clean interface for bot operations.
func (*Client) ArchiveThread ¶
ArchiveThread archives a forum thread.
func (*Client) ChannelMessages ¶
func (c *Client) ChannelMessages(ctx context.Context, channelID string, limit int) ([]*discordgo.Message, error)
ChannelMessages retrieves recent messages from a channel.
func (*Client) ChannelType ¶
ChannelType returns the type of a channel (forum, text, etc.).
func (*Client) FindChannelMessage ¶
func (c *Client) FindChannelMessage(ctx context.Context, channelID, prURL string) (messageID string, found bool)
FindChannelMessage searches for an existing message containing the PR URL. Returns messageID if found.
func (*Client) FindDMForPR ¶
func (c *Client) FindDMForPR(ctx context.Context, userID, prURL string) (channelID, messageID string, found bool)
FindDMForPR searches for an existing DM about a specific PR. Returns channelID, messageID if found.
func (*Client) FindForumThread ¶
func (c *Client) FindForumThread(ctx context.Context, forumID, prURL string) (threadID, messageID string, found bool)
FindForumThread searches for an existing forum thread by PR URL in the content. Returns threadID, messageID if found. Uses retry logic for API calls.
func (*Client) IsBotInChannel ¶
IsBotInChannel checks if the bot has permission to send messages in a channel.
func (*Client) IsForumChannel ¶
IsForumChannel returns true if the channel is a forum channel.
func (*Client) IsUserActive ¶
IsUserActive checks if a user is currently online, idle, or do-not-disturb (not offline).
func (*Client) IsUserInGuild ¶
IsUserInGuild checks if a user is a member of the guild.
func (*Client) LookupUserByUsername ¶
LookupUserByUsername finds a Discord user ID by username match. Uses multi-tier matching: exact, case-insensitive, then prefix (if unambiguous).
func (*Client) MessageContent ¶
MessageContent retrieves the content of a specific message.
func (*Client) PostForumThread ¶
func (c *Client) PostForumThread(ctx context.Context, channelID, title, content string) (threadID, messageID string, err error)
PostForumThread creates a forum post with title and content, with link embeds suppressed.
func (*Client) PostMessage ¶
PostMessage sends a plain text message to a channel with link embeds suppressed.
func (*Client) ResolveChannelID ¶
ResolveChannelID resolves a channel name to its ID.
func (*Client) SendDM ¶
func (c *Client) SendDM(ctx context.Context, userID, text string) (channelID, messageID string, err error)
SendDM sends a direct message to a user with link embeds suppressed.
func (*Client) SetGuildID ¶
SetGuildID sets the guild ID for this client.
type DailyReportDebug ¶
type DailyReportDebug struct {
LastSentAt time.Time
NextEligibleAt time.Time
LastSeenActiveAt time.Time
Reason string // Why report was/wasn't sent
HoursSinceLastSent float64
MinutesActive float64
IncomingPRCount int
OutgoingPRCount int
UserOnline bool
Eligible bool
ReportSent bool
}
DailyReportDebug contains debug information about daily report eligibility.
type DailyReportGetter ¶
type DailyReportGetter interface {
// DailyReport generates and sends a daily report for a user, returning debug info.
DailyReport(ctx context.Context, guildID, userID string, force bool) (*DailyReportDebug, error)
}
DailyReportGetter provides daily report generation and debugging.
type GuildManager ¶
type GuildManager struct {
// contains filtered or unexported fields
}
GuildManager manages Discord clients for multiple guilds.
func NewGuildManager ¶
func NewGuildManager(logger *slog.Logger) *GuildManager
NewGuildManager creates a new guild manager.
func (*GuildManager) Client ¶
func (m *GuildManager) Client(guildID string) (*Client, bool)
Client returns the Discord client for a guild.
func (*GuildManager) ClientFromToken ¶
ClientFromToken creates and registers a new client from a bot token.
func (*GuildManager) ForEach ¶
func (m *GuildManager) ForEach(fn func(guildID string, client *Client))
ForEach calls the given function for each registered client.
func (*GuildManager) GuildIDs ¶
func (m *GuildManager) GuildIDs() []string
GuildIDs returns all registered guild IDs.
func (*GuildManager) RegisterClient ¶
func (m *GuildManager) RegisterClient(guildID string, client *Client)
RegisterClient registers a Discord client for a guild.
func (*GuildManager) RemoveClient ¶
func (m *GuildManager) RemoveClient(guildID string)
RemoveClient removes a Discord client for a guild.
type PRSummary ¶
type PRSummary struct {
Repo string
Title string
Author string
State string
URL string
Action string
UpdatedAt string
Number int
IsBlocked bool
}
PRSummary contains summary info for a single PR.
type RepoChannelMapping ¶
RepoChannelMapping represents repo to channels mapping.
type ReportGetter ¶
type ReportGetter interface {
// Report generates a PR report for a user.
Report(ctx context.Context, guildID, userID string) (*PRReport, error)
}
ReportGetter provides PR report generation.
type SlashCommandHandler ¶
type SlashCommandHandler struct {
// contains filtered or unexported fields
}
SlashCommandHandler handles Discord slash commands.
func NewSlashCommandHandler ¶
func NewSlashCommandHandler(session *discordgo.Session, logger *slog.Logger) *SlashCommandHandler
NewSlashCommandHandler creates a new slash command handler.
func (*SlashCommandHandler) RegisterCommands ¶
func (h *SlashCommandHandler) RegisterCommands(guildID string) error
RegisterCommands registers the slash commands with Discord.
func (*SlashCommandHandler) RemoveCommands ¶
func (h *SlashCommandHandler) RemoveCommands(guildID string) error
RemoveCommands removes all registered commands for a guild.
func (*SlashCommandHandler) SetChannelMapGetter ¶
func (h *SlashCommandHandler) SetChannelMapGetter(getter ChannelMapGetter)
SetChannelMapGetter sets the channel mapping provider.
func (*SlashCommandHandler) SetDailyReportGetter ¶
func (h *SlashCommandHandler) SetDailyReportGetter(getter DailyReportGetter)
SetDailyReportGetter sets the daily report provider.
func (*SlashCommandHandler) SetDashboardURL ¶
func (h *SlashCommandHandler) SetDashboardURL(url string)
SetDashboardURL sets the dashboard URL.
func (*SlashCommandHandler) SetReportGetter ¶
func (h *SlashCommandHandler) SetReportGetter(getter ReportGetter)
SetReportGetter sets the report provider.
func (*SlashCommandHandler) SetStatusGetter ¶
func (h *SlashCommandHandler) SetStatusGetter(getter StatusGetter)
SetStatusGetter sets the status provider.
func (*SlashCommandHandler) SetStore ¶
func (h *SlashCommandHandler) SetStore(store state.Store)
SetStore sets the state store.
func (*SlashCommandHandler) SetUserMapGetter ¶
func (h *SlashCommandHandler) SetUserMapGetter(getter UserMapGetter)
SetUserMapGetter sets the user mapping provider.
func (*SlashCommandHandler) SetupHandler ¶
func (h *SlashCommandHandler) SetupHandler()
SetupHandler sets up the interaction handler.
type StatusGetter ¶
type StatusGetter interface {
// Status returns the current bot status for a guild.
Status(ctx context.Context, guildID string) BotStatus
}
StatusGetter provides bot status information.
type UserMapGetter ¶
type UserMapGetter interface {
// UserMappings returns all user mappings for a guild.
UserMappings(ctx context.Context, guildID string) (*UserMappings, error)
}
UserMapGetter provides user mapping information.
type UserMapping ¶
type UserMapping struct {
GitHubUsername string
DiscordUserID string
DiscordName string // Optional: Discord display name if available
Source string // "config", "username_match", "cached"
Org string
}
UserMapping represents a single user mapping.
type UserMappings ¶
type UserMappings struct {
ConfigMappings []UserMapping // Hardcoded in config
DiscoveredMappings []UserMapping // Auto-discovered or cached
TotalUsers int
}
UserMappings contains all user mapping information.