Bot

package
v0.0.0-...-06d5ffc Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmbedLimitTitle       = 256
	EmbedLimitDescription = 2048
	EmbedLimitFieldValue  = 1024
	EmbedLimitFieldName   = 256
	EmbedLimitField       = 25
	EmbedLimitFooter      = 2048
	EmbedLimit            = 4000
)

Constants for message embed character limits

Variables

View Source
var (
	ServerCollection *mongo.Collection
	RSSCollection    *mongo.Collection
	UserCollection   *mongo.Collection
	Log              *logging.Logger
)

Functions

This section is empty.

Types

type AniListUserData

type AniListUserData struct {
	UserId      int       `bson:"aniuserid"`
	LastUpdated time.Time `bson:"lastupdated"`
}

type Bot

type Bot struct {
	ConfigPath string
	BotID      string
	Config     Config
	Modules    []Module
	Server     Server
	Session    *discordgo.Session
}

func New

func New(l *logging.Logger) (b *Bot)

func (*Bot) CanExecute

func (b *Bot) CanExecute(cmd Command, s *discordgo.Session, m *discordgo.MessageCreate, data *ServerData) bool

func (*Bot) CommandAllowed

func (b *Bot) CommandAllowed(c Command, cmdName string) bool

func (*Bot) FindLastMessageWithAttachOrEmbed

func (b *Bot) FindLastMessageWithAttachOrEmbed(s *discordgo.Session, m *discordgo.MessageCreate, amount int) (result string, e error)

func (*Bot) GetAccountCreationDate

func (b *Bot) GetAccountCreationDate(user *discordgo.User) (timestamp int64)

// discordgo.User helpers ////

func (*Bot) GetCommandTarget

func (b *Bot) GetCommandTarget(s *discordgo.Session, m *discordgo.MessageCreate, data *ServerData, targetName string) (target *discordgo.User)

func (*Bot) GetRoleByName

func (b *Bot) GetRoleByName(name string, roles []*discordgo.Role) (r discordgo.Role, e error)

func (*Bot) GetRolePermissions

func (b *Bot) GetRolePermissions(id string, perms []*discordgo.PermissionOverwrite) (p discordgo.PermissionOverwrite, e error)

Gets the permission override object from a role id.

func (*Bot) GetRolePermissionsByName

func (b *Bot) GetRolePermissionsByName(ch *discordgo.Channel, sv *discordgo.Guild, name string) (p discordgo.PermissionOverwrite, e error)

func (*Bot) InitBot

func (b *Bot) InitBot(m []Module, site Server, configPath string)

func (*Bot) IsBlocked

func (b *Bot) IsBlocked(cmd string, data *ServerData) (isBlocked bool)

func (*Bot) ParseMention

func (b *Bot) ParseMention(tag string) (res string, err error)

func (*Bot) ServerDataFromChannel

func (b *Bot) ServerDataFromChannel(s *discordgo.Session, channelID string) *ServerData

func (*Bot) ServerDataFromID

func (b *Bot) ServerDataFromID(guildID string) *ServerData

func (*Bot) Usage

func (b *Bot) Usage(cmd Command, s *discordgo.Session, m *discordgo.MessageCreate, data *ServerData) *Embed

type ChannelData

type ChannelData struct {
	ID     string   `json:"id" bson:"id"`
	Albums []string `json:"albums" bson:"albums"`
}

ChannelData is the data which is saved for every channel

type Command

type Command interface {
	Name() string
	Description() string
	Usage() string
	Permission() int
	Aliases() []string
}

type CommandData

type CommandData struct {
	Name    string `json:"name" bson:"name"`
	Content string `json:"content" bson:"content"`
}

CommandData is the data which is saved for every command

type Config

type Config struct {
	BotToken      string `json:"bottoken"`
	OsuToken      string `json:"osutoken"`
	ImgurToken    string `json:"imgurtoken"`
	SauceNaoToken string `json:"saucenaotoken"`
	DataLocation  string `json:"datalocation"`
	WebsiteUrl    string `json:"websiteurl"`
	OwmToken      string `json:"openweathermaptoken"`
	Mongo         string `json:"mongo"`
	Database      string `json:"database"`
}

The Config of the bot

type Embed

type Embed struct {
	*discordgo.MessageEmbed
}

func NewEmbed

func NewEmbed() *Embed

NewEmbed returns a new embed object

func (*Embed) AddField

func (e *Embed) AddField(name, value string) *Embed

AddField [name] [value]

func (*Embed) AddInlineField

func (e *Embed) AddInlineField(name, value string, inline bool) *Embed

AddField [name] [value]

func (*Embed) InlineAllFields

func (e *Embed) InlineAllFields() *Embed

InlineAllFields sets all fields in the embed to be inline

func (*Embed) SetAuthor

func (e *Embed) SetAuthor(args ...string) *Embed

SetAuthor ...

func (*Embed) SetAuthorFromUser

func (e *Embed) SetAuthorFromUser(author *discordgo.User) *Embed

func (*Embed) SetColor

func (e *Embed) SetColor(clr int) *Embed

func (*Embed) SetColorFromUser

func (e *Embed) SetColorFromUser(s *discordgo.Session, channelID string, author *discordgo.User) *Embed

SetColor ...

func (*Embed) SetDescription

func (e *Embed) SetDescription(description string) *Embed

SetDescription [desc]

func (*Embed) SetFooter

func (e *Embed) SetFooter(args ...string) *Embed

SetFooter [Text] [iconURL]

func (*Embed) SetImage

func (e *Embed) SetImage(args ...string) *Embed

SetImage ...

func (*Embed) SetThumbnail

func (e *Embed) SetThumbnail(args ...string) *Embed

SetThumbnail ...

func (*Embed) SetTitle

func (e *Embed) SetTitle(name string) *Embed

SetTitle ...

func (*Embed) SetURL

func (e *Embed) SetURL(URL string) *Embed

SetURL ...

func (*Embed) Truncate

func (e *Embed) Truncate() *Embed

Truncate truncates any embed value over the character limit.

func (*Embed) TruncateDescription

func (e *Embed) TruncateDescription() *Embed

TruncateDescription ...

func (*Embed) TruncateFields

func (e *Embed) TruncateFields() *Embed

TruncateFields truncates fields that are too long

func (*Embed) TruncateFooter

func (e *Embed) TruncateFooter() *Embed

TruncateFooter ...

func (*Embed) TruncateTitle

func (e *Embed) TruncateTitle() *Embed

TruncateTitle ...

type MeIrlData

type MeIrlData struct {
	UserID   string `json:"id" bson:"id"`
	Nickname string `json:"nickname" bson:"nickname"`
	Content  string `json:"content" bson:"content"`
}

MeIrlData is the data which is saved for every meIrlCommand

type Module

type Module interface {
	Execute(*discordgo.Session, *discordgo.MessageCreate, *ServerData)
	HelpFields() (title string, content string)
	CommandInfo(name string, data *ServerData) (response *Embed, found bool)
}

type Server

type Server interface {
	Start()
	GetUrlFromID(guildID string) string
}

type ServerData

type ServerData struct {
	ID              string                  `json:"id" bson:"id"`
	Commanders      map[string]bool         `json:"commanders" bson:"commanders"`
	Channels        map[string]*ChannelData `json:"channels" bson:"channels"`
	CustomCommands  map[string]*CommandData `json:"commands" bson:"commands"`
	BlockedCommands map[string]bool         `json:"blockedcommands" bson:"blockedcommands"`
	MeIrlData       map[string]*MeIrlData   `json:"me_irl" bson:"me_irl"`
	Key             string                  `json:"Key" bson:"Key"`
}

ServerData is the data which is saved for every server the bot is in.

func (*ServerData) CreateCustomCommand

func (data *ServerData) CreateCustomCommand(commandName, content string) (err error)

func (*ServerData) CreateMeIrl

func (data *ServerData) CreateMeIrl(meIrl MeIrlData) (err error)

func (*ServerData) DeleteCustomCommand

func (data *ServerData) DeleteCustomCommand(commandName string) (deleted bool, err error)

func (*ServerData) DeleteMeIrl

func (data *ServerData) DeleteMeIrl(target string) (deleted bool, err error)

func (*ServerData) EditKey

func (data *ServerData) EditKey(key string) (err error)

func (*ServerData) UpdateBlockedCommand

func (data *ServerData) UpdateBlockedCommand(commandName string, isBlocked bool) (err error)

func (*ServerData) UpdateCommander

func (data *ServerData) UpdateCommander(userId string, isCommander bool) (err error)

func (*ServerData) WriteToDB

func (data *ServerData) WriteToDB() (err error)

type UserData

type UserData struct {
	UserId      string          `bson:"userid"`
	AniListData AniListUserData `bson:"anilistdata"`
}

func UserDataFromID

func UserDataFromID(userID string) *UserData

func UserDataFromMessage

func UserDataFromMessage(m *discordgo.MessageCreate) (userData *UserData)

func (*UserData) WriteToDB

func (data *UserData) WriteToDB() (err error)

Jump to

Keyboard shortcuts

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