discord

package
v0.0.0-...-229e418 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package discord provides Discord API client functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotInfo

type BotInfo struct {
	UserID   string
	Username string
}

BotInfo holds basic bot user information.

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 New

func New(token string) (*Client, error)

New creates a new Discord client for a specific guild.

func (*Client) ArchiveThread

func (c *Client) ArchiveThread(ctx context.Context, threadID string) error

ArchiveThread archives a forum thread.

func (*Client) BotInfo

func (c *Client) BotInfo(ctx context.Context) (BotInfo, error)

BotInfo returns the bot's user information.

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

func (c *Client) ChannelType(ctx context.Context, channelID string) (discordgo.ChannelType, error)

ChannelType returns the type of a channel (forum, text, etc.).

func (*Client) Close

func (c *Client) Close() error

Close closes the WebSocket connection.

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) GuildID

func (c *Client) GuildID() string

GuildID returns the current guild ID.

func (*Client) GuildInfo

func (c *Client) GuildInfo(ctx context.Context) (GuildInfo, error)

GuildInfo returns information about the current guild.

func (*Client) IsBotInChannel

func (c *Client) IsBotInChannel(ctx context.Context, channelID string) bool

IsBotInChannel checks if the bot has permission to send messages in a channel.

func (*Client) IsForumChannel

func (c *Client) IsForumChannel(ctx context.Context, channelID string) bool

IsForumChannel returns true if the channel is a forum channel.

func (*Client) IsUserActive

func (c *Client) IsUserActive(ctx context.Context, userID string) bool

IsUserActive checks if a user is currently online, idle, or do-not-disturb (not offline).

func (*Client) IsUserInGuild

func (c *Client) IsUserInGuild(ctx context.Context, userID string) bool

IsUserInGuild checks if a user is a member of the guild.

func (*Client) LookupUserByUsername

func (c *Client) LookupUserByUsername(ctx context.Context, username string) string

LookupUserByUsername finds a Discord user ID by username match. Uses multi-tier matching: exact, case-insensitive, then prefix (if unambiguous).

func (*Client) MessageContent

func (c *Client) MessageContent(ctx context.Context, channelID, messageID string) (string, error)

MessageContent retrieves the content of a specific message.

func (*Client) Open

func (c *Client) Open() error

Open opens the WebSocket connection to Discord with a timeout.

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

func (c *Client) PostMessage(ctx context.Context, channelID, text string) (string, error)

PostMessage sends a plain text message to a channel with link embeds suppressed.

func (*Client) ResolveChannelID

func (c *Client) ResolveChannelID(ctx context.Context, channelName string) string

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) Session

func (c *Client) Session() *discordgo.Session

Session returns the underlying discordgo session.

func (*Client) SetGuildID

func (c *Client) SetGuildID(guildID string)

SetGuildID sets the guild ID for this client.

func (*Client) UpdateDM

func (c *Client) UpdateDM(ctx context.Context, channelID, messageID, newText string) error

UpdateDM updates an existing DM message.

func (*Client) UpdateForumPost

func (c *Client) UpdateForumPost(ctx context.Context, threadID, messageID, newTitle, newContent string) error

UpdateForumPost updates both the thread title and starter message.

func (*Client) UpdateMessage

func (c *Client) UpdateMessage(ctx context.Context, channelID, messageID, newText string) error

UpdateMessage edits an existing message.

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 GuildInfo

type GuildInfo struct {
	ID   string
	Name string
}

GuildInfo holds basic guild information.

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

func (m *GuildManager) ClientFromToken(ctx context.Context, guildID, token string) (*Client, error)

ClientFromToken creates and registers a new client from a bot token.

func (*GuildManager) Close

func (m *GuildManager) Close() error

Close closes all Discord clients.

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 PRReport

type PRReport struct {
	GeneratedAt string
	IncomingPRs []PRSummary
	OutgoingPRs []PRSummary
}

PRReport contains PR summary for a user.

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

type RepoChannelMapping struct {
	Repo         string
	Org          string
	Channels     []string
	ChannelTypes []string
}

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.

Jump to

Keyboard shortcuts

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