Пример #1
0
def type_afk_is_not_true(message):
    if TEMP_SETTINGS['IS_AFK']:
        TEMP_SETTINGS['IS_AFK'] = False
        reply(message, f'**{get_translation("afkEnd")}**')
        sleep(2)
        send_log(
            get_translation(
                'afkMessages',
                [
                    '`',
                    '**',
                    str(len(TEMP_SETTINGS['AFK_USERS'])),
                    str(TEMP_SETTINGS['COUNT_MSG']),
                ],
            ))
        for i in TEMP_SETTINGS['AFK_USERS']:
            name = app.get_chat(i)
            name0 = str(name.first_name)
            send_log(
                get_translation(
                    'afkMentionUsers',
                    [
                        '**', name0,
                        str(i), '`',
                        str(TEMP_SETTINGS['AFK_USERS'][i])
                    ],
                ))
        TEMP_SETTINGS['COUNT_MSG'] = 0
        TEMP_SETTINGS['AFK_USERS'] = {}
        if 'AFK_REASON' in TEMP_SETTINGS:
            del TEMP_SETTINGS['AFK_REASON']
    raise ContinuePropagation
Пример #2
0
def afk_on_pm(message):
    if PM_AUTO_BAN:
        try:
            from Skem.sql.pm_permit_sql import is_approved

            apprv = is_approved(message.from_user.id)
        except BaseException:
            apprv = True
    else:
        apprv = True
    if apprv and TEMP_SETTINGS['IS_AFK']:
        me = TEMP_SETTINGS['ME']
        if message.from_user.id not in TEMP_SETTINGS['AFK_USERS']:
            if 'AFK_REASON' in TEMP_SETTINGS:
                reply(
                    message,
                    get_translation(
                        "afkMessage2",
                        [
                            '**', me.first_name, me.id, '`',
                            TEMP_SETTINGS['AFK_REASON']
                        ],
                    ),
                )
            else:
                reply(message, f"```{choice(AFKSTR)}```")
            TEMP_SETTINGS['AFK_USERS'].update({message.from_user.id: 1})
            TEMP_SETTINGS['COUNT_MSG'] = TEMP_SETTINGS['COUNT_MSG'] + 1
        else:
            if TEMP_SETTINGS['AFK_USERS'][message.from_user.id] % randint(
                    1, 2) == 0:
                if 'AFK_REASON' in TEMP_SETTINGS:
                    reply(
                        message,
                        get_translation(
                            "afkMessage2",
                            [
                                '**',
                                me.first_name,
                                me.id,
                                '`',
                                TEMP_SETTINGS['AFK_REASON'],
                            ],
                        ),
                    )
                else:
                    reply(message, f"```{choice(AFKSTR)}```")
                TEMP_SETTINGS['AFK_USERS'][message.from_user.id] = (
                    TEMP_SETTINGS['AFK_USERS'][message.from_user.id] + 1)
                TEMP_SETTINGS['COUNT_MSG'] = TEMP_SETTINGS['COUNT_MSG'] + 1
            else:
                TEMP_SETTINGS['AFK_USERS'][message.from_user.id] = (
                    TEMP_SETTINGS['AFK_USERS'][message.from_user.id] + 1)
                TEMP_SETTINGS['COUNT_MSG'] = TEMP_SETTINGS['COUNT_MSG'] + 1
    raise ContinuePropagation
Пример #3
0
def mention_afk(msg):
    me = TEMP_SETTINGS['ME']
    mentioned = msg.mentioned
    rep_m = msg.reply_to_message
    if mentioned or rep_m and rep_m.from_user and rep_m.from_user.id == me.id:
        if TEMP_SETTINGS['IS_AFK']:
            if msg.from_user.id not in TEMP_SETTINGS['AFK_USERS']:
                if 'AFK_REASON' in TEMP_SETTINGS:
                    reply(
                        msg,
                        get_translation(
                            "afkMessage2",
                            [
                                '**',
                                me.first_name,
                                me.id,
                                '`',
                                TEMP_SETTINGS['AFK_REASON'],
                            ],
                        ),
                    )
                else:
                    reply(msg, f"```{choice(AFKSTR)}```")
                TEMP_SETTINGS['AFK_USERS'].update({msg.from_user.id: 1})
                TEMP_SETTINGS['COUNT_MSG'] = TEMP_SETTINGS['COUNT_MSG'] + 1
            else:
                if TEMP_SETTINGS['AFK_USERS'][msg.from_user.id] % randint(
                        1, 2) == 0:
                    if 'AFK_REASON' in TEMP_SETTINGS:
                        reply(
                            msg,
                            get_translation(
                                "afkMessage2",
                                [
                                    '**',
                                    me.first_name,
                                    me.id,
                                    '`',
                                    TEMP_SETTINGS['AFK_REASON'],
                                ],
                            ),
                        )
                    else:
                        reply(msg, f"```{choice(AFKSTR)}```")
                    TEMP_SETTINGS['AFK_USERS'][msg.from_user.id] = (
                        TEMP_SETTINGS['AFK_USERS'][msg.from_user.id] + 1)
                    TEMP_SETTINGS['COUNT_MSG'] = TEMP_SETTINGS['COUNT_MSG'] + 1
                else:
                    TEMP_SETTINGS['AFK_USERS'][msg.from_user.id] = (
                        TEMP_SETTINGS['AFK_USERS'][msg.from_user.id] + 1)
                    TEMP_SETTINGS['COUNT_MSG'] = TEMP_SETTINGS['COUNT_MSG'] + 1
    raise ContinuePropagation
