Exemplo n.º 1
0
async def _check_warns_of_user(_, msg: Message):
    global WARN_LIMIT  # pylint: disable=global-statement
    replied = msg.reply_to_message
    if replied:
        user_id = replied.from_user.id
        mention = f"[{replied.from_user.first_name}](tg://user?id={user_id})"
    else:
        user_id = msg.from_user.id
        mention = f"[{msg.from_user.first_name}](tg://user?id={user_id})"
    if is_dev(user_id):
        await msg.reply("`He is My Master, I never Warned him.`")
        return
    if await is_self(user_id):
        return
    if is_admin(msg.chat.id, user_id):
        await msg.reply("`He is admin, I never Warned him.`")
        return
    if replied and not is_admin(msg.chat.id, msg.from_user.id,
                                check_devs=True):
        await msg.reply("`You can Only see your Warnings.`")
        return
    if DATA.get(user_id):
        w_c = DATA[user_id]["limit"]  # warn counts
        reason = "\n".join(DATA[user_id]["reason"])
        reply_msg = ("#WARNINGS\n"
                     f"**User:** {mention}\n"
                     f"**Warn Counts:** {w_c}/{WARN_LIMIT} Warnings\n"
                     f"**Reason:** {reason}")
        await msg.reply(reply_msg)
    else:
        await msg.reply("`Warnings not Found.`")
Exemplo n.º 2
0
async def _unmute_user(_, msg: Message):
    chat_id = msg.chat.id
    if not await check_rights(chat_id, msg.from_user.id,
                              "can_restrict_members"):
        return
    replied = msg.reply_to_message
    if replied:
        id_ = replied.from_user.id
    elif len(msg.text) > 7:
        _, id_ = msg.text.split(maxsplit=1)
    else:
        await msg.reply("`No valid User_id or message specified.`")
        return
    try:
        user_id = (await bot.get_users(id_)).id
    except (UsernameInvalid, PeerIdInvalid, UserIdInvalid):
        await msg.reply(
            "`Invalid user_id or username, try again with valid info ⚠`")
        return
    if await is_self(user_id):
        return
    if is_admin(chat_id, user_id):
        await msg.reply("`User is Admin.`")
        return
    if not await check_bot_rights(chat_id, "can_restrict_members"):
        await msg.reply("`Give me rights to UnMute Users.`")
        await sed_sticker(msg)
        return
    sent = await msg.reply("`Trying to UnMute User...`")
    try:
        await bot.unban_chat_member(chat_id, user_id)
        await sent.edit("`🛡 Successfully Unmuted🛡️`")
    except Exception as e_f:  # pylint: disable=broad-except
        await sent.edit(f"`Something went wrong!` 🤔\n\n**ERROR:** `{e_f}`")
Exemplo n.º 3
0
async def _report(msg: Message):
    replied = msg.reply_to_message
    if not replied:
        return
    f_u_id = replied.from_user.id
    if await is_self(f_u_id) or is_dev(f_u_id) or is_admin(
            msg.chat.id, f_u_id):
        return
    if len(msg.text) < 9:
        return
    _, args = msg.text.split(maxsplit=1)
    if not args:
        return
    reason = f"**Reported User:** {replied.from_user.mention}\n"
    reason += f"**Reported Msg link:** {replied.link}\n"
    reason += f"**Reason:** `{args}`\n\n"
    reason += f"**Report From:** {msg.from_user.mention}"
    sent = await msg.reply("`Reporting ...`")
    for admin_id in Config.ADMINS.get(msg.chat.id):
        try:
            await bot.send_message(admin_id,
                                   reason,
                                   disable_web_page_preview=True)
        except Exception:  # pylint: disable=broad-except
            pass
    await sent.edit("`Reported to all Admins !`")
