From 71b12970dfbde6b639343a711d6ed10685143f6e Mon Sep 17 00:00:00 2001 From: Astra Date: Fri, 30 Jan 2026 11:44:46 +0000 Subject: [PATCH] Add delete request message config, update reason text --- config.go | 24 +++++++++++++----------- main.go | 20 +++++++++++++++++--- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/config.go b/config.go index 1c65d1f..83eb279 100644 --- a/config.go +++ b/config.go @@ -8,12 +8,13 @@ import ( ) type Config struct { - BotToken string `yaml:"bot_token"` - AdminChatId int64 `yaml:"admin_chat_id"` - AdminChatTopicId int `yaml:"admin_chat_topic_id"` - TargetChatId int64 `yaml:"target_chat_id"` - EntryMessage string `yaml:"entry_message"` - ApprovalMessage string `yaml:"approval_message"` + BotToken string `yaml:"bot_token"` + AdminChatId int64 `yaml:"admin_chat_id"` + AdminChatTopicId int `yaml:"admin_chat_topic_id"` + TargetChatId int64 `yaml:"target_chat_id"` + EntryMessage string `yaml:"entry_message"` + ApprovalMessage string `yaml:"approval_message"` + DeleteRequestAfterDecision bool `yaml:"delete_request_after_decision"` } func (c *Config) LoadConfig() error { @@ -37,11 +38,12 @@ func (c *Config) CreateConfig() error { defer f.Close() defaultConfig := Config{ - BotToken: "YOUR_BOT_TOKEN_HERE", - AdminChatId: 0, - TargetChatId: 0, - EntryMessage: "You have requested to join the group, please write a brief message explaining why you want to join.", - ApprovalMessage: "", + BotToken: "YOUR_BOT_TOKEN_HERE", + AdminChatId: 0, + TargetChatId: 0, + EntryMessage: "You have requested to join the group, please write a brief message explaining why you want to join.", + ApprovalMessage: "", + DeleteRequestAfterDecision: false, } encoder := yaml.NewEncoder(f) diff --git a/main.go b/main.go index dbfa182..838374e 100644 --- a/main.go +++ b/main.go @@ -76,14 +76,18 @@ func main() { if update.Message.Chat.ID == b.Config.AdminChatId && update.Message.ReplyToMessage != nil { // handle admin declineion reason repliedMsg := update.Message.ReplyToMessage - if strings.Contains(repliedMsg.Text, "(no reason provided, reply to this to send one)") { + if strings.Contains(repliedMsg.Text, "(no reason provided, reply to this to send one, prepend with + to also send to user)") { // now we need to make sure the one that declined it is the one replying lines := strings.Split(repliedMsg.Text, "\n") if strings.TrimPrefix(lines[3], "Declined by: ") == update.Message.From.String() { + reason := escapeHTML(update.Message.Text) + if after, ok := strings.CutPrefix(update.Message.Text, "+"); ok { + reason = escapeHTML(after) + } userID, username, joinReason, declinedBy, declinedAt := GetInfoFromMsg(repliedMsg.Text) edit := api.NewEditMessageText(b.Config.AdminChatId, repliedMsg.MessageID, fmt.Sprintf(AdminDeclinedMsg, - username, userID, joinReason, declinedBy, declinedAt, escapeHTML(update.Message.Text))) + username, userID, joinReason, declinedBy, declinedAt, reason)) edit.ParseMode = api.ModeHTML b.API.Send(edit) m := api.NewMessage(userID, fmt.Sprintf("Your join request was declined for the following reason:\n\n%s", @@ -213,7 +217,7 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) { } edit := api.NewEditMessageText(bot.Config.AdminChatId, user.JoinRequestMessageID, fmt.Sprintf(AdminDeclinedMsg, - userString, user.From.ID, user.JoinReason, query.From.String(), time.Now().Format("2006-01-02 15:04:05"), "(no reason provided, reply to this to send one)")) + userString, user.From.ID, user.JoinReason, query.From.String(), time.Now().Format("2006-01-02 15:04:05"), "(no reason provided, reply to this to send one, prepend with + to also send to user)")) edit.ParseMode = api.ModeHTML bot.API.Send(edit) @@ -221,6 +225,16 @@ func (bot *Bot) handleCallbackQuery(query *api.CallbackQuery) { bot.API.Request(callback) } + if bot.Config.DeleteRequestAfterDecision { + deleteTimer := time.NewTimer(10 * time.Second) + go func() { + <-deleteTimer.C + + del := api.NewDeleteMessage(bot.Config.AdminChatId, user.JoinRequestMessageID) + bot.API.Send(del) + }() + } + delete(bot.WaitingForApproval, userId) } }