bot

package
v0.0.0-...-a2b456a Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPrefixLength = errors.New("bot: prefix cannot be greater than a character in length")
	ErrDBNil        = errors.New("bot: the provided database is nil")
)

Errors returned by the bot during initialization

Functions

This section is empty.

Types

type BaseCommand

type BaseCommand interface {
	Permissions() int
}

BaseCommand is a basis for all Commands.

type Bot

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

Bot is a Discord bot backed by Harmony.

func NewBot

func NewBot(o *Options) (*Bot, error)

NewBot creates a new Bot.

func (*Bot) ChangeActivity

func (b *Bot) ChangeActivity(act *harmony.Activity) error

ChangeActivity changes the Bot's Discord activity.

func (*Bot) Connect

func (b *Bot) Connect(ctx context.Context) error

Connect initiates a connection to Discord.

func (*Bot) Disconnect

func (b *Bot) Disconnect()

Disconnect closes a connection to Discord.

func (*Bot) Start

func (b *Bot) Start(ctx context.Context) error

Start starts

func (*Bot) Stop

func (b *Bot) Stop() error

Stop closes all subsequent Goroutines as well as any connection to Discord. It blocks until all tasks have finished, returning any errors encountered.

type ChatCommands

type ChatCommands struct {
	Help     helpCmd     `cmd:"" help:"Get help with a command"`
	Version  versionCmd  `cmd:"" help:"Print the current bot version"`
	Jerkcity jerkcityCmd `cmd:"" help:"Slurping and drooling and hurrrr"`
	Pronouns pronounsCmd `cmd:"" help:"Generate pronoun roles for your guild"`
}

ChatCommands are default Commands provided by the bot.

type ChatContext

type ChatContext struct {
	Bot     *Bot
	Message *harmony.Message
}

ChatContext is supplied to Commands upon execution.

func (*ChatContext) Channel

func (c *ChatContext) Channel(ctx context.Context) (*harmony.Channel, error)

Channel retrieves the parent Channel.

func (*ChatContext) Guild

func (c *ChatContext) Guild(ctx context.Context) (*harmony.Guild, error)

Guild retrieves the parent Guild.

func (*ChatContext) LogError

func (c *ChatContext) LogError(msg string, err error, fields ...zapcore.Field)

LogError logs an error to the internal Bot's logger.

func (*ChatContext) LogErrorWithGuild

func (c *ChatContext) LogErrorWithGuild(msg string, err error, guildID string, fields ...zapcore.Field)

LogErrorWithGuild logs an error with a specific Guild ID rather than the Context's own.

func (*ChatContext) Member

func (c *ChatContext) Member(ctx context.Context) (*harmony.GuildMember, error)

Member retrieves the GuildMember that invoked the parent Command.

func (*ChatContext) Reply

func (c *ChatContext) Reply(ctx context.Context, msg string, args ...interface{}) error

Reply sends a message to the parent channel.

func (*ChatContext) ReplyEmbed

func (c *ChatContext) ReplyEmbed(ctx context.Context, embed *embed.Embed, msg string, args ...interface{}) error

ReplyEmbed sends a Rich Embed and optionally a message to the parent channel.

func (*ChatContext) ReplyWithEmoji

func (c *ChatContext) ReplyWithEmoji(ctx context.Context, emojiName string, msg string, args ...interface{}) error

ReplyWithEmoji sends a message as if it were being said by the given emoji (if it exists) to the parent channel.

func (*ChatContext) Username

func (c *ChatContext) Username(discrim bool) string

Username returns the Bot's Discord username, optionally suffixing it with its discriminator.

type Options

type Options struct {
	Token        string
	Prefixes     []string
	ActivityFile string
	OwnerIDs     []string
	BotGuild     string

	HarmonyOptions []harmony.ClientOption

	Logger *zap.Logger
	DB     *sql.DB
}

Options are used to configure a Bot.

Jump to

Keyboard shortcuts

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