mirror of https://github.com/hak5/scuzzy.git
master
parent
15ce404ec8
commit
3619177cc9
|
@ -6,20 +6,22 @@ import (
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/foxtrot/scuzzy/commands"
|
"github.com/foxtrot/scuzzy/commands"
|
||||||
|
"github.com/foxtrot/scuzzy/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserMessageStat struct {
|
type UserMessageStat struct {
|
||||||
UserID string
|
UserID string
|
||||||
Username string
|
Username string
|
||||||
MessagesLastDay uint64
|
MessagesLastDay int
|
||||||
MessagesLastHour uint64
|
MessagesLastHour int
|
||||||
MessagesLastFiveMins uint64
|
MessagesLastFiveMins int
|
||||||
MessagesLastTenSecs uint64
|
MessagesLastTenSecs int
|
||||||
|
Warnings int
|
||||||
Kicks int
|
Kicks int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerStat struct {
|
type ServerStat struct {
|
||||||
JoinsLastTenMins uint64
|
JoinsLastTenMins int
|
||||||
SlowmodeFlood bool
|
SlowmodeFlood bool
|
||||||
SlowmodeFloodStartTime time.Time
|
SlowmodeFloodStartTime time.Time
|
||||||
}
|
}
|
||||||
|
@ -29,6 +31,7 @@ type Overwatch struct {
|
||||||
UserMessages map[string]*UserMessageStat
|
UserMessages map[string]*UserMessageStat
|
||||||
ServerStats ServerStat
|
ServerStats ServerStat
|
||||||
Commands *commands.Commands
|
Commands *commands.Commands
|
||||||
|
Config *models.Configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Overwatch) ProcessMessage(s *discordgo.Session, m interface{}) {
|
func (o *Overwatch) ProcessMessage(s *discordgo.Session, m interface{}) {
|
||||||
|
@ -54,6 +57,9 @@ func (o *Overwatch) ProcessMessage(s *discordgo.Session, m interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Overwatch) filterUserMessage(s *discordgo.Session, m *discordgo.MessageCreate) error {
|
func (o *Overwatch) filterUserMessage(s *discordgo.Session, m *discordgo.MessageCreate) error {
|
||||||
|
if o.Config.FilterLanguage {
|
||||||
|
// load regex from config?
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,23 +104,26 @@ func (o *Overwatch) handleServerJoin(s *discordgo.Session, m *discordgo.GuildMem
|
||||||
|
|
||||||
// this is fucking amazing code
|
// this is fucking amazing code
|
||||||
func (o *Overwatch) Run() {
|
func (o *Overwatch) Run() {
|
||||||
// this shit needs a go channel
|
|
||||||
// State of the art anti-spam loop
|
// State of the art anti-spam loop
|
||||||
go func() {
|
go func() {
|
||||||
for range time.Tick(5 * time.Second) {
|
for range time.Tick(5 * time.Second) {
|
||||||
for _, user := range o.UserMessages {
|
for _, user := range o.UserMessages {
|
||||||
// load the threshold from the config file, dipshit
|
if user.MessagesLastTenSecs > o.Config.UserMessageThreshold {
|
||||||
if user.MessagesLastTenSecs > 20 {
|
|
||||||
// Set slow mode, kick user? add kick count?
|
// Set slow mode, kick user? add kick count?
|
||||||
if user.Kicks > 2 {
|
if user.Warnings > o.Config.MaxUserWarnings {
|
||||||
// ban that sucker
|
if user.Kicks > o.Config.MaxUserKicks {
|
||||||
delete(o.UserMessages, user.UserID)
|
// ban that sucker
|
||||||
log.Printf("[*] User %s (%s) was banned due to previous spam-related kicks", user.Username, user.UserID)
|
delete(o.UserMessages, user.UserID)
|
||||||
|
log.Printf("[*] User %s (%s) was banned due to previous spam-related kicks\n", user.Username, user.UserID)
|
||||||
|
} else {
|
||||||
|
user.Kicks++
|
||||||
|
// kick user
|
||||||
|
user.MessagesLastTenSecs = 0
|
||||||
|
log.Printf("[*] User %s (%s) has been kicked for message spam\n", user.Username, user.UserID)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
user.Kicks++
|
user.Warnings++
|
||||||
// kick user
|
log.Printf("[*] User %s (%s) was warned for spamming\n", user.Username, user.UserID)
|
||||||
user.MessagesLastTenSecs = 0
|
|
||||||
log.Printf("[*] User %s (%s) has triggered the message threshold.", user.Username, user.UserID)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue