2016-01-17 18:00:44 +00:00
|
|
|
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
|
2013-12-10 23:37:07 +00:00
|
|
|
|
2016-03-24 17:32:40 +00:00
|
|
|
package your
|
2013-03-18 21:21:37 +00:00
|
|
|
|
|
|
|
import (
|
2013-09-14 03:27:11 +00:00
|
|
|
"log"
|
2013-03-18 21:21:37 +00:00
|
|
|
"math/rand"
|
|
|
|
"strings"
|
2013-03-18 21:29:19 +00:00
|
|
|
"time"
|
2013-03-18 21:21:37 +00:00
|
|
|
|
2016-01-17 18:00:44 +00:00
|
|
|
"github.com/velour/catbase/bot"
|
2013-03-18 21:21:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type YourPlugin struct {
|
2016-03-24 17:49:44 +00:00
|
|
|
bot *bot.Bot
|
2013-03-18 21:21:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewYourPlugin creates a new YourPlugin with the Plugin interface
|
|
|
|
func NewYourPlugin(bot *bot.Bot) *YourPlugin {
|
2013-09-14 03:27:11 +00:00
|
|
|
rand.Seed(time.Now().Unix())
|
2013-03-18 21:21:37 +00:00
|
|
|
return &YourPlugin{
|
2016-03-24 17:49:44 +00:00
|
|
|
bot: bot,
|
2013-03-18 21:21:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
lower := strings.ToLower(message.Body)
|
2016-03-24 17:49:44 +00:00
|
|
|
config := p.bot.Config.Your
|
|
|
|
if len(message.Body) > config.MaxLength {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2013-09-14 03:27:11 +00:00
|
|
|
if strings.Contains(message.Body, "the fucking") { // let's not mess with case
|
|
|
|
log.Println("Found a fucking")
|
2016-03-24 17:49:44 +00:00
|
|
|
if rand.Float64() < config.FuckingChance {
|
2013-09-14 03:27:11 +00:00
|
|
|
log.Println("Replacing a fucking")
|
|
|
|
r := strings.NewReplacer("the fucking", "fucking the")
|
|
|
|
msg := r.Replace(message.Body)
|
2016-03-24 17:49:44 +00:00
|
|
|
p.bot.SendMessage(message.Channel, msg)
|
2013-09-14 03:27:11 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if strings.Contains(lower, "your") || strings.Contains(lower, "you're") {
|
2016-03-24 17:49:44 +00:00
|
|
|
if rand.Float64() < config.YourChance {
|
2013-03-18 21:21:37 +00:00
|
|
|
r := strings.NewReplacer("Your", "You're", "your", "you're", "You're",
|
|
|
|
"Your", "you're", "your", "Youre", "Your", "youre", "your")
|
|
|
|
msg := r.Replace(message.Body)
|
2016-03-24 17:49:44 +00:00
|
|
|
p.bot.SendMessage(message.Channel, msg)
|
2013-03-18 21:21:37 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Help responds to help requests. Every plugin must implement a help function.
|
|
|
|
func (p *YourPlugin) Help(channel string, parts []string) {
|
2016-03-24 17:49:44 +00:00
|
|
|
p.bot.SendMessage(channel, "Your corrects people's grammar.")
|
2013-03-18 21:21:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2013-05-08 00:08:18 +00:00
|
|
|
|
|
|
|
// Handler for bot's own messages
|
|
|
|
func (p *YourPlugin) BotMessage(message bot.Message) bool {
|
|
|
|
return false
|
|
|
|
}
|
2013-06-01 17:10:15 +00:00
|
|
|
|
|
|
|
// Register any web URLs desired
|
|
|
|
func (p *YourPlugin) RegisterWeb() *string {
|
|
|
|
return nil
|
|
|
|
}
|