Пример #1
0
def removetag(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return
    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return
        else:
            raise
    if user_id == context.bot.id:
        message.reply_text("how I supposed to tag or untag myself")
        return
    chat_id = str(chat.id)[1:]
    tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}'))
    match_user = mention_html(member.user.id, member.user.first_name)
    if match_user not in tagall_list:
        message.reply_text("{} is doesn't exist in {}'s list!".format(
            mention_html(member.user.id, member.user.first_name), chat.title),
                           parse_mode=ParseMode.HTML)
        return
    member = chat.get_member(int(user_id))
    chat_id = str(chat.id)[1:]
    REDIS.srem(f'tagall2_{chat_id}',
               mention_html(member.user.id, member.user.first_name))
    message.reply_text("{} is successfully removed from {}'s list.".format(
        mention_html(member.user.id, member.user.first_name), chat.title),
                       parse_mode=ParseMode.HTML)
Пример #2
0
def feedback(update: Update, context: CallbackContext):
    message = update.effective_message
    chat = update.effective_chat
    name = update.effective_user.first_name
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    feedbak = extract_text(message)

    feed_text = f"#FEEDBACK \n\n{context.bot.first_name}'s New Feedback From [{name}](tg://user?id={user_id}) \nUser ID: `{user_id}`  \n"

    if chat.username and chat.type == Chat.SUPERGROUP:
        feed_link = feed_text + f"Message Link: [Here](https://t.me/{chat.username}/{message.message_id}) \n\n• Feedback : ↧ \n{feedbak}"

    else:
        feed_link = feed_text + f"\n• Feedback : ↧ \n{feedbak}"

    context.bot.send_message(-1001175341127,
                             feed_link,
                             parse_mode=ParseMode.MARKDOWN,
                             disable_web_page_preview=True)

    reply_text = f"Thank-You For Giving Us Your Feedback ;)"
    message.reply_text(reply_text,
                       reply_markup=InlineKeyboardMarkup([[
                           InlineKeyboardButton(
                               text="You Can See Your Feedback Here",
                               url="t.me/{}".format(SUPPORT_CHAT))
                       ]]))
Пример #3
0
def gkickset(update, context):
    message = update.effective_message
    args = context.args
    bot = context.bot
    user_id, value = extract_user_and_text(message, args)
    try:
        user_chat = context.bot.get_chat(user_id)
    except BadRequest as excp:
        if excp.message in GKICK_ERRORS:
            pass
        else:
            message.reply_text("GENERIC ERROR: {}".format(excp.message))
    except TelegramError:
        pass
    if not user_id:
        message.reply_text("You do not seems to be referring to a user")
        return

    if int(user_id) in OFFICERS:
        message.reply_text("Error! (^_-)")
        return

    if user_id == bot.id:
        message.reply_text("Error! (¯―¯٥)")
        return

    if not value:
        message.reply_text("Please Give Me A Valid Numerical Value (1 to 10) ")
        return

    sql.gkick_setvalue(user_id, user_chat.username, int(value))
    update.effective_message.reply_text("GKICK VALUE UPDATED!")
    return
