bot

package
v24.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package bot is the high-level constructs around a discord bot

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateCommand = errors.New("duplicate command")

ErrDuplicateCommand represents having multiple commands with the same name

Functions

This section is empty.

Types

type Config

type Config struct {
	ClientID     string
	ClientSecret string
	BotToken     string
	APIURL       string
	NumWorkers   int

	OS          string
	BotName     string
	BotPresence string

	GlobalSlashCommands []entity.ApplicationCommand
}

Config is the set of configuration options for creating a DiscordBot with NewDiscordBot

type DiscordBot

type DiscordBot struct {
	// contains filtered or unexported fields
}

DiscordBot is the actal bot

func NewDiscordBot

func NewDiscordBot(deps dependencies, conf Config, permissions, intents int) *DiscordBot

NewDiscordBot creates a new DiscordBot

func (*DiscordBot) API

API returns the DiscordJSONClient

func (*DiscordBot) AuthenticateAndConnect

func (d *DiscordBot) AuthenticateAndConnect() error

AuthenticateAndConnect sets up the bot to run

func (*DiscordBot) Config

func (d *DiscordBot) Config() Config

Config returns the bot config

func (*DiscordBot) Disconnect

func (d *DiscordBot) Disconnect() error

Disconnect stops the bot

func (*DiscordBot) Dispatcher

func (d *DiscordBot) Dispatcher() Dispatcher

Dispatcher returns the bot dispatcher

func (*DiscordBot) Intents

func (d *DiscordBot) Intents() int

Intents returns the combined discord intents

func (*DiscordBot) LastSequence

func (d *DiscordBot) LastSequence() int

LastSequence is the last sequence number seen

func (*DiscordBot) ReconfigureHeartbeat

func (d *DiscordBot) ReconfigureHeartbeat(ctx context.Context, interval int)

ReconfigureHeartbeat re-configures the heartbeat ticker

func (*DiscordBot) RegisterGlobalCommands

func (d *DiscordBot) RegisterGlobalCommands(ctx context.Context) error

RegisterGlobalCommands registers the global bot commands with discord

func (*DiscordBot) RegisterGuildCommands

func (d *DiscordBot) RegisterGuildCommands(ctx context.Context, gid snowflake.Snowflake, cmds []entity.ApplicationCommand) ([]entity.ApplicationCommand, error)

RegisterGuildCommands registers the guild-specific commands for a guild with discord

func (*DiscordBot) Run

func (d *DiscordBot) Run(ctx context.Context) error

Run starts handling websocket requests and heartbeats after calling AuthenticateAndConnect

func (*DiscordBot) SetDebug

func (d *DiscordBot) SetDebug(val bool)

SetDebug turns on/off debug mode

func (*DiscordBot) UpdateSequence

func (d *DiscordBot) UpdateSequence(seq int) bool

UpdateSequence updates the sequence number if it is newer

type DispatchHandlerFunc

type DispatchHandlerFunc = func(Payload, wsapi.WSMessage, chan<- wsapi.WSMessage) snowflake.Snowflake

DispatchHandlerFunc is the api that a bot expects a handler function to have

type Dispatcher

type Dispatcher interface {
	ConnectToBot(*DiscordBot)
	GenerateHeartbeat(context.Context, int) (wsapi.WSMessage, error)
	AddHandler(string, DispatchHandlerFunc)
	HandleRequest(wsapi.WSMessage, chan<- wsapi.WSMessage) snowflake.Snowflake
}

Dispatcher is the api that a bot expects a handler manager to have

type Logger

type Logger = interface {
	Log(keyvals ...interface{}) error
	Message(string, ...interface{})
	Err(string, error, ...interface{})
	Printf(string, ...interface{})
}

Logger is the interface expected for logging

type Payload

type Payload = interface {
	EventName() string
	Contents() map[string]etfapi.Element
}

Payload is the interface expected for an etf payload

Directories

Path Synopsis
Package session handles the discord session caching/maintenance
Package session handles the discord session caching/maintenance

Jump to

Keyboard shortcuts

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