discord

package
v0.0.0-...-05eea06 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package discord implements a Discord bot that can join and run in guilds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arg

type Arg func(o *discordArgs)

Arg is an argument for constructing a Discord bot.

func WithBettorClient

func WithBettorClient(c bettorv1alphaconnect.BettorServiceClient) Arg

WithBettorClient provides a Bettor client to the Discord bot.

func WithCleanUp

func WithCleanUp() Arg

WithCleanUp configured Discord bot to clean up registered commands on shutdown.

func WithLogger

func WithLogger(logger log.Logger) Arg

WithLogger provides a logger to the Discord bot.

func WithToken

func WithToken(token string) Arg

WithToken provides a Discord token to the Discord bot.

type Bot

type Bot struct {
	Ctx     context.Context
	D       *discordgo.Session
	Client  bettorClient
	Logger  log.Logger
	CleanUp bool

	Commands map[string]*DGCommand

	// keep track of all guilds we have joined so we can clean up commands on termination.
	GuildIDs []string
	// contains filtered or unexported fields
}

Bot is a Discord Bot for Bettor. Only one instance can be running.

func New

func New(ctx context.Context, args ...Arg) (*Bot, error)

New initializes a new Bot.

func (*Bot) Run

func (b *Bot) Run() error

Run starts the bot. This blocks until the bot is terminated.

type Command

type Command struct {
	Def     *discordgo.ApplicationCommand
	Handler Handler
}

Command is a helper struct for an discordgo ApplicationCommand and its handler function. This contains a internal Handler type which is nice for generic instrumentation and error handling.

type CommandError

type CommandError struct {
	UserMsg string // user-facing error message. will be sent back as feedback via Discord interaction response
	Err     error  // wrapped error. internal
}

CommandError represents an error handling a Discord command.

func CErr

func CErr(userMsg string, err error) *CommandError

CErr returns a CommandError.

func (*CommandError) Error

func (e *CommandError) Error() string

Error returns error string for CommandError.

func (*CommandError) Unwrap

func (e *CommandError) Unwrap() error

Unwrap unwraps a CommandError.

type DGCommand

type DGCommand struct {
	Def     *discordgo.ApplicationCommand
	Handler func(*discordgo.Session, *discordgo.InteractionCreate)
}

DGCommand is a helper struct for an discordgo ApplicationCommand and its handler function. This contains types ready to be used with a discordgo.Session.

type Handler

Handler is an InteractionCreate handler. It returns a InteractionResponseData which will serve as our universal interface for generic handling.

func CancelBet

func CancelBet(ctx context.Context, client bettorClient) Handler

CancelBet is the handler for the /cancel-bet command.

func GetBet

func GetBet(ctx context.Context, client bettorClient) Handler

GetBet is the handler for the /get-bet command.

func GetBettor

func GetBettor(ctx context.Context, client bettorClient) Handler

GetBettor is the handler for the /bettor command.

func GetBettors

func GetBettors(ctx context.Context, client bettorClient) Handler

GetBettors is the handler for the /get-bet command.

func JoinBet

func JoinBet(ctx context.Context, client bettorClient) Handler

JoinBet is the handler for the /join-bet command.

func LockBet

func LockBet(ctx context.Context, client bettorClient) Handler

LockBet is the handler for the /lock-bet command.

func SettleBet

func SettleBet(ctx context.Context, client bettorClient) Handler

SettleBet is the handler for the /settle-bet command.

func StartBet

func StartBet(ctx context.Context, client bettorClient) Handler

StartBet is the handler for the /start-bet command.

Jump to

Keyboard shortcuts

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