From 849454016d483e48c7a5d3447fe1d12941901c08 Mon Sep 17 00:00:00 2001 From: Astra Date: Thu, 29 Jan 2026 15:09:59 +0000 Subject: [PATCH] Fix declined reason breaking formatting --- main.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 2b8970a..dbfa182 100644 --- a/main.go +++ b/main.go @@ -80,13 +80,12 @@ func main() { // 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() { - + userID, username, joinReason, declinedBy, declinedAt := GetInfoFromMsg(repliedMsg.Text) edit := api.NewEditMessageText(b.Config.AdminChatId, repliedMsg.MessageID, - strings.Replace(repliedMsg.Text, "(no reason provided, reply to this to send one)", - escapeHTML(update.Message.Text), 1)) + fmt.Sprintf(AdminDeclinedMsg, + username, userID, joinReason, declinedBy, declinedAt, escapeHTML(update.Message.Text))) edit.ParseMode = api.ModeHTML b.API.Send(edit) - userID := GetUserIDFromMessage(repliedMsg.Text) m := api.NewMessage(userID, fmt.Sprintf("Your join request was declined for the following reason:\n\n%s", update.Message.Text)) b.API.Send(m) @@ -257,9 +256,15 @@ func newApprovalKeyboard(userID int64) api.InlineKeyboardMarkup { return api.NewInlineKeyboardMarkup([]api.InlineKeyboardButton{approveBtn, declineBtn}) } -func GetUserIDFromMessage(msg string) int64 { +func GetInfoFromMsg(msg string) (userId int64, username, joinReason, declinedBy, declinedAt string) { start := strings.Index(msg, "[") end := strings.Index(msg, "]") - num, _ := strconv.Atoi(msg[start+1 : end]) - return int64(num) + userID, _ := strconv.Atoi(msg[start+1 : end]) + username = msg[31 : start-1] + lines := strings.Split(msg, "\n") + joinReason = strings.TrimPrefix(lines[2], "Join reason: ") + declinedBy = strings.TrimPrefix(lines[3], "Declined by: ") + declinedAt = strings.TrimPrefix(lines[4], "Declined at: ") + + return int64(userID), username, joinReason, declinedBy, declinedAt }