mirror of https://github.com/hak5/scuzzy.git
master
parent
f448466391
commit
f8c40280a3
|
@ -7,11 +7,12 @@ import (
|
|||
)
|
||||
|
||||
type UserMessageStat struct {
|
||||
UserID string
|
||||
Username string
|
||||
MessagesLastDay uint64
|
||||
MessagesLastHour uint64
|
||||
MessagesLastFive uint64
|
||||
UserID string
|
||||
Username string
|
||||
MessagesLastDay uint64
|
||||
MessagesLastHour uint64
|
||||
MessagesLastFiveMins uint64
|
||||
MessagesLastTenSecs uint64
|
||||
}
|
||||
|
||||
type Overwatch struct {
|
||||
|
@ -33,52 +34,71 @@ func (o *Overwatch) ProcessMessage(s *discordgo.Session, m interface{}) {
|
|||
}
|
||||
|
||||
func (o *Overwatch) handleUserStat(s *discordgo.Session, m *discordgo.MessageCreate) error {
|
||||
for _, user := range o.UserMessages {
|
||||
log.Printf("User: %+v\n", user)
|
||||
}
|
||||
|
||||
userID := m.Author.ID
|
||||
user, ok := o.UserMessages[userID]
|
||||
if !ok {
|
||||
log.Println("Couldn't find user, making a new one")
|
||||
o.UserMessages[userID] = &UserMessageStat{
|
||||
UserID: userID,
|
||||
Username: m.Author.Username,
|
||||
MessagesLastDay: 0,
|
||||
MessagesLastHour: 0,
|
||||
MessagesLastFive: 0,
|
||||
UserID: userID,
|
||||
Username: m.Author.Username,
|
||||
MessagesLastDay: 0,
|
||||
MessagesLastHour: 0,
|
||||
MessagesLastFiveMins: 0,
|
||||
MessagesLastTenSecs: 0,
|
||||
}
|
||||
user = o.UserMessages[userID]
|
||||
}
|
||||
|
||||
user.MessagesLastDay++
|
||||
user.MessagesLastHour++
|
||||
user.MessagesLastFive++
|
||||
user.MessagesLastFiveMins++
|
||||
user.MessagesLastTenSecs++
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// this is fucking amazing code
|
||||
func (o *Overwatch) Run() {
|
||||
// Five second loop
|
||||
go func() {
|
||||
for range time.Tick(10 * time.Second) {
|
||||
log.Println("Printing UserMessages (10 Seconds)...")
|
||||
for _, user := range o.UserMessages {
|
||||
log.Printf("User: %+v\n", user)
|
||||
// load the threshold from the config file
|
||||
if user.MessagesLastTenSecs > 10 {
|
||||
// Set slow mode, kick user? add kick count?
|
||||
log.Printf("[*] User %s (%s) has triggered the message threshold.", user.Username, user.UserID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Clear Counters
|
||||
go func() {
|
||||
for range time.Tick(10 * time.Second) {
|
||||
log.Printf("[*] Resetting all users 10 second message counters")
|
||||
for _, user := range o.UserMessages {
|
||||
user.MessagesLastTenSecs = 0
|
||||
}
|
||||
}
|
||||
|
||||
for range time.Tick(5 * time.Minute) {
|
||||
log.Printf("[*] Resetting all users 5 minute message counters")
|
||||
for _, user := range o.UserMessages {
|
||||
user.MessagesLastFive = 0
|
||||
user.MessagesLastFiveMins = 0
|
||||
}
|
||||
}
|
||||
|
||||
for range time.Tick(10 * time.Minute) {
|
||||
log.Printf("[*] Resetting all users 10 minute message counters")
|
||||
for range time.Tick(1 * time.Hour) {
|
||||
log.Printf("[*] Resetting all users 60 minute message counters")
|
||||
for _, user := range o.UserMessages {
|
||||
user.MessagesLastHour = 0
|
||||
}
|
||||
}
|
||||
|
||||
for range time.Tick(24 * time.Hour) {
|
||||
log.Println("[*] Resetting all users 1 day message counters")
|
||||
for _, user := range o.UserMessages {
|
||||
user.MessagesLastDay = 0
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue