dbot

package module
v2.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RegexChannelMention matches strings that are channel mentions
	RegexChannelMention = regexp.MustCompile("<#(\\d+)>")

	// RegexUserMention matches strings that are user mentions
	RegexUserMention = regexp.MustCompile("<@!?(\\d+)>")

	// RegexRoleMention matches strings that are role mentions
	RegexRoleMention = regexp.MustCompile("<@&(\\d+)>")
)

Functions

func FormatBotToken

func FormatBotToken(t string) string

FormatBotToken ensures that a bot token begins with "Bot", as required by the Discord API

Types

type Argument

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

func (*Argument) Channel

func (arg *Argument) Channel(session *dgo.Session) (*dgo.Channel, error)

Channel parses the argument and returns a pointer to a channel struct, if the argument is of the correct type

func (*Argument) ChannelID

func (arg *Argument) ChannelID() (string, error)

ChannelID returns the argument as a channel ID, if the argument is of the correct type

func (*Argument) Float

func (arg *Argument) Float() (float64, error)

Float returns the argument as a float64, if the argument is of the correct type

func (*Argument) Int

func (arg *Argument) Int() (int, error)

Int returns the argument as an int, if the argument is of the correct type

func (*Argument) Member

func (arg *Argument) Member(session *dgo.Session, guildID string) (*dgo.Member, error)

Member parses the argument and returns a pointer to a Member struct, if the argument is of the correct type

func (*Argument) Role

func (arg *Argument) Role(session *dgo.Session, guildID string) (*dgo.Role, error)

Role parses the argument and returns a pointer to a Role struct, if the argument is of the correct type

func (*Argument) RoleID

func (arg *Argument) RoleID() (string, error)

RoleID returns the argument as a role ID, if the argument is of the correct type

func (*Argument) String

func (arg *Argument) String() string

String returns the argument as a string

func (*Argument) Type

func (arg *Argument) Type() ArgumentType

Type returns the type of the argument

func (*Argument) User

func (arg *Argument) User(session *dgo.Session) (*dgo.User, error)

User parses the argument and returns a pointer to a User struct, if the argument is of the correct type

func (*Argument) UserID

func (arg *Argument) UserID() (string, error)

UserID returns the argument as a user ID, if the argument is of the correct type

type ArgumentType

type ArgumentType string
const (
	ArgumentTypeString          ArgumentType = "string"
	ArgumentTypeInt             ArgumentType = "int"
	ArgumentTypeFloat           ArgumentType = "float"
	ArgumentTypeURL             ArgumentType = "url"
	ArgumentTypeChannelMention  ArgumentType = "channelMention"
	ArgumentTypeEveryoneMention ArgumentType = "everyoneMention"
	ArgumentTypeUserMention     ArgumentType = "userMention"
	ArgumentTypeRoleMention     ArgumentType = "roleMention"
)

type Arguments

type Arguments struct {
	Arguments []*Argument
	// contains filtered or unexported fields
}

func ParseArguments

func ParseArguments(s string) *Arguments

ParseArguments parses a prefix-less string into a set of arguments

type Bot

type Bot struct {
	Name        string `json:"name"`
	Version     string `json:"version"`
	Description string `json:"description"`

	Config *BotConfig `json:"config"`
	// contains filtered or unexported fields
}

Bot represents a collection of commands

func New

func New(options Options) (*Bot, error)

New creates a new Bot from the provided options and returns a pointer to it

func (*Bot) AddCommands

func (bot *Bot) AddCommands(commands ...*Command) error

func (*Bot) DefaultGuildConfig

func (bot *Bot) DefaultGuildConfig(guildID string) *GuildConfig

func (*Bot) DefaultUserConfig

func (bot *Bot) DefaultUserConfig(userID string) *UserConfig

func (*Bot) GetGuildConfig

func (bot *Bot) GetGuildConfig(guildID string) *GuildConfig

