def help_button(bot: Bot, update: Update): query = update.callback_query chat = update.effective_chat # type: Optional[Chat] mod_match = re.match(r"help_module\((.+?)\)", query.data) prev_match = re.match(r"help_prev\((.+?)\)", query.data) next_match = re.match(r"help_next\((.+?)\)", query.data) back_match = re.match(r"help_back", query.data) try: if mod_match: module = mod_match.group(1) mod_name = tld(chat.id, HELPABLE[module].__mod_name__) help_txt = tld_help(chat.id, HELPABLE[module].__mod_name__) if help_txt == False: help_txt = HELPABLE[module].__help__ text = tld(chat.id, "Here is the help for the *{}* module:\n{}").format( mod_name, help_txt) query.message.reply_text(text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text=tld(chat.id, "Back"), callback_data="help_back") ]])) elif prev_match: curr_page = int(prev_match.group(1)) query.message.reply_text(tld(chat.id, "send-help").format( dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld( chat.id, "\nAll commands can either be used with `/` or `!`.\n")), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules( chat.id, curr_page - 1, HELPABLE, "help"))) elif next_match: next_page = int(next_match.group(1)) query.message.reply_text(tld(chat.id, "send-help").format( dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld( chat.id, "\nAll commands can either be used with `/` or `!`.\n")), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules( chat.id, next_page + 1, HELPABLE, "help"))) elif back_match: query.message.reply_text(text=tld(chat.id, "send-help").format( dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld( chat.id, "\nAll commands can either be used with `/` or `!`.\n")), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules( chat.id, 0, HELPABLE, "help"))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Message is not modified": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Message can't be deleted": pass else: LOGGER.exception("Exception in help buttons. %s", str(query.data))
def settings_button(bot: Bot, update: Update): query = update.callback_query user = update.effective_user mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) text = "*{}* has the following settings for the *{}* module:\n\n".format(escape_markdown(chat.title), CHAT_SETTINGS[module].__mod_name__) + \ CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id) query.message.reply_text( text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Back", callback_data="stngs_back({})".format(chat_id)) ]])) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "Hi there! There are quite a few settings for {} - go ahead and pick what " "you're interested in.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "Hi there! There are quite a few settings for {} - go ahead and pick what " "you're interested in.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text( text= "Hi there! There are quite a few settings for {} - go ahead and pick what " "you're interested in.".format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Message is not modified": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Message can't be deleted": pass else: LOGGER.exception("Exception in settings buttons. %s", str(query.data))
def settings_button(bot: Bot, update: Update): query = update.callback_query user = update.effective_user mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) text = "*{}* modulu aşağıdakı parametrlərə malikdir *{}* :\n\n".format(escape_markdown(chat.title), CHAT_SETTINGS[module].__mod_name__) + \ CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id) query.message.reply_text( text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Geri", callback_data="stngs_back({})".format(chat_id)) ]])) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "Salam! {} üçün kifayət qədər az parametr var. Davam edin. " "Sən maraqlanırsan".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "Salam! {} üçün kifayət qədər az parametr var. Davam edin. " "Sən maraqlanırsan".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text( text="Salam! {} üçün kifayət qədər az parametr var. Davam edin. " "Sən maraqlanırsan".format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Mesaj dəyişdirilməyib": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Mesaj silinməyib.": pass else: LOGGER.exception("Ayarlar düymələrindəki istisna. %s", str(query.data))
def help_button(bot: Bot, update: Update): """Inlinebutton for Help Module""" query = update.callback_query mod_match = re.match(r"help_module\((.+?)\)", query.data) prev_match = re.match(r"help_prev\((.+?)\)", query.data) next_match = re.match(r"help_next\((.+?)\)", query.data) back_match = re.match(r"help_back", query.data) try: if mod_match: module = mod_match.group(1) text = "Here is the help for the *{}* module:\n".format( HELPABLE[module].__mod_name__) + HELPABLE[module].__help__ query.message.reply_text(text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton(text="Back", callback_data="help_back")]])) elif prev_match: curr_page = int(prev_match.group(1)) query.message.reply_text( HELP_STRINGS, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules( curr_page - 1, HELPABLE, "help"))) elif next_match: next_page = int(next_match.group(1)) query.message.reply_text( HELP_STRINGS, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules( next_page + 1, HELPABLE, "help"))) elif back_match: query.message.reply_text( text=HELP_STRINGS, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules( 0, HELPABLE, "help"))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Message is not modified": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Message can't be deleted": pass else: LOGGER.exception("Exception in help buttons. %s", str(query.data))
def help_button(bot: Bot, update: Update): query = update.callback_query chat = update.effective_chat prev_match = re.match(r"help_prev\((.+?)\)", query.data) next_match = re.match(r"help_next\((.+?)\)", query.data) back_match = re.match(r"help_back", query.data) mod_match = re.match(r"help_module\((.+?)\)", query.data) try: if mod_match: module = mod_match.group(1) mod_name = tld(chat.id, "modname_" + module).strip() help_txt = tld( chat.id, module + "_help") # tld_help(chat.id, HELPABLE[module].__mod_name__) if not help_txt: LOGGER.exception(f"Help string for {module} not found!") text = tld(chat.id, "here_is_help").format(mod_name, help_txt) bot.edit_message_text(chat_id=query.message.chat_id, message_id=query.message.message_id, text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text=tld(chat.id, "btn_go_back"), callback_data="help_back") ]]), disable_web_page_preview=True) elif prev_match: curr_page = int(prev_match.group(1)) bot.edit_message_text(chat_id=query.message.chat_id, message_id=query.message.message_id, text=tld(chat.id, "send-help").format( dispatcher.bot.first_name, tld(chat.id, "cmd_multitrigger")), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(chat.id, curr_page - 1, HELPABLE, "help"))) elif next_match: next_page = int(next_match.group(1)) bot.edit_message_text(chat_id=query.message.chat_id, message_id=query.message.message_id, text=tld(chat.id, "send-help").format( dispatcher.bot.first_name, tld(chat.id, "cmd_multitrigger")), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(chat.id, next_page + 1, HELPABLE, "help"))) elif back_match: bot.edit_message_text(chat_id=query.message.chat_id, message_id=query.message.message_id, text=tld(chat.id, "send-help").format( dispatcher.bot.first_name, tld(chat.id, "cmd_multitrigger")), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(chat.id, 0, HELPABLE, "help")), disable_web_page_preview=True) # ensure no spinny white circle bot.answer_callback_query(query.id) # query.message.delete() except BadRequest: pass
def settings_button(bot: Bot, update: Update): query = update.callback_query user = update.effective_user mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) text = "*{}* لديه الإعدادات التالية ل * {} * الوحدة النمطية:\n\n".format(escape_markdown(chat.title), CHAT_SETTINGS[module].__mod_name__) + \ CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id) query.message.reply_text( text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="رجوع", callback_data="stngs_back({})".format(chat_id)) ]])) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "مرحبا هناك عدد قليل من الإعدادات ل {} - المضي قدما واختيار ما" "توقف! انت متهم بـ".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "مرحبا هناك عدد قليل من الإعدادات ل {} - المضي قدما واختيار ما" "توقف! انت متهم بـ".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text( text= "مرحبا هناك عدد قليل من الإعدادات ل {} - المضي قدما واختيار ما" "توقف! انت متهم بـ".format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Message is not modified": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Message can't be deleted": pass else: LOGGER.exception("Exception in settings buttons. %s", str(query.data))
def settings_button(bot: Bot, update: Update): query = update.callback_query user = update.effective_user mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) text = "*{}* සඳහා පහත සැකසුම් ඇත *{}* module:\n\n".format(escape_markdown(chat.title), CHAT_SETTINGS[module].__mod_name__) + \ CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id) query.message.reply_text(text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton(text="Back", callback_data="stngs_back({})".format(chat_id))]])) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text("ආයුබෝවන් කොහොම ද! සඳහා සැකසුම් කිහිපයක් තිබේ {} - ඉදිරියට ගොස් කුමක් තෝරා ගන්න " "ඔබ උනන්දුයි".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text("ආයුබෝවන් කොහොම ද! සඳහා සැකසුම් කිහිපයක් තිබේ {} - ඉදිරියට ගොස් කුමක් තෝරා ගන්න " "ඔබ උනන්දුයි.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text(text="ආයුබෝවන් කොහොම ද! සඳහා සැකසුම් කිහිපයක් තිබේ {} - ඉදිරියට ගොස් කුමක් තෝරා ගන්න " "ඔබ උනන්දුයි.".format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "පණිවිඩය වෙනස් කර නොමැත": pass elif excp.message == "විමසුම_අවස්ථාව": pass elif excp.message == "පණිවිඩය මකා දැමිය නොහැක": pass else: LOGGER.exception("සැකසුම් බොත්තම් වල ව්යතිරේකය. %s", str(query.data))
def settings_button(bot: Bot, update: Update): query = update.callback_query user = update.effective_user chatP = update.effective_chat # type: Optional[Chat] mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) text = "*{}* telah mengikuti pengaturan module *{}*:\n\n".format(escape_markdown(chat.title), CHAT_SETTINGS[ module].__mod_name__) + \ CHAT_SETTINGS[module].__chat_settings__(bot, update, chat, chatP, user) query.message.reply_text(text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton(text="Back", callback_data="stngs_back({})".format(chat_id))]])) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text(tld(user.id, "send-group-settings").format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text(tld(user.id, "send-group-settings").format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text(text=tld(user.id, "send-group-settings").format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(paginate_modules(user.id, 0, CHAT_SETTINGS, "stngs", chat=chat_id))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Pesan tidak di edit": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Pesan tidak bisa di hapus": pass else: LOGGER.exception("Exception in settings buttons. %s", str(query.data))
def settings_button(bot: Bot, update: Update): query = update.callback_query user = update.effective_user mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) text = "*{}*, *{}* modülü için aşağıdaki ayarlara sahiptir:\n\n".format(escape_markdown(chat.title), CHAT_SETTINGS[ module].__mod_name__) + \ CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id) query.message.reply_text( text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Geri", callback_data="stngs_back({})".format(chat_id)) ]])) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "Vay arkadaş! {} için epeyce ayar var - Devam et ve " "ilgilendiğin şeyi seç.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "Vay arkadaş! {} için epeyce ayar var - Devam et ve " "ilgilendiğin şeyi seç.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text( text="Vay arkadaş! {} için epeyce ayar var - Devam et ve " "ilgilendiğin şeyi seç.".format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "The message has not been changed": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Stop right there! This message cannot be deleted": pass else: LOGGER.exception("Exception in settings buttons. %s", str(query.data))
def settings_button(bot: Bot, update: Update): query = update.callback_query user = update.effective_user mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) text = "*{}* memiliki pengaturan berikut untuk modul *{}*:\n\n".format( escape_markdown(chat.title), CHAT_SETTINGS[module].__mod_name__ ) + CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id) query.message.reply_text( text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton( text="Kembali", callback_data="stngs_back({})".format(chat_id), ) ] ] ), ) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "Halo yang disana! Ada beberapa setelan untuk {} - lanjutkan dan pilih apa " "yang Anda tertarik.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules( curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id ) ), ) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "Halo yang disana! Ada beberapa setelan untuk {} - lanjutkan dan pilih apa " "yang Anda tertarik.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules( next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id ) ), ) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text( text="Halo yang disana! Ada beberapa setelan untuk {} - lanjutkan dan pilih apa " "yang Anda tertarik.".format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id) ), ) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Pesan tidak diubah": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Pesan tidak dapat dihapus": pass else: LOGGER.exception("Exception in settings buttons. %s", str(query.data))
def settings_button(bot: Bot, update: Update): query = update.callback_query user = update.effective_user mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) getstatusadmin = bot.get_chat_member(chat_id, user.id) isadmin = getstatusadmin.status in ('administrator', 'creator') if isadmin == False or user.id != OWNER_ID: query.message.edit_text("Status admin anda telah berubah") return text = tl(update.effective_message, "*{}* memiliki pengaturan berikut untuk modul *{}*:\n\n").format(escape_markdown(chat.title), CHAT_SETTINGS[ module].__mod_name__) + \ CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id) try: set_button = CHAT_SETTINGS[module].__chat_settings_btn__( chat_id, user.id) except AttributeError: set_button = [] set_button.append([ InlineKeyboardButton( text=tl(query.message, "Kembali"), callback_data="stngs_back({})".format(chat_id)) ]) query.message.reply_text( text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(set_button)) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text(text=tl( update.effective_message, "Hai! Ada beberapa pengaturan untuk {} - lanjutkan dan pilih " "apa yang Anda minati.").format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text(text=tl( update.effective_message, "Hai! Ada beberapa pengaturan untuk {} - lanjutkan dan pilih " "apa yang Anda minati.").format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text(text=tl( update.effective_message, "Hai! Ada beberapa pengaturan untuk {} - lanjutkan dan pilih " "apa yang Anda minati.").format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id))) # ensure no spinny white circle query.message.delete() bot.answer_callback_query(query.id) except Exception as excp: if excp.message == "Message is not modified": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Message can't be deleted": pass else: query.message.edit_text(excp.message) LOGGER.exception("Exception in settings buttons. %s", str(query.data))
def on_callback_query(bot: telegram.Bot, update: telegram.Update): try: session = db.Session() if update.callback_query.data.startswith("vote_"): if update.callback_query.data == "vote_yes": status = db.VoteChoices.YES emoji = "🔵" elif update.callback_query.data == "vote_no": status = db.VoteChoices.NO emoji = "🔴" elif update.callback_query.data == "vote_abstain": status = db.VoteChoices.ABSTAIN emoji = "⚫️" else: raise NotImplementedError() user = session.query(db.Telegram).filter_by(telegram_id=update.callback_query.from_user.id).one_or_none() if user is None: bot.answer_callback_query(update.callback_query.id, show_alert=True, text=strings.LINK.ERRORS.ROYALNET_NOT_LINKED, parse_mode="Markdown") return question = session.query(db.VoteQuestion)\ .filter_by(message_id=update.callback_query.message.message_id)\ .one() answer = session.query(db.VoteAnswer).filter_by(question=question, user=user).one_or_none() if answer is None: answer = db.VoteAnswer(question=question, choice=status, user=user) session.add(answer) bot.answer_callback_query(update.callback_query.id, text=f"Hai votato {emoji}.", cache_time=1) elif answer.choice == status: session.delete(answer) bot.answer_callback_query(update.callback_query.id, text=f"Hai ritratto il tuo voto.", cache_time=1) else: answer.choice = status bot.answer_callback_query(update.callback_query.id, text=f"Hai cambiato il tuo voto in {emoji}.", cache_time=1) session.commit() inline_keyboard = IKMarkup([[IKButton("🔵 Sì", callback_data="vote_yes")], [IKButton("🔴 No", callback_data="vote_no")], [IKButton("⚫️ Astieniti", callback_data="vote_abstain")]]) bot.edit_message_text(message_id=update.callback_query.message.message_id, chat_id=update.callback_query.message.chat.id, text=question.generate_text(session), reply_markup=inline_keyboard, parse_mode="HTML") elif update.callback_query.data.startswith("match_"): user = session.query(db.Telegram).filter_by(telegram_id=update.callback_query.from_user.id).one_or_none() if user is None: bot.answer_callback_query(update.callback_query.id, show_alert=True, text=strings.LINK.ERRORS.ROYALNET_NOT_LINKED, parse_mode="Markdown") return match = session.query(db.Match).filter_by(message_id=update.callback_query.message.message_id).one() if update.callback_query.data == "match_close": if not (match.creator == user or user.telegram_id == 25167391): bot.answer_callback_query(update.callback_query.id, show_alert=True, text=strings.MATCHMAKING.ERRORS.NOT_ADMIN) return match.closed = True for partecipation in match.players: if int(partecipation.status) >= 1: try: reply_msg(bot, partecipation.user.telegram_id, strings.MATCHMAKING.GAME_START[int(partecipation.status)], **match.format_dict()) except Unauthorized: reply_msg(bot, main_group_id, strings.TELEGRAM.ERRORS.UNAUTHORIZED_USER, mention=partecipation.user.mention()) elif update.callback_query.data == "match_cancel": if not (match.creator == user or user.telegram_id == 25167391): bot.answer_callback_query(update.callback_query.id, show_alert=True, text=strings.MATCHMAKING.ERRORS.NOT_ADMIN) return match.closed = True status = { "match_ready": db.MatchmakingStatus.READY, "match_wait_for_me": db.MatchmakingStatus.WAIT_FOR_ME, "match_maybe": db.MatchmakingStatus.MAYBE, "match_ignore": db.MatchmakingStatus.IGNORED, "match_close": None, "match_cancel": None, }.get(update.callback_query.data) if status: if match.closed: bot.answer_callback_query(update.callback_query.id, show_alert=True, text=strings.MATCHMAKING.ERRORS.MATCH_CLOSED) return partecipation = session.query(db.MatchPartecipation).filter_by(match=match, user=user).one_or_none() if partecipation is None: partecipation = db.MatchPartecipation(match=match, status=status.value, user=user) session.add(partecipation) else: partecipation.status = status.value session.commit() bot.answer_callback_query(update.callback_query.id, text=strings.MATCHMAKING.TICKER_TEXT[update.callback_query.data], cache_time=1) if not match.closed: inline_keyboard = IKMarkup([([IKButton(strings.MATCHMAKING.BUTTONS[key], callback_data=key)]) for key in strings.MATCHMAKING.BUTTONS]) else: inline_keyboard = None while True: try: bot.edit_message_text(message_id=update.callback_query.message.message_id, chat_id=config["Telegram"]["announcement_group"], text=match.generate_text(session), reply_markup=inline_keyboard, parse_mode="HTML") break except BadRequest: break except TimedOut: time.sleep(1) except Exception: try: bot.answer_callback_query(update.callback_query.id, show_alert=True, text=strings.TELEGRAM.ERRORS.CRITICAL_ERROR_QUERY) except Exception: pass logger.error(f"Critical error: {sys.exc_info()}") sentry.user_context({ "id": update.effective_user.id, "telegram": { "username": update.effective_user.username, "first_name": update.effective_user.first_name, "last_name": update.effective_user.last_name } }) sentry.extra_context({ "update": update.to_dict() }) sentry.captureException() finally: try: # noinspection PyUnboundLocalVariable session.close() except Exception: pass
def settings_button(bot: Bot, update: Update): query = update.callback_query user = update.effective_user mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) text = "*{}* निम्नलिखित सेटिंग्स के लिए है *{}* module:\n\n".format(escape_markdown(chat.title), CHAT_SETTINGS[module].__mod_name__) + \ CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id) query.message.reply_text( text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Back", callback_data="stngs_back({})".format(chat_id)) ]])) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "नमस्ते!आपके के लिए काफी कुछ सेटिंग्स हैं {} - आगे बढ़ो और देखो " "आप में रुचि रखते हैं".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text( "नमस्ते!आपके के लिए काफी कुछ सेटिंग्स हैं {} -आगे बढ़ो और देखो " "आप में रुचि रखते हैं.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text( text= "नमस्ते!आपके के लिए काफी कुछ सेटिंग्स हैं {} - आगे बढ़ो और देखो " "आप में रुचि रखते हैं".format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Message is not modified": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Message can't be deleted": pass else: LOGGER.exception("Exception in settings buttons. %s", str(query.data))
class Defender: def __init__(self): # INIT self.bot = Bot(bot_token) # vtx Defender Initialization client = MongoClient(connectionString) db = client.get_default_database() self.col_captcha = db['captcha'] self.col_users = db['Users'] self.spam_msgs_collection = db['spam'] self.pending_msgs_collection = db['pending_messages'] self.users_whitelist = db['whitelist'] self.col_questions = db['questions'] # processing captchas self.captcha_processing() # get chat updates self.new_message = self.wait_new_message() self.message = self.new_message.message \ if self.new_message.message is not None \ else self.new_message.callback_query.message self.text, _is_document = self.get_action(self.new_message) self.message_text = str(self.text).lower() print(self.text) # init user data try: self.first_name = self.new_message.effective_user.first_name self.username = self.new_message.effective_user.username self.user_id = self.new_message.effective_user.id except Exception as exc: print(exc) try: self._is_verified = self.col_users.find_one({"_id": self.user_id })['IsVerified'] except Exception as exc: print(exc) self._is_verified = True print(self.username) print(self.user_id) print(self.first_name) print(self.message_text, '\n\n') self.group_id = self.message.chat.id self.action_processing() if 'group' in self.message.chat.type: # parse user_info self.group_username = self.get_group_username() _is_whitelist_user = False for _x in list(self.users_whitelist.find()): try: if str(_x['key']).lower() in str( self.message.from_user).lower(): _is_whitelist_user = True except Exception as exc: print(exc) if not _is_whitelist_user and _is_document: self.bot.delete_message(chat_id=self.group_id, message_id=self.message.message_id) # init group collection if not self._is_verified: # check msg on spam if not self._is_msg_spam(): self.save_unverified_msg() self.bot.delete_message(chat_id=self.group_id, message_id=self.message.message_id) self.send_captcha(self.first_name, self.user_id) elif not _is_whitelist_user: self.check_whitelist() """ This method save msg of unverified user with target to send it again, if user will auth. """ def save_unverified_msg(self): try: # forward msg to PM(Own Account to avoid spam of all admins) a = self.bot.forward_message(MY_ID, self.group_id, message_id=self.message.message_id) # Add msg_id, group_id, user_id, datetime into db to define specified msg of users. self.pending_msgs_collection.update({"_id": a.message_id}, { "$set": { "_id": a.message_id, "group_id": self.group_id, "user_id": self.user_id, "Datetime": datetime.datetime.now() } }, upsert=True) except Exception as exc: print(exc) """ Check if user's msg is spam """ def check_whitelist(self): # Receive admin list admin_list = self.get_admin_list() # check is this user exists in admin's list _is_user_admin = str(self.user_id) in admin_list if not _is_user_admin: self.check_admin_commands(_is_user_admin) def check_admin_commands(self, _is_user_admin): if _is_user_admin and "/ban" == str(self.message_text) and \ self.message.reply_to_message is not None: user_to_ban_id = self.message.reply_to_message.from_user.id reply_message_id = self.message.reply_to_message.message_id self.bot.delete_message(chat_id=self.group_id, message_id=reply_message_id) self.bot.kick_chat_member(chat_id=self.group_id, user_id=user_to_ban_id) self.bot.delete_message(chat_id=self.group_id, message_id=self.message.message_id) self.bot.send_message(BROADCAST_CHANNEL, "Group: @%s\n" "USER %s BANNED BY USER: %s" % ( self.group_username, self.message.reply_to_message. \ from_user.username, self.username) ) elif _is_user_admin and "/mute" in str(self.message_text) and \ self.message.reply_to_message is not None and \ len(self.message_text.split(' ')) > 0: timestamp_now = datetime.datetime.now().timestamp() user_date = int(self.message_text.split(' ')[1]) until_date = timestamp_now + \ datetime.timedelta(days= user_date).total_seconds() user_to_ban_id = self.message.reply_to_message.from_user.id reply_message_id = self.message.reply_to_message.message_id self.bot.delete_message(chat_id=self.group_id, message_id=reply_message_id) self.bot.restrict_chat_member(chat_id=self.group_id, user_id=user_to_ban_id, until_date=until_date) self.bot.send_message(self.group_id, text='<i>User muted for a %s day(s)!</i>' % (str(user_date)), parse_mode='HTML') self.bot.send_message(BROADCAST_CHANNEL, "Group: @%s\n" "USER %s Muted BY USER: %s" % ( self.group_username, self.message.reply_to_message. \ from_user.username, self.username) ) else: if not _is_user_admin: matches = re.search(REGEX_ALL, self.message_text) if matches is not None: # self.restrict_user() self.bot.delete_message(self.group_id, self.message.message_id) # print("Check_message: %s" % matches.groups()) self.bot.send_message( BROADCAST_CHANNEL, "Group: @%s\n" "USER SPAM " "MESSAGE: %s" "\nUsername: %s\n%s" % (self.group_username, matches.groups(), self.username, self.message_text)) self.new_users = self.message.new_chat_members _is_new_users = len(self.message.new_chat_members) > 0 _db_user = self.col_users.find_one({"_id": self.user_id}) _is_user_in_collection = _db_user is not None _is_forward = self.message.forward_from is not None _is_chat_forward = self.message.forward_from_chat is not None _is_document = self.message.document is not None _is_photo = len(self.message.photo) > 0 # Reason Forward Messages from chat or users if not _is_user_admin and (_is_chat_forward or _is_forward): try: _user_join_date = _db_user['JoinDate'] _is_join_long_time_ago = datetime.datetime.now() - \ datetime.timedelta(days=20) \ > _user_join_date if not _is_join_long_time_ago: self.bot.delete_message(self.group_id, self.message.message_id) self.bot.send_message( BROADCAST_CHANNEL, "Group: @%s\n" "FORWARD " "MESSAGE" "\nUsername: %s\n%s" % (self.group_username, self.username, self.message_text)) except Exception as exc: print(exc) traceback.print_exc() if _is_chat_forward: for _link in self.message.entities: matches = re.search(REGEX_ALL, str(_link)) if matches is not None: self.bot.delete_message(self.group_id, self.message.message_id) self.bot.send_message( BROADCAST_CHANNEL, "Group: @%s\n" "TEXTLINK " "MESSAGE: %s" "\nUsername: %s\n%s" % (self.group_username, matches.groups(), self.username, self.message_text)) break if _is_new_users: self.set_new_users() elif _is_user_in_collection: _user_join_date = _db_user['JoinDate'] _is_join_today = datetime.datetime.now() - \ datetime.timedelta(days=1) \ > _user_join_date if _is_forward and not _is_join_today: # self.restrict_user() self.bot.delete_message(self.group_id, self.message.message_id) self.bot.send_message( BROADCAST_CHANNEL, "Group: @%s\n" "Forward MESSAGE: %s\n%s" % (self.group_username, self.username, self.message_text)) self.spam_msgs_collection.update( {"_id": str(self.message_text.lower())}, {"$set": { "_id": str(self.message_text.lower()) }}, upsert=True) elif _is_photo and not _is_join_today: self.bot.delete_message(self.group_id, self.message.message_id) self.bot.send_message( BROADCAST_CHANNEL, "Group: @%s\n" "INLINEKEYBOARD/IMAGE " "MESSAGE: %s\n%s" % (self.group_username, self.username, self.message_text)) elif _is_document and not _is_join_today: self.bot.delete_message(self.group_id, self.message.message_id) self.bot.send_message( BROADCAST_CHANNEL, "Group: @%s\n" "GIF/IMAGE MESSAGE: " "%s\n%s" % (self.group_username, self.username, self.message_text)) elif not _is_join_today: self.check_message() elif not _is_user_admin: matches = re.search(REGEX_ALL, self.message_text) if matches is not None: # self.restrict_user() self.bot.delete_message(self.group_id, self.message.message_id) # print("Check_message: %s" % matches.groups()) self.bot.send_message( BROADCAST_CHANNEL, "Group: @%s\n" "LONGTIME USER SPAM " "MESSAGE: %s" "\nUsername: %s\n%s" % (self.group_username, matches.groups(), self.username, self.message_text)) def get_admin_list(self): admins = self.bot.get_chat_administrators(self.message.chat.id) admin_list = "" for admin in admins: admin_list += str(admin.user.id) + " " print(str(admin_list)) return admin_list def check_message(self): matches = re.search(REGEX, str(self.message_text).lower()) if matches is not None: # self.restrict_user() self.bot.delete_message(self.group_id, self.message.message_id) # print("Check_message: %s" % matches.groups()) self.bot.send_message( BROADCAST_CHANNEL, "Channel: @%s\n" "SPAM MESSAGE: %s\nUsername: %s\n%s" % (self.group_username, matches.groups(), self.username, self.message_text)) self.spam_msgs_collection.update( {"_id": str(self.message_text.lower())}, {"$set": { "_id": str(self.message_text.lower()) }}, upsert=True) def _is_msg_spam(self): matches = re.search(REGEX, self.message_text) if matches is not None: return True matches = re.search(REGEX_ALL, self.message_text) if matches is not None: return True return False """ Method to add users into the whitelist """ def add_user_to_whitelist(self, username): self.users_whitelist.insert({"key": username}) self.bot.send_message( BROADCAST_CHANNEL, "User <b>%s</b> was successfully added into the whitelist!" % username, parse_mode='HTML') self.bot.send_message( self.user_id, "User <b>%s</b> was successfully added into the whitelist!" % username, parse_mode='HTML') """ Restrict chat member for 7 days """ def restrict_user(self): self.bot.restrict_chat_member(self.group_id, self.user_id, until_date=datetime.datetime.now() + datetime.timedelta(days=7), can_send_messages=False, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False) """ Method checks is user new and add him to db collection """ def set_new_users(self): # loop uses to check each user, on the way if any user invite somebody. for user in self.new_users: try: # Is spam in the nickname matches = re.search(REGEX, str(user.first_name)) if matches is not None: self.restrict_user() # Update data of user self.col_users.insert({"_id": user.id}, { "$set": { "_id": user.id, "first_name": user.first_name, "username": user.username, "Balance": 0, "IsVerified": False, "JoinDate": datetime.datetime.now() } }, upsert=True) # Send msg about new user to the monitor channel self.bot.send_message( BROADCAST_CHANNEL, "Channel: @%s Title: %s\n" "New User: %s\n%s" % (self.group_username, self.message.chat.title, user.first_name, user.username)) except Exception as exc: print(exc) # send captcha if self.col_users.find_one({"_id": self.user_id })['IsVerified'] is False: # Send captcha to the new users that joined into the group if they weren't verified. self.send_captcha(self.new_users[0].first_name, self.new_users[0].id) self.bot.delete_message(self.group_id, self.message.message_id) """ Send captcha to check, Is user bot? """ def send_captcha(self, first_name, user_id): msg = self.bot.send_message( self.group_id, "Welcome [%s](tg://user?id=%s) to Volentix Group. Confirm that you're not a bot" % (first_name, user_id), parse_mode='Markdown', reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text="I'm not a bot", url="https://t.me/vtxprotector_bot") ]])) self.col_captcha.update({"_id": msg.message_id}, { "$set": { "_id": msg.message_id, "group_id": self.group_id, "Datetime": datetime.datetime.now() } }, upsert=True) def captcha_processing(self): captcha_list = list(self.col_captcha.find()) for _c in captcha_list: try: if datetime.datetime.now( ) > _c['Datetime'] + datetime.timedelta(seconds=10): self.bot.delete_message(chat_id=_c['group_id'], message_id=_c['_id']) self.col_captcha.remove(_c) except Exception as exc: self.col_captcha.remove(_c) traceback.print_exc() print(exc) messages = list(self.pending_msgs_collection.find()) for _msg in messages: try: if datetime.datetime.now( ) > _msg['Datetime'] + datetime.timedelta(minutes=5): self.bot.delete_message(MY_ID, _msg['_id']) self.pending_msgs_collection.remove(_msg) except Exception as exc: self.pending_msgs_collection.remove(_msg) print(exc) """ Get group username """ def get_group_username(self): try: return str(self.message.chat.username) except: return str(self.message.chat.id) """ Get User username """ def get_user_username(self): try: return str(self.message.from_user.username) except: return None def wait_new_message(self): while True: updates = self.bot.get_updates() if len(updates) > 0: break update = updates[0] self.bot.get_updates(offset=update["update_id"] + 1) return update @staticmethod def get_action(message): _is_document = False if message['message'] is not None: menu_option = message['message']['text'] _is_document = message['message']['document'] is not None elif message["callback_query"] != 0: menu_option = message["callback_query"]["data"] return str(menu_option), _is_document """ Check each user actions """ def action_processing(self): if "/faq" in self.text: self.get_questions() elif "get_questions|" in self.text: self.get_questions() elif "answer|" in self.text: self.get_answer() elif "vote|" in self.text: self.check_vote() elif "/balance" in self.text: if 'private' in self.message.chat.type: self.print_balance() else: self.bot.delete_message(self.group_id, self.message.message_id) elif "/add" in self.message_text: username = self.message_text.split(' ')[1].replace('@', '') self.add_user_to_whitelist(username) elif "/start" in self.message_text: if not self._is_verified: self.bot.send_message(self.user_id, WELCOME_MESSAGE, parse_mode='html', disable_web_page_preview=True) self.bot.send_message( self.user_id, "<b>⚠️SCAMMER 🚨\n" "BEWARE OF ANYONE SENDING YOU PM WHO IS NOT ADMIN STATUS AND PRETENDING TO ASSIST YOU IN GETTING VTX.\n" "NEVER SEND FUNDS TO ANY BTC or ETH address or any address sent to you via PM. Volentix WILL NEVER DO THAT!</b>\n<b>The Volentix group Admins are</b>:\n@Vaudevillian\n@T_Naqi\n@ioannafo\n@Vionidas\n@lou1ou\n@Realrhys\n@TheVguy\n@buona4tuna\n@Jelly_SL\n@sylvaincormier", parse_mode='html', disable_web_page_preview=True) self.col_users.update({"_id": self.user_id}, {"$set": { "IsVerified": True }}) else: self.col_users.update({"_id": self.user_id}, { "$set": { "_id": self.user_id, "first_name": self.first_name, "username": self.username, "IsVerified": True, "JoinDate": datetime.datetime.now() - datetime.timedelta(days=5) } }, upsert=True) self.bot.send_message(self.user_id, WELCOME_MESSAGE, parse_mode='html') self.bot.send_message( self.user_id, "<b>⚠️SCAMMER 🚨\n" "BEWARE OF ANYONE SENDING YOU PM WHO IS NOT ADMIN STATUS AND PRETENDING TO ASSIST YOU IN GETTING VTX.\n" "NEVER SEND FUNDS TO ANY BTC or ETH address or any address sent to you via PM. Volentix WILL NEVER DO THAT!</b>\n<b>The Volentix group Admins are</b>:\n@Vaudevillian\n@T_Naqi\n@ioannafo\n@Vionidas\n@lou1ou\n@Realrhys\n@TheVguy\n@buona4tuna\n@Jelly_SL\n@sylvaincormier", parse_mode='html', disable_web_page_preview=True) elif "|confirm" in self.message_text: user_id = self.message_text.split('|')[0] print(user_id) print(type(user_id)) user = self.col_users.find_one({"_id": int(user_id)}) _is_verified = user['IsVerified'] if not _is_verified: self.col_users.update({"_id": int(user_id)}, {"$set": { "IsVerified": True }}) self.bot.send_message( BROADCAST_CHANNEL, "Channel: @%s Title: %s\n" "User Confirmed: %s\n%s" % (self.message.chat.username, self.message.chat.title, user['first_name'], str(user['username']))) def check_vote(self): try: split = self.text.split('|') _id = split[1] answer_id = int(split[2]) q = self.col_questions.find_one({"_id": ObjectId(_id)}) if str(self.user_id) in str(q): self.bot.answer_callback_query( self.new_message.callback_query.id, text="❗️You have already voted and can't change vote❗️", show_alert=True) return _is_users_auth = self.col_users.find_one({ '_id': self.user_id, "IsVerified": True }) is not None if not _is_users_auth: self.bot.answer_callback_query( self.new_message.callback_query.id, text= "❗️You need to complete authetication in the %s. Push start btn❗️" % quiz_bot, show_alert=True) return if q['Completed'] is False: _is_winner_exists = q['Winner'] is not None repliers = q[q['answers'][answer_id]] repliers.append([ self.user_id, self.first_name, datetime.datetime.now().timestamp() ]) self.col_questions.update( {"_id": ObjectId(_id)}, {"$set": { q['answers'][answer_id]: repliers }}) if answer_id == q['correct_answer'] and not _is_winner_exists: self.col_questions.update( {"_id": ObjectId(_id)}, {"$set": { "Winner": [self.user_id, self.first_name] }}) user = self.col_users.find_one({"_id": self.user_id}) self.col_users.update(user, { "$set": { "Balance": float(user['Balance']) + win_amount } }, upsert=True) self.bot.answer_callback_query( self.new_message.callback_query.id, text= "🔥Congratulations! You Won and received 10 VTX for %s️⃣" % (int(answer_id) + 1), show_alert=True) else: self.bot.answer_callback_query( self.new_message.callback_query.id, text="✅You voted for %s️⃣" % (int(answer_id) + 1), show_alert=True) else: self.bot.answer_callback_query( self.new_message.callback_query.id, text="❗️Attention: Quiz completed❗️", show_alert=True) except Exception as exc: print(exc) def print_balance(self): user = self.col_users.find_one({"_id": self.user_id}) self.bot.send_message(self.user_id, '<b>Balance</b>: %s VTX' % user['Balance'], parse_mode='HTML') def get_questions(self): try: if "get_questions|" in self.text: step = int(self.text.split('|')[1]) else: step = 5 if step < len(faq_data): reply_markup = [[]] for x in range(step - 5, step): reply_markup.append([ InlineKeyboardButton(text="%s" % faq_data[x]['Q'], callback_data='answer|%s' % str(faq_data[x]['id'])) ]) reply_markup.append([ InlineKeyboardButton(text="Previous", callback_data='get_questions|%s' % str(step - 5)), InlineKeyboardButton(text="Next", callback_data='get_questions|%s' % str(step + 5)) ]) try: self.bot.delete_message(self.group_id, self.message.message_id) except Exception as exc: print(exc) self.bot.send_message( self.group_id, '<b>Frequently Asked Questions</b>', parse_mode='HTML', reply_markup=InlineKeyboardMarkup(reply_markup)) except Exception as exc: print(exc) traceback.print_exc() def get_answer(self): try: self.bot.delete_message(self.group_id, self.message.message_id) except Exception as exc: print(exc) _id = str(self.text.split('|')[1]) item = self.get_data_item(_id) self.bot.send_message(self.group_id, '<b>%s</b>\n%s' % (item['Q'], item['A']), parse_mode='HTML') @staticmethod def get_data_item(_id): for x in faq_data: if x['id'] == _id: return x
def settings_button(bot: Bot, update: Update): query = update.callback_query user = update.effective_user mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = bot.get_chat(chat_id) text = "* {} * sohbetinin, *{}* modülü aşağıdaki ayarlara sahiptir:\n\n".format(escape_markdown(chat.title), CHAT_SETTINGS[module].__mod_name__) + \ CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id) query.message.reply_text(text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton(text="Back", callback_data="stngs_back({})".format(chat_id))]])) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text("Merhaba! {} için epeyce ayar var - Birini seçin " "you're interested in.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = bot.get_chat(chat_id) query.message.reply_text("Merhaba! {} için epeyce ayar var - Birini seçin " "you're interested in.".format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif back_match: chat_id = back_match.group(1) chat = bot.get_chat(chat_id) query.message.reply_text(text="Merhaba! {} sohbetinin ayarları için epeyce özelliğim var - devam edin ve hangisini seçmek istediğinize karar verin! " ".".format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id))) # ensure no spinny white circle bot.answer_callback_query(query.id) query.message.delete() except BadRequest as excp: if excp.message == "Mesaj editlenemedi🥵": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Mesaj silinemedi😕": pass else: LOGGER.exception("Ayarlar düğmelerinde sıkıntı oluştu😕. %s", str(query.data))