bot

package
v2.0.0-...-e570596 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	Discord  string `toml:"discord"`
	Postgres string `toml:"postgres"`
	Redis    string `toml:"redis"`
	Sentry   string `toml:"sentry"`

	Influx AuthInfluxConfig `toml:"influx"`
}

type AuthInfluxConfig

type AuthInfluxConfig struct {
	URL          string `toml:"url"`
	Token        string `toml:"token"`
	Organization string `toml:"organization"`
	Database     string `toml:"database"`
}

type Bot

type Bot struct {
	Router  *bcr.Router
	DB      *db.DB
	PK      *pkgo.Session
	Metrics *metrics.Client

	Config Config

	Cabinet store.Cabinet
	// contains filtered or unexported fields
}

func New

func New(c Config) (*Bot, error)

New creates a new Bot.

func (*Bot) AddHandler

func (bot *Bot) AddHandler(i ...any)

AddHandler adds handlers to all states.

func (*Bot) Close

func (bot *Bot) Close() error

func (*Bot) GuildUser

func (bot *Bot) GuildUser(guildID discord.GuildID, userID discord.UserID) (*discord.User, error)

GuildUser returns a user from the given guild. If the user is still a member of the guild, it will grab the user from cache. Otherwise, it will request the user object from Discord directly.

func (*Bot) Me

func (bot *Bot) Me() discord.User

func (*Bot) Open

func (bot *Bot) Open(ctx context.Context) error

func (*Bot) ReportError

func (bot *Bot) ReportError(c bcr.HasContext, err error) error

func (*Bot) Send

func (bot *Bot) Send(
	guildID discord.GuildID,
	event any,
	data SendData,
)

Send either sends a slice of embeds immediately, or queues a single embed. `event` should either be the event received in the handler, or a string name.

func (*Bot) ShouldLog

func (bot *Bot) ShouldLog() bool

ShouldLog returns true if test mode is not enabled.

func (*Bot) StateFromGuildID

func (bot *Bot) StateFromGuildID(guildID discord.GuildID) (s *state.State, id int)

func (*Bot) User

func (bot *Bot) User(userID discord.UserID) (*discord.User, error)

User returns a user from the cache, or from Discord's API if the user is not cached. NOTE: This method should be used very sparingly! If a guild ID is available, GuildUser should always be used instead.

type BotConfig

type BotConfig struct {
	Owner           discord.UserID    `toml:"owner"`
	AESKey          string            `toml:"aes_key"`
	CommandsGuildID discord.GuildID   `toml:"commands_guild_id"`
	NoSyncCommands  bool              `toml:"no_sync_commands"`
	JoinLeaveLog    discord.ChannelID `toml:"join_leave_log"`
	// Ready event logs
	MetaLog discord.ChannelID `toml:"meta_log"`

	// TestMode disables all interaction with Discord that is not necessary for building a cache.
	// No logging or command responses are done in this mode, invites and members are still fetched.
	TestMode bool `toml:"test_mode"`

	// NoAutoMigrate specifies if migrations should be done automatically when the bot starts.
	// If this is set to true, migrations must be done manually by running the `./catalogger migrate` command.
	NoAutoMigrate bool `toml:"no_auto_migrate"`
}

type Config

type Config struct {
	Auth      AuthConfig      `toml:"auth"`
	Bot       BotConfig       `toml:"bot"`
	Dashboard DashboardConfig `toml:"dashboard"`
	Info      InfoConfig      `toml:"info"`
}

func ReadConfig

func ReadConfig(path string) (c Config, err error)

type DashboardConfig

type DashboardConfig struct {
	ClientID     string `toml:"client_id"`
	ClientSecret string `toml:"client_secret"`
	HTTPS        bool   `toml:"https"`
	Port         string `toml:"port"`
	Host         string `toml:"host"`

	AnnouncementChannel discord.ChannelID `toml:"announcement_channel"`
}

type InfoConfig

type InfoConfig struct {
	SupportServer string `toml:"support_server"`
	DashboardBase string `toml:"dashboard_base"`

	HelpFields []discord.EmbedField `toml:"help_fields"`
}

type SendData

type SendData struct {
	// If ChannelID is not valid, the channel ID is fetched by bot.Send.
	// This should only be set if the log channel ID is checked in the log handler.
	ChannelID discord.ChannelID

	Embeds []discord.Embed
	Files  []sendpart.File
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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