Пример #1
0
async def mute_user(message, user_id, chat_id, time_val, no_msg=False):
    real_chat_id = message.chat.id
    if str(user_id) in WHITELISTED:
        await message.reply("This user is whitelisted")
        return

    if user_id == BOT_ID:
        await message.reply(
            get_string("bans", "bot_cant_be_muted", real_chat_id))
        return False
    if await is_user_admin(chat_id, user_id) is None:
        await message.reply(get_string("bans", "user_admin_mute",
                                       real_chat_id))
        return False

    try:
        await bot.restrict_chat_member(chat_id,
                                       user_id,
                                       permissions=ChatPermissions(
                                           can_send_messages=False,
                                           until_date=time_val))
    except NotEnoughRightsToRestrict:
        raise NotEnoughRights('mute')

    return True
Пример #2
0
async def ban_user(message, user_id, chat_id, time_val, no_msg=False):
    real_chat_id = message.chat.id

    await update_admin_cache(real_chat_id)

    if str(user_id) in WHITELISTED:
        if no_msg is False:
            await message.reply("This user is whitelisted")
        return

    if user_id == BOT_ID:
        if no_msg is False:
            await message.reply(
                get_string("bans", "bot_cant_be_banned", real_chat_id))
        return False
    if await is_user_admin(chat_id, user_id) is True:
        if no_msg is False:
            await message.reply(
                get_string("bans", "user_admin_ban", real_chat_id))
        return False

    banned_rights = ChatBannedRights(until_date=time_val, view_messages=True)

    try:
        await tbot(EditBannedRequest(chat_id, user_id, banned_rights))
    except ChatAdminRequiredError:
        raise NotEnoughRights('ban')

    return True
Пример #3
0
async def kick_user(message, user_id, chat_id, no_msg=False):
    real_chat_id = message.chat.id

    if user_id == BOT_ID:
        if no_msg is False:
            await message.reply(
                get_string("bans", "bot_cant_be_kicked", real_chat_id))
        return False
    if await is_user_admin(chat_id, user_id) is True:
        if no_msg is False:
            await message.reply(
                get_string("bans", "user_admin_kick", real_chat_id))
        return False

    try:
        await tbot.kick_participant(chat_id, user_id)
        await bot.unban_chat_member(chat_id, user_id)
    except NotEnoughRightsToRestrict:
        raise NotEnoughRights('kick')

    return True
Пример #4
0
async def unmute_user(message, user_id, chat_id):
    real_chat_id = message.chat.id

    if user_id == BOT_ID:
        await message.reply(
            get_string("bans", "bot_cant_be_unmuted", real_chat_id))
        return False
    if await is_user_admin(chat_id, user_id) is None:
        await message.reply(
            get_string("bans", "user_admin_unmute", real_chat_id))
        return False

    try:
        await bot.restrict_chat_member(chat_id,
                                       user_id,
                                       can_send_messages=True,
                                       can_send_media_messages=True,
                                       can_send_other_messages=True,
                                       can_add_web_page_previews=True)
    except NotEnoughRightsToRestrict:
        raise NotEnoughRights('unmute')

    return True