Exemplo n.º 4
0
async def _mute_user(_, msg: Message):
    chat_id = msg.chat.id
    if not await check_rights(chat_id, msg.from_user.id, "can_restrict_members"):
        return
    cmd = len(msg.text)
    replied = msg.reply_to_message
    if replied:
        id_ = replied.from_user.id
        if not (msg.text and cmd > 5):
            await msg.reply("`Give a reason to Mute him.`")
            return
        _, reason = msg.text.split(maxsplit=1)
    elif msg.text and cmd > 5:
        _, args = msg.text.split(maxsplit=1)
        try:
            id_, reason = args.split(' ', maxsplit=1)
        except Exception:  # pylint: disable=broad-except
            await msg.reply("**Syntax:** /mute user_id reason")
            return
    else:
        await msg.reply("`No valid User_id or message specified.`")
        return
    try:
        user = await bot.get_users(id_)
        user_id = user.id
        mention = user.mention
    except (UsernameInvalid, PeerIdInvalid, UserIdInvalid):
        await msg.reply("`Invalid user_id or username, try again with valid info ⚠`")
        return
    if await is_self(user_id):
        await sed_sticker(msg)
        return
    if is_dev(user_id):
        await msg.reply("`He is My Master, I will not Mute him.`")
        return
    if is_admin(chat_id, user_id):
        await msg.reply("`User is Admin, Can't Mute him.`")
        return
    if not await check_bot_rights(chat_id, "can_restrict_members"):
        await msg.reply("`Give me rights to Mute Users.`")
        await sed_sticker(msg)
        return
    sent = await msg.reply("`Trying to Mute User.. Hang on!! ⏳`")
    try:
        await bot.restrict_chat_member(chat_id, user_id, ChatPermissions())
        await asyncio.sleep(1)
        await sent.edit(
            f"#MUTE\n"
            f"USER: {mention}\n"
            f"TIME: `Forever`\n"
            f"REASON: `{reason}`")
    except Exception as e_f:  # pylint: disable=broad-except
        await sent.edit(f"`Something went wrong 🤔`\n\n**ERROR**: `{e_f}`")
Exemplo n.º 5
0
async def _ban_user(_, msg: Message):
    chat_id = msg.chat.id
    if not await check_rights(chat_id, msg.from_user.id,
                              "can_restrict_members"):
        return
    cmd = len(msg.text)
    replied = msg.reply_to_message
    reason = ''
    if replied:
        id_ = replied.from_user.id
        if cmd > 4:
            _, reason = msg.text.split(maxsplit=1)
    elif cmd > 4:
        _, args = msg.text.split(maxsplit=1)
        if ' ' in args:
            id_, reason = args.split(' ', maxsplit=1)
        else:
            id_ = args
    else:
        await msg.reply("`No valid User_id or message specified.`")
        return
    try:
        user = await bot.get_users(id_)
        user_id = user.id
        mention = user.mention
    except (UsernameInvalid, PeerIdInvalid, UserIdInvalid):
        await msg.reply(
            "`Invalid user_id or username, try again with valid info ⚠`")
        return
    if await is_self(user_id):
        await sed_sticker(msg)
        return
    if is_dev(user_id):
        await msg.reply("`He is My Master, I will not Ban him.`")
        return
    if is_admin(chat_id, user_id):
        await msg.reply("`User is Admin, Can't Ban him.`")
        return
    if not await check_bot_rights(chat_id, "can_restrict_members"):
        await msg.reply("`Give me rights to Ban Users.`")
        await sed_sticker(msg)
        return
    sent = await msg.reply("`Trying to Ban User... `")
    try:
        await bot.kick_chat_member(chat_id, user_id)
        await sent.edit(f"BANNED\n"
                        f"USER: {mention}\n"
                        f"REASON: `{reason or None}`")
    except Exception as e_f:  # pylint: disable=broad-except
        await sent.edit(f"`Something went wrong! 🤔`\n\n**ERROR:** `{e_f}`")