Пример #4
0
def unapprove(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return
    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return
        else:
            raise
    if user_id == context.bot.id:
        message.reply_text("how I supposed to approve or unapprove myself")
        return
    chat_id = str(chat.id)[1:]
    approve_list = list(REDIS.sunion(f'approve_list_{chat_id}'))
    target_user = mention_html(member.user.id, member.user.first_name)
    if target_user not in approve_list:
        message.reply_text("{} isn't approved yet.".format(
            mention_html(member.user.id, member.user.first_name)),
                           parse_mode=ParseMode.HTML)
        return
    member = chat.get_member(int(user_id))
    chat_id = str(chat.id)[1:]
    REDIS.srem(f'approve_list_{chat_id}',
               mention_html(member.user.id, member.user.first_name))
    message.reply_text("{} is no longer approved in {}.".format(
        mention_html(member.user.id, member.user.first_name), chat.title),
                       parse_mode=ParseMode.HTML)
Пример #5
0
def gkickreset(update, context):
    message = update.effective_message
    args = context.args
    bot = context.bot
    user_id, value = extract_user_and_text(message, args)
    try:
        user_chat = context.bot.get_chat(user_id)
    except BadRequest as excp:
        if excp.message in GKICK_ERRORS:
            pass
        else:
            message.reply_text("GENERIC ERROR: {}".format(excp.message))
    except TelegramError:
        pass
    if not user_id:
        message.reply_text("You do not seems to be referring to a user")
        return

    if int(user_id) in OFFICERS:
        message.reply_text("Error! (^_-)")
        return

    if user_id == bot.id:
        message.reply_text("Error! (¯―¯٥)")
        return

    sql.gkick_reset(user_id)
    update.effective_message.reply_text("GKICK RESETED!")
    return
Пример #6
0
def set_title(update, context):
    args = context.args
    chat = update.effective_chat
    message = update.effective_message

    user_id, title = extract_user_and_text(message, args)
    try:
        user_member = chat.get_member(user_id)
    except Exception:
        return

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return

    if user_member.status == "creator":
        message.reply_text(
            "This person CREATED the chat, how can i set custom title for him?"
        )
        return

    if not user_member.status == "administrator":
        message.reply_text(
            "Can't set title for non-admins!\nPromote them first to set custom title!"
        )
        return

    if user_id == context.bot.id:
        message.reply_text(
            "I can't set my own title myself! Get the one who made me admin to do it for me."
        )
        return

    if not title:
        message.reply_text("Setting blank title doesn't do anything!")
        return

    if len(title) > 16:
        message.reply_text(
            "The title length is longer than 16 characters.\nTruncating it to 16 characters."
        )

    try:
        context.bot.set_chat_administrator_custom_title(
            chat.id, user_id, title)
        message.reply_text(
            "Sucessfully set title for <b>{}</b> to <code>{}</code>!".format(
                user_member.user.first_name or user_id, title[:16]),
            parse_mode=ParseMode.HTML,
        )

    except BadRequest:
        message.reply_text(
            "I can't set custom title for admins that I didn't promote!")
Пример #7
0
def unban(update, context):
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    args = context.args

    if user_can_ban(chat, user, context.bot.id) is False:
        message.reply_text(
            "You don't have enough rights to unban people here!")
        return ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return ""

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

    if user_id == context.bot.id:
        message.reply_text("How would I unban myself if I wasn't here...?")
        return ""

    if is_user_in_chat(chat, user_id):
        message.reply_text(
            "Why are you trying to unban someone who's already in this chat?")
        return ""

    chat.unban_member(user_id)
    message.reply_text("Done, they can join again!")

    log = ("<b>{}:</b>"
           "\n#UNBANNED"
           "\n<b>Admin:</b> {}"
           "\n<b>User:</b> {} (<code>{}</code>)".format(
               html.escape(chat.title),
               mention_html(user.id, user.first_name),
               mention_html(member.user.id, member.user.first_name),
               member.user.id,
           ))
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    return log
Пример #8
0
def addtag(update, context):
    chat = update.effective_chat  
    user = update.effective_user 
    message = update.effective_message
    args = context.args 
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return 
    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return 
        else:
            raise
    if user_id == context.bot.id:
        message.reply_text("how I supposed to tag myself")
        return 
    
    chat_id = str(chat.id)[1:] 
    tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}'))
    match_user = mention_html(member.user.id, member.user.first_name)
    if match_user in tagall_list:
        message.reply_text(
            "{} is already exist in {}'s tag list.".format(mention_html(member.user.id, member.user.first_name),
                                                           chat.title),
            parse_mode=ParseMode.HTML
        )
        return
    message.reply_text(
        "{} accept this, if you want to add yourself into {}'s tag list! or just simply decline this.".format(mention_html(member.user.id, member.user.first_name),
                                                                     chat.title),
        reply_markup=InlineKeyboardMarkup(
                                   [
                                       [
                                           InlineKeyboardButton(text="Accept", callback_data=f"tagall_accept={user_id}"),
                                           InlineKeyboardButton(text="Decline", callback_data=f"tagall_dicline={user_id}")  
                                        ]
                                    ]
                                   ),
        parse_mode=ParseMode.HTML
    )
