Help: init

Signed-off-by: Sayan Biswas <sayan@pokurt.me>
This commit is contained in:
Sayan Biswas 2021-10-08 21:47:20 +05:30
parent 7edd230552
commit d5123be9d1
No known key found for this signature in database
GPG Key ID: E1220C019C89B488
4 changed files with 64 additions and 5 deletions

7
handlers/constants.go Normal file
View File

@ -0,0 +1,7 @@
package handlers
const (
HELP_CMD = "help"
START_CMD = "start"
FETCH_CMD = "fetch"
)

38
handlers/help.go Normal file
View File

@ -0,0 +1,38 @@
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/helpers"
)
func getHelp(u *gotgbot.User) string {
msg := mdparser.GetBold("Hai ").AppendMention(u.FirstName, u.Id).AppendBold(", welcome!").AppendNormal("\n\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.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(HELP_CMD).AppendNormal(": makes me send THIS message\n")
msg = msg.AppendNormal("- ").AppendMono(FETCH_CMD).AppendNormalThis(": fetch a user on the API")
return msg.ToString()
}
func helpHandler(b *gotgbot.Bot, ctx *ext.Context) error {
m := ctx.EffectiveMessage
if m.Chat.Type != "private" {
_, err := m.Reply(b, "Contact me in PM", &gotgbot.SendMessageOpts{ReplyMarkup: gotgbot.InlineKeyboardMarkup{InlineKeyboard: [][]gotgbot.InlineKeyboardButton{{
{Text: "Click me for help!", Url: fmt.Sprintf("t.me/%s?start=help", b.Username)},
}}}})
if err != nil {
helpers.SendError(err, ctx, b)
return err
}
} else {
_, err := b.SendMessage(m.Chat.Id, getHelp(m.From), &gotgbot.SendMessageOpts{ParseMode: "markdownv2"})
return err
}
return nil
}

View File

@ -6,10 +6,14 @@ import (
)
func LoadHandlers(d *ext.Dispatcher) {
startCMD := handlers.NewCommand("start", startHandler)
getMeCMD := handlers.NewCommand("fetch", fetchHandler)
autoBan := handlers.NewMessage(msgFilter, autoBanHandler)
startCMD := handlers.NewCommand(START_CMD, startHandler)
helpCMD := handlers.NewCommand(HELP_CMD, helpHandler)
getMeCMD := handlers.NewCommand(FETCH_CMD, fetchHandler)
autoBan := handlers.NewMessage(msgFilter, autoBanHandler)
logHandler := handlers.NewMessage(logChatFilter, logChat)
d.AddHandler(startCMD)
d.AddHandler(helpCMD)
d.AddHandler(getMeCMD)
d.AddHandler(autoBan)
d.AddHandler(logHandler)
}

View File

@ -1,15 +1,25 @@
package handlers
import (
"fmt"
"github.com/ALiwoto/mdparser/mdparser"
"github.com/PaulSonOfLars/gotgbot/v2"
"github.com/PaulSonOfLars/gotgbot/v2/ext"
)
func startHandler(b *gotgbot.Bot, ctx *ext.Context) error {
txt := mdparser.GetBold("Hi, I'm " + b.FirstName).AppendNormal("\n\n")
args := ctx.Args()
m := ctx.EffectiveMessage
if len(args) > 1 && args[1] == "help" {
_, err := b.SendMessage(m.Chat.Id, getHelp(m.From), &gotgbot.SendMessageOpts{ParseMode: "markdownv2"})
return err
}
txt := mdparser.GetBold("Hi, I'm " + b.FirstName).AppendNormal("\n\n")
txt = txt.AppendNormal(`I'm a mirror of @SpamProtectionBot, this means`)
txt = txt.AppendNormal(` I enforce all bans made through that bot and also provide user information related to it`)
_, err := b.SendMessage(ctx.Message.Chat.Id, txt.ToString(), &gotgbot.SendMessageOpts{ParseMode: "markdownv2"})
_, err := b.SendMessage(ctx.Message.Chat.Id, txt.ToString(), &gotgbot.SendMessageOpts{ParseMode: "markdownv2",
ReplyMarkup: gotgbot.InlineKeyboardMarkup{InlineKeyboard: [][]gotgbot.InlineKeyboardButton{{
{Text: "Click me for help!", Url: fmt.Sprintf("t.me/%s?start=help", b.Username)},
}}}})
return err
}