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
|
"/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() {
|
func main() {
|
||||||
var bc = GetBotController()
|
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) {
|
func handlePanelCommand(bc BotController, update tgbotapi.Update, user User) {
|
||||||
handlePanel(bc, user)
|
handlePanel(bc, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleUserModeCommand(bc BotController, update tgbotapi.Update, user 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) {
|
func handlePanelCallback(bc BotController, update tgbotapi.Update, user User) {
|
||||||
handlePanel(bc, user)
|
handlePanel(bc, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DownloadFile(filepath string, url string) error {
|
func DownloadFile(filepath string, url string) error {
|
||||||
@ -315,12 +315,12 @@ func DownloadFile(filepath string, url string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func notifyAdminAboutError(bc BotController, errorMessage string) {
|
func notifyAdminAboutError(bc BotController, errorMessage string) {
|
||||||
// admins := getAdmins(bc)
|
// admins := getAdmins(bc)
|
||||||
// for _, admin := range admins {
|
// for _, admin := range admins {
|
||||||
// bc.bot.Send(tgbotapi.NewMessage(admin.ID, "ChannelID is set to "+strconv.FormatInt(post.SenderChat.ID, 10)))
|
// 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)
|
// delcmd := tgbotapi.NewDeleteMessage(post.SenderChat.ID, post.MessageID)
|
||||||
// bc.bot.Send(delcmd)
|
// bc.bot.Send(delcmd)
|
||||||
// }
|
// }
|
||||||
// Check if AdminID is set in the config
|
// Check if AdminID is set in the config
|
||||||
adminID := *bc.cfg.AdminID
|
adminID := *bc.cfg.AdminID
|
||||||
if adminID == 0 {
|
if adminID == 0 {
|
||||||
@ -335,7 +335,7 @@ func notifyAdminAboutError(bc BotController, errorMessage string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getAdmins(bc BotController) []User {
|
func getAdmins(bc BotController) []User {
|
||||||
var admins []User
|
var admins []User
|
||||||
bc.db.Where("role_bitmask & 1 = ?", 1).Find(&admins)
|
bc.db.Where("role_bitmask & 1 = ?", 1).Find(&admins)
|
||||||
return admins
|
return admins
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,24 +1,26 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
var assets = map[string]string {
|
var assets = map[string]string{
|
||||||
"Стартовая картинка": "preview_image",
|
"Стартовая картинка": "preview_image",
|
||||||
"Приветственный текст": "start",
|
"Приветственный текст": "start",
|
||||||
"Кнопка для заявки": "leave_ticket_button",
|
"Кнопка для заявки": "leave_ticket_button",
|
||||||
"ID чата": "supportchatid",
|
"ID чата": "supportchatid",
|
||||||
"ID канала": "channelid",
|
"ID канала": "channelid",
|
||||||
"Уведомление об отправке тикета": "sended_notify",
|
"Уведомление об отправке тикета": "sended_notify",
|
||||||
"Просьба оставить тикет": "leaveticket_message",
|
"Просьба оставить тикет": "leaveticket_message",
|
||||||
"Просьба подписаться на канал": "subscribe_message",
|
"Просьба подписаться на канал": "subscribe_message",
|
||||||
"Ссылка на канал": "channel_link",
|
"Ссылка на канал": "channel_link",
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePanel(bc BotController, user User) {
|
func handlePanel(bc BotController, user User) {
|
||||||
if !user.IsAdmin() {return}
|
if !user.IsAdmin() {
|
||||||
|
return
|
||||||
|
}
|
||||||
if !user.IsEffectiveAdmin() {
|
if !user.IsEffectiveAdmin() {
|
||||||
bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask|0b10)
|
bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask|0b10)
|
||||||
sendMessage(bc, user.ID, "You was in usermode, turned back to admin mode...")
|
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)
|
kbd := generateTgInlineKeyboard(m)
|
||||||
sendMessageKeyboard(bc, user.ID, "Выберите пункт для изменения", kbd)
|
sendMessageKeyboard(bc, user.ID, "Выберите пункт для изменения", kbd)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,24 +5,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Map[K comparable, T, V any](ts map[K]T, fn func(T) V) map[K]V {
|
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))
|
result := make(map[K]V, len(ts))
|
||||||
for k, t := range ts {
|
for k, t := range ts {
|
||||||
result[k] = fn(t)
|
result[k] = fn(t)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTgInlineKeyboard(buttonsCallback map[string]string) tgbotapi.InlineKeyboardMarkup {
|
func generateTgInlineKeyboard(buttonsCallback map[string]string) tgbotapi.InlineKeyboardMarkup {
|
||||||
rows := [][]tgbotapi.InlineKeyboardButton{}
|
rows := [][]tgbotapi.InlineKeyboardButton{}
|
||||||
for k, v := range buttonsCallback {
|
for k, v := range buttonsCallback {
|
||||||
rows = append(rows,
|
rows = append(rows,
|
||||||
tgbotapi.NewInlineKeyboardRow(
|
tgbotapi.NewInlineKeyboardRow(
|
||||||
tgbotapi.NewInlineKeyboardButtonData(k, v),
|
tgbotapi.NewInlineKeyboardButtonData(k, v),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tgbotapi.NewInlineKeyboardMarkup(rows...)
|
return tgbotapi.NewInlineKeyboardMarkup(rows...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendMessage(bc BotController, UserID int64, Msg string) {
|
func sendMessage(bc BotController, UserID int64, Msg string) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user