def verify_welcome(update, context, chat_id): user_id = update.effective_user.id is_clicked = sql.get_chat_userlist(chat_id) if user_id not in list(is_clicked): send_message(update.effective_message, tl(update.effective_message, "Anda sedang tidak dalam mode verifikasi, jika anda sedang di bisukan, anda dapat meminta tolong pada admin di grup yang bersangkutan")) return elif user_id in list(is_clicked) and is_clicked[user_id] == True: send_message(update.effective_message, tl(update.effective_message, "Anda sedang tidak dalam mode verifikasi, jika anda sedang di bisukan, anda dapat meminta tolong pada admin di grup yang bersangkutan")) return verify_code = ["🙏", "👈", "👉", "👇", "👆", "❤️", "🅰️", "🅱️", "0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"] print(len(verify_code)) real_btn = random.choice(verify_code) verify_code.remove(real_btn) verbox = (random.randint(1, 3), random.randint(1, 3)) buttons = [] linebox = [] for x in range(3): x += 1 if verbox[1] == x: ver1 = True else: ver1 = False for y in range(3): y += 1 if verbox[0] == y and ver1: verify_emoji = real_btn linebox.append(InlineKeyboardButton(text=verify_emoji, callback_data="verify_me(y|{}|{})".format(user_id, chat_id))) else: verify_emoji = random.choice(verify_code) linebox.append(InlineKeyboardButton(text=verify_emoji, callback_data="verify_me(n|{}|{})".format(user_id, chat_id))) verify_code.remove(verify_emoji) buttons.append(linebox) linebox = [] context.bot.send_photo(user_id, photo=verify_code_images[real_btn], caption=tl(update.effective_message, "Tolong pilih emoji yang sama dibawah ini:"), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(buttons))
def check_bot_button(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] query = update.callback_query # type: Optional[CallbackQuery] match = re.match(r"check_bot_\((.+?)\)", query.data) user_id = int(match.group(1)) message = update.effective_message # type: Optional[Message] print("-> {} was clicked welcome sec button".format(user.id)) # This method will unmute user when that user is clicked welc security button # It has two method, so select one method. I'm using first method as default. # With second script, bot will edit welcome message and remove welcome security button # But when muted user in old welcomes, bot will remove that button, # and then new member will not have welcome security button. # The problem is bot using list of new member which has been muted, # and when that user is match, bot will response True and unmute him/her. # All we need is using different filter, it easy but old member has muted by # welcome security is no longer unmuted on any welcome security button, # need to search their welcome button to get unmute. # And you will need two decision, unmute specific user or unmute all user # who has muted by security button. # Also you can remove add_to_userlist and rm_from_userlist script # if you want to use second method since it unused. # PLEASE SELECT ONE # use """ to set it as comment and disable that script # => Use this if you want to unmute user who has muted by welcome security getalluser = sql.get_chat_userlist(chat.id) if user.id in getalluser: try: query.answer(text=tl(update.effective_message, "Kamu telah disuarakan!")) except BadRequest as err: print("-> Failed: {}".format(err)) return # Unmute user bot.restrict_chat_member(chat.id, user.id, can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True) sql.rm_from_userlist(chat.id, user.id) else: print("Not new user") try: query.answer(text=tl(update.effective_message, "Kamu bukan pengguna baru!")) except BadRequest as err: print("-> Failed: {}".format(err)) return # => Or use this to unmute specific user and remove that security button """
def verify_button_pressed(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] query = update.callback_query # type: Optional[CallbackQuery] match = re.match(r"verify_me\((.+?)\)", query.data) match = match.group(1).split("|") is_ok = match[0] user_id = match[1] chat_id = match[2] message = update.effective_message # type: Optional[Message] print("-> {} was clicked welcome verify button".format(user.id)) if is_ok == "y": if context.bot.getChatMember(chat_id, user_id).status in ('left'): query.answer( text=tl(update.effective_message, "Failed: user left chat")) return try: context.bot.restrict_chat_member( chat_id, user_id, permissions=ChatPermissions(can_send_messages=True, can_send_media_messages=True, can_send_polls=True, can_send_other_messages=True, can_add_web_page_previews=True, can_change_info=True, can_invite_users=True, can_pin_messages=True)) sql.add_to_userlist(chat_id, user_id, True) sql.rm_from_timeout(chat_id, user_id) except BadRequest as err: if not update.effective_chat.get_member( context.bot.id).can_restrict_members: query.answer(text=tl( update.effective_message, "Saya tidak dapat membatasi orang disini, tanya admin untuk unmute!" )) else: query.answer(text="Error: " + str(err)) return chat_name = context.bot.get_chat(chat_id).title # query.message.delete() # context.bot.send_photo(chat.id, photo="https://telegra.ph/file/06d2c5ec80af3858c2d4b.jpg", caption=tl(update.effective_message, "*Berhasil!*\n\nKerja bagus manusia, kini Anda dapat chatting di: *{}*").format(chat_name), parse_mode="markdown") context.bot.edit_message_media( chat.id, message_id=query.message.message_id, media=InputMediaPhoto( media=open("emilia/modules/helper_funcs/emojis/done.jpg", 'rb'), caption=tl( update.effective_message, "*Berhasil!*\n\nKerja bagus manusia, kini Anda dapat chatting di: *{}*" ).format(chat_name), parse_mode="markdown")) query.answer(text=tl( update.effective_message, "Berhasil! Anda dapat chatting di {} sekarang").format(chat_name), show_alert=True) elif is_ok == "re": user_id = update.effective_user.id is_clicked = sql.get_chat_userlist(chat_id) if user_id not in list(is_clicked): context.bot.edit_message_text( chat.id, message_id=query.message.message_id, text=tl( update.effective_message, "Anda sedang tidak dalam mode verifikasi, jika anda sedang di bisukan, anda dapat meminta tolong pada admin di grup yang bersangkutan" )) return query.answer(text=tl(update.effective_message, "Error"), show_alert=False) elif user_id in list(is_clicked) and is_clicked[user_id] == True: context.bot.edit_message_text( chat.id, message_id=query.message.message_id, text=tl( update.effective_message, "Anda sedang tidak dalam mode verifikasi, jika anda sedang di bisukan, anda dapat meminta tolong pada admin di grup yang bersangkutan" )) return query.answer(text=tl(update.effective_message, "Error"), show_alert=False) verify_code = [ "🙏", "👈", "👉", "👇", "👆", "❤️", "🅰️", "🅱️", "0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟" ] real_btn = random.choice(verify_code) print(real_btn) verify_code.remove(real_btn) verbox = (random.randint(1, 3), random.randint(1, 3)) buttons = [] linebox = [] was_set = False for x in range(3): x += 1 for y in range(3): y += 1 if verbox[0] == y and verbox[1] == x: was_set = True print("button was set to " + real_btn + "at " + str(verbox[0]) + " - " + str(verbox[1])) linebox.append( InlineKeyboardButton( text=real_btn, callback_data="verify_me(y|{}|{})".format( user_id, chat_id))) else: verify_emoji = random.choice(verify_code) linebox.append( InlineKeyboardButton( text=verify_emoji, callback_data="verify_me(n|{}|{})".format( user_id, chat_id))) verify_code.remove(verify_emoji) buttons.append(linebox) linebox = [] if not was_set: verbox = (random.randint(1, 3), random.randint(1, 3)) linebox[verbox[0] - 1][verbox[1] - 1] = InlineKeyboardButton( text=real_btn, callback_data="verify_me(y|{}|{})".format(user_id, chat_id)) print("[x] button was set to " + real_btn + "at " + str(verbox[0]) + " - " + str(verbox[1])) buttons.append([ InlineKeyboardButton(text="Refresh", callback_data="verify_me(re|{}|{})".format( user_id, chat_id)) ]) # query.message.delete() # context.bot.send_photo(chat.id, photo=open("emilia/modules/helper_funcs/emojis/" + verify_code_images[real_btn], 'rb'), caption=tl(update.effective_message, "Tolong pilih emoji yang sama dibawah ini:") + "\n" + tl(update.effective_message, "Jika tidak ada emoji yang sama, harap klik tombol refresh"), parse_mode="markdown", reply_markup=InlineKeyboardMarkup(buttons)) context.bot.edit_message_media( chat.id, message_id=query.message.message_id, media=InputMediaPhoto( media=open( "emilia/modules/helper_funcs/emojis/" + verify_code_images[real_btn], 'rb'), caption=tl(update.effective_message, "Tolong pilih emoji yang sama dibawah ini:") + "\n" + tl( update.effective_message, "Jika tidak ada emoji yang sama, harap klik tombol refresh" ), parse_mode="markdown"), reply_markup=InlineKeyboardMarkup(buttons)) query.answer(text=tl(update.effective_message, "Done"), show_alert=False) else: # query.message.delete() # context.bot.send_photo(chat.id, photo=open("emilia/modules/helper_funcs/emojis/fail.jpg", 'rb'), caption=tl(update.effective_message, "Maaf robot, kamu telah salah klik tombol verifikasi.\n\nCoba lagi dengan klik tombol verifikasi pada pesan selamat datang."), parse_mode="markdown") context.bot.edit_message_media( chat.id, message_id=query.message.message_id, media=InputMediaPhoto( media=open("emilia/modules/helper_funcs/emojis/fail.jpg", 'rb'), caption=tl( update.effective_message, "Maaf robot, kamu telah salah klik tombol verifikasi.\n\nCoba lagi dengan klik tombol verifikasi pada pesan selamat datang." ), parse_mode="markdown")) query.answer(text=tl( update.effective_message, "Gagal! Kamu telah salah mengklik tombol verifikasi"), show_alert=True)
def verify_welcome(update, context, chat_id): user_id = update.effective_user.id is_clicked = sql.get_chat_userlist(chat_id) if user_id not in list(is_clicked): send_message( update.effective_message, tl( update.effective_message, "You are not in verification mode, if you are muted, you can ask the admin in the group concerned for help" )) return elif user_id in list(is_clicked) and is_clicked[user_id] == True: send_message( update.effective_message, tl( update.effective_message, "You are not in verification mode, if you are muted, you can ask the admin in the group concerned for help" )) return verify_code = [ "🙏", "👈", "👉", "👇", "👆", "❤️", "🅰️", "🅱️", "0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟" ] print(len(verify_code)) real_btn = random.choice(verify_code) verify_code.remove(real_btn) verbox = (random.randint(1, 3), random.randint(1, 3)) buttons = [] linebox = [] was_set = False for x in range(3): x += 1 for y in range(3): y += 1 if verbox[0] == y and verbox[1] == x: was_set = True linebox.append( InlineKeyboardButton( text=real_btn, callback_data="verify_me(y|{}|{})".format( user_id, chat_id))) else: verify_emoji = random.choice(verify_code) linebox.append( InlineKeyboardButton( text=verify_emoji, callback_data="verify_me(n|{}|{})".format( user_id, chat_id))) verify_code.remove(verify_emoji) buttons.append(linebox) linebox = [] if not was_set: verbox = (random.randint(1, 3), random.randint(1, 3)) linebox[verbox[0] - 1][verbox[1] - 1] = InlineKeyboardButton( text=real_btn, callback_data="verify_me(y|{}|{})".format(user_id, chat_id)) buttons.append([ InlineKeyboardButton(text="Refresh", callback_data="verify_me(re|{}|{})".format( user_id, chat_id)) ]) context.bot.send_photo( user_id, photo=open( "emilia/modules/helper_funcs/emojis/" + verify_code_images[real_btn], 'rb'), caption=tl(update.effective_message, "Please choose the same emoji below:") + "\n" + tl( update.effective_message, "If none of the emojis are the same, please click the refresh button" ), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(buttons))
def verify_button_pressed(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] query = update.callback_query # type: Optional[CallbackQuery] match = re.match(r"verify_me\((.+?)\)", query.data) match = match.group(1).split("|") is_ok = match[0] user_id = match[1] chat_id = match[2] message = update.effective_message # type: Optional[Message] print("-> {} was clicked welcome verify button".format(user.id)) if is_ok == "y": if context.bot.getChatMember(chat_id, user_id).status in ('left'): query.answer( text=tl(update.effective_message, "Failed: user left chat")) return try: context.bot.restrict_chat_member( chat_id, user_id, permissions=ChatPermissions(can_send_messages=True, can_send_media_messages=True, can_send_polls=True, can_send_other_messages=True, can_add_web_page_previews=True, can_change_info=True, can_invite_users=True, can_pin_messages=True)) sql.add_to_userlist(chat_id, user_id, True) sql.rm_from_timeout(chat_id, user_id) except BadRequest as err: if not update.effective_chat.get_member( context.bot.id).can_restrict_members: query.answer(text=tl( update.effective_message, "I can't limit people here, asked the admin to unmute!")) else: query.answer(text="Error: " + str(err)) return chat_name = context.bot.get_chat(chat_id).title # query.message.delete() # context.bot.send_photo(chat.id, photo="https://telegra.ph/file/06d2c5ec80af3858c2d4b.jpg", caption=tl(update.effective_message, "*It works!*\n\nGreat job man, now you can chat on: *{}*").format(chat_name), parse_mode="markdown") context.bot.edit_message_media( chat.id, message_id=query.message.message_id, media=InputMediaPhoto( media=open("emilia/modules/helper_funcs/emojis/done.jpg", 'rb'), caption=tl( update.effective_message, "*It works!*\n\nGreat job man, now you can chat on: *{}*"). format(chat_name), parse_mode="markdown")) query.answer( text=tl(update.effective_message, "It works! You can chat on {} now").format(chat_name), show_alert=True) elif is_ok == "re": user_id = update.effective_user.id is_clicked = sql.get_chat_userlist(chat_id) if user_id not in list(is_clicked): context.bot.edit_message_text( chat.id, message_id=query.message.message_id, text=tl( update.effective_message, "You are not in verification mode, if you are muted, you can ask the admin in the group concerned for help" )) return query.answer(text=tl(update.effective_message, "Error"), show_alert=False) elif user_id in list(is_clicked) and is_clicked[user_id] == True: context.bot.edit_message_text( chat.id, message_id=query.message.message_id, text=tl( update.effective_message, "You are not in verification mode, if you are muted, you can ask the admin in the group concerned for help" )) return query.answer(text=tl(update.effective_message, "Error"), show_alert=False) verify_code = [ "🙏", "👈", "👉", "👇", "👆", "❤️", "🅰️", "🅱️", "0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟" ] real_btn = random.choice(verify_code) print(real_btn) verify_code.remove(real_btn) verbox = (random.randint(1, 3), random.randint(1, 3)) buttons = [] linebox = [] was_set = False for x in range(3): x += 1 for y in range(3): y += 1 if verbox[0] == y and verbox[1] == x: was_set = True print("button was set to " + real_btn + "at " + str(verbox[0]) + " - " + str(verbox[1])) linebox.append( InlineKeyboardButton( text=real_btn, callback_data="verify_me(y|{}|{})".format( user_id, chat_id))) else: verify_emoji = random.choice(verify_code) linebox.append( InlineKeyboardButton( text=verify_emoji, callback_data="verify_me(n|{}|{})".format( user_id, chat_id))) verify_code.remove(verify_emoji) buttons.append(linebox) linebox = [] if not was_set: verbox = (random.randint(1, 3), random.randint(1, 3)) linebox[verbox[0] - 1][verbox[1] - 1] = InlineKeyboardButton( text=real_btn, callback_data="verify_me(y|{}|{})".format(user_id, chat_id)) print("[x] button was set to " + real_btn + "at " + str(verbox[0]) + " - " + str(verbox[1])) buttons.append([ InlineKeyboardButton(text="Refresh", callback_data="verify_me(re|{}|{})".format( user_id, chat_id)) ]) # query.message.delete() # context.bot.send_photo(chat.id, photo=open("emilia/modules/helper_funcs/emojis/" + verify_code_images[real_btn], 'rb'), caption=tl(update.effective_message, "Please choose the same emoji below:") + "\n" + tl(update.effective_message, "If none of the emojis are the same, please click the refresh button"), parse_mode="markdown", reply_markup=InlineKeyboardMarkup(buttons)) context.bot.edit_message_media( chat.id, message_id=query.message.message_id, media=InputMediaPhoto( media=open( "emilia/modules/helper_funcs/emojis/" + verify_code_images[real_btn], 'rb'), caption=tl(update.effective_message, "Please choose the same emoji below:") + "\n" + tl( update.effective_message, "If none of the emojis are the same, please click the refresh button" ), parse_mode="markdown"), reply_markup=InlineKeyboardMarkup(buttons)) query.answer(text=tl(update.effective_message, "Done"), show_alert=False) else: # query.message.delete() # context.bot.send_photo(chat.id, photo=open("emilia/modules/helper_funcs/emojis/fail.jpg", 'rb'), caption=tl(update.effective_message, "Sorry robot, you have clicked the wrong verification button.\n\nTry again by clicking the verify button in the welcome message."), parse_mode="markdown") context.bot.edit_message_media( chat.id, message_id=query.message.message_id, media=InputMediaPhoto( media=open("emilia/modules/helper_funcs/emojis/fail.jpg", 'rb'), caption=tl( update.effective_message, "Sorry robot, you have clicked the wrong verification button..\n\nTry again by clicking the verify button in the welcome message." ), parse_mode="markdown")) query.answer(text=tl( update.effective_message, "Failed! You have clicked the verification button incorrectly"), show_alert=True)