示例#1
0
def unmute(bot, update, args):
    chat = update.effective_chat
    message = update.effective_message

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

    member = chat.get_member(int(user_id))

    if member.status != 'kicked' and member.status != 'left':
        if member.can_send_messages and member.can_send_media_messages \
                and member.can_send_other_messages and member.can_add_web_page_previews:
            message.reply_text("This user already has the right to speak.")
        else:
            success = bot.restrict_chat_member(chat.id,
                                               int(user_id),
                                               can_send_messages=True,
                                               can_send_media_messages=True,
                                               can_send_other_messages=True,
                                               can_add_web_page_previews=True)
            if success:
                message.reply_text("Unmuted!")

            else:
                message.reply_text("Uh... I couldn't unmute this one")
    else:
        message.reply_text(
            "This user isn't even in the chat, unmuting them won't make them talk more than they "
            "already do!")
示例#2
0
def ban(bot, update, args):
    chat = update.effective_chat
    message = update.effective_message

    user_id = extract_user(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 really wish I could ban admins...")
        return

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

    res = update.effective_chat.kick_member(user_id)
    if res:
        bot.send_sticker(update.effective_chat.id,
                         BAN_STICKER)  # banhammer marie sticker
        message.reply_text("Banned!")
    else:
        message.reply_text("Well damn, I can't ban that user.")
示例#3
0
def get_id(bot, update, args):
    user_id = extract_user(update.effective_message, args)
    if user_id:
        if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from:
            user1 = update.effective_message.reply_to_message.from_user
            user2 = update.effective_message.reply_to_message.forward_from
            update.effective_message.reply_text(
                "The original sender, {}, has an ID of `{}`.\nThe forwarder, {}, has an ID of `{}`."
                .format(escape_markdown(user2.first_name), user2.id,
                        escape_markdown(user1.first_name), user1.id),
                parse_mode=ParseMode.MARKDOWN)
        else:
            user = bot.get_chat(user_id)
            update.effective_message.reply_text("{}'s id is `{}`.".format(
                escape_markdown(user.first_name), user.id),
                                                parse_mode=ParseMode.MARKDOWN)
    else:
        chat = update.effective_chat
        if chat.type == "private":
            update.effective_message.reply_text("Your id is `{}`.".format(
                chat.id),
                                                parse_mode=ParseMode.MARKDOWN)

        else:
            update.effective_message.reply_text(
                "This group's id is `{}`.".format(chat.id),
                parse_mode=ParseMode.MARKDOWN)
示例#4
0
def mute(bot, update, args):
    chat = update.effective_chat
    message = update.effective_message

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

    if user_id == bot.id:
        message.reply_text("I'm not muting myself!")
        return

    member = chat.get_member(int(user_id))

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

        elif member.can_send_messages is None or member.can_send_messages:
            success = bot.restrict_chat_member(chat.id,
                                               user_id,
                                               can_send_messages=False)
            if success:
                message.reply_text("Muted!")
            else:
                message.reply_text(
                    "Did not go as expected - couldn't mute this user!")

        else:
            message.reply_text("This user is already muted!")
    else:
        message.reply_text("This user isn't in the chat!")
示例#5
0
def ungban(bot, update, args):
    message = update.effective_message

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

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

    banner = update.effective_user

    message.reply_text("I'll give {} a second chance, globally.".format(
        user_chat.first_name))

    send_to_list(
        bot,
        SUDO_USERS + SUPPORT_USERS,
        "[{}](tg://user?id={}) has ungbanned user [{}](tg://user?id={})".
        format(escape_markdown(banner.first_name), banner.id,
               escape_markdown(user_chat.first_name), user_chat.id),
        markdown=True)

    sql.ungban_user(user_id)

    chats = get_all_chats()
    for chat in chats:
        chat_id = chat.chat_id
        try:
            member = bot.get_chat_member(chat_id, user_id)
            if member.status == 'kicked':
                bot.unban_chat_member(chat_id, user_id)

        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 == "Method is available for supergroup and channel chats only":
                pass
            else:
                message.reply_text("Could not un-gban due to: {}".format(
                    excp.message))
                bot.send_message(
                    OWNER_ID,
                    "Could not un-gban due to: {}".format(excp.message))
                return
        except TelegramError:
            pass

    send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "un-gban complete!")

    message.reply_text("Person has been un-gbanned.")
