less debug, fixed an error
This commit is contained in:
parent
6ed12b7e83
commit
4460e988fd
@ -10,14 +10,20 @@ func (app *application) messageCreate(s *discordgo.Session, m *discordgo.Message
|
|||||||
if m.Author.Bot {
|
if m.Author.Bot {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.infoLog.Printf("Adding entry\n")
|
|
||||||
app.limiter.LogInteraction(m.Author.ID, "messagecreate")
|
app.limiter.LogInteraction(m.Author.ID, "messagecreate")
|
||||||
|
|
||||||
/* Check if the user is even allowed by the rate limiter */
|
/* Check if the user is even allowed by the rate limiter */
|
||||||
err := app.limiter.CheckAllowed(m.Author.ID)
|
err := app.limiter.CheckAllowed(m.Author.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
/* normally don't send, but now do for debug purposes. This is the admin bot channel */
|
/* normally don't send, but now do for debug purposes. This is the admin bot channel */
|
||||||
app.unknownError(err, s, true, "815952128106430514")
|
//app.unknownError(err, s, true, "815952128106430514")
|
||||||
|
app.infoLog.Printf("Rate limit exceeded by used %s", m.Author.Username)
|
||||||
|
channel, err := s.UserChannelCreate(m.Author.ID)
|
||||||
|
if err != nil {
|
||||||
|
app.errorLog.Printf("Cannot create user PM channel to inform about rate limit, %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.ChannelMessageSend(channel.ID, "You exceeded the rate limit for the server, please stop spamming")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,11 +32,9 @@ func (l *Limiter) CheckAllowed(userid string) error {
|
|||||||
for i := 0; i < len(l.Logs[userid]); i++ {
|
for i := 0; i < len(l.Logs[userid]); i++ {
|
||||||
/* If the timestamp plus the timelimit is happened before "Now" */
|
/* If the timestamp plus the timelimit is happened before "Now" */
|
||||||
if l.Logs[userid][i].Timestamp.Add(l.TimeLimit).Before(time.Now()) {
|
if l.Logs[userid][i].Timestamp.Add(l.TimeLimit).Before(time.Now()) {
|
||||||
log.Printf("Expired entry\n")
|
|
||||||
expiredEntries = append(expiredEntries, i)
|
expiredEntries = append(expiredEntries, i)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Increasing counter\n")
|
|
||||||
counter++
|
counter++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user