Documentation ¶
Index ¶
- Variables
- func CreateViperConfig(path, name, configType, serverName string) (*viper.Viper, error)
- func GetConfigDirectory() (string, error)
- func Itob(i int) bool
- func LoadBot(bot *Bot) error
- type BadWord
- type Bot
- func (bot *Bot) AddCommand(item Item) error
- func (bot *Bot) AddPermittedUser(username string)
- func (bot *Bot) AddQuote(quote string, submitter string) error
- func (bot *Bot) AddTimer(item Item) error
- func (bot *Bot) Connect() error
- func (bot *Bot) ConvertPermToInt(perm string) (uint8, error)
- func (bot *Bot) DeletePermittedUser(username string) bool
- func (bot *Bot) DeleteQuote(quoteID string) error
- func (bot *Bot) DeleteTimer(item Item) error
- func (bot *Bot) DetectURL(message string) bool
- func (bot *Bot) EditCommand(item Item) error
- func (bot *Bot) FindCommand(key string) (bool, CommandValue)
- func (bot *Bot) GetOAuth() string
- func (bot *Bot) GetQuote(index int) (string, error)
- func (bot *Bot) HandlePing(message, pingIndicator, response string, messenger Messenger) (bool, error)
- func (bot *Bot) IncrementCommandCount(command string) error
- func (bot *Bot) LoadBadWords() error
- func (bot *Bot) LoadCommands() error
- func (bot *Bot) LoadQuotes() error
- func (bot *Bot) LoadTimers() error
- func (bot *Bot) ParseForBadWord(msg string) (bool, BadWord)
- func (bot *Bot) RandomQuote() (string, error)
- func (bot *Bot) RemoveCommand(key string) (bool, error)
- func (bot *Bot) RunDefaultCommands(caller Item) (bool, error)
- func (bot *Bot) RunTimers(messenger Messenger)
- func (bot *Bot) SetOAuth(token string)
- func (bot *Bot) WriteToConn(msg string) error
- type BotLoaderFunc
- type CommandValue
- type Database
- type DefaultCommand
- type DefaultFunc
- type FatalError
- type Item
- type Messenger
- type NonFatalError
- type QuoteValues
- type TimedValue
- type User
Constants ¶
This section is empty.
Variables ¶
var SliceEmptyErorr = "the bot's slice of default commands is empty"
Functions ¶
func CreateViperConfig ¶
CreateViperConfig creates a viper object. The path is the directory where the config should reside, and name is the filename.
func GetConfigDirectory ¶
GetConfigDirectory the "default" location to put in pleasantbot's config files, so Runners can use this function if desired.
Types ¶
type Bot ¶
type Bot struct { Name string ChannelName string ServerName string Config *viper.Viper `json:"-"` Authenticated bool Conn net.Conn `json:"-"` Storage *Database PurgeForLinks bool PurgeForLongMsg bool LongMsgAmount int EnableServer bool PostLinkPerm uint8 Perms []string `json:"-"` // holds a list of users that can post a link DefaultCommands []DefaultCommand `json:"-"` Commands map[string]*CommandValue `json:"-"` BadWords []BadWord `json:"-"` Quotes map[int]*QuoteValues `json:"-"` Timers map[string]*TimedValue `json:"-"` PermittedUsers map[string]struct{} // list of users that can post links // contains filtered or unexported fields }
Bot struct contains the necessary data to run an instance of a bot
func CreateBot ¶
func CreateBot(viper *viper.Viper, storage Database, dbInit storage.InitFunc, loader BotLoaderFunc, prepareFunc storage.DatabasePrepareFunc) (*Bot, error)
CreateBot creates an instance of a bot. The function makes no assumptions on what the viper config, Database, and loader funcs for the database and bot data loading should be. It just makes the assumption that these loaders MUST exist, so the caller may pass in custom ones based on the needs of the service (e.g. twitch, youtube, etc.) or it may use the default ones listed in this package.
func (*Bot) AddCommand ¶
AddCommandString takes in a string of the form !addcom !comtitle <command response>
func (*Bot) AddPermittedUser ¶
AddPermittedUser adds a user to the PermittedUsers slice, allowing them to post a link without being purged
func (*Bot) AddTimer ¶
AddTimer takes in an item and parses it to add an associated timer. Will assume enabled by default.
func (*Bot) ConvertPermToInt ¶
ConvertPermToInt takes in a string "all", "moderator" etc and converts it to the associated int.
func (*Bot) DeletePermittedUser ¶
DeletePermittedUser deletes a user from the permittedusers map if they exist in it
func (*Bot) DeleteQuote ¶
func (*Bot) DeleteTimer ¶
DeleteTimer will delete a timer from the map and DB.
func (*Bot) DetectURL ¶
DetectURl uses urlRegex to determine if the passed in message is a URL. The caller than perform whatever action is desired with this information
func (*Bot) EditCommand ¶
func (*Bot) FindCommand ¶
func (bot *Bot) FindCommand(key string) (bool, CommandValue)
FindCommand takes in a key (command name) and returns matching command, if found
func (*Bot) GetQuote ¶
GetQuote returns a quote of a specified index / id. Correlates to the automatically generated ID in sqlite.
func (*Bot) HandlePing ¶
func (bot *Bot) HandlePing(message, pingIndicator, response string, messenger Messenger) (bool, error)
HandlePing will send a PONG as a response to a PING. Returns true if a PONG had to be sent pingIndicator is the string to check for
func (*Bot) IncrementCommandCount ¶
IncrementCommandCount takes in a command name (key) and increments the associated count value in the DB
func (*Bot) LoadBadWords ¶
LoadBadWords loads all badwords from the databases TODO: generalize this for all bot data
func (*Bot) LoadCommands ¶
LoadCommands queries the sqlite3 database for existing commands
func (*Bot) LoadQuotes ¶
LoadQuotes loads all quotes from the DB. TODO: generalize this for all loading functions
func (*Bot) LoadTimers ¶
LoadTimers gets all of the timers that exist in storage
func (*Bot) ParseForBadWord ¶
ParseForBadWord reads in a string and sees if a bad word was found and returns that bad word. Callers should check if the bool is true, then use the returned BadWord if true.
func (*Bot) RandomQuote ¶
RandomQuote returns a random string, it does not print. It's up to the caller on what to do with it.
func (*Bot) RemoveCommand ¶
RemoveCommand takes in a command name as a string, presumably from the chat, and removes it
func (*Bot) RunDefaultCommands ¶
RunDefaultCommands will run a default command if caller contains the right invocation
func (*Bot) RunTimers ¶
RunTimers will loop over and run any timers in the database that are enabled. A service who wants to use RunTimers must define a Messenger.Message definition so this function knows how to send the timer's contents.
func (*Bot) WriteToConn ¶
WriteToConn when given a string sends a properly formatted message, easy replacement for using fmt.Fprintf
type BotLoaderFunc ¶
type CommandValue ¶
type CommandValue struct { Response string `json:"response"` Perm string `json:"perm"` Count int `json:"count"` }
CommandValue makes up a single command, used as the value in the bot's underyling commands map
type Database ¶
type Database struct { DB storage.Sqlite `json:"-"` Path string `json:"-"` // path to the database file CommandColumns []string QuoteColumns []string TimerColumns []string }
defines some DB options, specifically the columns for the various tables
type DefaultCommand ¶
type DefaultCommand struct { Type string Command string ExecFunc DefaultFunc }
type DefaultFunc ¶
type FatalError ¶
type FatalError struct {
Err error
}
FatalError is an error that would warrant an immediate end to the bot
func (FatalError) Error ¶
func (fe FatalError) Error() string
type Item ¶
type Item struct { IsServerInfo bool // if true, consider item not from user and can be ignored Sender User Type string // ex: com Command string // ex: add Key string // ex: !somecommand Contents string // ex: this is the value of some command }
Item represents a new key / value item for the bot such as a command. e.g. a new item request would have a structure such as: !addcom !command <contents> This struct will hold the !command and <contents> values respectively. Each field will hold the value with any leading ! chars removed.
type Messenger ¶
Messenger is used in those times where a function in the bot package HAS to send a message within its definition. This is avoided whenever possible, since the caller (service) should be determining what to do. However there are rare cases, such as with RunTimers, when a interface for sending messages is needed.
type NonFatalError ¶
type NonFatalError struct {
Err error
}
NonFatalError explains that an error occurred due to a non fatal condition and shouldn't be considered a terrible issue.
func (NonFatalError) Error ¶
func (nfe NonFatalError) Error() string
type QuoteValues ¶
QuoteValues represents the values associated with a quote. The ID in the DB will be the map key
type TimedValue ¶
TimedValues contains the values needed to run a single timed command.