mirror of https://github.com/velour/catbase.git
Adding your plugin
This commit is contained in:
parent
8913914bbb
commit
80295590af
1
main.go
1
main.go
|
@ -52,6 +52,7 @@ func main() {
|
||||||
b.AddHandler("counter", plugins.NewCounterPlugin(b))
|
b.AddHandler("counter", plugins.NewCounterPlugin(b))
|
||||||
b.AddHandler("remember", plugins.NewRememberPlugin(b))
|
b.AddHandler("remember", plugins.NewRememberPlugin(b))
|
||||||
b.AddHandler("skeleton", plugins.NewSkeletonPlugin(b))
|
b.AddHandler("skeleton", plugins.NewSkeletonPlugin(b))
|
||||||
|
b.AddHandler("your", plugins.NewYourPlugin(b))
|
||||||
// catches anything left, will always return true
|
// catches anything left, will always return true
|
||||||
b.AddHandler("factoid", plugins.NewFactoidPlugin(b))
|
b.AddHandler("factoid", plugins.NewFactoidPlugin(b))
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package plugins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"bitbucket.org/phlyingpenguin/godeepintir/bot"
|
||||||
|
)
|
||||||
|
|
||||||
|
type YourPlugin struct {
|
||||||
|
Bot *bot.Bot
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewYourPlugin creates a new YourPlugin with the Plugin interface
|
||||||
|
func NewYourPlugin(bot *bot.Bot) *YourPlugin {
|
||||||
|
return &YourPlugin{
|
||||||
|
Bot: bot,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message responds to the bot hook on recieving messages.
|
||||||
|
// This function returns true if the plugin responds in a meaningful way to the users message.
|
||||||
|
// Otherwise, the function returns false and the bot continues execution of other plugins.
|
||||||
|
func (p *YourPlugin) Message(message bot.Message) bool {
|
||||||
|
fmt.Println("Your got a message!")
|
||||||
|
lower := strings.ToLower(message.Body)
|
||||||
|
if strings.Contains(lower, "your") || strings.Contains(lower, "you're") {
|
||||||
|
if rand.Float64() < 0.2 {
|
||||||
|
r := strings.NewReplacer("Your", "You're", "your", "you're", "You're",
|
||||||
|
"Your", "you're", "your", "Youre", "Your", "youre", "your")
|
||||||
|
msg := r.Replace(message.Body)
|
||||||
|
fmt.Println(msg)
|
||||||
|
p.Bot.SendMessage(message.Channel, msg)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadData imports any configuration data into the plugin. This is not strictly necessary other
|
||||||
|
// than the fact that the Plugin interface demands it exist. This may be deprecated at a later
|
||||||
|
// date.
|
||||||
|
func (p *YourPlugin) LoadData() {
|
||||||
|
rand.Seed(time.Now().Unix())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Help responds to help requests. Every plugin must implement a help function.
|
||||||
|
func (p *YourPlugin) Help(channel string, parts []string) {
|
||||||
|
p.Bot.SendMessage(channel, "Your corrects people's grammar.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty event handler because this plugin does not do anything on event recv
|
||||||
|
func (p *YourPlugin) Event(kind string, message bot.Message) bool {
|
||||||
|
return false
|
||||||
|
}
|
Loading…
Reference in New Issue