package main import ( tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" "strconv" ) func (ctx *Context) handleUpdate(update tgbotapi.Update) { if update.Message != nil { ctx.messageHandler(update) } if update.CallbackQuery != nil { ctx.callbackQueryHandler(update) } } func (ctx *Context) callbackQueryHandler(update tgbotapi.Update) { if !ctx.isAuth(update.CallbackQuery.From.ID) || len(update.CallbackQuery.Data) < 3 { ctx.callbackQuery(update.CallbackQuery.ID, "āŒ Unauthorized") return } if update.CallbackQuery.Data == "next" { ctx.Next <- update.CallbackQuery.From.ID ctx.callbackQuery(update.CallbackQuery.ID, "āœ… Confirmed") return } queryType := update.CallbackQuery.Data[0] queryCmd := rune(update.CallbackQuery.Data[1]) queryID, err := strconv.Atoi(update.CallbackQuery.Data[2:]) if err != nil { return } if queryType == 'w' { ctx.editWip(queryCmd, queryID, update.CallbackQuery.Message.Chat.ID, update.CallbackQuery.Message.MessageID, update.CallbackQuery.ID) } } func (ctx *Context) messageHandler(update tgbotapi.Update) { if ctx.isAuth(update.Message.From.ID) { if update.Message.Sticker != nil { ctx.createProject(update.Message.Sticker.FileID, update.Message.From.ID) } if update.Message.Photo != nil { if len(update.Message.Photo) > 0 { ctx.createProject(update.Message.Photo[len(update.Message.Photo)-1].FileID, update.Message.From.ID) } } if update.Message.Document != nil { ctx.createProject(update.Message.Document.FileID, update.Message.From.ID) } } else { if update.Message.Sticker != nil || update.Message.Photo != nil || update.Message.Document != nil { ctx.sendMessage(update.Message.From.ID, "šŸ›‘ You currently don't have the authorization to print. Check for a passcode near the printer and send it here as a message.") } } if update.Message.Text == "/start" { ctx.startHandler(update) } if update.Message.Text == ctx.Settings.Password && !ctx.isAuth(update.Message.From.ID) { ctx.PassedPasswordCheck = append(ctx.PassedPasswordCheck, update.Message.From.ID) ctx.sendMessage(update.Message.From.ID, "āœ… Authorized") } if update.Message.From.ID == ctx.Settings.Admin && update.Message.Text == "/next" { ctx.Next <- update.Message.From.ID ctx.sendMessage(update.Message.From.ID, "sent, left: "+strconv.Itoa(len(ctx.Next))) } } func (ctx *Context) startHandler(update tgbotapi.Update) { txt := "šŸ‘‹ Welcome to PublicPrintBot! Send me a sticker, a photo or file and I will print it for you." if !ctx.isAuth(update.Message.From.ID) { txt += "\n\nšŸ›‘ You currently don't have the authorization to print. Check for a passcode near the printer and send it here as a message." } kb := tgbotapi.NewInlineKeyboardMarkup( tgbotapi.NewInlineKeyboardRow( tgbotapi.NewInlineKeyboardButtonURL("šŸ“š Code", "https://git.massivebox.net/massivebox/publicprintbot"), ), ) ctx.sendMessage(update.Message.From.ID, txt, kb) }