Exemplo n.º 6
0
async def _check_warns_of_user(msg: Message):
    replied = msg.reply_to_message
    if replied:
        user_id = str(replied.from_user.id)
        mention = f"[{replied.from_user.first_name}](tg://user?id={user_id})"
    else:
        user_id = str(msg.from_user.id)
        mention = f"[{msg.from_user.first_name}](tg://user?id={user_id})"
    if is_dev(int(user_id)):
        await msg.reply("`He is My Master, I never Warned him.`")
        return
    if await is_self(int(user_id)):
        return
    if is_admin(msg.chat.id, int(user_id)):
        await msg.reply("`He is admin, I never Warned him.`")
        return
    if replied and not is_admin(msg.chat.id, msg.from_user.id,
                                check_devs=True):
        await msg.reply("`You can only see your Warnings.`")
        return
    DATA = await bot.load_data(bot.WARN_DATA_ID)
    w_l = (await bot.load_data(bot.WARN_LIMIT_ID)).get(str(msg.chat.id))
    if DATA.get(str(msg.chat.id)) is None:
        await msg.reply("`Warnings not Found.`")
        return

    if DATA[str(msg.chat.id)].get(user_id):
        w_c = DATA[str(msg.chat.id)][user_id]['limit']  # warn counts
        reason = '\n'.join(DATA[str(msg.chat.id)][user_id]['reason'])
        reply_msg = ("**#WARNINGS**\n"
                     f"**User:** {mention}\n"
                     f"**Warn Counts:** `{w_c}/{w_l} Warnings.`\n"
                     f"**Reason:** `{reason}`")
        await msg.reply(reply_msg)
    else:
        await msg.reply("`Warnings not Found.`")
Exemplo n.º 7
0
async def remove_warn(_, c_q: CallbackQuery):
    user_id = int(c_q.matches[0].group(1))
    if is_admin(c_q.message.chat.id, c_q.from_user.id, check_devs=True):
        if DATA.get(user_id):
            up_l = DATA[user_id]['limit'] - 1  # up_l = updated limit
            if up_l > 0:
                DATA[user_id]['limit'] = up_l
                del DATA[user_id]['reason'][-1]
            else:
                DATA.pop(user_id)
            text = f"[{c_q.from_user.first_name}](tg://user?id={c_q.from_user.id})"
            text += " `removed this Warn.`"
            await c_q.edit_message_text(text)
        else:
            await c_q.edit_message_text("This User already not have any Warn.")
    else:
        await c_q.answer("Only Admins Can Remove this Warn", show_alert=True)
Exemplo n.º 8
0
async def _demote_user(_, msg: Message):
    chat_id = msg.chat.id
    if not await check_rights(chat_id, msg.from_user.id,
                              "can_promote_members"):
        return
    replied = msg.reply_to_message
    if replied:
        id_ = replied.from_user.id
    elif len(msg.text) > 7:
        _, id_ = msg.text.split(maxsplit=1)
    else:
        await msg.reply("`No valid User_id or message specified.`")
        return
    try:
        user_id = (await bot.get_users(id_)).id
    except (UsernameInvalid, PeerIdInvalid, UserIdInvalid):
        await msg.reply(
            "`Invalid user_id or username, try again with valid info ⚠`")
        return
    if await is_self(user_id):
        await sed_sticker(msg)
        return
    if is_dev(user_id):
        return
    if not is_admin(chat_id, user_id):
        await msg.reply("`Cant demote a Demoted User`")
        return
    if not await check_bot_rights(chat_id, "can_promote_members"):
        await msg.reply("`Give me rights to Demote User.`")
        await sed_sticker(msg)
        return
    sent = await msg.reply("`Trying to Demote User.. Hang on!! ⏳`")
    try:
        await bot.promote_chat_member(
            chat_id,
            user_id,
            can_change_info=False,
            can_delete_messages=False,
            can_restrict_members=False,
            can_invite_users=False,
            can_pin_messages=False,
        )
        await sent.edit("`🛡 Demoted Successfully..`")
    except Exception as e_f:  # pylint: disable=broad-except
        await sent.edit(f"`Something went wrong! 🤔`\n\n**ERROR:** `{e_f}`")
