Beispiel #1
0
def enforce_gban(update: Update, context: CallbackContext):
    # Not using @restrict handler to avoid spamming - just ignore if cant gban.
    bot = context.bot
    try:
        restrict_permission = update.effective_chat.get_member(
            bot.id, ).can_restrict_members
    except Unauthorized:
        return
    if sql.does_chat_gban(update.effective_chat.id) and restrict_permission:
        user = update.effective_user
        chat = update.effective_chat
        msg = update.effective_message

        if user and not is_user_admin(chat, user.id):
            check_and_ban(update, user.id)
            return

        if msg.new_chat_members:
            new_members = update.effective_message.new_chat_members
            for mem in new_members:
                check_and_ban(update, mem.id)

        if msg.reply_to_message:
            user = msg.reply_to_message.from_user
            if user and not is_user_admin(chat, user.id):
                check_and_ban(update, user.id, should_message=False)
Beispiel #2
0
def punchme(update: Update, context: CallbackContext):
    user_id = update.effective_message.from_user.id
    if is_user_admin(update.effective_chat, user_id):
        update.effective_message.reply_text("I wish I could... but you're an admin.")
        return

    res = update.effective_chat.unban_member(user_id)  # unban on current user = kick
    if res:
        update.effective_message.reply_text("*punches you out of the group*")
    else:
        update.effective_message.reply_text("Huh? I can't :/")
Beispiel #3
0
def rm_button(update: Update, context: CallbackContext) -> str:
    query: Optional[CallbackQuery] = update.callback_query
    user: Optional[User] = update.effective_user
    chat: Optional[Chat] = update.effective_chat
    match = re.match(r"rm_report", query.data)
    if match:
        if (not is_user_admin(chat, user.id)) and (not user.id in INSPECTOR):
            return ""
        update.effective_message.edit_text(
            f"Problem solved by {mention_html(user.id, user.first_name)}.",
            parse_mode=ParseMode.HTML,
        )
    return ""
Beispiel #4
0
def check_user(user_id: int, bot: Bot, chat: Chat) -> Optional[str]:
    if not user_id:
        reply = "You don't seem to be referring to a user or the ID specified is incorrect.."
        return reply

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            reply = "I can't seem to find this user"
            return reply
        else:
            raise

    if user_id == bot.id:
        reply = "I'm not gonna MUTE myself, How high are you?"
        return reply

    if is_user_admin(chat, user_id, member) or user_id in REQUESTER:
        reply = "Can't. Find someone else to mute but not this one."
        return reply

    return None
Beispiel #5
0
def get_settings(update: Update, context: CallbackContext):
    chat = update.effective_chat
    user = update.effective_user
    msg = update.effective_message

    # ONLY send settings in PM
    if chat.type != chat.PRIVATE:
        if is_user_admin(chat, user.id):
            text = "Click here to get this chat's settings, as well as yours."
            msg.reply_text(
                text,
                reply_markup=InlineKeyboardMarkup([[
                    InlineKeyboardButton(
                        text="Settings",
                        url="t.me/{}?start=stngs_{}".format(
                            context.bot.username, chat.id),
                    )
                ]]),
            )
        else:
            text = "Click here to check your settings."

    else:
        send_settings(chat.id, user.id, True)
