all repos — escarbot @ 0d332b999873f9a6d035d0977c0649b8ef7b6b19

Earthbound Café's custom Telegram bot, with lots of cool utilities built-in.

remove feedback prompt
Marco Andronaco andronacomarco@gmail.com
Thu, 17 Oct 2024 01:26:39 +0200
commit

0d332b999873f9a6d035d0977c0649b8ef7b6b19

parent

5a1c4dca3f0ea4889431508a27670a518b367c05

4 files changed, 8 insertions(+), 62 deletions(-)

jump to
D telegram/inline.go

@@ -1,44 +0,0 @@

-package telegram - -import ( - "log" - "strconv" - - tgbotapi "github.com/BiRabittoh/telegram-bot-api/v5" -) - -var emptyKeyboard tgbotapi.InlineKeyboardMarkup -var inlineKeyboardFeedback = tgbotapi.NewInlineKeyboardMarkup( - tgbotapi.NewInlineKeyboardRow( - tgbotapi.NewInlineKeyboardButtonData("✅", "1"), - tgbotapi.NewInlineKeyboardButtonData("❌", "0"), - ), -) - -func callbackQueryHandler(bot *tgbotapi.BotAPI, query *tgbotapi.CallbackQuery) { - res, err := strconv.ParseInt(query.Data, 10, 64) - if err != nil { - log.Println("Could not parse int:", err) - return - } - - var callbackResponse tgbotapi.CallbackConfig - var action tgbotapi.Chattable - - if res == 0 { - callbackResponse = tgbotapi.NewCallback(query.ID, "Ci ho provato...") - action = tgbotapi.NewDeleteMessage(query.Message.Chat.ID, query.Message.MessageID) - } else { - callbackResponse = tgbotapi.NewCallback(query.ID, "Bene!") - action = tgbotapi.NewEditMessageReplyMarkup(query.Message.Chat.ID, query.Message.MessageID, emptyKeyboard) - } - - if _, err := bot.Request(callbackResponse); err != nil { - panic(err) - } - _, err = bot.Request(action) - if err != nil { - log.Fatal(err) - } - -}
M telegram/replace.gotelegram/replace.go

@@ -97,7 +97,6 @@ text := fmt.Sprintf(linkMessage, link, user)

msg := tgbotapi.NewMessage(message.Chat.ID, text) msg.MessageThreadID = message.MessageThreadID msg.ParseMode = parseMode - msg.ReplyMarkup = inlineKeyboardFeedback bot.Send(msg) }
M telegram/telegram.gotelegram/telegram.go

@@ -43,9 +43,6 @@ if err != nil {

log.Fatal("Error while converting ADMIN_ID to int64:", err) } - emptyKeyboard = tgbotapi.NewInlineKeyboardMarkup() - emptyKeyboard.InlineKeyboard = [][]tgbotapi.InlineKeyboardButton{} - return &EscarBot{ Bot: bot, Power: true,

@@ -79,10 +76,6 @@ if update.ChannelPost != nil { // If we got a channel post

if escarbot.ChannelForward { channelPostHandler(escarbot, update.ChannelPost) } - } - query := update.CallbackQuery - if query != nil { // If we got a callback query - callbackQueryHandler(bot, query) } } }
M webui/webui.gowebui/webui.go

@@ -19,8 +19,6 @@ }

var indexTemplate = template.Must(template.ParseFiles("index.html")) -const toggleFormName = "toggle" - func indexHandler(bot *telegram.EscarBot) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { buf := &bytes.Buffer{}

@@ -33,14 +31,14 @@ buf.WriteTo(w)

} } -func toggleBotProperty(w http.ResponseWriter, r *http.Request, bot *telegram.EscarBot) bool { +func toggleBotProperty(w http.ResponseWriter, r *http.Request) bool { r.ParseForm() res := r.Form.Get("toggle") http.Redirect(w, r, "/", http.StatusFound) return res == "on" } -func getChatID(w http.ResponseWriter, r *http.Request, bot *telegram.EscarBot) (int64, error) { +func getChatID(w http.ResponseWriter, r *http.Request) (int64, error) { r.ParseForm() res := r.Form.Get("id") http.Redirect(w, r, "/", http.StatusFound)

@@ -49,25 +47,25 @@ }

func linksHandler(bot *telegram.EscarBot) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - bot.LinkDetection = toggleBotProperty(w, r, bot) + bot.LinkDetection = toggleBotProperty(w, r) } } func channelForwardHandler(bot *telegram.EscarBot) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - bot.ChannelForward = toggleBotProperty(w, r, bot) + bot.ChannelForward = toggleBotProperty(w, r) } } func adminForwardHandler(bot *telegram.EscarBot) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - bot.AdminForward = toggleBotProperty(w, r, bot) + bot.AdminForward = toggleBotProperty(w, r) } } func channelHandler(bot *telegram.EscarBot) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - res, err := getChatID(w, r, bot) + res, err := getChatID(w, r) if err != nil { log.Println(err) return

@@ -78,7 +76,7 @@ }

func groupHandler(bot *telegram.EscarBot) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - res, err := getChatID(w, r, bot) + res, err := getChatID(w, r) if err != nil { log.Println(err) return

@@ -89,7 +87,7 @@ }

func adminHandler(bot *telegram.EscarBot) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - res, err := getChatID(w, r, bot) + res, err := getChatID(w, r) if err != nil { log.Println(err) return