Exemplo n.º 9
0
async def _unmute_user(_, msg: Message):
    chat_id = msg.chat.id
    if not await check_rights(chat_id, msg.from_user.id, "can_restrict_members"):
        return
    replied = msg.reply_to_message
    if replied:
        id_ = replied.from_user.id
    elif msg.text and len(msg.text) > 7:
        _, id_ = msg.text.split(maxsplit=1)
    else:
        await msg.reply("`No valid User_id or message specified.`")
        return
    try:
        user_id = (await bot.get_users(id_)).id
    except (UsernameInvalid, PeerIdInvalid, UserIdInvalid):
        await msg.reply("`Invalid user_id or username, try again with valid info ⚠`")
        return
    if await is_self(user_id):
        return
    if is_admin(chat_id, user_id):
        await msg.reply("`User is Admin.`")
        return
    if not await check_bot_rights(chat_id, "can_restrict_members"):
        await msg.reply("`Give me rights to UnMute Users.`")
        await sed_sticker(msg)
        return
    sent = await msg.reply("`Trying to UnMute User.. Hang on!! ⏳`")
    try:
        await bot.restrict_chat_member(
            chat_id, user_id,
            ChatPermissions(
                can_send_messages=msg.chat.permissions.can_send_messages,
                can_send_media_messages=msg.chat.permissions.can_send_media_messages,
                can_send_stickers=msg.chat.permissions.can_send_stickers,
                can_send_animations=msg.chat.permissions.can_send_animations,
                can_send_games=msg.chat.permissions.can_send_games,
                can_use_inline_bots=msg.chat.permissions.can_use_inline_bots,
                can_add_web_page_previews=msg.chat.permissions.can_add_web_page_previews,
                can_send_polls=msg.chat.permissions.can_send_polls,
                can_change_info=msg.chat.permissions.can_change_info,
                can_invite_users=msg.chat.permissions.can_invite_users,
                can_pin_messages=msg.chat.permissions.can_pin_messages))
        await sent.edit("`🛡 Successfully Unmuted..`")
    except Exception as e_f:  # pylint: disable=broad-except
        await sent.edit(f"`Something went wrong!` 🤔\n\n**ERROR:** `{e_f}`")
Exemplo n.º 10
0
async def _reset_all_warns(_, msg: Message):
    replied = msg.reply_to_message
    if not replied:
        return
    user_id = replied.from_user.id
    if is_dev(user_id):
        await msg.reply("`He is My Master, I never Warned him.`")
        return
    if await is_self(user_id):
        return
    if is_admin(msg.chat.id, user_id):
        await msg.reply("`He is admin, I never Warned him.`")
        return
    if DATA.get(user_id):
        DATA.pop(user_id)
        await msg.reply("`All Warns are removed for this User.`")
    else:
        await msg.reply("`User already not have any warn.`")
Exemplo n.º 11
0
async def _warn_user(msg: Message):
    replied = msg.reply_to_message
    if not replied:
        return
    chat_id = msg.chat.id
    user_id = replied.from_user.id
    if is_dev(user_id):
        await msg.reply("`He is My Master, Can't Warn him.`")
        return
    if await is_self(user_id):
        await sed_sticker(msg)
        return
    if is_admin(chat_id, user_id):
        await msg.reply("`User is Admin, Can't Warn him.`")
        return
    cmd = len(msg.text)
    reason = None
    if msg.text and cmd > 5:
        _, reason = msg.text.split(maxsplit=1)
    await warn(msg, chat_id, user_id, reason)
Exemplo n.º 12
0
async def _reset_all_warns(msg: Message):
    replied = msg.reply_to_message
    if not replied:
        return
    user_id = replied.from_user.id
    if is_dev(user_id):
        await msg.reply("`He is My Master, I never Warned him.`")
        return
    if await is_self(user_id):
        return
    if is_admin(msg.chat.id, user_id):
        await msg.reply("`He is admin, I never Warned him.`")
        return
    DATA = await bot.load_data(bot.WARN_DATA_ID)
    if DATA.get(str(msg.chat.id)) is None:
        await msg.reply("`User already not have any warn.`")
        return
    if DATA[str(msg.chat.id)].get(str(user_id)):
        DATA[str(msg.chat.id)].pop(str(user_id))
        await bot.save_data(bot.WARN_DATA_ID, json.dumps(DATA))
        await msg.reply("`All Warns are removed for this User.`")
    else:
        await msg.reply("`User already not have any warn.`")
