summaryrefslogtreecommitdiff
path: root/ATRI/plugins/plugin_utils/__init__.py
blob: 4181e3003583e7bc1ec555772fdc945478e4c84a (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@File    :   __init__.py
@Time    :   2020/11/07 14:20:08
@Author  :   Kyomotoi
@Contact :   [email protected]
@Github  :   https://github.com/Kyomotoi
@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
'''
__author__ = 'kyomotoi'

import re
import random
from time import strftime
from datetime import datetime, timedelta

from nonebot.plugin import on_command
from nonebot.typing import Bot, Event

from ATRI.utils.utils_error import errorRepo
from ATRI.utils.utils_rule import check_banlist, check_switch
from .data_source import Generate, Genshin, Roll, RCNB

plugin_name_0 = "one-key-adult"
generateID = on_command("我要转大人,一天打25小时游戏",
                        aliases={'虚拟身份', '一键成年', '登dua郎'},
                        rule=check_banlist()
                        & check_switch(plugin_name_0, True))


@generateID.handle()
async def _(bot: Bot, event: Event, state: dict) -> None:
    NAME, AREA = Generate().infoID()

    BIRTH_BEGIN = datetime(*[1980, 10, 10])  # type: ignore
    BIRTH_END = datetime(*[2002, 10, 10])  # type: ignore

    id_card_area = int(random.choice(list(AREA.keys())))
    id_card_area_name = AREA[str(id_card_area)]
    id_card_year_old = timedelta(
        days=random.randint(0, (BIRTH_END - BIRTH_BEGIN).days) + 1)
    id_card_birth_day = strftime("%Y%m%d",
                                 (BIRTH_BEGIN + id_card_year_old).timetuple())
    id_card_sex = random.choice([0, 1])
    id_card_name = random.choice(NAME[{0: "female", 1: "male"}[id_card_sex]])
    id_card_id = Generate().numberID(id_card_area, id_card_sex,
                                     id_card_birth_day)  # type: ignore

    msg0 = "恭喜,你已经成大人了!\n"
    msg0 += f"NumberID: {id_card_id}\n"
    msg0 += f"Gender: {'男' if id_card_sex == 1 else '女'}\n"
    msg0 += f"Name: {id_card_name} || Address: {id_card_area_name}\n"
    msg0 += "注: 1、以上信息根据国家公开标准生成,非真实信息。\n"
    msg0 += "      2、不适用于网易和腾讯。"

    await generateID.finish(msg0)


rollD = on_command("/roll", rule=check_banlist())


@rollD.handle()
async def _(bot: Bot, event: Event, state: dict) -> None:
    args = str(event.message).strip()

    if args:
        state['resu'] = args


@rollD.got("resu", prompt="roll 参数不能为空~!\ndemo:1d10 或 2d10+2d10")
async def _(bot: Bot, event: Event, state: dict) -> None:
    resu = state['resu']
    match = re.match(r'^([\dd+\s]+?)$', resu)

    if not match:
        await rollD.finish("请输入正确的参数!!\ndemo:1d10 或 2d10+2d10")

    await rollD.finish(Roll().roll_dice(resu))


plugin_name_1 = 'genshin-search'
genshinInfo = on_command('/genshin',
                         rule=check_banlist()
                         & check_switch(plugin_name_1, True))


@genshinInfo.handle()
async def _(bot: Bot, event: Event, state: dict) -> None:
    args = str(event.message).strip()

    if args:
        state['uid'] = args


@genshinInfo.got('uid', prompt='请告诉咱需要查询的UID,暂时只支持国服嗷~(')
async def _(bot: Bot, event: Event, state: dict) -> None:
    uid = str(state['uid'])

    if (len(uid) == 9):
        await bot.send(event, '别急,在搜索了!')
        uid_info = ''

        try:
            uid_info = Genshin().JsonAnalysis(Genshin().GetInfo(uid))
        except:
            await genshinInfo.finish(
                errorRepo("数据请求错误,原因可能为ID输入错误或不存在\n暂时只支持国服查询("))

        msg0 = f'{uid} Genshin Info:\n'
        msg0 += uid_info
        print(uid_info)
        await genshinInfo.finish(msg0)

    else:
        await genshinInfo.finish('UID检查未通过,请确保此ID为9位数或者是否为国服ID~!')


rcnb = RCNB()

rcnbEncode = on_command('RC一下',
                        aliases={'rc一下', '啊西一下', '阿西一下'},
                        rule=check_banlist())


@rcnbEncode.handle()
async def _(bot: Bot, event: Event, state: dict) -> None:
    msg = str(event.message).strip()

    if msg:
        state['msg'] = msg


@rcnbEncode.got('msg', prompt='请告诉咱需要RC一下的字符~!')
async def _(bot: Bot, event: Event, state: dict) -> None:
    msg = state['msg']
    await rcnbEncode.finish(rcnb._encode(msg))


rcnbDecode = on_command('一下RC',
                        aliases={'一下rc', '一下啊西', '一下阿西'},
                        rule=check_banlist())


@rcnbDecode.handle()
async def _(bot: Bot, event: Event, state: dict) -> None:
    msg = str(event.message).strip()

    if msg:
        state['msg'] = msg


@rcnbDecode.got('msg', prompt='请告诉咱需要一下RC的字符~!')
async def _(bot: Bot, event: Event, state: dict) -> None:
    msg = state['msg']
    await rcnbDecode.finish(rcnb._decode(msg))