Esempio n. 1
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!")
Esempio n. 2
0
def unlock(bot, update, args):
    chat = update.effective_chat
    message = update.effective_message
    if is_user_admin(chat, message.from_user.id):
        if len(args) >= 1:
            if args[0] in LOCK_TYPES:
                sql.update_lock(chat.id, args[0], locked=False)
                message.reply_text("Unlocked {} for everyone!".format(args[0]))

            elif args[0] in RESTRICTION_TYPES:
                sql.update_restriction(chat.id, args[0], locked=False)
                members = users_sql.get_chat_members(chat.id)

                if args[0] == "messages":
                    unrestr_members(bot, chat.id, members, media=False, other=False, previews=False)

                elif args[0] == "media":
                    unrestr_members(bot, chat.id, members, other=False, previews=False)

                elif args[0] == "other":
                    unrestr_members(bot, chat.id, members, previews=False)

                elif args[0] == "previews":
                    unrestr_members(bot, chat.id, members)

                elif args[0] == "all":
                    unrestr_members(bot, chat.id, members, True, True, True, True)

                message.reply_text("Unlocked {} for everyone!".format(args[0]))

            else:
                message.reply_text("What are you trying to unlock...? Try /locktypes for the list of lockables")

        else:
            bot.sendMessage(chat.id, "What are you trying to unlock...?")
Esempio n. 3
0
def rest_msg(bot, update):
    msg = update.effective_message
    chat = update.effective_chat
    if sql.is_restr_locked(chat.id, "messages") \
            and can_delete(chat, bot.id) \
            and not is_user_admin(chat, msg.from_user.id):
        msg.delete()
        bot.restrict_chat_member(chat.id, msg.from_user.id,
                                 can_send_messages=False)
Esempio n. 4
0
def rest_previews(bot, update):
    msg = update.effective_message
    chat = update.effective_chat
    if sql.is_restr_locked(chat.id, "previews") \
            and can_delete(chat, bot.id) \
            and not is_user_admin(chat, msg.from_user.id):
        msg.delete()
        bot.restrict_chat_member(chat.id, msg.from_user.id,
                                 can_send_messages=True,
                                 can_send_media_messages=True,
                                 can_send_other_messages=True,
                                 can_add_web_page_previews=False)
Esempio n. 5
0
def kickme(bot, update):
    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("No problem.")
    else:
        update.effective_message.reply_text("Huh? I can't :/")
Esempio n. 6
0
def check_flood(bot, update):
    user = update.effective_user
    chat = update.effective_chat
    message = update.effective_message

    # ignore admins
    if is_user_admin(chat, user.id):
        sql.update_flood(chat.id, None)
        return

    should_ban = sql.update_flood(chat.id, user.id)
    if should_ban:
        try:
            res = chat.kick_member(user.id)
            message.reply_text("I like to leave the flooding to natural disasters. But you, you were just a "
                               "disappointment. Get out.")

        except BadRequest:
            message.reply_text("I can't kick people here, give me permissions first!")
Esempio n. 7
0
def warn(user_id, chat, reason, bot, message):
    if is_user_admin(chat, user_id):
        message.reply_text("Damn admins, can't even be warned!")
        return

    user_warned = sql.warn_user(user_id, chat.id, reason)
    if user_warned.num_warns >= 3:
        res = chat.kick_member(user_id)
        if res:
            bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
            message.reply_text("3 warnings, this user has been banned!")
            sql.reset_warns(user_id, chat.id)
        else:
            message.reply_text("An error occurred, I couldn't ban this person!")
    else:
        keyboard = InlineKeyboardMarkup(
            [[InlineKeyboardButton("Remove warn", callback_data="rm_warn({})".format(user_id))]])
        if reason:
            message.reply_text(
                "{}/3 warnings... watch out! Latest one was because:\n{}".format(user_warned.num_warns, reason),
                reply_markup=keyboard)
        else:
            message.reply_text("{}/3 warnings... watch out!".format(user_warned.num_warns), reply_markup=keyboard)