Exemplo n.º 13
0
async def remove_warn(_, c_q: CallbackQuery):
    user_id = str(c_q.matches[0].group(1))
    DATA = await bot.load_data(bot.WARN_DATA_ID)
    if is_admin(c_q.message.chat.id, c_q.from_user.id, check_devs=True):
        if DATA.get(str(c_q.message.chat.id)) is None:
            await c_q.edit_message_text("This User already not have any Warn.")
            return
        if DATA[str(c_q.message.chat.id)].get(user_id):
            up_l = DATA[str(c_q.message.chat.id
                            )][user_id]['limit'] - 1  # up_l = updated limit
            if up_l > 0:
                DATA[str(c_q.message.chat.id)][user_id]['limit'] = up_l
                del DATA[str(c_q.message.chat.id)][user_id]['reason'][-1]
            else:
                DATA[str(c_q.message.chat.id)].pop(user_id)
            await bot.save_data(bot.WARN_DATA_ID, json.dumps(DATA))
            text = f"[{c_q.from_user.first_name}](tg://user?id={c_q.from_user.id})"
            text += " `removed this Warn.`"
            await c_q.edit_message_text(text)
        else:
            await c_q.edit_message_text("This User already not have any Warn.")
    else:
        await c_q.answer("Only Admins can remove this Warn", show_alert=True)
Exemplo n.º 14
0
async def _tban_user(_, msg: Message):
    chat_id = msg.chat.id
    if not await check_rights(chat_id, msg.from_user.id,
                              "can_restrict_members"):
        return
    cmd = len(msg.text)
    replied = msg.reply_to_message
    if replied:
        id_ = replied.from_user.id
        if cmd <= 5:
            await msg.reply("`Time limit not found.`")
            return
        _, args = msg.text.split(maxsplit=1)
    elif cmd > 5:
        _, text = msg.text.split(maxsplit=1)
        if ' ' in text:
            id_, args = text.split(' ', maxsplit=1)
        else:
            await msg.reply("`Time limit not found.`")
    else:
        await msg.reply("`No valid User_id or message specified.`")
        return
    if ' ' in args:
        split = args.split(None, 1)
        time_val = split[0].lower()
        reason = split[1]
    else:
        time_val = args
        reason = ''

    time_ = await extract_time(msg, time_val)
    if not time_:
        return
    try:
        user = await bot.get_users(id_)
        user_id = user.id
        mention = user.mention
    except (UsernameInvalid, PeerIdInvalid, UserIdInvalid):
        await msg.reply(
            "`Invalid user_id or username, try again with valid info ⚠`")
        return
    if await is_self(user_id):
        await sed_sticker(msg)
        return
    if is_dev(user_id):
        await msg.reply("`He is My Master, I will not Ban him.`")
        return
    if is_admin(chat_id, user_id):
        await msg.reply("`User is Admin, Can't Ban him.`")
        return
    if not await check_bot_rights(chat_id, "can_restrict_members"):
        await msg.reply("`Give me rights to Ban Users.`")
        await sed_sticker(msg)
        return
    sent = await msg.reply("`Trying to Ban User...`")
    try:
        await bot.kick_chat_member(chat_id, user_id, time_)
        await asyncio.sleep(1)
        await sent.edit(f"TEMP_BANNED\n"
                        f"USER: {mention}\n"
                        f"TIME: `{time_val}`\n"
                        f"REASON: `{reason or None}`")
    except Exception as e_f:  # pylint: disable=broad-except
        await sent.edit(f"`Something went wrong 🤔`\n\n**ERROR**: `{e_f}`")