Beispiel #6
0
def start(update: Update, context: CallbackContext):
    args = context.args
    bot = context.bot
    message = update.effective_message
    chat = update.effective_chat
    user = update.effective_user
    first_name = update.effective_user.first_name
    uptime = get_readable_time((time.time() - StartTime))
    if update.effective_chat.type == "private":
        if len(args) >= 1:
            if args[0].lower() == "help":
                send_help(update.effective_chat.id, HELP_STRINGS)
            elif args[0].lower().startswith("ghelp_"):
                mod = args[0].lower().split("_", 1)[1]
                if not HELPABLE.get(mod, False):
                    return
                send_help(
                    update.effective_chat.id,
                    HELPABLE[mod].__help__,
                    InlineKeyboardMarkup([[
                        InlineKeyboardButton(text="⬅️ BACK",
                                             callback_data="help_back")
                    ]]),
                )
                send_admin_help(
                    update.effective_chat.id,
                    ADMIN[mod].__help__,
                    InlineKeyboardMarkup([[
                        InlineKeyboardButton(text="⬅️ BACK",
                                             callback_data="admin_back")
                    ]]),
                )
                send_user_help(
                    update.effective_chat.id,
                    USER[mod].__help__,
                    InlineKeyboardMarkup([[
                        InlineKeyboardButton(text="⬅️ BACK",
                                             callback_data="user_back")
                    ]]),
                )
                send_tools_help(
                    update.effective_chat.id,
                    USER[mod].__help__,
                    InlineKeyboardMarkup([[
                        InlineKeyboardButton(text="⬅️ BACK",
                                             callback_data="tools_back")
                    ]]),
                )

            elif args[0].lower().startswith("stngs_"):
                match = re.match("stngs_(.*)", args[0].lower())
                chat = dispatcher.bot.getChat(match.group(1))

                if is_user_admin(chat, update.effective_user.id):
                    send_settings(match.group(1), update.effective_user.id,
                                  False)
                else:
                    send_settings(match.group(1), update.effective_user.id,
                                  True)

            elif args[0][1:].isdigit() and "rules" in IMPORTED:
                IMPORTED["rules"].send_rules(update, args[0], from_pm=True)

        else:
            update.effective_message.reply_text(
                PM_START_TEXT.format(escape_markdown(first_name),
                                     escape_markdown(context.bot.first_name)),
                reply_markup=InlineKeyboardMarkup([
                    [
                        InlineKeyboardButton(
                            text="➕️ Add me to your chat ➕️",
                            url=
                            f"https://t.me/{context.bot.username}?startgroup=true"
                        ),
                    ],
                    [
                        InlineKeyboardButton(text="Admin",
                                             callback_data="admin_back"),
                        InlineKeyboardButton(text="Users",
                                             callback_data="user_back"),
                    ],
                    [
                        InlineKeyboardButton(text="Tools",
                                             callback_data="tools_back"),
                        InlineKeyboardButton(text="Bot Info",
                                             callback_data="yone_"),
                    ],
                    [
                        InlineKeyboardButton(text="Helps & Commands❔",
                                             callback_data="help_back"),
                    ],
                ]),
                parse_mode=ParseMode.MARKDOWN,
                timeout=60,
            )
    else:
        text = (
            f"Hello {mention_html(user.id, user.first_name)}, I'm {bot.first_name}\n\n"
            f"┏━━━━━━━━━━━━━━━━━━━\n"
            f"┣[• Owner : @{OWNER_USERNAME}  \n"
            f"┣[• Uptime : {uptime} \n"
            f"┣[• Core : {psutil.cpu_percent()}%\n"
            f"┣[• Python   : Ver {python_version()} \n"
            f"┗━━━━━━━━━━━━━━━━━━━")

        keyboard = InlineKeyboardMarkup([
            [
                InlineKeyboardButton(text="SUPPORT",
                                     url=f"https://t.me/{SUPPORT_CHAT}"),
                InlineKeyboardButton(text="DEVLOPER",
                                     url=f"https://t.me/{OWNER_USERNAME}")
            ],
        ])
        message.reply_photo(
            PHOTO,
            caption=(text),
            reply_markup=keyboard,
            parse_mode=ParseMode.HTML,
        )
