Initial commit

This commit is contained in:
eleksir
2025-06-08 04:32:16 +03:00
parent c1ad1d3925
commit 0ed09563e2
20 changed files with 600 additions and 280 deletions

View File

@@ -1,11 +1,11 @@
package moon
import (
"fmt"
"slices"
"time"
"github.com/NicoNex/echotron/v3"
"github.com/akyoto/cache"
)
// TODO: refactor to return bool, error
@@ -16,18 +16,12 @@ func squash(chatid int64, chattype, chattitle string, userid int64, firstname, l
// If there is no such chatid, means that no such cache too.
if len(ChatList) == 0 || !slices.Contains(ChatList, chatid) {
Log.Debugf("Creating caches for new %s %s (%d)", chattype, chattitle, chatid)
NewMembers[chatid] = cache.New(1 * time.Minute)
AppearedMembers[chatid] = cache.New(1 * time.Minute)
SquashedMembers[chatid] = cache.New(5 * time.Minute)
Log.Debugf("Add %s %s (%d) to list of known chats", chattype, chattitle, chatid)
ChatList = append(ChatList, chatid)
}
if found, exist := SquashedMembers[chatid].Get(userid); exist && found.(bool) {
if _, exist := SquashedMembers.Get(userid); exist {
Log.Infof(
"Skip banning user %s %s (username = %s, id = %d) in %s %s (%d), already banned",
firstname,
@@ -85,9 +79,12 @@ func squash(chatid int64, chattype, chattitle string, userid int64, firstname, l
chatid,
)
SquashedMembers[chatid].Set(userid, true, 30*time.Second)
NewMembers[chatid].Delete(userid)
AppearedMembers[chatid].Delete(userid)
key := fmt.Sprintf("%d+%d", chatid, userid)
SquashedMembers.Set(key, true, 30*time.Second)
NewMembers.Delete(key)
AppearedMembers.Delete(key)
}
}
}
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */