mirror of https://github.com/velour/catbase.git
commit
885fe097c0
|
@ -93,6 +93,7 @@ type Config struct {
|
|||
Reaction struct {
|
||||
GeneralChance float64
|
||||
HarrassChance float64
|
||||
NegativeHarrassmentMultiplier int
|
||||
HarrassList []string
|
||||
PositiveReactions []string
|
||||
NegativeReactions []string
|
||||
|
|
|
@ -78,6 +78,7 @@
|
|||
"Reaction" : {
|
||||
"GeneralChance": 0.01,
|
||||
"HarrassChance": 0.05,
|
||||
"NegativeHarrassmentMultiplier": 2,
|
||||
"HarrassList": ["msherms"],
|
||||
"PositiveReactions": ["+1", "authorized", "aw_yea","joy"],
|
||||
"NegativeReactions": ["bullshit","fake","tableflip","vomit"]
|
||||
|
|
|
@ -26,27 +26,40 @@ func New(bot bot.Bot) *ReactionPlugin {
|
|||
}
|
||||
|
||||
func (p *ReactionPlugin) Message(message msg.Message) bool {
|
||||
outOf := int(1. / p.Config.Reaction.GeneralChance)
|
||||
|
||||
for _, reaction := range p.Config.Reaction.PositiveReactions {
|
||||
if rand.Intn(outOf) == 0 {
|
||||
p.Bot.React(message.Channel, reaction, message)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
harrass := false
|
||||
for _, nick := range p.Config.Reaction.HarrassList {
|
||||
if message.User.Name == nick {
|
||||
outOf = int(1. / p.Config.Reaction.HarrassChance)
|
||||
harrass = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, reaction := range p.Config.Reaction.NegativeReactions {
|
||||
if rand.Intn(outOf) == 0 {
|
||||
p.Bot.React(message.Channel, reaction, message)
|
||||
return false
|
||||
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)
|
||||
|
||||
maxIndex := numPositiveReactions + numNegativeReactions * negativeWeight
|
||||
|
||||
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]
|
||||
}
|
||||
|
||||
p.Bot.React(message.Channel, reaction, message)
|
||||
}
|
||||
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue