Add a /settings command to check group settings
Signed-off-by: Sayan Biswas <sayan@pokurt.me>
This commit is contained in:
parent
d5123be9d1
commit
93c799fed3
|
@ -7,13 +7,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ShiinaConfig struct {
|
type ShiinaConfig struct {
|
||||||
BotToken string
|
BotToken string
|
||||||
DatabaseName string
|
DatabaseName string
|
||||||
BotAdmins []int64
|
CoffeeHouseKey string
|
||||||
Debug bool
|
BotAdmins []int64
|
||||||
DropUpdates bool
|
Debug bool
|
||||||
|
DropUpdates bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Data *ShiinaConfig
|
||||||
|
|
||||||
func NewShiinaConfig() *ShiinaConfig {
|
func NewShiinaConfig() *ShiinaConfig {
|
||||||
return &ShiinaConfig{}
|
return &ShiinaConfig{}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +33,7 @@ func (c *ShiinaConfig) ReadFile(path string) error {
|
||||||
c.BotAdmins = conf.GetInt64List("ShiinaConfig.BotAdmins")
|
c.BotAdmins = conf.GetInt64List("ShiinaConfig.BotAdmins")
|
||||||
c.Debug = conf.GetBoolean("ShiinaConfig.Debug")
|
c.Debug = conf.GetBoolean("ShiinaConfig.Debug")
|
||||||
c.DropUpdates = conf.GetBoolean("ShiinaConfig.DropUpdates")
|
c.DropUpdates = conf.GetBoolean("ShiinaConfig.DropUpdates")
|
||||||
|
Data = c
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,19 @@ type Chat struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chat) DoesAutoBan() bool {
|
func (c *Chat) DoesAutoBan() bool {
|
||||||
|
if c == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return c.AutoBan
|
return c.AutoBan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Chat) DetectSpam() bool {
|
||||||
|
if c == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return c.SpamDetect
|
||||||
|
}
|
||||||
|
|
||||||
func InsertChat(ChatID int64, AutoBan bool, SpamDetect bool, SpamAction string) {
|
func InsertChat(ChatID int64, AutoBan bool, SpamDetect bool, SpamAction string) {
|
||||||
tx := SESSION.Begin()
|
tx := SESSION.Begin()
|
||||||
chat := &Chat{ChatID: ChatID, AutoBan: AutoBan, SpamDetect: SpamDetect, SpamAction: SpamAction}
|
chat := &Chat{ChatID: ChatID, AutoBan: AutoBan, SpamDetect: SpamDetect, SpamAction: SpamAction}
|
||||||
|
|
|
@ -21,8 +21,7 @@ func autoBanHandler(b *gotgbot.Bot, ctx *ext.Context) error {
|
||||||
}
|
}
|
||||||
data, err := spamProtection.GetInfoByID(user.Id)
|
data, err := spamProtection.GetInfoByID(user.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helpers.SendError(err, ctx, b)
|
return helpers.SendError(err, ctx, b)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
if !data.Success {
|
if !data.Success {
|
||||||
return nil
|
return nil
|
||||||
|
@ -46,4 +45,4 @@ func msgFilter(msg *gotgbot.Message) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return msg.From != nil
|
return msg.From != nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HELP_CMD = "help"
|
HelpCmd = "help"
|
||||||
START_CMD = "start"
|
StartCmd = "start"
|
||||||
FETCH_CMD = "fetch"
|
FetchCmd = "fetch"
|
||||||
|
SettingsCmd = "settings"
|
||||||
|
PrivateChat = "private"
|
||||||
|
MarkdownV2 = "markdownv2"
|
||||||
|
TimeLayout = "Jan 2, 2006 at 3:04pm (MST)"
|
||||||
)
|
)
|
||||||
|
|
|
@ -13,9 +13,9 @@ func getHelp(u *gotgbot.User) string {
|
||||||
msg = msg.AppendNormal("I am a bot, with the primary purpose of adding more overhead on @SpamProtectionBot.").AppendNormal("\n")
|
msg = msg.AppendNormal("I am a bot, with the primary purpose of adding more overhead on @SpamProtectionBot.").AppendNormal("\n")
|
||||||
msg = msg.AppendNormal("Due to this, I function quite similarly to it, I might look like a clone of it.").AppendNormalThis("\n\n")
|
msg = msg.AppendNormal("Due to this, I function quite similarly to it, I might look like a clone of it.").AppendNormalThis("\n\n")
|
||||||
msg = msg.AppendBold("Here are the commands I currently accept").AppendNormal(":\n")
|
msg = msg.AppendBold("Here are the commands I currently accept").AppendNormal(":\n")
|
||||||
msg = msg.AppendNormal("- ").AppendMono(START_CMD).AppendNormal(": starts me, as usual\n")
|
msg = msg.AppendNormal("- ").AppendMono(StartCmd).AppendNormal(": starts me, as usual\n")
|
||||||
msg = msg.AppendNormal("- ").AppendMono(HELP_CMD).AppendNormal(": makes me send THIS message\n")
|
msg = msg.AppendNormal("- ").AppendMono(HelpCmd).AppendNormal(": makes me send THIS message\n")
|
||||||
msg = msg.AppendNormal("- ").AppendMono(FETCH_CMD).AppendNormalThis(": fetch a user on the API")
|
msg = msg.AppendNormal("- ").AppendMono(FetchCmd).AppendNormalThis(": fetch a user on the API")
|
||||||
return msg.ToString()
|
return msg.ToString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,7 @@ func helpHandler(b *gotgbot.Bot, ctx *ext.Context) error {
|
||||||
{Text: "Click me for help!", Url: fmt.Sprintf("t.me/%s?start=help", b.Username)},
|
{Text: "Click me for help!", Url: fmt.Sprintf("t.me/%s?start=help", b.Username)},
|
||||||
}}}})
|
}}}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helpers.SendError(err, ctx, b)
|
return helpers.SendError(err, ctx, b)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,14 +6,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadHandlers(d *ext.Dispatcher) {
|
func LoadHandlers(d *ext.Dispatcher) {
|
||||||
startCMD := handlers.NewCommand(START_CMD, startHandler)
|
startCMD := handlers.NewCommand(StartCmd, startHandler)
|
||||||
helpCMD := handlers.NewCommand(HELP_CMD, helpHandler)
|
helpCMD := handlers.NewCommand(HelpCmd, helpHandler)
|
||||||
getMeCMD := handlers.NewCommand(FETCH_CMD, fetchHandler)
|
getMeCMD := handlers.NewCommand(FetchCmd, fetchHandler)
|
||||||
|
settingsCMD := handlers.NewCommand(SettingsCmd, settingsHandler)
|
||||||
autoBan := handlers.NewMessage(msgFilter, autoBanHandler)
|
autoBan := handlers.NewMessage(msgFilter, autoBanHandler)
|
||||||
logHandler := handlers.NewMessage(logChatFilter, logChat)
|
logHandler := handlers.NewMessage(logChatFilter, logChat)
|
||||||
d.AddHandler(startCMD)
|
d.AddHandler(startCMD)
|
||||||
d.AddHandler(helpCMD)
|
d.AddHandler(helpCMD)
|
||||||
d.AddHandler(getMeCMD)
|
d.AddHandler(getMeCMD)
|
||||||
|
d.AddHandler(settingsCMD)
|
||||||
d.AddHandler(autoBan)
|
d.AddHandler(autoBan)
|
||||||
d.AddHandler(logHandler)
|
d.AddHandler(logHandler)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/ALiwoto/mdparser/mdparser"
|
||||||
|
"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"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func settingsHandler(b *gotgbot.Bot, ctx *ext.Context) error {
|
||||||
|
chat := ctx.EffectiveChat
|
||||||
|
message := ctx.EffectiveMessage
|
||||||
|
if chat.Type == PrivateChat {
|
||||||
|
_, err := message.Reply(b, mdparser.GetItalic("Command only for group").ToString(), &gotgbot.SendMessageOpts{ParseMode: MarkdownV2})
|
||||||
|
return helpers.SendError(err, ctx, b)
|
||||||
|
}
|
||||||
|
data, err := database.GetChat(chat.Id)
|
||||||
|
if err != nil {
|
||||||
|
return helpers.SendError(err, ctx, b)
|
||||||
|
}
|
||||||
|
txt := mdparser.GetBold(chat.Title).AppendMono(fmt.Sprintf(" (%d)", chat.Id)).AppendNormal("\n\n")
|
||||||
|
if data == nil {
|
||||||
|
txt.AppendItalicThis("No data found")
|
||||||
|
} else {
|
||||||
|
txt.AppendBoldThis("SpamProtection Bans: ")
|
||||||
|
if data.DoesAutoBan() {
|
||||||
|
txt.AppendMonoThis("On")
|
||||||
|
} else {
|
||||||
|
txt.AppendMonoThis("Off")
|
||||||
|
}
|
||||||
|
txt.AppendNormalThis("\n")
|
||||||
|
txt.AppendBoldThis("Spam Prediction: ")
|
||||||
|
if data.DetectSpam() {
|
||||||
|
txt.AppendMonoThis("On")
|
||||||
|
} else {
|
||||||
|
txt.AppendMonoThis("Off")
|
||||||
|
}
|
||||||
|
txt.AppendNormalThis("\n")
|
||||||
|
txt.AppendNormalThis("\n").AppendBoldThis("Fetched on ").AppendBoldThis(time.Now().UTC().Format(TimeLayout))
|
||||||
|
}
|
||||||
|
_, err = message.Reply(b, txt.ToString(), &gotgbot.SendMessageOpts{ParseMode: MarkdownV2})
|
||||||
|
return helpers.SendError(err, ctx, b)
|
||||||
|
}
|
|
@ -8,10 +8,17 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SendError(err error, ctx *ext.Context, b *gotgbot.Bot) {
|
func SendError(err error, ctx *ext.Context, b *gotgbot.Bot) error {
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
msg := mdparser.GetBold("Error: ").AppendItalic(err.Error())
|
msg := mdparser.GetBold("Error: ").AppendItalic(err.Error())
|
||||||
_, er := b.SendMessage(ctx.EffectiveChat.Id, strings.ReplaceAll(msg.ToString(), b.Token, "token"), &gotgbot.SendMessageOpts{ParseMode: "markdownv2"})
|
txt := msg.ToString()
|
||||||
|
m := strings.ReplaceAll(txt, b.Token, "token")
|
||||||
|
m = strings.ReplaceAll(m, core.Data.CoffeeHouseKey, "cf_key")
|
||||||
|
_, er := b.SendMessage(ctx.EffectiveChat.Id, m, &gotgbot.SendMessageOpts{ParseMode: "markdownv2"})
|
||||||
if er != nil {
|
if er != nil {
|
||||||
core.SUGARED.Error(err)
|
core.SUGARED.Error(err)
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue