Documentation ¶
Overview ¶
Package dad is an extension of hellabot that plays the role of an IRC chat bot, either as a mom or a dad
Index ¶
- Constants
- Variables
- func AddArticle(s string) string
- func GetChannelTargetOrDefault(to, msg string) (string, string)
- func GetICanHazDadJoke() string
- func GetVariableRegex(s string, regex RegexData) string
- func HandleTextReplacement(message *hbot.Message, response *Response, variable string) string
- func MustCompileRegexData(regex RegexData) (*regexp.Regexp, *regexp.Regexp)
- func RemoveLiteralRegex(s string, regex string) string
- func RemoveTriggerRegex(s string, regex RegexData) string
- func StringInSlice(a string, s []string) int
- type BotConfiguration
- type ICanHazDadJoke
- type IRCBot
- func (ib IRCBot) AddTrigger(t hbot.Trigger)
- func (ib *IRCBot) FormatReply(message *hbot.Message, adminSpeak bool, sIndex int) Reply
- func (ib *IRCBot) Ground(name string)
- func (ib *IRCBot) MessageRateMet(message *hbot.Message) bool
- func (ib *IRCBot) PerformAction(reply Reply, speak *SpeakData, variable string) (Reply, string)
- func (ib *IRCBot) PerformReply(m *hbot.Message, adminSpeak bool) bool
- func (ib *IRCBot) ReadConfig(ircFileName, botFileName, mutedFileName string)
- func (ib *IRCBot) Run(ircConfigFileName, botConfigFileName, mutedListFileName string)
- func (ib *IRCBot) SendMessageType(m *hbot.Message, to string, replyType int, msg string)
- func (ib *IRCBot) SendReply(m *hbot.Message, reply Reply) bool
- func (ib *IRCBot) TestMessage(regex RegexData, message *hbot.Message) bool
- func (ib *IRCBot) Unground(name string)
- func (ib *IRCBot) UpdateBotConfig()
- type IRCBotInterface
- type IRCConfiguration
- type MutedList
- type RegexData
- type Reply
- type Response
- type SpeakData
Constants ¶
const ( // ReplyType indicates to send a message to where the message came from ReplyType = iota // 0 // MessageType indicates to send a message to a specified user or channel MessageType // 1 // NoticeType indicates to send a notice to a specified user or channel NoticeType // 2 // ActionType indicates to send an action to a specified user or channel ActionType // 3 // TopicType indicates to set the topic for the current channel TopicType // 4 // SendType indicates to send any command to the server SendType // 5 // ChModeType indicates to change a user's mode in the channel ChModeType // 6 // JoinType indicates to join a channel JoinType // 7 // PartType indicates to leave a specified channel PartType // 8 // QuitType indicates to quit the existing IRC connection QuitType // 9 )
Variables ¶
var AdminTrigger = hbot.Trigger{ func(bot *hbot.Bot, m *hbot.Message) bool { return (m.From == Irc.IRCConfig.Admin) }, func(bot *hbot.Bot, m *hbot.Message) bool { responded := Irc.PerformReply(m, true) if !responded { Irc.PerformReply(m, false) } return false }, }
AdminTrigger is for the admin user. If no admin response is performed, a user reponse is attempted.
var UserTrigger = hbot.Trigger{ func(bot *hbot.Bot, m *hbot.Message) bool { return (m.From != Irc.IRCConfig.Admin) }, func(bot *hbot.Bot, m *hbot.Message) bool { Irc.PerformReply(m, false) return false }, }
UserTrigger is for all non-admin users.
Functions ¶
func AddArticle ¶
AddArticle prepands the given string with an "a" or "an" based on the first word and returns the result
func GetChannelTargetOrDefault ¶
GetChannelTargetOrDefault looks for a "#channel:" or "user:" in the passed msg. If found, it's split from the message and returned as the new destination, alongside the rest of the message. If not found, the original destination (to) and msg is returned
func GetICanHazDadJoke ¶
func GetICanHazDadJoke() string
GetICanHazDadJoke sends an HTTP request to https://icanhazdadjoke.com and returns a parsed string of the joke
func GetVariableRegex ¶
GetVariableRegex returns only the part of the string that matches the Variable portion of RegexData
func HandleTextReplacement ¶
HandleTextReplacement determines what to do with each flag in a response #a indicates an article "a" or "an" #c indicates a response generated from an action handler #u indicates the name of the user who sent the trigger message #v indicates the string captured by the Variable regex Other conditionals can be added here. A string with all flags replaced is returned.
func MustCompileRegexData ¶
MustCompileRegexData compiles and returns all parts of the passed RegexData variable
func RemoveLiteralRegex ¶
RemoveLiteralRegex removes a matching literal that is passed as regex from the given string, s, and returns the result.
func RemoveTriggerRegex ¶
RemoveTriggerRegex removes Trigger matching substrings from the given string This doesn't necessarily leave behind the Variable portion, as there could be additional message content that matches neither the Trigger nor Variable.
func StringInSlice ¶
StringInSlice checks slice s for string a and returns the first matching index, and -1 otherwise
Types ¶
type BotConfiguration ¶
type BotConfiguration struct { AdminSpeak []SpeakData Channels []string Debug bool Name string Speak []SpeakData }
BotConfiguration gives structure to any bot config file
type ICanHazDadJoke ¶
type ICanHazDadJoke struct { ID string `json:"id"` Joke string `json:"joke"` Status int `json:"status"` }
ICanHazDadJoke declares the expected json format of jokes from ICanHazDadJoke.com
type IRCBot ¶
type IRCBot struct { Bot *hbot.Bot BotConfig BotConfiguration BotConfigFile string Muted MutedList MutedFile string IRCConfig IRCConfiguration IRCConfigFile string CurrentReply Reply LastReply Reply }
IRCBot is an extension of hellabot's Bot that includes an indicator for whether the bot is acting as mom or dad, the config information, and the last reply sent by the bot
var Irc IRCBot
Irc is the global variable that tracks any common, constant values between the two bots. This is only accessed once at startup by each bot
func (IRCBot) AddTrigger ¶
func (ib IRCBot) AddTrigger(t hbot.Trigger)
AddTrigger adds the given Trigger to the bot
func (*IRCBot) FormatReply ¶
FormatReply formulates the bot's response given the message, whether or not the sender was an admin (adminSpeak), and the index of the SpeakData to format the reply to (sIndex). It returns the reply with set content and destination (but not the time). Message content is split into multiple messages anywhere a "\n" is found
func (*IRCBot) Ground ¶
Ground checks the list of currently grounded users and adds the name if it has not yet been added.
func (*IRCBot) MessageRateMet ¶
MessageRateMet checks whether or not enough time has passed since the Last reply was sent. If the message just sent was from an admin, ignore time passed.
func (*IRCBot) PerformAction ¶
PerformAction evaluates the action associated with the response (speak) and performs any necessary actions. Any content that needs to be used in the response will be returned.
func (*IRCBot) PerformReply ¶
PerformReply determines whether or not a reply should be formulated and then performs it by passing it the bot in use (bot), the message just sent (m), and whether or not the sender was the admin (adminSpeak). If an action was performed, return true.
func (*IRCBot) ReadConfig ¶
ReadConfig reads each config file and returns a struct of each
func (*IRCBot) Run ¶
Run starts an instance of the bot, with variable dad indicating whether the bot should behave like a dad or a mom
func (*IRCBot) SendMessageType ¶
SendMessageType accepts the bot and message and sends a message (msg) to the specified user/channel (to) of type replyType.
func (*IRCBot) SendReply ¶
SendReply accepts the bot, message, and the bot's reply. It returns true if at least one line was sent, and false if nothing was sent.
func (*IRCBot) TestMessage ¶
TestMessage tests the passed message against the passed regex and returns whether or not a match was found
func (*IRCBot) Unground ¶
Unground checks the list of grounded users for the requested name and removes it if it is found.
func (*IRCBot) UpdateBotConfig ¶
func (ib *IRCBot) UpdateBotConfig()
UpdateBotConfig parses the existing bot configuration data into a writable format and updates the corresponding data file.
type IRCBotInterface ¶
type IRCBotInterface interface { AddTrigger(t *hbot.Trigger) Run() ReadConfig() PerformReply() SendReply() SendMessageType() TestMessage() UpdateBotConfig() }
IRCBotInterface is a temporary place-holder
type IRCConfiguration ¶
IRCConfiguration contains all content that should be common between the bots
type RegexData ¶
RegexData makes it a little easier to capture text by having regex that seperates the message content into two parts. The Trigger section acts as the command that the bot responds to. The Variable is what the bot will take and use in its response (if needed). If no reuse of message content is needed in a response, leave Variable blank.
type Reply ¶
Reply includes the final formatted response (all text replacement blocks dealt with), the destination, the time the message was sent at, and the type.
type Response ¶
ResponseData contains the bot's reply, the number of times the reply has been sent, and the type of response the bot should give. Message may contain action tags (#<char>) for different types of text replacement/manipulation.
type SpeakData ¶
SpeakData is the regex-to-response pairing for each possible response. There can be more than one response, and it will be chosen semi-randomly.
func (*SpeakData) GetRandomLeastUsedResponse ¶
GetRandomLeastUsedResponse chooses a random response among all within the given speak data, giving priority to responses that have not yet been used as much. It returns a reference to the response it chose
func (*SpeakData) GetRandomResponse ¶
GetRandomResponse chooses a random response among all within the given speak data. It returns a reference to the response it chose.