Exemplo n.º 15
0
async def _warn_user(_, msg: Message):
    global WARN_MODE, WARN_LIMIT  # pylint: disable=global-statement

    replied = msg.reply_to_message
    if not replied:
        return
    chat_id = msg.chat.id
    user_id = replied.from_user.id
    mention = f"[{replied.from_user.first_name}](tg://user?id={user_id})"

    if is_dev(user_id):
        await msg.reply("`He is My Master, Can't Warn him.`")
        return
    if await is_self(user_id):
        await sed_sticker(msg)
        return
    if is_admin(chat_id, user_id):
        await msg.reply("`User is Admin, Can't Warn him.`")
        return

    cmd = len(msg.text)
    if msg.text and cmd == 5:
        await msg.reply("`Give a reason to warn him.`")
        return
    _, args = msg.text.split(maxsplit=1)
    args += f"\n   -By {msg.from_user.mention}"

    w_l = WARN_LIMIT
    w_m = WARN_MODE
    if not DATA.get(user_id):
        w_d = {"limit": 1, "reason": [args]}
        DATA[user_id] = w_d  # warning data
        keyboard = InlineKeyboardMarkup([[
            InlineKeyboardButton(
                "Remove this Warn",
                callback_data=f"rm_warn({user_id} {msg.from_user.id})",
            )
        ]])
        reply_text = f"#Warned\n{mention} has 1/{w_l} warnings.\n"
        reply_text += f"**Reason:** {args}"
        await replied.reply_text(reply_text, reply_markup=keyboard)
    else:
        p_l = DATA[user_id]["limit"]  # previous limit
        nw_l = p_l + 1  # new limit
        if nw_l >= w_l:
            if w_m == "ban":
                await bot.kick_chat_member(chat_id, user_id)
                exec_str = "BANNED"
            elif w_m == "kick":
                await bot.kick_chat_member(chat_id, user_id, time.time() + 60)
                exec_str = "KICKED"
            else:
                await bot.restrict_chat_member(chat_id, user_id,
                                               ChatPermissions())
                exec_str = "MUTED"
            reason = "\n".join(DATA[user_id]["reason"]) + "\n" + str(args)
            await msg.reply(f"#WARNED_{exec_str}\n"
                            f"**{exec_str} User:** {mention}\n"
                            f"**Warn Counts:** {w_l}/{w_l} Warnings\n"
                            f"**Reason:** {reason}")
            DATA.pop(user_id)

        else:
            DATA[user_id]["limit"] = nw_l
            DATA[user_id]["reason"].append(args)
            keyboard = InlineKeyboardMarkup([[
                InlineKeyboardButton(
                    "Remove this Warn",
                    callback_data=f"rm_warn({user_id} {msg.from_user.id})",
                )
            ]])
            r_t = f"#Warned\n{mention} has {nw_l}/{w_l} warnings.\n"
            r_t += f"**Reason:** {args}"  # r_t = reply text
            await replied.reply_text(r_t, reply_markup=keyboard)
Exemplo n.º 16
0
async def _ban_user(_, msg: Message):
    chat_id = msg.chat.id
    if not await check_rights(chat_id, msg.from_user.id, "can_restrict_members"):
        return
    cmd = len(msg.text)
    replied = msg.reply_to_message
    if replied:
        id_ = replied.from_user.id
        if not (msg.text and cmd > 4):
            await msg.reply("`Give a reason to Ban him.`")
            return
        _, args = msg.text.split(maxsplit=1)
    elif msg.text and cmd > 4:
        _, text = msg.text.split(maxsplit=1)
        try:
            id_, args = text.split(' ', maxsplit=1)
        except Exception:  # pylint: disable=broad-except
            await msg.reply("**Syntax:** /ban user_id reason")
            return
    else:
        await msg.reply("`No valid User_id or message specified.`")
        return
    try:
        split = args.split(None, 1)
        time_val = split[0].lower()

        if len(split) > 1:
            reason = split[1]
        else:
            await msg.reply("`Syntax: /ban [user_id | reply to User] 30m reason`")
            return

        time_ = await extract_time(msg, time_val)
        if not time_:
            return
    except Exception:  # pylint: disable=broad-except
        time_val = "Forever"
        time_ = int(time.time() + 0)
        reason = args
    try:
        user = await bot.get_users(id_)
        user_id = user.id
        mention = user.mention
    except (UsernameInvalid, PeerIdInvalid, UserIdInvalid):
        await msg.reply("`Invalid user_id or username, try again with valid info ⚠`")
        return
    if await is_self(user_id):
        await sed_sticker(msg)
        return
    if is_dev(user_id):
        await msg.reply("`He is My Master, I will not Ban him.`")
        return
    if is_admin(chat_id, user_id):
        await msg.reply("`User is Admin, Can't Ban him.`")
        return
    if not await check_bot_rights(chat_id, "can_restrict_members"):
        await msg.reply("`Give me rights to Ban Users.`")
        await sed_sticker(msg)
        return
    sent = await msg.reply("`Trying to Ban User.. Hang on!! ⏳`")
    try:
        await bot.kick_chat_member(chat_id, user_id, time_)
        await sent.edit(
            "#BAN\n"
            f"USER: {mention}\n"
            f"TIME: `{time_val}`\n"
            f"REASON: `{reason}`")
    except Exception as e_f:  # pylint: disable=broad-except
        await sent.edit(f"`Something went wrong! 🤔`\n\n**ERROR:** `{e_f}`")