discord

package
v0.0.0-...-a93ac6b Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatParamString

func FormatParamString(pr string) string

FormatParamString removes certain characters like "" from the param response string.

func ParseParams

func ParseParams(content string) []string

ParseParams gets a slice of arguments in a string.

Goes through each rune and determines what to do with it.
If the rune is in Quotes "something something", it will return the whole string in quotes.

Types

type Bot

type Bot struct {
	Session    *dgo.Session
	Prefix     string
	CmdHandler *CommandHandler

	MessageCreate chan *dgo.MessageCreate
	// contains filtered or unexported fields
}

Bot is a discord bot, yo!

func NewBot

func NewBot(token string, prefix string) *Bot

NewBot creates a new bot!

func (*Bot) Connect

func (b *Bot) Connect()

Connect opens the connection to the discord gateway.

func (*Bot) Disconnect

func (b *Bot) Disconnect()

Disconnect disconnects, yo!

type Command

type Command struct {
	Signature   string
	Description string
	Prefix      string
	Aliases     []string
	Parameters  []*CommandParameter
	Handler     newCommandHandlerFunc
}

Command : this is a command...

func NewCommand

func NewCommand(sig string, desc string, handler newCommandHandlerFunc) *Command

NewCommand creates a new command and returns it!

func (*Command) AddParam

func (c *Command) AddParam(param *CommandParameter)

AddParam adds a param to a command.

func (*Command) AddParameter

func (c *Command) AddParameter(name string, description string, required bool)

AddParameter adds a new parameter to the command. Parameters should be added in order.

func (*Command) GetParam

func (c *Command) GetParam(content string, name string) (pr string, err error)

GetParam : parses the params and gets the correct value for the param with the name given. TODO: change this so it can be used like:

p := c.GetParam(content, "paramName")
if !p {
	did not find the param.
}

func (*Command) GetRequiredParam

func (c *Command) GetRequiredParam(content string, name string) (pr string, err error)

GetRequiredParam TODO actually not really sure where I was going with this. Something about sending a response back to the user..

func (*Command) HelpString

func (c *Command) HelpString() string

HelpString returns a string of how this Command is used.

func (*Command) HelpUsage

func (c *Command) HelpUsage() string

func (*Command) SignatureWithPrefix

func (c *Command) SignatureWithPrefix() string

SignatureWithPrefix returns a concatenated string with prefix and signature

type CommandHandler

type CommandHandler struct {
	Commands      []*Command
	Prefix        string
	Triggers      []*Trigger
	Conversations []*Conversation
}

CommandHandler : Holds a list of commands and specifies the Bot prefix. TODO: use maps for some stuff...

func NewCommandHandler

func NewCommandHandler(Prefix string) *CommandHandler

NewCommandHandler creates a new CommandHandler with Prefix and sets up the default commands.

default commands: help

TODO: Move this away from here!

func (*CommandHandler) AddCommand

func (ch *CommandHandler) AddCommand(cmd *Command)

AddCommand adds a command to the command handler.

func (*CommandHandler) AddMessageTrigger

func (ch *CommandHandler) AddMessageTrigger(s string, r string)

AddMessageTrigger adds a new Trigger to the Triggers slice on CommandHandler

func (*CommandHandler) FindCommand

func (ch *CommandHandler) FindCommand(content string, withPrefix bool) (c *Command, err error)

FindCommand finds a command (if it exists) within the commandHandler.

func (*CommandHandler) MaybeHandleCodeBlock

func (ch *CommandHandler) MaybeHandleCodeBlock(s *dgo.Session, m *dgo.MessageCreate) (res string, err error)

MaybeHandleCodeBlock takes a string and figures out if it's in a codeblock format. TODO: figure out what language is being passed in. ```js <- js should be the language. TODO: Have a separate Handler for each language that is supported. TODO: Can an API be generalized for creating Maybe handlers? TODO: Create a handler for a specific language. Do something!!!!

func (*CommandHandler) MaybeHandleMessageTrigger

func (ch *CommandHandler) MaybeHandleMessageTrigger(s *dgo.Session, m *dgo.MessageCreate) (r string, err error)

MaybeHandleMessageTrigger looks for a pattern in any message and responds

type CommandParameter

type CommandParameter struct {
	Name        string
	Description string
	Position    int
	Required    bool
}

CommandParameter : Specifies the name, position and what this parameter does.

type Conversation

type Conversation struct {
	UserID string
}

Conversation between the bot and a user..

type MessageContext

type MessageContext struct {
	Session *dgo.Session
	Bot     *Bot
	Message *dgo.MessageCreate
	Command *Command
}

MessageContext is usually just for when Command handlers are being run, but this could be used for different things.

func (*MessageContext) GetVal

func (c *MessageContext) GetVal() (b *Bot, m *dgo.MessageCreate, cmd *Command, s *dgo.Session)

GetVal gets the values from MessageContext... this makes it easier to extract the info when all are needed.

type Trigger

type Trigger struct {
	Pattern  string
	Response string
}

Trigger takes a pattern and returns a response

Jump to

Keyboard shortcuts

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