mirror of https://github.com/hak5/scuzzy.git
master
parent
f448466391
commit
f8c40280a3
|
@ -11,7 +11,8 @@ type UserMessageStat struct {
|
||||||
Username string
|
Username string
|
||||||
MessagesLastDay uint64
|
MessagesLastDay uint64
|
||||||
MessagesLastHour uint64
|
MessagesLastHour uint64
|
||||||
MessagesLastFive uint64
|
MessagesLastFiveMins uint64
|
||||||
|
MessagesLastTenSecs uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type Overwatch struct {
|
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 {
|
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
|
userID := m.Author.ID
|
||||||
user, ok := o.UserMessages[userID]
|
user, ok := o.UserMessages[userID]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Println("Couldn't find user, making a new one")
|
|
||||||
o.UserMessages[userID] = &UserMessageStat{
|
o.UserMessages[userID] = &UserMessageStat{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
Username: m.Author.Username,
|
Username: m.Author.Username,
|
||||||
MessagesLastDay: 0,
|
MessagesLastDay: 0,
|
||||||
MessagesLastHour: 0,
|
MessagesLastHour: 0,
|
||||||
MessagesLastFive: 0,
|
MessagesLastFiveMins: 0,
|
||||||
|
MessagesLastTenSecs: 0,
|
||||||
}
|
}
|
||||||
user = o.UserMessages[userID]
|
user = o.UserMessages[userID]
|
||||||
}
|
}
|
||||||
|
|
||||||
user.MessagesLastDay++
|
user.MessagesLastDay++
|
||||||
user.MessagesLastHour++
|
user.MessagesLastHour++
|
||||||
user.MessagesLastFive++
|
user.MessagesLastFiveMins++
|
||||||
|
user.MessagesLastTenSecs++
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this is fucking amazing code
|
||||||
func (o *Overwatch) Run() {
|
func (o *Overwatch) Run() {
|
||||||
|
// Five second loop
|
||||||
go func() {
|
go func() {
|
||||||
for range time.Tick(10 * time.Second) {
|
for range time.Tick(10 * time.Second) {
|
||||||
log.Println("Printing UserMessages (10 Seconds)...")
|
|
||||||
for _, user := range o.UserMessages {
|
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) {
|
for range time.Tick(5 * time.Minute) {
|
||||||
log.Printf("[*] Resetting all users 5 minute message counters")
|
log.Printf("[*] Resetting all users 5 minute message counters")
|
||||||
for _, user := range o.UserMessages {
|
for _, user := range o.UserMessages {
|
||||||
user.MessagesLastFive = 0
|
user.MessagesLastFiveMins = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for range time.Tick(10 * time.Minute) {
|
for range time.Tick(1 * time.Hour) {
|
||||||
log.Printf("[*] Resetting all users 10 minute message counters")
|
log.Printf("[*] Resetting all users 60 minute message counters")
|
||||||
for _, user := range o.UserMessages {
|
for _, user := range o.UserMessages {
|
||||||
user.MessagesLastHour = 0
|
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