示例#6
0
def demote(bot, update, args):
    chat = update.effective_chat
    message = update.effective_message

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

    if chat.get_member(user_id).status == 'creator':
        message.reply_text(
            "This person CREATED the chat, how would I demote them?")
        return

    if not chat.get_member(user_id).status == 'administrator':
        message.reply_text("Can't demote what wasn't promoted!")
        return

    if user_id == bot.id:
        update.effective_message.reply_text(
            "I can't demote myself! Get an admin to do it for me.")
        return

    try:
        res = bot.promoteChatMember(int(chat.id),
                                    int(user_id),
                                    can_change_info=False,
                                    can_post_messages=False,
                                    can_edit_messages=False,
                                    can_delete_messages=False,
                                    can_invite_users=False,
                                    can_restrict_members=False,
                                    can_pin_messages=False,
                                    can_promote_members=False)
        if res:
            message.reply_text("Successfully demoted!")
        else:
            message.reply_text("Could not demote.")
    except BadRequest:
        message.reply_text(
            "Could not demote. I might not be admin, or the admin status was appointed by another "
            "user, so I can't act upon them!")
示例#7
0
def demote(bot, update, args):
    chat = update.effective_chat
    message = update.effective_message

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text("Who is it? a user? .")
        return

    if chat.get_member(user_id).status == 'creator':
        message.reply_text(
            "Well, this guy right here , he is the creator of this chat. ?")
        return

    if not chat.get_member(user_id).status == 'administrator':
        message.reply_text("Can't demote what wasn't promoted!")
        return

    if user_id == bot.id:
        update.effective_message.reply_text(
            "I can't demote myself! You do it LAZYASS.")
        return

    try:
        res = bot.promoteChatMember(int(chat.id),
                                    int(user_id),
                                    can_change_info=False,
                                    can_post_messages=False,
                                    can_edit_messages=False,
                                    can_delete_messages=False,
                                    can_invite_users=False,
                                    can_restrict_members=False,
                                    can_pin_messages=False,
                                    can_promote_members=False)
        if res:
            message.reply_text("Done, demoted!")
        else:
            message.reply_text("Error 420 - could not demote.")
    except BadRequest:
        message.reply_text(
            "Could not demote. I might not be admin, or the admin status was appointed by another "
            "user, so I can't act upon them!")
示例#8
0
def slap(bot, update, args):
    msg = update.effective_message

    # reply to correct message
    reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text

    # get user who sent message
    if msg.from_user.username:
        curr_user = "******" + escape_markdown(msg.from_user.username)
    else:
        curr_user = "******".format(msg.from_user.first_name,
                                                   msg.from_user.id)

    user_id = extract_user(update.effective_message, args)
    if user_id:
        slapped_user = bot.get_chat(user_id)
        user1 = curr_user
        if slapped_user.username:
            user2 = "@" + escape_markdown(slapped_user.username)
        else:
            user2 = "[{}](tg://user?id={})".format(slapped_user.first_name,
                                                   slapped_user.id)

    # if no target found, bot targets the sender
    else:
        user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id)
        user2 = curr_user

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

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

    reply_text(repl, parse_mode=ParseMode.MARKDOWN)
示例#9
0
def about_me(bot, update, args):
    message = update.effective_message
    user_id = extract_user(message, args)

    if user_id:
        user = bot.get_chat(user_id)
    else:
        user = message.from_user

    info = sql.get_user_me_info(user.id)

    if info:
        update.effective_message.reply_text("*{}*:\n{}".format(
            user.first_name, escape_markdown(info)),
                                            parse_mode=ParseMode.MARKDOWN)
    elif message.reply_to_message:
        username = message.reply_to_message.from_user.first_name
        update.effective_message.reply_text(
            username + " hasn't set an info message about themselves  yet!")
    else:
        update.effective_message.reply_text(
            "You haven't set an info message about yourself yet!")
示例#10
0
def info(bot, update, args):
    msg = update.effective_message
    user_id = extract_user(update.effective_message, args)
    if user_id:
        user = bot.get_chat(user_id)
    else:
        user = msg.from_user

    text = "*User info*:" \
           "\nID: `{}`" \
           "\nFirst Name: {}".format(user.id, escape_markdown(user.first_name))

    if user.last_name:
        text += "\nLast Name: {}".format(escape_markdown(user.last_name))

    if user.username:
        text += "\nUsername: @{}".format(escape_markdown(user.username))

    if user.id == OWNER_ID:
        text += "\n\nThis person is my owner - I would never do anything against them!"
    else:
        if user.id in SUDO_USERS:
            text += "\nThis person is one of my sudo users! " \
                    "Nearly as powerful as my owner - so watch it."
        else:
            if user.id in SUPPORT_USERS:
                text += "\nThis person is one of my support users! " \
                        "Not quite a sudo user, but can still gban you off the map."

            if user.id in WHITELIST_USERS:
                text += "\nThis person has been whitelisted! " \
                        "That means I'm not allowed to ban/kick them."

    for mod in USER_INFO:
        mod_info = mod.__user_info__(user.id).strip()
        if mod_info:
            text += "\n\n" + mod_info

    update.effective_message.reply_text(text, parse_mode=ParseMode.MARKDOWN)
示例#11
0
def unban(bot, update, args):
    message = update.effective_message
    chat = update.effective_chat

    user_id = extract_user(message, args)
    if not user_id:
        return

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

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

    res = update.effective_chat.unban_member(user_id)
    if res:
        message.reply_text("Yep, this user can join!")
    else:
        message.reply_text("Hm, couldn't unban this person.")
