def __handleCHOOSE_REGION(self, msg, btnText, btnId):
logDebug("__handleCHOOSE_REGION: {}#{}".format(btnText, btnId))
userId = msg.from_user.id
rows = self._db.fetchall("SELECT COUNT(id) FROM orders WHERE consumer_id={} AND cancelled=true".format(userId))
numCanceled = rows[0][0]
if numCanceled > MAX_ORDERS_PER_24H:
pass # TODO: Можно что-то сделать если пользователь отменил очень много заказов
self.__sendMessage(
userId, "За последние сутки Вы уже отменили {}. ".format(numCanceled) +
"При отмене больше {} заказов за 24 часа Вы будете автоматически забанены навсегда.".format(
MAX_ORDERS_PER_24H))
if self.__checkUserHasOrder(userId):
self.__setUserMenu(userId, self.UserMenu.ORDER_CREATED)
self.__sendORDER_CREATED(msg)
return
self._Memories[userId].Region = DB.Region([btnId, self._Memories[userId].City.id, btnText])
self.__createOrder(userId)
self.__sendMessage(userId, "Заказ создан!")
self.__setUserMenu(userId, self.UserMenu.CHOOSE_PAYMENT_METHOD)
self.__sendCHOOSE_PAYMENT_METHOD(msg)
def handleCallback(self, msg):
if not self.__receiveMessage():
return
userId = msg.from_user.id
logDebug("Received callback: {}".format(msg.data))
if not self.__updateUserMem(userId):
self.__handleStart(msg)
return
self.__updateUserMem(userId)
switcher = {
self.UserMenu.CHOOSE_CITY: self.__handleCHOOSE_CITY,
self.UserMenu.CHOOSE_PRODUCT: self.__handleCHOOSE_PRODUCT,
self.UserMenu.CHOOSE_REGION: self.__handleCHOOSE_REGION,
self.UserMenu.CHOOSE_PAYMENT_METHOD: self.__handleCHOOSE_PAYMENT_METHOD,
self.UserMenu.ORDER_READY: self.__handleORDER_READY,
self.UserMenu.ORDER_STATUS: self.__handleORDER_STATUS,
self.UserMenu.CANCEL_ORDER: self.__handleCANCEL_ORDER,
self.UserMenu.ORDER_CREATED: self.__handleORDER_CREATED,
self.UserMenu.USER_REVIEWS: self.__handleUSER_REVIEWS,
# Специальные меню
self.UserMenu.ADMIN: self.__handleADMIN,
self.UserMenu.ADMIN_REVIEWS: self.__handleADMIN_REVIEWS
}
func = switcher.get(self.__getMenuFromCallback(msg))
if func:
func(msg, self.__getBtnTextFromCallback(msg), self.__getBtnIdFromCallback(msg))
else:
logError("Unable to handle callback: {}".format(msg.data))
self.__handleORDER_STATUS_help(msg)
@client.callback_query_handler(func=lambda call: True)
def callbackHandler(call):
bot.handleCallback(call)