def my_tacos_callback(bot, message): """ shows users taco-balance """ cid = get_cid(message) uid = str(get_uid(message)) with db: chat = Chats.get(Chats.cid == message.chat.id) tacos = Tacos.get(Tacos.chat == cid) balances = tacos.taco_balance delete_message(bot, message) user_name = store_name(message.from_user) if uid in balances.keys(): balance = balances.get(uid) else: balances.update({uid: default_taco_amount}) tacos.taco_balance = balances tacos.save() balance = default_taco_amount if chat.less is True: comment = '' else: if balance < 25: comment = balance_comment_low elif balance > 60: comment = balance_comment_high else: comment = balance_comment_medium if chat.autohide: msg = bot.send_message(chat_id=cid, text=balance_phrase.format(user_name, balance, comment), reply_to_message_id=get_mid(message), parse_mode='html') time = datetime.datetime.now() + datetime.timedelta(minutes=chat.autohide_delay) sched.add_job(delete_message, 'date', run_date=time, args=[bot, msg]) else: ok_button = InlineKeyboardButton('OK', callback_data='delete:{}'.format(message.from_user.id)) ok_keyboard = InlineKeyboardMarkup([[ok_button]]) msg = bot.send_message(chat_id=cid, text=balance_phrase.format(user_name, balance, comment), reply_to_message_id=get_mid(message), reply_markup=ok_keyboard, parse_mode='html') chat.mids = [msg.message_id] chat.save()
def my_tacos_callback(bot, message): """ shows users taco-balance """ cid = get_cid(message) chat = Chats.get(Chats.cid == message.chat.id) clean_chat(chat.mids, chat.cid, message, bot) store_name(message) uid = str(get_uid(message)) tacos = Tacos.get(Tacos.chat == cid) ok_button = InlineKeyboardButton('OK', callback_data='delete:{}'.format( message.from_user.id)) ok_keyboard = InlineKeyboardMarkup([[ok_button]]) balances = json.loads(tacos.taco_balance) if uid in balances.keys(): balance = balances.get(uid) else: balances.update({uid: default_taco_amount}) tacos.taco_balance = json.dumps(balances) tacos.save() balance = default_taco_amount if chat.less is True: comment = '' else: if balance < 25: comment = balance_comment_low elif balance > 60: comment = balance_comment_high else: comment = balance_comment_medium mid = bot.send_message(chat_id=cid, text=balance_phrase.format(balance, comment), reply_to_message_id=get_mid(message), reply_markup=ok_keyboard, parse_mode='html').message_id chat.mids = json.dumps([mid]) chat.save()
def help_callback(bot, message): """ callback for /help (private) """ uid = get_uid(message) bot.send_message(uid, help_phrase, parse_mode='html')
def start_callback(bot, message): """ callback for /start (private) """ uid = get_uid(message) bot.send_message(uid, start_phrase, parse_mode='html')