mirror of https://github.com/velour/catbase.git
Merge pull request #75 from velour/more_reactions
supplement catbase's ability to react
This commit is contained in:
commit
594e54a880
|
@ -92,6 +92,13 @@ type Config struct {
|
||||||
Emojify struct {
|
Emojify struct {
|
||||||
Chance float64
|
Chance float64
|
||||||
}
|
}
|
||||||
|
Reaction struct {
|
||||||
|
GeneralChance float64
|
||||||
|
HarrassChance float64
|
||||||
|
HarrassList []string
|
||||||
|
PositiveReactions []string
|
||||||
|
NegativeReactions []string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -74,5 +74,12 @@
|
||||||
},
|
},
|
||||||
"Emojify": {
|
"Emojify": {
|
||||||
"Chance": 0.02
|
"Chance": 0.02
|
||||||
|
},
|
||||||
|
"Reaction" : {
|
||||||
|
"GeneralChance": 0.01,
|
||||||
|
"HarrassChance": 0.05,
|
||||||
|
"HarrassList": ["msherms"],
|
||||||
|
"PositiveReactions": ["+1", "authorized", "aw_yea","joy"],
|
||||||
|
"NegativeReactions": ["bullshit","fake","tableflip","vomit"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,12 @@ import (
|
||||||
|
|
||||||
"github.com/velour/catbase/bot"
|
"github.com/velour/catbase/bot"
|
||||||
"github.com/velour/catbase/bot/msg"
|
"github.com/velour/catbase/bot/msg"
|
||||||
|
"github.com/velour/catbase/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReactionPlugin struct {
|
type ReactionPlugin struct {
|
||||||
Bot bot.Bot
|
Bot bot.Bot
|
||||||
|
Config *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(bot bot.Bot) *ReactionPlugin {
|
func New(bot bot.Bot) *ReactionPlugin {
|
||||||
|
@ -19,13 +21,34 @@ func New(bot bot.Bot) *ReactionPlugin {
|
||||||
|
|
||||||
return &ReactionPlugin{
|
return &ReactionPlugin{
|
||||||
Bot: bot,
|
Bot: bot,
|
||||||
|
Config: bot.Config(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReactionPlugin) Message(message msg.Message) bool {
|
func (p *ReactionPlugin) Message(message msg.Message) bool {
|
||||||
if rand.Intn(100) == 0 {
|
outOf := int(1. / p.Config.Reaction.GeneralChance)
|
||||||
p.Bot.React(message.Channel, "+1", message)
|
|
||||||
|
for _, reaction := range p.Config.Reaction.PositiveReactions {
|
||||||
|
if rand.Intn(outOf) == 0 {
|
||||||
|
p.Bot.React(message.Channel, reaction, message)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, nick := range p.Config.Reaction.HarrassList {
|
||||||
|
if message.User.Name == nick {
|
||||||
|
outOf = int(1. / p.Config.Reaction.HarrassChance)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, reaction := range p.Config.Reaction.NegativeReactions {
|
||||||
|
if rand.Intn(outOf) == 0 {
|
||||||
|
p.Bot.React(message.Channel, reaction, message)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue