예제 #1
0
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_invite_users=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
		context.bot.edit_message_media(chat.id, message_id=query.message.message_id, media=InputMediaPhoto(media="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"))
		query.answer(text=tl(update.effective_message, "Berhasil! Anda dapat chatting di {} sekarang").format(chat_name), show_alert=True)
	else:
		context.bot.edit_message_media(chat.id, message_id=query.message.message_id, media=InputMediaPhoto(media="https://telegra.ph/file/d81cdcbafb240071add84.jpg", 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)
예제 #2
0
def welcome_timeout(context):
	for cht in sql.get_all_chat_timeout():
		user_id = cht.user_id
		chat_id = cht.chat_id
		if int(time.time()) >= int(cht.timeout_int):
			getcur, extra_verify, cur_value, timeout, timeout_mode, cust_text = sql.welcome_security(chat_id)
			if timeout_mode == 1:
				try:
					context.bot.unbanChatMember(chat_id, user_id)
					send_message_raw(chat_id, tl(user_id, "Verifikasi gagal!\n{} telah di tendang!").format(mention_markdown(user_id, context.bot.getChatMember(chat_id, user_id).user.first_name)), parse_mode="markdown")
				except Exception as err:
					send_message_raw(chat_id, tl(user_id, "Verifikasi gagal!\nTetapi gagal menendang {}: {}").format(mention_markdown(user_id, context.bot.getChatMember(chat_id, user_id).user.first_name), str(err)), parse_mode="markdown")
			elif timeout_mode == 2:
				try:
					context.bot.kickChatMember(chat_id, user_id)
					send_message_raw(chat_id, tl(user_id, "Verifikasi gagal!\n{} telah di banned!").format(mention_markdown(user_id, context.bot.getChatMember(chat_id, user_id).user.first_name)), parse_mode="markdown")
				except Exception as err:
					send_message_raw(chat_id, tl(user_id, "Verifikasi gagal!\nTetapi gagal membanned {}: {}").format(mention_markdown(user_id, context.bot.getChatMember(chat_id, user_id).user.first_name), str(err)), parse_mode="markdown")
			sql.rm_from_timeout(chat_id, user_id)
예제 #3
0
def welcome_timeout(context):
    for cht in sql.get_all_chat_timeout():
        user_id = cht.user_id
        chat_id = cht.chat_id
        if int(time.time()) >= int(cht.timeout_int):
            getcur, extra_verify, cur_value, timeout, timeout_mode, cust_text = sql.welcome_security(
                chat_id)
            if timeout_mode == 1:
                try:
                    context.bot.unbanChatMember(chat_id, user_id)
                    # send_message_raw(chat_id, tl(user_id, "Verification failed!\n{} has been kicked!").format(mention_markdown(user_id, context.bot.getChatMember(chat_id, user_id).user.first_name)), parse_mode="markdown")
                except Exception as err:
                    pass
                    # send_message_raw(chat_id, tl(user_id, "Verification failed!\nBut failed to kick {}: {}").format(mention_markdown(user_id, context.bot.getChatMember(chat_id, user_id).user.first_name), str(err)), parse_mode="markdown")
            elif timeout_mode == 2:
                try:
                    context.bot.kickChatMember(chat_id, user_id)
                    # send_message_raw(chat_id, tl(user_id, "Verification failed!\n{} has been banned!").format(mention_markdown(user_id, context.bot.getChatMember(chat_id, user_id).user.first_name)), parse_mode="markdown")
                except Exception as err:
                    pass
                    # send_message_raw(chat_id, tl(user_id, "Verification failed!\nBut failed to ban {}: {}").format(mention_markdown(user_id, context.bot.getChatMember(chat_id, user_id).user.first_name), str(err)), parse_mode="markdown")
            sql.rm_from_timeout(chat_id, user_id)
예제 #4
0
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)
예제 #5
0
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)