master
Marc 2021-05-29 00:09:48 +01:00
parent 2bcf6b7136
commit 7fb7473e73
No known key found for this signature in database
GPG Key ID: 0657563F705ACAAE
1 changed files with 17 additions and 17 deletions

View File

@ -12,7 +12,7 @@ type UserMessageStat struct {
MessagesLastDay uint64
MessagesLastHour uint64
MessagesLastFiveMins uint64
MessagesLastTenSecs uint64
MessagesLastThirtySecs uint64
}
type Overwatch struct {
@ -43,7 +43,7 @@ func (o *Overwatch) handleUserStat(s *discordgo.Session, m *discordgo.MessageCre
MessagesLastDay: 0,
MessagesLastHour: 0,
MessagesLastFiveMins: 0,
MessagesLastTenSecs: 0,
MessagesLastThirtySecs: 0,
}
user = o.UserMessages[userID]
}
@ -51,7 +51,7 @@ func (o *Overwatch) handleUserStat(s *discordgo.Session, m *discordgo.MessageCre
user.MessagesLastDay++
user.MessagesLastHour++
user.MessagesLastFiveMins++
user.MessagesLastTenSecs++
user.MessagesLastThirtySecs++
return nil
}
@ -60,11 +60,11 @@ func (o *Overwatch) handleUserStat(s *discordgo.Session, m *discordgo.MessageCre
func (o *Overwatch) Run() {
// Five second loop
go func() {
for range time.Tick(10 * time.Second) {
for range time.Tick(5 * time.Second) {
for _, user := range o.UserMessages {
log.Printf("User: %+v", user)
// load the threshold from the config file
if user.MessagesLastTenSecs > 10 {
if user.MessagesLastThirtySecs > 10 {
// Set slow mode, kick user? add kick count?
log.Printf("[*] User %s (%s) has triggered the message threshold.", user.Username, user.UserID)
}
@ -74,10 +74,10 @@ func (o *Overwatch) Run() {
// Clear Counters
go func() {
for range time.Tick(10 * time.Second) {
for range time.Tick(30 * time.Second) {
log.Printf("[*] Resetting all users 10 second message counters")
for _, user := range o.UserMessages {
user.MessagesLastTenSecs = 0
user.MessagesLastThirtySecs = 0
}
}