func sendToChat(bot *tgbotapi.BotAPI, message string) { chatid, err := strconv.Atoi(os.Getenv("TG_CHAT_ID")) if err != nil { log.Fatal(err) } msgconf := tgbotapi.NewMessage(int64(chatid), message) bot.Send(msgconf) }
func botman(b *tgbotapi.BotAPI, u tgbotapi.UpdateConfig) error { const defaultMessage = `Choose your destiny!` keyboard := tgbotapi.NewKeyboardButtonRow( tgbotapi.NewKeyboardButton(`/easy`), tgbotapi.NewKeyboardButton(`/hard`)) updates, err := b.GetUpdatesChan(u) if err != nil { return err } for update := range updates { chatID := update.Message.Chat.ID text := update.Message.Text if b.Debug == true { log.Printf("[%s] %s", update.Message.From.UserName, text) } switch text { case "/start": { msg := tgbotapi.NewMessage(chatID, defaultMessage) msg.ReplyMarkup = tgbotapi.NewReplyKeyboard(keyboard) b.Send(msg) } case "/stop": { msg := tgbotapi.NewMessage(chatID, `SeeYa!`) msg.ReplyMarkup = tgbotapi.ReplyKeyboardHide{HideKeyboard: true} b.Send(msg) } case "/easy": { msg := tgbotapi.NewMessage(chatID, genPass(10)) b.Send(msg) } case "/hard": { msg := tgbotapi.NewMessage(chatID, genPass(20)) b.Send(msg) } default: { msg := tgbotapi.NewMessage(chatID, defaultMessage) b.Send(msg) } } } return nil }