2017-12-23 01:40:36 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package router
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
|
|
|
"regexp"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// RouteCallback routes inline requests to bot
|
|
|
|
|
func (r *Router) RouteCallback(update *tgbotapi.Update) string {
|
2018-01-29 23:50:25 +04:00
|
|
|
|
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.CallbackQuery.From.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Log.Error(err.Error())
|
2017-12-23 01:40:36 +04:00
|
|
|
|
return "fail"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var enableAlarmCallback = regexp.MustCompile("enable_reminder_(\\d+)\\z")
|
|
|
|
|
var disableAlarmCallback = regexp.MustCompile("disable_reminder_(\\d+)\\z")
|
|
|
|
|
|
|
|
|
|
switch {
|
|
|
|
|
case enableAlarmCallback.MatchString(update.CallbackQuery.Data):
|
2018-01-29 23:50:25 +04:00
|
|
|
|
return c.Reminder.CreateAlarmSetting(update, playerRaw)
|
2017-12-23 01:40:36 +04:00
|
|
|
|
case disableAlarmCallback.MatchString(update.CallbackQuery.Data):
|
2018-01-29 23:50:25 +04:00
|
|
|
|
return c.Reminder.DestroyAlarmSetting(update, playerRaw)
|
2017-12-23 01:40:36 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "ok"
|
|
|
|
|
}
|