def cancel_chat(update: Update, context: CallbackContext): tel_id = active_chats.get(update.callback_query.message.chat.id, None) if tel_id: Db.get_instance().update_user_disconnected(tel_id) Db.get_instance().update_user_disconnected(active_chats[tel_id]) req = Request() req.make(tel_id, active_chats[tel_id], 1) Db.get_instance().update_request(req) req.make(active_chats[tel_id], tel_id, 1) Db.get_instance().update_request(req) delete_msg(tel_id, context) delete_msg(active_chats[tel_id], context) active_commands[tel_id] = context.bot.send_message( text=f'``` Chat Cancelled ```', parse_mode=ParseMode.MARKDOWN, chat_id=tel_id).message_id active_commands[active_chats[tel_id]] = context.bot.send_message( text=f'``` Chat Cancelled ```', parse_mode=ParseMode.MARKDOWN, chat_id=active_chats[tel_id]).message_id context.bot.send_message(text="/chat for chat settings", parse_mode=ParseMode.MARKDOWN, chat_id=active_chats[tel_id]) context.bot.send_message(text="/chat for chat settings", parse_mode=ParseMode.MARKDOWN, chat_id=tel_id) del active_chats[active_chats[tel_id]] del active_chats[tel_id]
def status_code(chat_id: int): if active_chats.get(chat_id, None): return 1 elif active_requests.get(chat_id, None): return 0 elif Db.get_instance().read_user_id(chat_id): return -1
def reveal(update: Update, context: CallbackContext) -> None: data = Db.get_instance().read_user_id( update.callback_query.message.chat_id) if data: if data.name == PLACEHOLDER: delete_msg(update.callback_query.message.chat.id, context) active_commands[ update.callback_query.message.chat. id] = context.bot.send_message( text="""``` You haven't provided the details```""", parse_mode=ParseMode.MARKDOWN, chat_id=update.callback_query.message.chat.id, ).message_id return else: data = Db.get_instance().read_user_id( active_chats[update.callback_query.message.chat_id]) if data: if data.name == PLACEHOLDER: delete_msg(update.callback_query.message.chat.id, context) active_commands[ update.callback_query.message.chat. id] = context.bot.send_message( text= """``` The user who's chatting with you hasn't provided the details```""", parse_mode=ParseMode.MARKDOWN, chat_id=update.callback_query.message.chat.id, ).message_id return keyboard = [ [ InlineKeyboardButton( "ACCEPT", callback_data=ACCEPT_REVEAL_CALLBACK_DATA), InlineKeyboardButton( "DECLINE", callback_data=DECLINE_REVEAL_CALLBACK_DATA), ], ] delete_msg( active_chats.get(update.callback_query.message.chat.id, None), context) delete_msg(update.callback_query.message.chat.id, context) active_commands[active_chats[ update.callback_query.message.chat.id]] = context.bot.send_message( text="""``` Reveal Request```""", parse_mode=ParseMode.MARKDOWN, chat_id=active_chats[update.callback_query.message.chat.id], reply_markup=InlineKeyboardMarkup(keyboard)).message_id active_commands[ update.callback_query.message.chat.id] = context.bot.send_message( text="""``` Reveal Request Sent```""", parse_mode=ParseMode.MARKDOWN, chat_id=update.callback_query.message.chat.id, ).message_id else: helper(update.callback_query.message.chat_id, context)
def decline_reveal_request(update: Update, context: CallbackContext) -> None: user_id = update.callback_query.message.chat.id delete_msg(active_chats.get(user_id, None), context) delete_msg(user_id, context) active_commands[active_chats[user_id]] = context.bot.send_message( text="``` Reveal Request Declined```", parse_mode=ParseMode.MARKDOWN, chat_id=active_chats[user_id]).message_id active_commands[user_id] = context.bot.send_message( text="``` Reveal Request Declined```", parse_mode=ParseMode.MARKDOWN, chat_id=user_id).message_id
def message_handler(update: Update, context: CallbackContext) -> None: if update.message.chat.id in black_list: return if check_for_name(update, context): return elif check_id(update, context): return elif check_batch(update, context): return if asked_questionnaire.get(update.message.chat.id, None): parse_questions(update, context) return if active_chats.get(update.message.chat.id, None): context.bot.send_message(text=update.message.text, chat_id=active_chats[update.message.chat.id])
def accept_reveal_request(update: Update, context: CallbackContext) -> None: user_id = update.callback_query.message.chat.id delete_msg(active_chats.get(user_id, None), context) delete_msg(user_id, context) data = Db.get_instance().read_user_id(user_id) if data: msg = f"``` Name:- {data.name}\n Instagram Id:- {data.instagram_id}\n Gender:- {data.GENDER[data.gender]}\n Year:- {data.batch}```" context.bot.send_message(text=msg, parse_mode=ParseMode.MARKDOWN, chat_id=active_chats[user_id]) data = Db.get_instance().read_user_id(active_chats[user_id]) if data: msg = f"``` Name:- {data.name}\n Instagram Id:- {data.instagram_id}\n Gender:- {data.GENDER[data.gender]}\n Year:- {data.batch}```" context.bot.send_message(text=msg, parse_mode=ParseMode.MARKDOWN, chat_id=user_id)
def sticker_handler(update: Update, context: CallbackContext): if update.message.chat.id in black_list: return if active_chats.get(update.message.chat.id, None): context.bot.send_sticker(sticker=update.message.sticker, chat_id=active_chats[update.message.chat.id])
def helper(chat_id, context): if chat_id in black_list: return if active_chats.get(chat_id, None): if Db.get_instance().get_questions(chat_id): menu = [[ InlineKeyboardButton("Reveal Identity Request", callback_data=REVEAL_IDENTITY_REQUEST), ], [ InlineKeyboardButton("Send Questionnaire", callback_data=QUESTIONNAIRE_SENT), ], [ InlineKeyboardButton("Report Chat", callback_data=REPORT_CHAT), InlineKeyboardButton("View/ Edit Questionnaire", callback_data=QUESTIONNAIRE) ], [ InlineKeyboardButton("Close Chat Portal", callback_data=CLOSE_CHAT), ]] else: menu = [[ InlineKeyboardButton("Reveal Identity Request", callback_data=REVEAL_IDENTITY_REQUEST), ], [ InlineKeyboardButton("Report Chat", callback_data=REPORT_CHAT), InlineKeyboardButton("View/ Edit Questionnaire", callback_data=QUESTIONNAIRE) ], [ InlineKeyboardButton("Close Chat Portal", callback_data=CLOSE_CHAT), ]] delete_msg(chat_id, context) active_commands[chat_id] = context.bot.send_message( text=WELCOME_TEXT, parse_mode=ParseMode.MARKDOWN, chat_id=chat_id, reply_markup=InlineKeyboardMarkup(menu)).message_id elif Db.get_instance().read_user_id(chat_id): menu = [[ InlineKeyboardButton("Random Chat", callback_data=RANDOM_CHAT_CALLBACK_DATA), ], [ InlineKeyboardButton("Questionnaire", callback_data=QUESTIONNAIRE), ], [ InlineKeyboardButton("Alter Interest", callback_data=RESET_CALLBACK_DATA), ], [ InlineKeyboardButton( "How This Works", callback_data=WALKABOUT_CALLBACK_DATA), InlineKeyboardButton("Commands", callback_data=COMMAND_CALLBACK_DATA) ]] delete_msg(chat_id, context) active_commands[chat_id] = context.bot.send_message( text=WELCOME_TEXT, parse_mode=ParseMode.MARKDOWN, chat_id=chat_id, reply_markup=InlineKeyboardMarkup(menu)).message_id else: welcome(chat_id, context)