Пример #9
0
def bl_user(update: Update, context: CallbackContext) -> str:
    message = update.effective_message
    user = update.effective_user
    bot, args = context.bot, context.args
    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("I doubt that's a user.")
        return ""

    if user_id == bot.id:
        message.reply_text(
            "How am I supposed to do my work if I am ignoring myself?")
        return ""

    if user_id in BLACKLISTWHITELIST:
        message.reply_text("No!\nNoticing Staff is my job.")
        return ""

    try:
        target_user = bot.get_chat(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user.")
            return ""
        else:
            raise

    sql.blacklist_user(user_id, reason)
    message.reply_text("I shall ignore the existence of this user!")
    log_message = (
        f"#BLACKLIST\n"
        f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
        f"<b>User:</b> {mention_html(target_user.id, html.escape(target_user.first_name))}"
    )
    if reason:
        log_message += f"\n<b>Reason:</b> {reason}"

    return log_message
Пример #10
0
def warn_user(update, context):
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    warner = update.effective_user  # type: Optional[User]
    args = context.args
    user_id, reason = extract_user_and_text(message, args)

    if user_id:
        if (message.reply_to_message
                and message.reply_to_message.from_user.id == user_id):
            return warn(
                message.reply_to_message.from_user,
                chat,
                reason,
                message.reply_to_message,
                warner,
            )
        else:
            return warn(
                chat.get_member(user_id).user, chat, reason, message, warner)
    else:
        message.reply_text("No user was designated!")
    return ""
Пример #11
0
def approvel(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return
    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return
        else:
            raise
    if user_id == context.bot.id:
        message.reply_text("How I supposed to approve myself")
        return

    chat_id = str(chat.id)[1:]
    approve_list = list(REDIS.sunion(f'approve_list_{chat_id}'))
    target_user = mention_html(member.user.id, member.user.first_name)
    if target_user in approve_list:
        message.reply_text(
            "{} is an approved user. Locks, antiflood, and blocklists won't apply to them."
            .format(mention_html(member.user.id, member.user.first_name)),
            parse_mode=ParseMode.HTML)
        return

    if target_user not in approve_list:
        message.reply_text(
            "{} is not an approved user. They are affected by normal commands."
            .format(mention_html(member.user.id, member.user.first_name)),
            parse_mode=ParseMode.HTML)
        return
Пример #12
0
def temp_mute(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    if user_can_ban(chat, user, context.bot.id) == False:
        message.reply_text(
            "You don't have enough rights to restrict someone from talking!")
        return ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return ""

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

    if is_user_admin(chat, user_id, member):
        message.reply_text("I really wish I could mute admins.")
        return ""

    if user_id == context.bot.id:
        message.reply_text("I'm not gonna mute myself.")
        return ""

    if user_id == 777000 or user_id == 1087968824:
        message.reply_text(
            str(user_id) +
            " is an account reserved for telegram, I cannot mute it!")
        return ""

    if not reason:
        message.reply_text(
            "You haven't specified a time to mute this user for!")
        return ""

    split_reason = reason.split(None, 1)

    time_val = split_reason[0].lower()
    if len(split_reason) > 1:
        reason = split_reason[1]
    else:
        reason = ""

    mutetime = extract_time(message, time_val)

    if not mutetime:
        return ""

    log = ("<b>{}:</b>"
           "\n#TEMP MUTED"
           "\n<b>Admin:</b> {}"
           "\n<b>User:</b> {}"
           "\n<b>Time:</b> {}".format(
               html.escape(chat.title),
               mention_html(user.id, user.first_name),
               mention_html(member.user.id, member.user.first_name),
               time_val,
           ))
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        if member.can_send_messages is None or member.can_send_messages:
            context.bot.restrict_chat_member(
                chat.id,
                user_id,
                until_date=mutetime,
                permissions=ChatPermissions(can_send_messages=False),
            )
            reply_msg = "*{}* (`{}`) has been muted in *{}* for {}!.".format(
                member.user.first_name, member.user.id, chat.title, time_val)
            message.reply_text(
                reply_msg,
                reply_markup=InlineKeyboardMarkup(
                    [[
                        InlineKeyboardButton(
                            text="Unmute",
                            callback_data="muteb_mute={}".format(user_id)),
                        InlineKeyboardButton(
                            text="Delete",
                            callback_data="del_{}=delete={}={}".format(
                                chat.id, user_id,
                                message.reply_to_message.message_id))
                    ],
                     [
                         InlineKeyboardButton(text="Close",
                                              callback_data="mute_close")
                     ]]),
                parse_mode=ParseMode.MARKDOWN)
            return log
        else:
            message.reply_text("This user is already muted.")

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text("shut up! muted for {}!".format(time_val),
                               quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR muting user %s in chat %s (%s) due to %s",
                user_id,
                chat.title,
                chat.id,
                excp.message,
            )
            message.reply_text("Well damn, I can't mute that user.")

    return ""
Пример #13
0
def gmute(update, context):
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat
    args = context.args
    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return

    if int(user_id) in OFFICERS:
        message.reply_text("I Can't Gmute My Officer.")
        return

    if user_id == context.bot.id:
        message.reply_text("I can't gmute myself.")
        return

    if not reason:
        message.reply_text(
            "Please give a reason why are you want to gmute this user!")
        return

    try:
        user_chat = context.bot.get_chat(user_id)
    except BadRequest as excp:
        message.reply_text(excp.message)
        return

    if user_chat.type != 'private':
        message.reply_text("That's not a user!")
        return

    if sql.is_user_gmuted(user_id):
        if not reason:
            message.reply_text(
                "This user is already gmuted; I'd change the reason, but you haven't given me one..."
            )
            return

        success = sql.update_gmute_reason(
            user_id, user_chat.username or user_chat.first_name, reason)
        if success:
            message.reply_text(
                "This user is already gmuted; I've gone and updated the gmute reason though!"
            )
        else:
            message.reply_text("I thought this person was gmuted.")

        return

    message.reply_text("Gets duct tape ready 😉")

    muter = update.effective_user  # type: Optional[User]

    sql.gmute_user(user_id, user_chat.username or user_chat.first_name, reason)

    chats = get_all_chats()
    for chat in chats:
        chat_id = chat.chat_id

        # Check if this group has disabled gmutes
        if not sql.does_chat_gmute(chat_id):
            continue

        try:
            context.bot.restrict_chat_member(
                chat_id,
                user_id,
                permissions=ChatPermissions(can_send_messages=False))
        except BadRequest as excp:
            if excp.message == "User is an administrator of the chat":
                pass
            elif excp.message == "Chat not found":
                pass
            elif excp.message == "Not enough rights to restrict/unrestrict chat member":
                pass
            elif excp.message == "User_not_participant":
                pass
            elif excp.message == "Peer_id_invalid":  # Suspect this happens when a group is suspended by telegram.
                pass
            elif excp.message == "Group chat was deactivated":
                pass
            elif excp.message == "Need to be inviter of a user to kick it from a basic group":
                pass
            elif excp.message == "Chat_admin_required":
                pass
            elif excp.message == "Only the creator of a basic group can kick group administrators":
                pass
            elif excp.message == "Method is available only for supergroups":
                pass
            elif excp.message == "Can't demote chat creator":
                pass
            else:
                message.reply_text("Unexpected Error!")
                context.bot.send_message(
                    ERROR_DUMP,
                    "Could not gmute due to: {}".format(excp.message))
                sql.ungmute_user(user_id)
                return
        except TelegramError:
            pass

    message.reply_text("They won't be talking again anytime soon.")
Пример #14
0
def dkick(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args
    bot = context.bot

    if user_can_ban(chat, user, context.bot.id) is False:
        message.reply_text("You don't have enough rights to kick users!")
        return ""

    if message.reply_to_message:
        user = update.effective_user  # type: Optional[User]
        chat = update.effective_chat  # type: Optional[Chat]
        if can_delete(chat, bot.id):
            update.effective_message.reply_to_message.delete()
    else:
        message.reply_text(
            "You have to reply to a message to delete it and kick the user.")
        return ""

    user_id, reason = extract_user_and_text(message, args)

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

    if is_user_ban_protected(chat, user_id):
        message.reply_text("Yeahh... let's start kicking admins?")
        return ""

    if user_id == context.bot.id:
        message.reply_text("Yeahhh I'm not gonna do that")
        return ""

    if user_id == 777000 or user_id == 1087968824:
        message.reply_text(
            str(user_id) +
            " is an account reserved for telegram, I cannot kick it!")
        return ""

    res = chat.unban_member(user_id)  # unban on current user = kick
    if res:

        context.bot.sendMessage(
            chat.id,
            "Admin {} has successfully kicked {} in <b>{}</b>!".format(
                mention_html(user.id, user.first_name),
                mention_html(member.user.id, member.user.first_name),
                html.escape(chat.title)),
            parse_mode=ParseMode.HTML,
        )
        log = ("<b>{}:</b>"
               "\n#KICKED"
               "\n<b>Admin:</b> {}"
               "\n<b>User:</b> {} (<code>{}</code>)".format(
                   html.escape(chat.title),
                   mention_html(user.id, user.first_name),
                   mention_html(member.user.id, member.user.first_name),
                   member.user.id,
               ))
        if reason:
            log += "\n<b>Reason:</b> {}".format(reason)

        return log

    else:
        message.reply_text("Get Out!.")

    return ""
Пример #15
0
def ban(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    if user_can_ban(chat, user, context.bot.id) is False:
        message.reply_text("You don't have enough rights to ban users!")
        return ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return ""

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

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text(
            "I'm not gonna ban an admin, don't make fun of yourself!")
        return ""

    if user_id == context.bot.id:
        message.reply_text(
            "I'm not gonna ban myself, that's pretty dumb idea!")
        return ""

    if user_id == 777000 or user_id == 1087968824:
        message.reply_text(
            str(user_id) +
            " is an account reserved for telegram, I cannot ban it!")
        return ""

    log = ("<b>{}:</b>"
           "\n#BANNED"
           "\n<b>Admin:</b> {}"
           "\n<b>User:</b> {} (<code>{}</code>)".format(
               html.escape(chat.title),
               mention_html(user.id, user.first_name),
               mention_html(member.user.id, member.user.first_name),
               member.user.id,
           ))
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        chat.kick_member(user_id)
        context.bot.sendMessage(
            chat.id,
            "Admin {} has successfully banned {} in <b>{}</b>!.".format(
                mention_html(user.id, user.first_name),
                mention_html(member.user.id, member.user.first_name),
                html.escape(chat.title)),
            parse_mode=ParseMode.HTML,
        )
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text("Banned!", quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR banning user %s in chat %s (%s) due to %s",
                user_id,
                chat.title,
                chat.id,
                excp.message,
            )
            message.reply_text("Well damn, I can't ban that user.")

    return ""
Пример #16
0
def temp_ban(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    if user_can_ban(chat, user, context.bot.id) is False:
        message.reply_text(
            "You don't have enough rights to temporarily ban someone!")
        return ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return ""

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

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text("Wow! let's start banning Admins themselves?...")
        return ""

    if user_id == context.bot.id:
        message.reply_text("I'm not gonna BAN myself, are you crazy or wot?")
        return ""

    if user_id == 777000 or user_id == 1087968824:
        message.reply_text(
            str(user_id) +
            " is an account reserved for telegram, I cannot ban it!")
        return ""

    if not reason:
        message.reply_text(
            "You haven't specified a time to ban this user for!")
        return ""

    split_reason = reason.split(None, 1)

    time_val = split_reason[0].lower()
    if len(split_reason) > 1:
        reason = split_reason[1]
    else:
        reason = ""

    bantime = extract_time(message, time_val)

    if not bantime:
        return ""

    log = ("<b>{}:</b>"
           "\n#TEMP BANNED"
           "\n<b>Admin:</b> {}"
           "\n<b>User:</b> {} (<code>{}</code>)"
           "\n<b>Time:</b> {}".format(
               html.escape(chat.title),
               mention_html(user.id, user.first_name),
               mention_html(member.user.id, member.user.first_name),
               member.user.id,
               time_val,
           ))
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        chat.kick_member(user_id, until_date=bantime)

        message.reply_text(
            "Admin {} has successfully banned {} in <b>{}</b> for {}!".format(
                mention_html(user.id, user.first_name),
                mention_html(member.user.id, member.user.first_name),
                html.escape(chat.title), time_val),
            quote=False,
            parse_mode=ParseMode.HTML)
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text(
                "Goodbye.. we'll meet after {}.".format(time_val), quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR banning user %s in chat %s (%s) due to %s",
                user_id,
                chat.title,
                chat.id,
                excp.message,
            )
            message.reply_text("Well damn, I can't ban that user.")

    return ""
Пример #17
0
def ungban(update, context):
    message = update.effective_message
    bot = context.bot
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return

    user_chat = context.bot.get_chat(user_id)
    if user_chat.type != "private":
        message.reply_text("That's not a user!")
        return

    if not sql.is_user_gbanned(user_id):
        message.reply_text("This user is not gbanned!")
        return

    if not reason:
        message.reply_text("Removal of Global Ban requires a reason.")
        return

    unbanner = update.effective_user  # type: Optional[User]
    full_reason = html.escape(f"{reason}")
    officer = "{unbanner.first_name}"
    officerid = "{unbanner.id}"

    message.reply_text(
        "\n<b>Regression Of Global Ban</b>"
        "\n<b>Officer:</b> {}"
        "\n\n<b>User:</b> {}"
        "\n<b>Reason:</b> {}".format(
            mention_html(unbanner.id, unbanner.first_name),
            mention_html(user_chat.id, user_chat.first_name),
            full_reason,
        ),
        parse_mode=ParseMode.HTML,
    )
    try:
        context.bot.sendMessage(
            GBAN_DUMP,
            "#UNGBANNED"
            "\n<b>Officer:</b> {}"
            "\n\n<b>User:</b> {}"
            "\n<b>ID:</b> <code>{}</code>"
            "\n<b>Reason:</b> {}".format(
                mention_html(unbanner.id, unbanner.first_name),
                mention_html(user_chat.id, user_chat.first_name),
                user_chat.id,
                full_reason,
            ),
            parse_mode=ParseMode.HTML,
        )
    except Exception:
        bot.send_message(GBAN_DUMP, "<b>[Error]</b>"
                         "\nFailed to Log un-gban user.")
    try:
        ungban_strating_user = f"#Event\n<b>You've Been Globally Unbanned</b>\n<b>Reason:</b> {full_reason}"

        bot.send_message(user_chat.id,
                         ungban_strating_user,
                         parse_mode=ParseMode.HTML,
                         disable_web_page_preview=True)

        bot.send_message(user_chat.id,
                         "This user have been ungbanned succesfully, they might have to ask 'admins' of chats they were banned to unban manually due to global ban." \
                        "\n\nPlease forward this message to them or let them know about this.",
                        parse_mode=ParseMode.HTML,
                        disable_web_page_preview=True
                        )
    except Exception:
        bot.send_message(ERROR_DUMP, f"<b>[Error]</b>\n"
                         f"Failed to send Un-Gban message to this user."
                         f"\nID: <code>{user_chat.id}</code>",
                         parse_mode=ParseMode.HTML)

        message.reply_text("This user have been ungbanned succesfully, they might have to ask 'admins' of chats they were banned to unban manually due to global ban." \
                       "\n\nPlease forward this message to them or let them know about this.")

    sql.ungban_user(user_id)
Пример #18
0
def gban(update, context):
    message = update.effective_message
    chat = update.effective_chat
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    if message.reply_to_message.photo:
        photo = context.bot.get_file(
            update.message.reply_to_message.photo[-1].file_id)
        evidence_img = photo.download(
            f'{str(update.message.from_user.id)}.jpg')
        evidence_img = upload_image(evidence_img)
    else:
        evidence = message.reply_to_message.text

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return

    if user_id == OWNER_ID:
        return

    if int(user_id) in DEV_USERS:
        return

    if int(user_id) in SUDO_USERS:
        return

    if int(user_id) in SUPPORT_USERS:
        return

    if int(user_id) in WHITELIST_USERS:
        return

    if user_id == context.bot.id:
        return

    try:
        user_chat = context.bot.get_chat(user_id)
    except BadRequest as excp:
        message.reply_text(excp.message)
        return

    if user_chat.type != "private":
        message.reply_text("That's not a user!")
        return

    if user_chat.first_name == "":
        message.reply_text(
            "This is a deleted account! no point to gban them...")
        return

    if not reason:
        message.reply_text(
            "Global Ban requires a reason to do so, why not send me one?")
        return

    if sql.is_user_gbanned(user_id):
        if not reason:
            message.reply_text(
                "This user is already gbanned; I'd change the reason, but you haven't given me one..."
            )
            return

        old_reason = sql.update_gban_reason(
            user_id, user_chat.username or user_chat.first_name, reason)
        user_id, new_reason = extract_user_and_text(message, args)

        if old_reason:
            banner = update.effective_user  # type: Optional[User]
            bannerid = banner.id
            bannername = banner.first_name
            new_reason = (f"{new_reason}")

            context.bot.sendMessage(
                GBAN_DUMP,
                "<b>Global Ban Reason Update</b>"
                "\n<b>Officer:</b> {}"
                "\n\n<b>User:</b> {}"
                "\n<b>ID:</b> <code>{}</code>"
                "\n<b>Previous Reason:</b> {}"
                "\n<b>New Reason:</b> {}".format(
                    mention_html(banner.id, banner.first_name),
                    mention_html(user_chat.id, user_chat.first_name
                                 or "Deleted Account"),
                    user_chat.id,
                    old_reason,
                    new_reason,
                ),
                parse_mode=ParseMode.HTML,
            )

            message.reply_text(
                "This user is already gbanned, for the following reason:\n"
                "<code>{}</code>\n"
                "I've gone and updated it with your new reason!".format(
                    html.escape(old_reason)),
                parse_mode=ParseMode.HTML,
            )

        else:
            message.reply_text(
                "This user is already gbanned, but had no reason set; I've gone and updated it!"
            )

        return

    banner = update.effective_user
    bannerid = banner.id
    bannername = banner.first_name
    reason = f"{reason}"
    officer = f"{bannername}"
    officerid = f"{bannerid}"

    if chat.type != 'private':
        chat_origin = "<b>{} ({})</b>".format(html.escape(chat.title), chat.id)
    else:
        chat_origin = "<b>{}</b>".format(chat.id)

    if message.reply_to_message.photo:
        evidence = f"<img src='{evidence_img}'>"
    else:
        evidence = evidence
    EVIDENSE_NEW_GBAN = f"<strong>New Global Ban</strong> \
                        \n<strong>Originated from:</strong> <code>{chat_origin}</code> \
                        \n<strong>Officer:</strong> {mention_html(banner.id, banner.first_name)} \n\
                        \n<strong>User:</strong> {mention_html(user_chat.id, user_chat.first_name)} \
                        \n<strong>ID:</strong> <code>{user_chat.id}</code> \
                        \n<strong>Reason:</strong> {reason} \
                        \n\n<strong>Evidence:</strong> <br>\n{evidence}"

    page = Chizuru_Gban.post(title=f"Chizuru-Gban-{user_chat.id}",
                             author=f"{banner.first_name} ({banner.id})",
                             text=EVIDENSE_NEW_GBAN)
    evidence_link = page.get('url')
    evidence_link = "<a href='{}'>{}</a>".format(evidence_link,
                                                 f"Chizuru Evidence")

    message.reply_text(
        f"<b>Beginning of Global Ban For</b> {mention_html(user_chat.id, user_chat.first_name)}"
        f"\n<b>With ID</b>: <code>{user_chat.id}</code>"
        f"\n\n<b>Officer</b>: {banner.first_name}"
        f"\n<b>Officer ID</b>: <code>{banner.id}</code>"
        f"\n\n<b>Reason</b>: <code>{reason}</code>"
        f"\n<b>Evidence:</b> {evidence_link}",
        parse_mode=ParseMode.HTML,
        disable_web_page_preview=True,
    )
    starting_usermsg = f"""#Event\n<b>You've Been Globally Banned</b>\n<b>Reason:</b> {reason}\n<b>Global Ban Log:</b> <a href="https://t.me/ElitesOfLogs">LOGS</a>\n<b>Appeal:</b> @{SUPPORT_CHAT}"""

    try:
        if chat.type != 'private':
            chat_origin = "<b>{} ({})</b>".format(html.escape(chat.title),
                                                  chat.id)
        else:
            chat_origin = "<b>{}</b>".format(chat.id)
        context.bot.sendMessage(
            GBAN_DUMP,
            "#GBANNED"
            f"\n<b>Originated from:</b> <code>{chat_origin}</code>"
            "\n<b>Officer:</b> {}"
            "\n\n<b>User:</b> {}"
            "\n<b>ID:</b> <code>{}</code>"
            "\n<b>Reason:</b> {}"
            "\n<b>Evidence:</b> {}".format(
                mention_html(banner.id, banner.first_name),
                mention_html(user_chat.id, user_chat.first_name),
                user_chat.id,
                reason,
                evidence_link,
            ),
            parse_mode=ParseMode.HTML,
            disable_web_page_preview=True,
        )

    except Exception:
        context.bot.send_message(ERROR_DUMP, "<b>[Error]</b>"
                                 "\nFailed to Log gban user.")

    try:
        context.bot.send_message(user_chat.id,
                                 starting_usermsg,
                                 parse_mode=ParseMode.HTML,
                                 disable_web_page_preview=True)
    except Exception:
        context.bot.send_message(ERROR_DUMP, f"<b>[Error]</b>\n"
                                 f"Failed to send Gban message to this user."
                                 f"\nID: <code>{user_chat.id}</code>",
                                 parse_mode=ParseMode.HTML)

    try:
        context.bot.kick_chat_member(chat.id, user_chat.id)
    except BadRequest as excp:
        if excp.message in GBAN_ERRORS:
            pass

    sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason)