bot

package
v0.0.0-...-6504193 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentTooLong

func ContentTooLong(content string) bool

ContentTooLong checks whether the given message content is longer than the acceptable limit.

func EmbedDescriptionTooLong

func EmbedDescriptionTooLong(embed *disgord.Embed) bool

EmbedDescriptionTooLong checks whether the given embed has description longer than the acceptable limit.

func MsgQueryBuilder

func MsgQueryBuilder(s disgord.Session, msg *disgord.Message) disgord.MessageQueryBuilder

MsgQueryBuilder returns a message query builder for the given message.

func SendPaginated

func SendPaginated(
	ctx context.Context,
	params *WidgetParams,
	session disgord.Session,
	channelID disgord.Snowflake,
) error

SendPaginated sends a paginated message.

func SuppressEmbeds

func SuppressEmbeds(session disgord.Session, msg *disgord.Message) (*disgord.Message, error)

SuppressEmbeds suppresses all embeds on the given message.

func UnsuppressEmbeds

func UnsuppressEmbeds(session disgord.Session, msg *disgord.Message) (*disgord.Message, error)

UnsuppressEmbeds unsuppresses all embeds on the given message.

Types

type AllowPredicateType

type AllowPredicateType func(*disgord.MessageReactionAdd) bool

AllowPredicateType is the predicate type that returns whether the operation on react is allowed.

type Bot

type Bot struct {
	Client *disgord.Client
	Info   Info
	// contains filtered or unexported fields
}

Bot is a simple wrapper over a disgord Client. It is not protected by a mutex.

func New

func New(info Info) *Bot

New creates a new bot with the given BotInfo.

func (*Bot) AddCommand

func (bot *Bot) AddCommand(command *Command)

AddCommand adds a Command to the bot.

func (*Bot) OnMessageCreate

func (bot *Bot) OnMessageCreate(handler func(*Context, *disgord.MessageCreate))

OnMessageCreate attaches a handler that is called on the message create event.

type Command

type Command struct {
	ID          string
	Usage       string
	Description string
	Handler     func(*Context)
}

Command represents a bot command.

func (*Command) FullUsage

func (com *Command) FullUsage() string

FullUsage returns the "ID Usage" form of the command.

func (*Command) IncorrectUsageMsg

func (com *Command) IncorrectUsageMsg() string

IncorrectUsageMsg returns a message that may be sent if the command is invoked with incorrect arguments.

type Context

type Context struct {
	Bot     *Bot
	Session disgord.Session
	Message *disgord.Message
	Command *Command
	Args    []string
	Logger  disgord.Logger
}

Context is passed to all command handlers and contains fields relevant to the current command invocation.

func (*Context) DeleteMsg

func (ctx *Context) DeleteMsg(msg *disgord.Message) error

DeleteMsg deletes the given message.

func (*Context) EditMsg

func (ctx *Context) EditMsg(msg *disgord.Message, content string) (*disgord.Message, error)

EditMsg edits a message to set the given string as content.

func (*Context) MakeErrorEmbed

func (ctx *Context) MakeErrorEmbed(msg string) *disgord.Embed

MakeErrorEmbed prepares an error embed with the bot's support URL if it exists.

func (*Context) React

func (ctx *Context) React(msg *disgord.Message, emoji interface{}) error

React reacts on the given message with the given emoji.

func (*Context) Send

func (ctx *Context) Send(data ...interface{}) (*disgord.Message, error)

Send sends a message in the current channel.

func (*Context) SendIncorrectUsageMsg

func (ctx *Context) SendIncorrectUsageMsg() (*disgord.Message, error)

SendIncorrectUsageMsg sends the incorrect usage message for the current command.

func (*Context) SendTimed

func (ctx *Context) SendTimed(
	deleteAfter time.Duration,
	data ...interface{},
) (*disgord.Message, error)

SendTimed sends a message and deletes it after a delay. Ignores any error if the delete fails.

func (*Context) SendWidget

func (ctx *Context) SendWidget(params *WidgetParams) error

SendPaginated sends a paginated widget in the current channel.

type DelCallbackType

type DelCallbackType func(*disgord.MessageReactionAdd)

DelCallbackType is the callback function type invoked on delete.

type Info

type Info struct {
	disgord.Config
	Name        string
	Prefix      string
	Description string
	SupportURL  string
}

Info wraps some bot info.

type Message

type Message struct {
	Content string
	Embed   *disgord.Embed
}

Message is a single Discord message.

type Messager

type Messager interface {
	Send(ctx context.Context, channelID disgord.Snowflake, params *disgord.CreateMessageParams) (*disgord.Message, error)
	Edit(ctx context.Context, msg *disgord.Message, content string, embed *disgord.Embed) (*disgord.Message, error)
	React(ctx context.Context, msg *disgord.Message, reaction string) error
	Unreact(ctx context.Context, msg *disgord.Message, reaction string) error
	UnreactUser(ctx context.Context, msg *disgord.Message, reaction string, userID disgord.Snowflake) error
	Delete(ctx context.Context, msg *disgord.Message) error
	AddReactListener(filter disgord.Middleware, ctrl disgord.HandlerCtrl, handler disgord.HandlerMessageReactionAdd)
}

Messager wraps a disgord.Session to do message stuff. Used by widgets. Disgord's fluent interface is nice to use but such a pain to mock. Maybe switch to discordgo.

type MsgCallbackType

type MsgCallbackType func(*disgord.Message)

MsgCallbackType is the callback function type invoked on message create.

type Page

type Page struct {
	// The message for this page.
	Default *Message

	// The expanded message for this page, optional.
	Expanded *Message
}

Page is a single widget page.

func NewPage

func NewPage(content string, embed *disgord.Embed) *Page

NewPage returns a Page with a default message and no expanded message.

func NewPageWithExpansion

func NewPageWithExpansion(
	content string,
	embed *disgord.Embed,
	expandedContent string,
	expandedEmbed *disgord.Embed,
) *Page

NewPageWithExpansion returns a Page with a default message and an expanded message.

type Pages

type Pages struct {
	Get   func(pageNum int) *Page
	Total int
	First int
	Files []disgord.CreateMessageFileParams
}

Pages is a set of pages, numbered 1 to Total. First is shown first.

type WidgetParams

type WidgetParams struct {
	Pages *Pages

	// Optional callback invoked when the message is created.
	MsgCallback MsgCallbackType

	// After this duration the message will not be monitored.
	Lifetime time.Duration

	// Optional callback to be invoked when the message is deleted.
	DelCallback DelCallbackType

	// Optional check called before performing any operation (delete, prev, next). Defaults to
	// always allowed.
	AllowOp AllowPredicateType
}

WidgetParams aggregates the params required for a paginated widget.

Directories

Path Synopsis
Package mock_bot is a generated GoMock package.
Package mock_bot is a generated GoMock package.

Jump to

Keyboard shortcuts

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