2017-06-17 20:20:06 +00:00
|
|
|
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
|
|
|
|
|
|
|
|
package reaction
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
|
|
|
|
"github.com/velour/catbase/bot"
|
|
|
|
"github.com/velour/catbase/bot/msg"
|
2017-08-30 17:41:58 +00:00
|
|
|
"github.com/velour/catbase/config"
|
2017-06-17 20:20:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ReactionPlugin struct {
|
2018-05-02 11:02:04 +00:00
|
|
|
Bot bot.Bot
|
2017-08-30 17:41:58 +00:00
|
|
|
Config *config.Config
|
2017-06-17 20:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func New(bot bot.Bot) *ReactionPlugin {
|
|
|
|
return &ReactionPlugin{
|
2018-05-02 11:02:04 +00:00
|
|
|
Bot: bot,
|
2017-08-30 17:41:58 +00:00
|
|
|
Config: bot.Config(),
|
2017-06-17 20:20:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ReactionPlugin) Message(message msg.Message) bool {
|
2017-08-30 18:44:04 +00:00
|
|
|
harrass := false
|
2017-08-30 17:41:58 +00:00
|
|
|
for _, nick := range p.Config.Reaction.HarrassList {
|
|
|
|
if message.User.Name == nick {
|
2017-08-30 18:44:04 +00:00
|
|
|
harrass = true
|
2017-08-30 17:41:58 +00:00
|
|
|
break
|
|
|
|
}
|
2017-06-17 20:20:06 +00:00
|
|
|
}
|
2017-08-30 17:41:58 +00:00
|
|
|
|
2017-08-30 18:44:04 +00:00
|
|
|
chance := p.Config.Reaction.GeneralChance
|
|
|
|
negativeWeight := 1
|
|
|
|
if harrass {
|
|
|
|
chance = p.Config.Reaction.HarrassChance
|
|
|
|
negativeWeight = p.Config.Reaction.NegativeHarrassmentMultiplier
|
|
|
|
}
|
|
|
|
|
|
|
|
if rand.Float64() < chance {
|
|
|
|
numPositiveReactions := len(p.Config.Reaction.PositiveReactions)
|
|
|
|
numNegativeReactions := len(p.Config.Reaction.NegativeReactions)
|
|
|
|
|
2018-05-02 11:02:04 +00:00
|
|
|
maxIndex := numPositiveReactions + numNegativeReactions*negativeWeight
|
2017-08-30 18:44:04 +00:00
|
|
|
|
|
|
|
index := rand.Intn(maxIndex)
|
|
|
|
|
|
|
|
reaction := ""
|
|
|
|
|
|
|
|
if index < numPositiveReactions {
|
|
|
|
reaction = p.Config.Reaction.PositiveReactions[index]
|
|
|
|
} else {
|
|
|
|
index -= numPositiveReactions
|
|
|
|
index %= numNegativeReactions
|
|
|
|
reaction = p.Config.Reaction.NegativeReactions[index]
|
2017-08-30 17:41:58 +00:00
|
|
|
}
|
2017-08-30 18:44:04 +00:00
|
|
|
|
|
|
|
p.Bot.React(message.Channel, reaction, message)
|
2017-08-30 17:41:58 +00:00
|
|
|
}
|
|
|
|
|
2017-06-17 20:20:06 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ReactionPlugin) Help(channel string, parts []string) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ReactionPlugin) Event(kind string, message msg.Message) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ReactionPlugin) BotMessage(message msg.Message) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ReactionPlugin) RegisterWeb() *string {
|
|
|
|
return nil
|
|
|
|
}
|
2017-10-31 18:14:45 +00:00
|
|
|
|
|
|
|
func (p *ReactionPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|