def lnk(c): bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) db_vote_set(c.from_user.id, db_vote_get(c.from_user.id) - 5) bot.send_message(c.message.chat.id, "*ID:" + str(c.from_user.id) + " Profile*" + "\n" + "Vote points: " + str(db_vote_get(c.from_user.id)) + "\n" + constants.LIKE_DISLIKE + str(db_value_get(c.from_user.id, "like")) + "|" + str(db_value_get(c.from_user.id, "dislike")), parse_mode="Markdown", reply_markup=prof_keyboard())
def del_actions(c): if c.data == 'del_to_prof': bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) bot.send_message(c.message.chat.id, "*ID:" + str(c.from_user.id) + " Profile*" + "\n" + "Vote points: " + str(db_vote_get(c.from_user.id)) + "\n" + constants.LIKE_DISLIKE + str(db_value_get(c.from_user.id, "like")) + "|" + str(db_value_get(c.from_user.id, "dislike")), parse_mode="Markdown", reply_markup=prof_keyboard()) elif c.data == 'delete_photo1': db_ph_set(c.from_user.id, 1, "None") bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) bot.send_message(c.message.chat.id, "*ID:" + str(c.from_user.id) + " Profile*" + "\n" + "Vote points: " + str(db_vote_get(c.from_user.id)) + "\n" + constants.LIKE_DISLIKE + str(db_value_get(c.from_user.id, "like")) + "|" + str(db_value_get(c.from_user.id, "dislike")), parse_mode="Markdown", reply_markup=prof_keyboard()) elif c.data == 'delete_photo2': db_ph_set(c.from_user.id, 2, "None") bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) bot.send_message(c.message.chat.id, "*ID:" + str(c.from_user.id) + " Profile*" + "\n" + "Vote points: " + str(db_vote_get(c.from_user.id)) + "\n" + constants.LIKE_DISLIKE + str(db_value_get(c.from_user.id, "like")) + "|" + str(db_value_get(c.from_user.id, "dislike")), parse_mode="Markdown", reply_markup=prof_keyboard()) elif c.data == 'delete_photo3': db_ph_set(c.from_user.id, 3, "None") bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) bot.send_message(c.message.chat.id, "*ID:" + str(c.from_user.id) + " Profile*" + "\n" + "Vote points: " + str(db_vote_get(c.from_user.id)) + "\n" + constants.LIKE_DISLIKE + str(db_value_get(c.from_user.id, "like")) + "|" + str(db_value_get(c.from_user.id, "dislike")), parse_mode="Markdown", reply_markup=prof_keyboard())
def lnk_key(id): keyboard = types.InlineKeyboardMarkup() btns = [types.InlineKeyboardButton( text='You have enough vote points (' + str(db_vote_get(id)) + '). ' + '\n' + 'Tap to enter Profile... (-5)', callback_data='lnk')] keyboard.add(*btns) return keyboard
def warn_key(id): keyboard = types.InlineKeyboardMarkup() btns = [types.InlineKeyboardButton( text='You don\'t have enough vote points (' + str(db_vote_get(id)) + '). Tap to start voting', callback_data='warn')] keyboard.add(*btns) return keyboard
def main_menu(m): if m.text == constants.MENU_RATE: db_votelist_update(m.from_user.id) bot.send_chat_action(m.from_user.id, constants.BOT_ACTION_PH_UPLOAD) someID = db_votelist_get(m.from_user.id) notID = db_votedlist_get(m.from_user.id) ntrsc = intersection(someID, notID) if len(ntrsc) == someID: bot.send_message(m.from_user.id, constants.NO_NEW_PHOTOS) return else: for t in ntrsc: someID.remove(t) try: currID = int(someID[0]) usrrand = db_rand_get(m.from_user.id) idtovote = db_ph_get(currID, usrrand) bot.send_photo(m.from_user.id, idtovote, reply_markup=pages_keyboard(currID)) except IndexError: bot.send_message(m.from_user.id, constants.NO_NEW_PHOTOS) if m.text == constants.MENU_HELP: bot.send_chat_action(m.from_user.id, constants.BOT_ACTION_TYPING) bot.send_message(m.from_user.id, constants.HELP_TEXT, reply_markup=reg_keyboard()) if m.text == constants.MENU_PROFILE: if db_vote_get(m.from_user.id) is not None: if db_vote_get(m.from_user.id) < 5: bot.send_message(m.from_user.id, constants.POINTS_NOT_ENOUGH, reply_markup=warn_key(m.from_user.id)) else: bot.send_message(m.from_user.id, constants.POINTS_ENOUGH, reply_markup=lnk_key(m.from_user.id))
def callback_like(c): bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) db_vote_set(c.from_user.id, db_vote_get(c.from_user.id) + 1) nowid = int(c.data[-9:]) db_like_set(nowid, db_like_get(nowid) + 1) cvlst = db_value_get(c.from_user.id, "votedlist") if cvlst is not None: # Get current votedlist db_value_set(c.from_user.id, "votedlist", cvlst + str(nowid) + '\n') else: db_value_set(c.from_user.id, "votedlist", str(nowid) + '\n') bot.send_chat_action(c.from_user.id, 'upload_photo') currID = db_vote_not_voted_get(c.from_user.id) if currID is None: bot.send_message(c.from_user.id, constants.NO_NEW_PHOTOS) return usrrand = db_rand_get(c.from_user.id) idtovote = db_ph_get(currID, usrrand) bot.send_photo(c.message.chat.id, idtovote, reply_markup=pages_keyboard(currID))
def profile_actions(c): # Close Profile by deleting message with it if c.data == 'p_close': bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) bot.send_message(c.message.chat.id, constants.INFO_CLOSED) # DELETE OPTION elif c.data == 'p_del': bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) bot.send_message(c.message.chat.id, constants.DEL_SELECT, reply_markup=del_keyboard()) elif c.data == 'p_del_1': bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) sphoto = db_ph_get(c.from_user.id, 1) has = 1 if sphoto == constants.DB_EMPTY_STR: has = 0 sphoto = constants.NO_PHOTO_1_ID # NONE 1 PHOTO bot.send_photo(c.from_user.id, sphoto, reply_markup=del_page_keyboard(1, has)) elif c.data == 'p_del_2': bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) sphoto = db_ph_get(c.from_user.id, 2) has = 1 if sphoto == constants.DB_EMPTY_STR: has = 0 sphoto = constants.NO_PHOTO_2_ID # NONE 2 PHOTO bot.send_photo(c.from_user.id, sphoto, reply_markup=del_page_keyboard(2, has)) elif c.data == 'p_del_3': bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) sphoto = db_ph_get(c.from_user.id, 3) has = 1 if sphoto == constants.DB_EMPTY_STR: has = 0 sphoto = constants.NO_PHOTO_3_ID # NONE 3 PHOTO bot.send_photo(c.from_user.id, sphoto, reply_markup=del_page_keyboard(3, has)) elif c.data == 'p_my': bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) bot.send_message(c.message.chat.id, constants.DEL_SELECT, reply_markup=my_keyboard()) elif c.data == 'p_my_1': bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) sphoto = db_ph_get(c.from_user.id, 1) has = 1 if sphoto == constants.DB_EMPTY_STR: has = 0 sphoto = constants.NO_PHOTO_1_ID # NONE 1 PHOTO bot.send_photo(c.from_user.id, sphoto, reply_markup=my_page_keyboard()) elif c.data == 'p_my_2': bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) sphoto = db_ph_get(c.from_user.id, 2) has = 1 if sphoto == constants.DB_EMPTY_STR: has = 0 sphoto = constants.NO_PHOTO_2_ID # NONE 2 PHOTO bot.send_photo(c.from_user.id, sphoto, reply_markup=my_page_keyboard()) elif c.data == 'p_my_3': bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) sphoto = db_ph_get(c.from_user.id, 3) has = 1 if sphoto == constants.DB_EMPTY_STR: has = 0 sphoto = constants.NO_PHOTO_3_ID # NONE 3 PHOTO bot.send_photo(c.from_user.id, sphoto, reply_markup=my_page_keyboard()) elif c.data == 'p_to_my': bot.delete_message(chat_id=c.message.chat.id, message_id=c.message.message_id) bot.send_message(c.message.chat.id, "*ID:" + str(c.from_user.id) + " Profile*" + "\n" + "Vote points: " + str(db_vote_get(c.from_user.id)) + "\n" + constants.LIKE_DISLIKE + str(db_value_get(c.from_user.id, "like")) + "|" + str(db_value_get(c.from_user.id, "dislike")), parse_mode="Markdown", reply_markup=prof_keyboard())