Documentation
¶
Overview ¶
Package sugo is a discord bot framework written in go.
Index ¶
- Constants
- type Command
- type Instance
- func (sg *Instance) AddCommand(c *Command)
- func (sg *Instance) AddRequestMiddleware(m RequestMiddleware)
- func (sg *Instance) AddResponseMiddleware(m ResponseMiddleware)
- func (sg *Instance) AddShutdownHandler(handler shutdownHandler)
- func (sg *Instance) AddStartupHandler(handler startupHandler)
- func (sg *Instance) FindCommand(req *Request, q string) (*Command, error)
- func (sg *Instance) HandleError(req *Request, err error)
- func (sg *Instance) Shutdown()
- func (sg *Instance) Startup(token string) (err error)
- type Request
- func (req *Request) AddReaction(reaction emoji) (err error)
- func (req *Request) GetGuild() (*discordgo.Guild, error)
- func (req *Request) IsChannelDM() bool
- func (req *Request) IsChannelDefault() bool
- func (req *Request) NewResponse(respType responseType, title string, text string) (resp *Response)
- func (req *Request) PlainTextResponse(text string) (resp *Response)
- func (req *Request) SimpleResponse(text string) (resp *Response)
- type RequestMiddleware
- type Response
- type ResponseMiddleware
Constants ¶
const ( ResponsePlainText responseType = "plain_text" ResponseDefault responseType = "default" ResponseInfo responseType = "info" ResponseSuccess responseType = "success" ResponseWarning responseType = "warning" ResponseDanger responseType = "danger" )
const ColorDanger = 0xd9534f
ColorDanger is red-ish.
const ColorDefault = 0x636c72
ColorDefault is gray-ish.
const ColorInfo = 0x5bc0de
ColorInfo is light-blue-ish.
const ColorPrimary = 0x0275d8
ColorPrimary is dark-blue-ish.
const ColorSuccess = 0x5cb85c
ColorSuccess is green-ish.
const ColorWarning = 0xf0ad4e
ColorWarning is yellow-ish.
const (
ReactionOk emoji = "👌"
)
const VERSION = "0.6.2"
VERSION contains current version of the Instance framework.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct { // Trigger is a sequence of symbols message should start with to match with the command. Trigger string // Description should contain short command description. Description string // HasParams specifies if command can have additional parameters in Request string. HasParams bool // PermissionsRequired specifies permissions set required by the command. PermissionsRequired int // RequireGuild specifies if this command works in guild chats only. RequireGuild bool // Execute method is executed if Request string matches the given command. Execute func(req *Request) (*Response, error) // SubCommands contains all subcommands of the given command. SubCommands []*Command // contains filtered or unexported fields }
Command struct describes basic command type.
type Instance ¶
type Instance struct { // Trigger specifies what should message start with for the bot to consider it to be command. DefaultTrigger string // HelpTrigger specifies what should message start with for the bot to consider it to be help command. HelpTrigger string // Session is a *discordgo.Session bot is wrapped around. Session *discordgo.Session // Self contains a giscordgo.User instance of the bot. Self *discordgo.User // RootCommand is a bot root meta-command. RootCommand *Command // IsTriggered should return true if the bot is to react to command and false otherwise. IsTriggered func(req *Request) (triggered bool) // ErrorHandler is the function that receives and handles all the errors. Keep in mind that *Request can be nil // if error handler is called outside of command request scope. ErrorHandler func(req *Request, err error) // contains filtered or unexported fields }
Instance struct describes bot.
func (*Instance) AddCommand ¶
AddCommand adds command to the bot's commands list.
func (*Instance) AddRequestMiddleware ¶
func (sg *Instance) AddRequestMiddleware(m RequestMiddleware)
AddRequestMiddleware adds request middleware.
func (*Instance) AddResponseMiddleware ¶
func (sg *Instance) AddResponseMiddleware(m ResponseMiddleware)
AddResponseMiddleware adds response middleware.
func (*Instance) AddShutdownHandler ¶
func (sg *Instance) AddShutdownHandler(handler shutdownHandler)
AddShutdownHandler adds function that will be called on bot shutdown.
func (*Instance) AddStartupHandler ¶
func (sg *Instance) AddStartupHandler(handler startupHandler)
AddStartupHandler adds function that will be called on bot startup.
func (*Instance) FindCommand ¶
FindCommand searches for the command in the modules registered.
func (*Instance) HandleError ¶
HandleError handles unexpected errors that were returned unhandled elsewhere.
type Request ¶
type Request struct { Ctx context.Context Sugo *Instance Message *discordgo.Message Channel *discordgo.Channel Command *Command Query string }
Request contains message context data along with some helpers to retrieve more information.
func (*Request) AddReaction ¶
ReactOk adds "ok" emoji to the command message.
func (*Request) GetGuild ¶
GetGuild allows to retrieve *discordgo.Guild from Request. Will not work and will throw error for channels that have no guild such as DirectMessages or GroupDirectMessages channels, so you probably want to check those beforehand.
func (*Request) IsChannelDM ¶
IsChannelDM returns true if channel is DirectMessages (or GroupDirectMessages) channel and false otherwise.
func (*Request) IsChannelDefault ¶
IsChannelDefault returns true if channel is Guild's default channel and false otherwise.
func (*Request) NewResponse ¶
Respond responds (via DM if viaDM is set to true) with the Text or Embed provided. If both provided - only Text is responded with.
func (*Request) PlainTextResponse ¶
PlainTextResponse creates a raw text response.
func (*Request) SimpleResponse ¶
SimpleResponse creates a default embed response.
type RequestMiddleware ¶
type Response ¶
type Response struct { Type responseType Request *Request Text string Embed *discordgo.MessageEmbed Emoji discordgo.Emoji }