示例#12
0
def promote(bot, update, args):
    chat_id = update.effective_chat.id
    message = update.effective_message
    chat = update.effective_chat

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

    user_member = chat.get_member(user_id)
    if user_member.status == 'administrator' or user_member.status == 'creator':
        message.reply_text(
            "How am I meant to promote someone that's already an admin?")
        return

    if user_id == bot.id:
        message.reply_text(
            "I can't promote myself! Get an admin to do it for me.")
        return

    # set same perms as bot - bot can't assign higher perms than itself!
    bot_member = chat.get_member(bot.id)

    res = bot.promoteChatMember(
        chat_id,
        user_id,
        can_change_info=bot_member.can_change_info,
        can_post_messages=bot_member.can_post_messages,
        can_edit_messages=bot_member.can_edit_messages,
        can_delete_messages=bot_member.can_delete_messages,
        # can_invite_users=bot_member.can_invite_users,
        can_restrict_members=bot_member.can_restrict_members,
        can_pin_messages=bot_member.can_pin_messages,
        can_promote_members=bot_member.can_promote_members)
    if res:
        message.reply_text("Successfully promoted!")
示例#13
0
def kick(bot, update, args):
    chat = update.effective_chat
    message = update.effective_message

    user_id = extract_user(message, args)
    if not user_id:
        return

    if is_user_ban_protected(chat, user_id):
        message.reply_text("I really wish I could kick admins...")
        return

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

    res = update.effective_chat.unban_member(
        user_id)  # unban on current user = kick
    if res:
        bot.send_sticker(update.effective_chat.id,
                         BAN_STICKER)  # banhammer marie sticker
        message.reply_text("Kicked!")
    else:
        message.reply_text("Well damn, I can't kick that user.")
示例#14
0
def promote(bot, update, args):
    chat_id = update.effective_chat.id
    message = update.effective_message
    chat = update.effective_chat

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text("Who is he? Doesn't sound like a user.")
        return

    user_member = chat.get_member(user_id)
    if user_member.status == 'administrator' or user_member.status == 'creator':
        message.reply_text("Senpai, have a look he is an admin already!")
        return

    if user_id == bot.id:
        message.reply_text(
            "I wish i cloud promote myself. Do it yourself lazy!.")
        return

    # set same perms as bot - bot can't assign higher perms than itself!
    bot_member = chat.get_member(bot.id)

    res = bot.promoteChatMember(
        chat_id,
        user_id,
        can_change_info=bot_member.can_change_info,
        can_post_messages=bot_member.can_post_messages,
        can_edit_messages=bot_member.can_edit_messages,
        can_delete_messages=bot_member.can_delete_messages,
        # can_invite_users=bot_member.can_invite_users,
        can_restrict_members=bot_member.can_restrict_members,
        can_pin_messages=bot_member.can_pin_messages,
        can_promote_members=bot_member.can_promote_members)
    if res:
        message.reply_text("Done, promoted!")
示例#15
0
def gban(bot, update, args):
    message = update.effective_message

    user_id = extract_user(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 SUDO_USERS:
        message.reply_text("I spy, with my little eye... a sudo user war! Why are you guys turning on each other?")
        return

    if int(user_id) in SUPPORT_USERS:
        message.reply_text("OOOH someone's trying to gban a support user! *grabs popcorn*")
        return

    if user_id == bot.id:
        message.reply_text("-_- So funny, lets gban myself why don't I? Nice try.")
        return

    try:
        user_chat = 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

    reason = ""

    if message.entities and message.parse_entities([MessageEntity.TEXT_MENTION]):
        entities = message.parse_entities([MessageEntity.TEXT_MENTION])
        end = entities[0].offset + entities[0].length
        reason = message.text[end:].strip()

    else:
        split_message = message.text.split(None, 2)
        if len(split_message) >= 3:
            reason = split_message[2]

    message.reply_text("*Blows dust off of banhammer* 😉")

    banner = update.effective_user
    send_to_list(bot, SUDO_USERS + SUPPORT_USERS,
                 "[{}](tg://user?id={}) is gbanning user [{}](tg://user?id={}) "
                 "because:\n{}".format(escape_markdown(banner.first_name),
                                       banner.id,
                                       escape_markdown(user_chat.first_name),
                                       user_chat.id, reason or "No reason given"),
                 markdown=True)

    sql.gban_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
        try:
            bot.kick_chat_member(chat_id, user_id)
        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
            else:
                message.reply_text("Could not gban due to: {}".format(excp.message))
                send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "Could not gban due to: {}".format(excp.message))
                sql.ungban_user(user_id)
                return
        except TelegramError:
            pass

    send_to_list(bot, SUDO_USERS + SUPPORT_USERS, "gban complete!")
    message.reply_text("Person has been gbanned.")