Пример #4
0
def gban_user(client, message):
    args = extract_args(message)
    reply = message.reply_to_message
    edit(message, f'`{get_translation("banProcess")}`')
    if args:
        try:
            user = client.get_users(args)
        except Exception:
            edit(message, f'`{get_translation("banFailUser")}`')
            return
    elif reply:
        user_id = reply.from_user.id
        user = client.get_users(user_id)
    else:
        edit(message, f'`{get_translation("banFailUser")}`')
        return

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotBanMyself")}`')
    except BaseException:
        pass

    if user.id in BRAIN:
        return edit(
            message,
            get_translation('brainError',
                            ['`', '**', user.first_name, user.id]),
        )

    try:
        if sql.is_gbanned(user.id):
            return edit(message, f'`{get_translation("alreadyBanned")}`')
        sql.gban(user.id)
        edit(
            message,
            get_translation('gbanResult',
                            ['**', user.first_name, user.id, '`']),
        )
        try:
            common_chats = client.get_common_chats(user.id)
            for i in common_chats:
                i.kick_member(user.id)
        except BaseException:
            pass
        sleep(1)
        send_log(get_translation('gbanLog', [user.first_name, user.id]))
    except Exception as e:
        edit(message, get_translation('banError', ['`', '**', e]))
        return
Пример #5
0
def gmute_user(client, message):
    args = extract_args(message)
    reply = message.reply_to_message
    edit(message, f'`{get_translation("muteProcess")}`')
    if len(args):
        try:
            user = client.get_users(args)
        except Exception:
            edit(message, f'`{get_translation("banFailUser")}`')
            return
    elif reply:
        user_id = reply.from_user.id
        user = client.get_users(user_id)
    else:
        edit(message, f'`{get_translation("banFailUser")}`')
        return

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotMuteMyself")}`')
    except BaseException:
        pass

    if user.id in BRAIN:
        return edit(
            message,
            get_translation('brainError',
                            ['`', '**', user.first_name, user.id]),
        )

    try:
        if sql2.is_gmuted(user.id):
            return edit(message, f'`{get_translation("alreadyMuted")}`')
        sql2.gmute(user.id)
        edit(
            message,
            get_translation('gmuteResult',
                            ['**', user.first_name, user.id, '`']),
        )
        try:
            common_chats = client.get_common_chats(user.id)
            for i in common_chats:
                i.restrict_member(user.id, ChatPermissions())
        except BaseException:
            pass
        sleep(1)
        send_log(get_translation('gmuteLog', [user.first_name, user.id]))
    except Exception as e:
        edit(message, get_translation('banError', ['`', '**', e]))
        return
Пример #6
0
def set_afk(message):
    args = extract_args(message)
    if len(args) > 0:
        TEMP_SETTINGS['AFK_REASON'] = args
        edit(
            message,
            get_translation('afkStartReason',
                            ['**', '`', TEMP_SETTINGS['AFK_REASON']]),
        )
    else:
        edit(message, f'**{get_translation("afkStart")}**')
    send_log(get_translation('afkLog'))
    TEMP_SETTINGS['IS_AFK'] = True
    raise StopPropagation
