Exemplo n.º 1
0
def kick(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:
        return ""
    
    if user_id == OWNER_ID:
        message.reply_text(tld(chat.id, "Insufficient rights to perform this action."))
        return ""
    
    if user_id == 777000:
        message.reply_text(tld(chat.id, "I'm not going to kick telegram."))
        return ""

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

    if is_user_creator(chat, user_id, member):
        message.reply_text(tld(chat.id, "I can't kick chat creator, u trying to kick the guy who have full rights in this chat."))
        return ""
        
    if is_user_ban_protected(chat, user_id):
        message.reply_text(tld(chat.id, "I really wish I could kick admins..."))
        return ""

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

    res = chat.unban_member(user_id)  # unban on current user = kick
    if res:
        context.bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
        message.reply_text(tld(chat.id, "Kicked!"))
        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(tld(chat.id, "Kicked!"))

    return ""
Exemplo n.º 2
0
def 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

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(
            tld(
                chat.id,
                "You'll need to either give me a username to mute, or reply to someone to be muted."
            ))
        return ""

    if user_id == OWNER_ID:
        message.reply_text(tld(chat.id, "-_- I'm not going to mute my master"))
        return ""

    if user_id == context.bot.id:
        message.reply_text(tld(chat.id, "I'm not muting myself!"))
        return ""
    if user_id == 777000:
        message.reply_text(tld(chat.id, "I'm Not going to mute tg ;__;"))
        return ""

    member = chat.get_member(int(user_id))

    if member:
        if is_user_creator(chat, user_id, member=member):
            message.reply_text(tld(chat.id, "I can't mute chat creator ;_; ."))

        if is_user_admin(chat, user_id, member=member):
            message.reply_text(
                tld(chat.id, "Afraid I can't stop an admin from talking!"))

        elif member.can_send_messages is None or member.can_send_messages:
            context.bot.restrict_chat_member(
                chat.id,
                user_id,
                permissions=ChatPermissions(can_send_messages=False))
            message.reply_text(tld(chat.id, "Muted!"))
            return "<b>{}:</b>" \
                   "\n#MUTE" \
                   "\n<b>Admin:</b> {}" \
                   "\n<b>User:</b> {}".format(html.escape(chat.title),
                                              mention_html(user.id, user.first_name),
                                              mention_html(member.user.id, member.user.first_name))

        else:
            message.reply_text(tld(chat.id, "This user is already muted!"))
    else:
        message.reply_text(tld(chat.id, "This user isn't in the chat!"))

    return ""
Exemplo n.º 3
0
def unban(update, context):
    message = update.effective_message
    user = update.effective_user
    chat = update.effective_chat
    args = context.args

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        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_creator(chat, user_id, member):
        return ""

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

    chat.unban_member(user_id)
    message.reply_text("Yep, this user 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
Exemplo n.º 4
0
def kickme(update, context):
    chat = update.effective_chat
    user_id = update.effective_message.from_user.id
    member = update.effective_chat.get_member(user_id)
    if user_id == OWNER_ID:
        update.effective_message.reply_text(tld(chat.id, "I can't kick My Master"))
        return
    if is_user_creator(update.effective_chat, user_id, member):
        update.effective_message.reply_text(tld(chat.id, "I wish i could kick the person who created this chat."))
        return
    if is_user_admin(update.effective_chat, user_id):
        update.effective_message.reply_text(tld(chat.id, "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(tld(chat.id, "No problem no need of noobs like uh."))
    else:
        update.effective_message.reply_text(tld(chat.id, "Huh? I can't :/"))
Exemplo n.º 5
0
def temp_ban(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(tld(chat.id, "You don't seem to be referring to a user."))
        return ""
    
    if user_id == OWNER_ID:
        return ""
    
    if user_id == 777000:
        message.reply_text(tld(chat.id, "I'm not going to ban telegram."))
        return ""

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

    if is_user_creator(chat, user_id, member):
        message.reply_text(tld(chat.id, "I can't ban chat creator, u trying to ban guy who promoted u nice try ;__;"))
        return ""
        
    if is_user_ban_protected(chat, user_id, member):
        message.reply_text(tld(chat.id, "I really wish I could ban admins..."))
        return ""

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

    if not reason:
        message.reply_text(tld(chat.id, "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)
        context.bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
        message.reply_text("Banned! User will be banned for {}.".format(time_val))
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text("Banned! User will be banned for {}.".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("Banned! User will be banned for {}.".format(time_val))

    return ""
Exemplo n.º 6
0
def ban(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(tld(chat.id, "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(tld(chat.id, "I can't seem to find this user"))
            return ""
        else:
            raise
    
    if is_user_creator(chat, user_id, member):
        message.reply_text(tld(chat.id, "I can't ban chat creator, u trying to ban guy who promoted uh nice try ;_;"))
        return ""
    
    if user_id == OWNER_ID:
        message.reply_text(tld(chat.id, "Not gonna do that he is my Boss!"))
        return ""

    if user_id == 777000:
        message.reply_text(tld(chat.id, "I'm not going to ban telegram."))
        return ""
    if is_user_ban_protected(chat, user_id, member):
        message.reply_text(tld(chat.id, "I really wish I could ban admins..."))
        return ""

    if user_id == context.bot.id:
        message.reply_text(tld(chat.id, "I'm not gonna BAN myself, are you crazy?"))
        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.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
        message.reply_text(tld(chat.id, "Banned!"))
        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(tld(chat.id, "Banned!."))

    return ""