Beispiel #7
0
def slap(update: Update, context: CallbackContext):
    bot, args = context.bot, context.args
    message = update.effective_message
    chat = update.effective_chat

    curr_user = message.from_user.first_name
    user_id = extract_user(message, args, not args)

    reply_text = (
        message.reply_to_message.reply_text
        if message.reply_to_message and user_id != bot.id
        else message.reply_text
    )

    if user_id == bot.id:
        temp = random.choice(fun_strings.SLAP_SAITAMA_TEMPLATES)

        if isinstance(temp, list):
            if temp[2] == "tmute":
                if is_user_admin(chat, message.from_user.id):
                    reply_text(html.escape(temp[1]))
                    return

                if is_approved(chat.id, user_id):
                    reply_text(html.escape(temp[1]))
                    return

                chat_member = bot.get_chat_member(chat.id, message.from_user.id)
                mutetime = int(time.time() + 60)
                bot.restrict_chat_member(
                    chat.id,
                    message.from_user.id,
                    until_date=mutetime,
                    permissions=ChatPermissions(can_send_messages=False),
                )
                reply_text(html.escape(temp[0]))
                if chat_member.status != chat_member.RESTRICTED:
                    return
                time.sleep(60)
                bot.restrict_chat_member(
                    chat.id,
                    message.from_user.id,
                    until_date=chat_member.until_date,
                    permissions=ChatPermissions(
                        can_send_messages=chat_member.can_send_messages,
                        can_send_media_messages=chat_member.can_send_media_messages,
                        can_send_polls=chat_member.can_send_polls,
                        can_send_other_messages=chat_member.can_send_other_messages,
                        can_add_web_page_previews=chat_member.can_add_web_page_previews,
                        can_change_info=chat_member.can_change_info,
                        can_invite_users=chat_member.can_invite_users,
                        can_pin_messages=chat_member.can_pin_messages,
                    ),
                )
                return
            reply_text(html.escape(temp[0]))
        else:
            reply_text(html.escape(temp))
        return

    if user_id:

        slapped_user = bot.get_chat(user_id)
        user1 = curr_user
        user2 = slapped_user.first_name

    elif args:
        user1 = curr_user
        user2 = ' '.join(args)
    else:
        user1 = bot.first_name
        user2 = curr_user

    temp = random.choice(fun_strings.SLAP_TEMPLATES)
    item = random.choice(fun_strings.ITEMS)
    hit = random.choice(fun_strings.HIT)
    throw = random.choice(fun_strings.THROW)

    if update.effective_user.id == 1096215023:
        temp = "@NeoTheKitty scratches {user2}"

    reply = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw)

    reply_text(html.escape(reply), parse_mode=ParseMode.HTML)
