summaryrefslogtreecommitdiff
path: root/ATRI/plugins/plugin_admin/__init__.py
blob: 3a7175c47994ffe84fe68148af43d292b2aff7dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re

from nonebot.plugin import on_command
from nonebot.adapters.cqhttp import Bot, Event
from nonebot.permission import GROUP_ADMIN, GROUP_OWNER, SUPERUSER

from utils.utils_banList import banList
from utils.utils_switch import controlSwitch

import ATRI


master = ATRI.config_SUPERUSERS


switch = on_command('switch', permission=(SUPERUSER|GROUP_OWNER|GROUP_ADMIN))

@switch.handle() # type: ignore
async def _(bot: Bot, event: Event, state: dict) -> None:
    user = str(event.user_id)
    group = str(event.group_id)

    if banList(user, group):
        func = str(event.message).strip()
        
        if func:
            pass
        else:
            msg0 = "-==ATRI Switch Control System==-\n"
            msg0 += "┌Usage: switch on/off-{service}\n"
            msg0 += "├For SUPERUSER:\n"
            msg0 += "│  └Usage: switch all-on/off-{service}\n"
            msg0 += "└Service:\n"
            msg0 += "    ├anime-setu\n"
            msg0 += "    ├anime-pic-search\n"
            msg0 += "    └anime-vid-search\n"

            await switch.finish(msg0)
        
        funct = re.findall(r"[on|off]-(.*)", func)
        print(func, funct)

        print(type(master[0]), type(user))
        
        if "all-on" in func:
            if int(user) in master:
                await switch.finish(controlSwitch(funct[0], True))

            else:
                await switch.finish("You don't have enough permissions do THIS!")
        
        elif "all-off" in func:
            if int(user) in master:
                await switch.finish(controlSwitch(funct[0], False))

            else:
                await switch.finish("You don't have enough permissions do THIS!")
        
        elif "on" in func:
            await switch.finish(controlSwitch(funct[0], True, group))
        
        elif "off" in func:
            await switch.finish(controlSwitch(funct[0], False, group))

        else:
            await switch.finish("请检查拼写是否正确嗷~~!")