Vladimir Hodakov
b8226d8aa8
Recent game update changed pokememes view in pokedeks, so we need to reflect it by updating parser. Introducing DataCache - a silver bullet for eliminating lags linked to database queries. Less queries, more in RAM, faster work. Needs testing in production environment.
31 lines
878 B
Go
31 lines
878 B
Go
// 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 {
|
||
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.CallbackQuery.From.ID)
|
||
if err != nil {
|
||
c.Log.Error(err.Error())
|
||
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):
|
||
return c.Reminder.CreateAlarmSetting(update, playerRaw)
|
||
case disableAlarmCallback.MatchString(update.CallbackQuery.Data):
|
||
return c.Reminder.DestroyAlarmSetting(update, playerRaw)
|
||
}
|
||
|
||
return "ok"
|
||
}
|