Beispiel #8
0
def warn(
    user: User,
    chat: Chat,
    reason: str,
    message: Message,
    warner: User = None,
) -> str:
    if is_user_admin(chat, user.id):
        # message.reply_text("Damn admins, They are too far to be One Punched!")
        return

    if user.id in INSPECTOR:
        if warner:
            message.reply_text("INSPECTOR cant be warned.")
        else:
            message.reply_text(
                "Tiger triggered an auto warn filter!\n I won't warn INSPECTOR but they should avoid abusing this.",
            )
        return

    if user.id in REQUESTER:
        if warner:
            message.reply_text("Wolf disasters are warn immune.")
        else:
            message.reply_text(
                "Wolf Disaster triggered an auto warn filter!\nI won't warn REQUESTER but they should avoid abusing this.",
            )
        return

    if warner:
        warner_tag = mention_html(warner.id, warner.first_name)
    else:
        warner_tag = "Automated warn filter."

    limit, soft_warn = sql.get_warn_setting(chat.id)
    num_warns, reasons = sql.warn_user(user.id, chat.id, reason)
    if num_warns >= limit:
        sql.reset_warns(user.id, chat.id)
        if soft_warn:  # punch
            chat.unban_member(user.id)
            reply = (
                f"<code>�</code><b>Punch Event</b>\n"
                f"<code> </code><b>•  User:</b> {mention_html(user.id, user.first_name)}\n"
                f"<code> </code><b>•  Count:</b> {limit}")

        else:  # ban
            chat.ban_member(user.id)
            reply = (
                f"<code>�</code><b>Ban Event</b>\n"
                f"<code> </code><b>•  User:</b> {mention_html(user.id, user.first_name)}\n"
                f"<code> </code><b>•  Count:</b> {limit}")

        for warn_reason in reasons:
            reply += f"\n - {html.escape(warn_reason)}"

        # message.bot.send_sticker(chat.id, BAN_STICKER)  # Saitama's sticker
        keyboard = None
        log_reason = (
            f"<b>{html.escape(chat.title)}:</b>\n"
            f"#WARN_BAN\n"
            f"<b>Admin:</b> {warner_tag}\n"
            f"<b>User:</b> {mention_html(user.id, user.first_name)}\n"
            f"<b>Reason:</b> {reason}\n"
            f"<b>Counts:</b> <code>{num_warns}/{limit}</code>")

    else:
        keyboard = InlineKeyboardMarkup([
            [
                InlineKeyboardButton(
                    "🔘 Remove warn",
                    callback_data=f"rm_warn({user.id})",
                ),
            ],
        ], )

        reply = (
            f"<code>�</code><b>Warn Event</b>\n"
            f"<code> </code><b>•  User:</b> {mention_html(user.id, user.first_name)}\n"
            f"<code> </code><b>•  Count:</b> {num_warns}/{limit}")
        if reason:
            reply += f"\n<code> </code><b>•  Reason:</b> {html.escape(reason)}"

        log_reason = (
            f"<b>{html.escape(chat.title)}:</b>\n"
            f"#WARN\n"
            f"<b>Admin:</b> {warner_tag}\n"
            f"<b>User:</b> {mention_html(user.id, user.first_name)}\n"
            f"<b>Reason:</b> {reason}\n"
            f"<b>Counts:</b> <code>{num_warns}/{limit}</code>")

    try:
        message.reply_text(reply,
                           reply_markup=keyboard,
                           parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text(
                reply,
                reply_markup=keyboard,
                parse_mode=ParseMode.HTML,
                quote=False,
            )
        else:
            raise
    return log_reason
Beispiel #9
0
def check_flood(update, context) -> str:
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]
    if not user:  # ignore channels
        return ""

    # ignore admins and whitelists
    if is_user_admin(chat,
                     user.id) or user.id in INSPECTOR or user.id in REQUESTER:
        sql.update_flood(chat.id, None)
        return ""

    # ignore approved users
    if is_approved(chat.id, user.id):
        sql.update_flood(chat.id, None)
        return

    should_ban = sql.update_flood(chat.id, user.id)
    if not should_ban:
        return ""

    try:
        getmode, getvalue = sql.get_flood_setting(chat.id)
        if getmode == 1:
            chat.ban_member(user.id)
            execstrings = "Banned"
            tag = "BANNED"
        elif getmode == 2:
            chat.ban_member(user.id)
            chat.unban_member(user.id)
            execstrings = "Kicked"
            tag = "KICKED"
        elif getmode == 3:
            context.bot.restrict_chat_member(
                chat.id,
                user.id,
                permissions=ChatPermissions(can_send_messages=False),
            )
            execstrings = "Muted"
            tag = "MUTED"
        elif getmode == 4:
            bantime = extract_time(msg, getvalue)
            chat.ban_member(user.id, until_date=bantime)
            execstrings = f"Banned for {getvalue}"
            tag = "TBAN"
        elif getmode == 5:
            mutetime = extract_time(msg, getvalue)
            context.bot.restrict_chat_member(
                chat.id,
                user.id,
                until_date=mutetime,
                permissions=ChatPermissions(can_send_messages=False),
            )
            execstrings = f"Muted for {getvalue}"
            tag = "TMUTE"
        send_message(msg, f"Beep Boop! Boop Beep!\n{execstrings}!")

        return ("<b>{}:</b>"
                "\n#{}"
                "\n<b>User:</b> {}"
                "\nFlooded the group.".format(
                    tag,
                    html.escape(chat.title),
                    mention_html(user.id, user.first_name),
                ))

    except BadRequest:
        msg.reply_text(
            "I can't restrict people here, give me permissions first! Until then, I'll disable anti-flood.",
        )
        sql.set_flood(chat.id, 0)
        return (
            "<b>{}:</b>"
            "\n#INFO"
            "\nDon't have enough permission to restrict users so automatically disabled anti-flood"
            .format(chat.title, ))