func (*Bot) GetUserConfig

func (bot *Bot) GetUserConfig(userID string) *UserConfig

func (*Bot) MessageCreateHandler

func (bot *Bot) MessageCreateHandler() func(*dgo.Session, *dgo.MessageCreate)

func (*Bot) Run

func (bot *Bot) Run() error

type BotConfig

type BotConfig struct {
	DefaultPrefix string `json:"default_prefix"`

	Guilds map[string]*GuildConfig `json:"guilds"`
	Users  map[string]*UserConfig  `json:"users"`

	IgnoreDMs      bool `json:"ignore_dms"`
	IgnoreMentions bool `json:"ignore_mentions"`
	IgnoreCase     bool `json:"ignore_prefix_case"`
}

type Command

type Command struct {
	*Config

	Name        string   `json:"name"`
	Description string   `json:"description"`
	Alias       []string `json:"alias"`
	Examples    []string `json:"usage"`
	Tags        []string `json:"tags"`

	Func func(*MessageEventContext) error
}

type Config

type Config struct {
	*VarFolder
}

Config is a generic config struct which contains vars

type GuildConfig

type GuildConfig struct {
	*Config

	GuildID  string   `json:"guild_id"`
	Prefixes []string `json:"prefixes"`
	Tags     []string `json:"tags"`
}

type MessageEventContext

type MessageEventContext struct {
	Arguments   *Arguments
	Command     *Command
	GuildConfig *GuildConfig
	UserConfig  *UserConfig

	Message *dgo.Message
	Session *dgo.Session
	Router  *Router
}

func (*MessageEventContext) RespondEmbed

func (ctx *MessageEventContext) RespondEmbed(args ...interface{}) (*dgo.Message, error)

type Options

type Options struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Version     string `json:"version"`

	Token         string `json:"token"`
	DefaultPrefix string `json:"default_prefix"`

	Guilds map[string]*GuildConfig `json:"guilds"`
	Users  map[string]*UserConfig  `json:"users"`

	IgnoreDMs      bool `json:"ignore_dms"`
	IgnoreMentions bool `json:"ignore_mentions"`
	IgnoreCase     bool `json:"ignore_prefix_case"`
}

Options provides a set of options for initialising Discord bots

type Router

type Router struct {
	Commands []*Command
	Storage  map[string]*Storage
}

func (*Router) AddCommand

func (router *Router) AddCommand(command *Command) error

func (*Router) GetCommand

func (router *Router) GetCommand(name string, ignoreCase bool) *Command

type Storage

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

func (*Storage) Delete

func (storage *Storage) Delete(key string)

func (*Storage) Get

func (storage *Storage) Get(key string) (interface{}, bool)

func (*Storage) Load

func (storage *Storage) Load(path string) error

func (*Storage) Save

func (storage *Storage) Save(path string) error

func (*Storage) Set

func (storage *Storage) Set(key string, i interface{})

type UserConfig

type UserConfig struct {
	*Config

	UserID string `json:"user_id"`
	Admin  bool   `json:"admin"`
	Ignore bool   `json:"ignored"`

	Tags []string `json:"tags"`
}

type Var

type Var struct {
	*VarFolder

	Key   string      `json:"key"`
	Value interface{} `json:"value"`
	// contains filtered or unexported fields
}

Var implements a basic key-value structure that can also contain other Vars

type VarFolder

type VarFolder struct {
	Vars []*Var `json:"vars"`
}

func (*VarFolder) Find

func (vf *VarFolder) Find(key string) (*Var, bool)

Find searches the current folder for a var and returns it. If the var was not found, false is returned. Otherwise, true is returned.

func (*VarFolder) Set

func (vf *VarFolder) Set(key string, value interface{}) (*Var, bool)

Set a var in the current folder and return a pointer to it. If a new var was created, true is also returned. Otherwise, false is returned.

Jump to

Keyboard shortcuts

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