Пример #7
0
def ungmute_user(client, message):
    args = extract_args(message)
    reply = message.reply_to_message
    edit(message, f'`{get_translation("unmuteProcess")}`')
    if len(args):
        try:
            user = client.get_users(args)
        except Exception:
            edit(message, f'`{get_translation("banFailUser")}`')
            return
    elif reply:
        user_id = reply.from_user.id
        user = client.get_users(user_id)
    else:
        edit(message, f'`{get_translation("banFailUser")}`')
        return

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotUnmuteMyself")}`')
    except BaseException:
        pass

    try:
        if not sql2.is_gmuted(user.id):
            return edit(message, f'`{get_translation("alreadyUnmuted")}`')
        sql2.ungmute(user.id)
        try:
            common_chats = client.get_common_chats(user.id)
            for i in common_chats:
                i.unban_member(user.id)
        except BaseException:
            pass
        edit(
            message,
            get_translation('unmuteResult',
                            ['**', user.first_name, user.id, '`']),
        )
    except Exception as e:
        edit(message, get_translation('banError', ['`', '**', e]))
        return
Пример #8
0
def globals_init():
    try:
        global sql, sql2
        from importlib import import_module

        sql = import_module('Skem.sql.gban_sql')
        sql2 = import_module('Skem.sql.gmute_sql')
    except Exception as e:
        sql = None
        sql2 = None
        LOGS.warn(get_translation('globalsSqlLog'))
        raise e
Пример #9
0
from random import choice, randint
from time import sleep

from pyrogram import ContinuePropagation, StopPropagation
from DaisyX import HELP, PM_AUTO_BAN, TEMP_SETTINGS, app
from Skem.core import (
    edit,
    extract_args,
    get_translation,
    reply,
    daisy,
    send_log,
)

# ========================= CONSTANTS ============================
AFKSTR = [get_translation(f'afkstr{i+1}') for i in range(0, 22)]
TEMP_SETTINGS['AFK_USERS'] = {}
TEMP_SETTINGS['IS_AFK'] = False
TEMP_SETTINGS['COUNT_MSG'] = 0
# =================================================================


@daisy(
    incoming=True,
    outgoing=False,
    disable_edited=True,
    private=False,
    bot=False,
    disable_notify=True,
)
def mention_afk(msg):
Пример #10
0
def ungban_user(client, message):
    args = extract_args(message)
    reply = message.reply_to_message
    edit(message, f'`{get_translation("unbanProcess")}`')
    if args:
        try:
            user = client.get_users(args)
        except Exception:
            edit(message, f'`{get_translation("banFailUser")}`')
            return
    elif reply:
        user_id = reply.from_user.id
        user = client.get_users(user_id)
    else:
        edit(message, f'`{get_translation("banFailUser")}`')
        return

    try:
        replied_user = reply.from_user
        if replied_user.is_self:
            return edit(message, f'`{get_translation("cannotUnbanMyself")}`')
    except BaseException:
        pass

    try:
        if not sql.is_gbanned(user.id):
            return edit(message, f'`{get_translation("alreadyUnbanned")}`')
        sql.ungban(user.id)

        def find_me():
            try:
                return dialog.chat.get_member(me_id).can_restrict_members
            except BaseException:
                return False

        def find_member():
            try:
                return (dialog.chat.get_member(user.id)
                        and dialog.chat.get_member(user.id).restricted_by
                        and dialog.chat.get_member(
                            user.id).restricted_by.id == me_id)
            except BaseException:
                return False

        try:
            dialogs = client.iter_dialogs()
            me_id = TEMP_SETTINGS['ME'].id
            chats = [
                dialog.chat for dialog in dialogs if
                ('group' in dialog.chat.type and find_me() and find_member())
            ]
            for chat in chats:
                chat.unban_member(user.id)
        except BaseException:
            pass
        edit(
            message,
            get_translation('unbanResult',
                            ['**', user.first_name, user.id, '`']),
        )
    except Exception as e:
        edit(message, get_translation('banError', ['`', '**', e]))
        return
Пример #11
0
@daisy(pattern='^.listgmute$')
def gmutelist(message):
    users = sql2.gmuted_users()
    if not users:
        return edit(message, f'`{get_translation("listEmpty")}`')
    gmute_list = f'**{get_translation("gmutedUsers")}**\n'
    count = 0
    for i in users:
        count += 1
        gmute_list += f'**{count} -** `{i.sender}`\n'
    return edit(message, gmute_list)


@daisy(incoming=True, outgoing=False, compat=False)
def gmute_check(client, message):
    if sql2.is_gmuted(message.from_user.id):
        sleep(0.1)
        message.delete()

        try:
            user_id = message.from_user.id
            chat_id = message.chat.id
            client.restrict_chat_member(chat_id, user_id, ChatPermissions())
        except BaseException:
            pass

    message.continue_propagation()


HELP.update({'globals': get_translation('globalsInfo')})