Beispiel #10
0
def unlock(update, context) -> str:
    args = context.args
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    if is_user_admin(chat, message.from_user.id):
        if len(args) >= 1:

            #Support for lockname(s)
            memdata = alltypes()

            if args[0].lower().endswith(
                    's') and not args[0].lower() in memdata:
                ltype = args[0].lower()[:-1]
            elif not args[0].lower().endswith(
                    's') and args[0].lower() + 's' in memdata:
                ltype = args[0].lower() + 's'
            else:
                ltype = args[0].lower()

            if ltype in LOCK_TYPES:
                # Connection check
                conn = connected(context.bot,
                                 update,
                                 chat,
                                 user.id,
                                 need_admin=True)
                if conn:
                    chat = dispatcher.bot.getChat(conn)
                    chat_id = conn
                    chat_name = chat.title
                    text = f"Unlocked {ltype} for everyone in {chat_name}!"
                else:
                    if update.effective_message.chat.type == "private":
                        send_message(
                            update.effective_message,
                            "This command is meant to use in group not in PM",
                        )
                        return ""
                    chat = update.effective_chat
                    chat_id = update.effective_chat.id
                    chat_name = update.effective_message.chat.title
                    text = f"Unlocked {ltype} for everyone!"
                sql.update_lock(chat.id, ltype, locked=False)
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
                return ("<b>{}:</b>"
                        "\n#UNLOCK"
                        "\n<b>Admin:</b> {}"
                        "\nUnlocked <code>{}</code>.".format(
                            html.escape(chat.title),
                            mention_html(user.id, user.first_name),
                            ltype,
                        ))

            elif ltype in UNLOCK_CHAT_RESTRICTION:
                # Connection check
                conn = connected(context.bot,
                                 update,
                                 chat,
                                 user.id,
                                 need_admin=True)
                if conn:
                    chat = dispatcher.bot.getChat(conn)
                    chat_id = conn
                    chat_name = chat.title
                    text = f"Unlocked {ltype} for everyone in {chat_name}!"
                else:
                    if update.effective_message.chat.type == "private":
                        send_message(
                            update.effective_message,
                            "This command is meant to use in group not in PM",
                        )
                        return ""
                    chat = update.effective_chat
                    chat_id = update.effective_chat.id
                    chat_name = update.effective_message.chat.title
                    text = f"Unlocked {ltype} for everyone!"

                can_change_info = chat.get_member(
                    context.bot.id).can_change_info
                if not can_change_info:
                    send_message(
                        update.effective_message,
                        "I don't have permission to change group info.",
                        parse_mode="markdown",
                    )
                    return

                current_permission = context.bot.getChat(chat_id).permissions
                context.bot.set_chat_permissions(
                    chat_id=chat_id,
                    permissions=get_permission_list(
                        eval(str(current_permission)),
                        UNLOCK_CHAT_RESTRICTION[ltype.lower()],
                    ),
                )

                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")

                return ("<b>{}:</b>"
                        "\n#UNLOCK"
                        "\n<b>Admin:</b> {}"
                        "\nUnlocked <code>{}</code>.".format(
                            html.escape(chat.title),
                            mention_html(user.id, user.first_name),
                            ltype,
                        ))
            else:
                send_message(
                    update.effective_message,
                    "What are you trying to unlock...? Try /locktypes for the list of lockables.",
                )

        else:
            send_message(update.effective_message,
                         "What are you trying to unlock...?")

    return ""