From 334fe2bf8f84228ef0e0bfabb0fd4173a29ebb62 Mon Sep 17 00:00:00 2001 From: Astra Date: Thu, 2 Apr 2026 13:29:12 +0100 Subject: [PATCH] Apply patch --- config/config.go | 4 +++- handlers/callbacks.go | 19 +++++++++++++++++++ handlers/join.go | 18 +++++++++++++++++- pkg/utils/utils.go | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 45215ea..51b4d4e 100644 --- a/config/config.go +++ b/config/config.go @@ -14,6 +14,7 @@ type Config struct { TargetChatId *int64 `yaml:"target_chat_id"` EntryMessage string `yaml:"entry_message"` ApprovalMessage string `yaml:"approval_message"` + ReminderMessage string `yaml:"reminder_message"` SendApprovalMessage bool `yaml:"send_approval_message"` DeleteRequestAfterDecision bool `yaml:"delete_request_after_decision"` CannedDeclineResponses []string `yaml:"canned_decline_responses"` @@ -44,7 +45,8 @@ func (c *Config) CreateConfig() error { AdminChatId: Int64Ptr(0), AdminChatTopicId: IntPtr(0), TargetChatId: Int64Ptr(0), - EntryMessage: "You have requested to join the group, please write a brief message explaining why you want to join.", + EntryMessage: "You have requested to join the group. Please write a brief message explaining why you want to join.", + ReminderMessage: "Don't forget to give a one-message response to your join request.", ApprovalMessage: "", SendApprovalMessage: false, DeleteRequestAfterDecision: false, diff --git a/handlers/callbacks.go b/handlers/callbacks.go index 59afc85..d39bc18 100644 --- a/handlers/callbacks.go +++ b/handlers/callbacks.go @@ -46,6 +46,9 @@ func (bot *Bot) HandleCallbackQuery(query *api.CallbackQuery) { case "banc": bot.handleBanRequest(query, user, userString, adminUserString) bot.DeletePendingUser(args) + case "remind": + bot.sendReminder(query, user, userString, adminUserString) + bot.API.Request(api.NewCallback(query.ID, "Reminder sent!")) case "cannedrespsel": parts := strings.Split(query.Data, "_") if len(parts) >= 3 { @@ -63,6 +66,22 @@ func (bot *Bot) HandleCallbackQuery(query *api.CallbackQuery) { } } +func (bot *Bot) sendReminder(query *api.CallbackQuery, user *ExtendedChatJoinRequest, userString, adminUserString string) { + utils.SendMessage(bot.API, user.From.ID, 0, bot.Config.ReminderMessage) + + // Edit admin message to show reminder was sent + messageText := fmt.Sprintf(AdminJoinRequestMsg, userString, user.From.ID, user.JoinReason) + messageText += fmt.Sprintf("\n\nReminder sent by: %s\nReminder sent at: %s", + adminUserString, time.Now().Format("2006-01-02 15:04:05")) + + keyboard := utils.NewApprovalKeyboard(user.From.ID) + + edit := api.NewEditMessageText(query.Message.Chat.ID, query.Message.MessageID, messageText) + edit.ParseMode = api.ModeHTML + edit.ReplyMarkup = &keyboard + bot.API.Send(edit) +} + // handleApproveRequest approves a join request and sends an approval callback. func (bot *Bot) handleApproveRequest(query *api.CallbackQuery, user *ExtendedChatJoinRequest, userString, adminUserString string) { r := api.ApproveChatJoinRequestConfig{ diff --git a/handlers/join.go b/handlers/join.go index b050d11..9badd98 100644 --- a/handlers/join.go +++ b/handlers/join.go @@ -19,6 +19,10 @@ func (bot *Bot) HandleJoinRequestResponse(user *ExtendedChatJoinRequest, update userString := utils.BuildUserString(&user.From) keyboard := utils.NewApprovalKeyboard(user.From.ID) + if bot.Config.ReminderMessage != "" { + newButton := api.NewInlineKeyboardButtonData("Send Reminder", fmt.Sprintf("remind_%d", user.From.ID)) + keyboard.InlineKeyboard[1] = append([]api.InlineKeyboardButton{newButton}, keyboard.InlineKeyboard[1]...) + } utils.EditMessageWithKeyboard(bot.API, *bot.Config.AdminChatId, user.JoinRequestMessageID, fmt.Sprintf(AdminJoinRequestMsg, userString, user.From.ID, user.JoinReason), &keyboard) @@ -27,12 +31,24 @@ func (bot *Bot) HandleJoinRequestResponse(user *ExtendedChatJoinRequest, update // HandleJoinRequest initiates the join approval flow by sending the entry message and admin notification. func (bot *Bot) HandleJoinRequest(request *api.ChatJoinRequest) { + // Check if user already has a pending request + if existingUser := bot.GetPendingUser(request.From.ID); existingUser != nil { + utils.SendMessage(bot.API, request.From.ID, 0, + "You have already requested to join. Please send a single message as your join reason.") + return + } + utils.SendMessage(bot.API, request.From.ID, 0, bot.Config.EntryMessage) userString := utils.BuildUserString(&request.From) + keyboard := utils.NewApprovalKeyboard(request.From.ID) + if bot.Config.ReminderMessage != "" { + newButton := api.NewInlineKeyboardButtonData("Send Reminder", fmt.Sprintf("remind_%d", request.From.ID)) + keyboard.InlineKeyboard[1] = append([]api.InlineKeyboardButton{newButton}, keyboard.InlineKeyboard[1]...) + } m := api.NewMessage(*bot.Config.AdminChatId, fmt.Sprintf(AdminJoinRequestMsg, userString, request.From.ID, "(awaiting user response)")) - m.ReplyMarkup = utils.NewApprovalKeyboard(request.From.ID) + m.ReplyMarkup = keyboard m.ParseMode = api.ModeHTML m.LinkPreviewOptions = api.LinkPreviewOptions{IsDisabled: true} if topic := *bot.Config.AdminChatTopicId; topic != 0 { diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 1456b40..c18a452 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -38,7 +38,7 @@ func EscapeHTML(s string) string { func NewApprovalKeyboard(userID int64) api.InlineKeyboardMarkup { approveBtn := api.NewInlineKeyboardButtonData("Approve", fmt.Sprintf("approve_%d", userID)) declineBtn := api.NewInlineKeyboardButtonData("Decline", fmt.Sprintf("decline_%d", userID)) - banBtn := api.NewInlineKeyboardButtonData("Ban (24h)", fmt.Sprintf("ban_%d", userID)) + banBtn := api.NewInlineKeyboardButtonData("⚠️ Ban (24h)", fmt.Sprintf("ban_%d", userID)) return api.NewInlineKeyboardMarkup( []api.InlineKeyboardButton{approveBtn, declineBtn}, []api.InlineKeyboardButton{banBtn},