go fmt
This commit is contained in:
parent
61214ca405
commit
b7c01addcf
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user