New chat logging handlers

Signed-off-by: Sayan Biswas <sayan@pokurt.me>
This commit is contained in:
Sayan Biswas 2021-10-08 21:42:14 +05:30
parent 85e6313322
commit 4cb8d3b35d
No known key found for this signature in database
GPG Key ID: E1220C019C89B488
2 changed files with 38 additions and 1 deletions

View File

@ -5,12 +5,20 @@ import (
"github.com/Intellivoid/Intellivoid.SpamProtection-go/spamProtection"
"github.com/PaulSonOfLars/gotgbot/v2"
"github.com/PaulSonOfLars/gotgbot/v2/ext"
"gitlab.com/Dank-del/SpamProtection-Mirror-Bot/database"
"gitlab.com/Dank-del/SpamProtection-Mirror-Bot/helpers"
)
func autoBanHandler(b *gotgbot.Bot, ctx *ext.Context) error {
chat := ctx.EffectiveChat
user := ctx.EffectiveUser
settings, err := database.GetChat(chat.Id)
if err != nil {
return err
}
if !settings.DoesAutoBan() {
return nil
}
data, err := spamProtection.GetInfoByID(user.Id)
if err != nil {
helpers.SendError(err, ctx, b)
@ -30,9 +38,12 @@ func autoBanHandler(b *gotgbot.Bot, ctx *ext.Context) error {
_, err = b.SendMessage(chat.Id, txt.ToString(), &gotgbot.SendMessageOpts{ParseMode: "markdownv2"})
return err
}
return nil
return ext.ContinueGroups
}
func msgFilter(msg *gotgbot.Message) bool {
if msg.Chat.Type == "private" {
return false
}
return msg.From != nil
}

26
handlers/log.go Normal file
View File

@ -0,0 +1,26 @@
package handlers
import (
"github.com/PaulSonOfLars/gotgbot/v2"
"github.com/PaulSonOfLars/gotgbot/v2/ext"
"gitlab.com/Dank-del/SpamProtection-Mirror-Bot/core"
"gitlab.com/Dank-del/SpamProtection-Mirror-Bot/database"
)
func logChat(b *gotgbot.Bot, ctx *ext.Context) error {
chat := ctx.EffectiveChat
d, err := database.GetChat(chat.Id)
if err != nil {
core.SUGARED.Error(err)
return err
}
if d.ChatID == 0 {
database.InsertChat(chat.Id, false, false, "")
}
// fmt.Println(d)
return ext.ContinueGroups
}
func logChatFilter(msg *gotgbot.Message) bool {
return msg.Chat.Type != "private"
}