From b7c01addcfb5a9356b66a6c6d9d2b22a83130e68 Mon Sep 17 00:00:00 2001 From: Akulij Date: Fri, 28 Mar 2025 15:48:57 +0800 Subject: [PATCH] go fmt --- cmd/app/main.go | 24 ++++++++++++------------ cmd/app/panel.go | 28 +++++++++++++++------------- cmd/app/tghelper.go | 32 ++++++++++++++++---------------- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/cmd/app/main.go b/cmd/app/main.go index 0931921..077e2f4 100644 --- a/cmd/app/main.go +++ b/cmd/app/main.go @@ -21,7 +21,7 @@ var adminCommands = map[string]func(BotController, tgbotapi.Update, User){ "/setchannelid": handleDefaultMessage, // just type it in channel which one is supposed to be lined with bot } -var nearDatesApril = []int {1, 3} // why? because it is as temporal as it can be +var nearDatesApril = []int{1, 3} // why? because it is as temporal as it can be func main() { var bc = GetBotController() @@ -140,7 +140,7 @@ func handleSecretCommand(bc BotController, update tgbotapi.Update, user User) { } func handlePanelCommand(bc BotController, update tgbotapi.Update, user User) { - handlePanel(bc, user) + handlePanel(bc, user) } func handleUserModeCommand(bc BotController, update tgbotapi.Update, user User) { @@ -290,7 +290,7 @@ func handleAdminCallback(bc BotController, update tgbotapi.Update, user User) { } func handlePanelCallback(bc BotController, update tgbotapi.Update, user User) { - handlePanel(bc, user) + handlePanel(bc, user) } func DownloadFile(filepath string, url string) error { @@ -315,12 +315,12 @@ func DownloadFile(filepath string, url string) error { } func notifyAdminAboutError(bc BotController, errorMessage string) { - // admins := getAdmins(bc) - // for _, admin := range admins { - // bc.bot.Send(tgbotapi.NewMessage(admin.ID, "ChannelID is set to "+strconv.FormatInt(post.SenderChat.ID, 10))) - // delcmd := tgbotapi.NewDeleteMessage(post.SenderChat.ID, post.MessageID) - // bc.bot.Send(delcmd) - // } + // admins := getAdmins(bc) + // for _, admin := range admins { + // bc.bot.Send(tgbotapi.NewMessage(admin.ID, "ChannelID is set to "+strconv.FormatInt(post.SenderChat.ID, 10))) + // delcmd := tgbotapi.NewDeleteMessage(post.SenderChat.ID, post.MessageID) + // bc.bot.Send(delcmd) + // } // Check if AdminID is set in the config adminID := *bc.cfg.AdminID if adminID == 0 { @@ -335,7 +335,7 @@ func notifyAdminAboutError(bc BotController, errorMessage string) { } func getAdmins(bc BotController) []User { - var admins []User - bc.db.Where("role_bitmask & 1 = ?", 1).Find(&admins) - return admins + var admins []User + bc.db.Where("role_bitmask & 1 = ?", 1).Find(&admins) + return admins } diff --git a/cmd/app/panel.go b/cmd/app/panel.go index fb7634c..63ae503 100644 --- a/cmd/app/panel.go +++ b/cmd/app/panel.go @@ -1,24 +1,26 @@ package main -var assets = map[string]string { - "Стартовая картинка": "preview_image", - "Приветственный текст": "start", - "Кнопка для заявки": "leave_ticket_button", - "ID чата": "supportchatid", - "ID канала": "channelid", - "Уведомление об отправке тикета": "sended_notify", - "Просьба оставить тикет": "leaveticket_message", - "Просьба подписаться на канал": "subscribe_message", - "Ссылка на канал": "channel_link", +var assets = map[string]string{ + "Стартовая картинка": "preview_image", + "Приветственный текст": "start", + "Кнопка для заявки": "leave_ticket_button", + "ID чата": "supportchatid", + "ID канала": "channelid", + "Уведомление об отправке тикета": "sended_notify", + "Просьба оставить тикет": "leaveticket_message", + "Просьба подписаться на канал": "subscribe_message", + "Ссылка на канал": "channel_link", } func handlePanel(bc BotController, user User) { - if !user.IsAdmin() {return} + if !user.IsAdmin() { + return + } if !user.IsEffectiveAdmin() { bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask|0b10) sendMessage(bc, user.ID, "You was in usermode, turned back to admin mode...") } - m := Map(assets, func(v string) string { return "update:" + v }) + m := Map(assets, func(v string) string { return "update:" + v }) kbd := generateTgInlineKeyboard(m) - sendMessageKeyboard(bc, user.ID, "Выберите пункт для изменения", kbd) + sendMessageKeyboard(bc, user.ID, "Выберите пункт для изменения", kbd) } diff --git a/cmd/app/tghelper.go b/cmd/app/tghelper.go index 119974f..0159fbf 100644 --- a/cmd/app/tghelper.go +++ b/cmd/app/tghelper.go @@ -5,33 +5,33 @@ import ( ) func Map[K comparable, T, V any](ts map[K]T, fn func(T) V) map[K]V { - result := make(map[K]V, len(ts)) - for k, t := range ts { - result[k] = fn(t) - } - return result + result := make(map[K]V, len(ts)) + for k, t := range ts { + result[k] = fn(t) + } + return result } func generateTgInlineKeyboard(buttonsCallback map[string]string) tgbotapi.InlineKeyboardMarkup { - rows := [][]tgbotapi.InlineKeyboardButton{} - for k, v := range buttonsCallback { - rows = append(rows, - tgbotapi.NewInlineKeyboardRow( - tgbotapi.NewInlineKeyboardButtonData(k, v), - ), - ) - } + rows := [][]tgbotapi.InlineKeyboardButton{} + for k, v := range buttonsCallback { + rows = append(rows, + tgbotapi.NewInlineKeyboardRow( + tgbotapi.NewInlineKeyboardButtonData(k, v), + ), + ) + } - return tgbotapi.NewInlineKeyboardMarkup(rows...) + return tgbotapi.NewInlineKeyboardMarkup(rows...) } func sendMessage(bc BotController, UserID int64, Msg string) { msg := tgbotapi.NewMessage(UserID, Msg) bc.bot.Send(msg) -} +} func sendMessageKeyboard(bc BotController, UserID int64, Msg string, Kbd tgbotapi.InlineKeyboardMarkup) { msg := tgbotapi.NewMessage(UserID, Msg) msg.ReplyMarkup = Kbd bc.bot.Send(msg) -} +}