diff options
-rw-r--r-- | .env.dev | 1 | ||||
-rw-r--r-- | ATRI/plugins/plugin_admin/__init__.py | 8 | ||||
-rw-r--r-- | ATRI/plugins/plugin_anime/__init__.py | 10 | ||||
-rw-r--r-- | ATRI/plugins/plugin_chat/__init__.py | 26 | ||||
-rw-r--r-- | ATRI/plugins/plugin_test/__init__.py | 2 | ||||
-rw-r--r-- | ATRI/plugins/plugin_utils/__init__.py | 67 | ||||
-rw-r--r-- | ATRI/plugins/plugin_utils/genshin.py | 119 | ||||
-rw-r--r-- | ATRI/plugins/plugin_utils/roll.py | 59 | ||||
-rw-r--r-- | bot.py | 3 | ||||
-rw-r--r-- | config.yml | 4 | ||||
-rw-r--r-- | utils/utils_rule/__init__.py | 4 | ||||
-rw-r--r-- | utils/utils_rule/switch.json | 2 | ||||
-rw-r--r-- | utils/utils_switch/__init__.py | 2 | ||||
-rw-r--r-- | utils/utils_switch/switch.json | 1 |
14 files changed, 273 insertions, 35 deletions
diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..719ba19 --- /dev/null +++ b/.env.dev @@ -0,0 +1 @@ +COMMAND_START=["", "/"]
\ No newline at end of file diff --git a/ATRI/plugins/plugin_admin/__init__.py b/ATRI/plugins/plugin_admin/__init__.py index e760ca9..7e19908 100644 --- a/ATRI/plugins/plugin_admin/__init__.py +++ b/ATRI/plugins/plugin_admin/__init__.py @@ -196,7 +196,7 @@ async def _(bot: Bot, event: Event, state: dict) -> None: await publicOpinion.finish(msg0) -trackError = on_command('track', permission=SUPERUSER) +trackError = on_command("track", permission=SUPERUSER) file_error = Path('.') / 'ATRI' / 'data' / 'data_Error' / 'error.json' @@ -235,12 +235,12 @@ async def _(bot: Bot, event: Event, state: dict) -> None: args = str(event.message) if args: - state['args'] = args + state['msg'] = args [email protected]('args', prompt='请告诉咱需要群发的内容~!') # type: ignore [email protected]('msg', prompt='请告诉咱需要群发的内容~!') # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: - msg = state['args'] + msg = state['msg'] group_list = await bot.get_group_list() sc_list = [] err_list = [] diff --git a/ATRI/plugins/plugin_anime/__init__.py b/ATRI/plugins/plugin_anime/__init__.py index 47dcf6c..b3dac52 100644 --- a/ATRI/plugins/plugin_anime/__init__.py +++ b/ATRI/plugins/plugin_anime/__init__.py @@ -195,12 +195,12 @@ plugin_name_2 = "anime-setu" key_LoliconAPI = config['api']['LoliconAPI'] setu_type = 1 # setu-type: 1(local), 2(url: https://api.lolicon.app/#/setu) default: 1(local) -setu = on_regex( +setus = on_regex( r"来[点丶张份副个幅][涩色瑟][图圖]|[涩色瑟][图圖]来|[涩色瑟][图圖][gkd|GKD|搞快点]|[gkd|GKD|搞快点][涩色瑟][图圖]", rule=check_banlist() & check_switch(plugin_name_1)) [email protected]() # type: ignore [email protected]() # type: ignore async def _setu(bot: Bot, event: Event, state: dict) -> None: group = str(event.group_id) @@ -225,7 +225,7 @@ async def _setu(bot: Bot, event: Event, state: dict) -> None: msg0 += f"[CQ:image,file=file:///{compress_image(await aio_download_pics(img))}]" if 1 <= res < 5: - await setu.finish(msg0) + await setus.finish(msg0) elif res == 5: await bot.send(event, "我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆") @@ -246,7 +246,7 @@ async def _setu(bot: Bot, event: Event, state: dict) -> None: data = json.loads( request_get('https://api.lolicon.app/setu/', params)) except Exception: - await setu.finish(errorRepo("请求数据失败,也可能为接口调用次数达上限")) + await setus.finish(errorRepo("请求数据失败,也可能为接口调用次数达上限")) msg0 = "setu info:\n" msg0 += f'Title: {data["data"][0]["title"]}\n' @@ -254,7 +254,7 @@ async def _setu(bot: Bot, event: Event, state: dict) -> None: msg0 += f'[CQ:image,file=file:///{compress_image(await aio_download_pics(data["data"][0]["url"]))}]' if 1 <= res < 5: - await setu.finish(msg0) + await setus.finish(msg0) elif res == 5: await bot.send(event, "我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆") diff --git a/ATRI/plugins/plugin_chat/__init__.py b/ATRI/plugins/plugin_chat/__init__.py index 9d70f7a..b8f3c2a 100644 --- a/ATRI/plugins/plugin_chat/__init__.py +++ b/ATRI/plugins/plugin_chat/__init__.py @@ -10,10 +10,11 @@ ''' __author__ = 'kyomotoi' +import re import json from pathlib import Path from random import choice -from requests import exceptions +from requests import exceptions from nonebot.log import logger from nonebot.rule import to_me @@ -65,9 +66,6 @@ async def _(bot: Bot, event: Event, state: dict) -> None: elif "萝卜子" in msg: await bot.send(event, "萝卜子是对咱的蔑称!!") - else: - pass - # 戳 一 戳 pokehah = on_command("戳一戳", rule=to_me() & check_banlist()) @@ -86,31 +84,31 @@ async def _poke(bot: Bot, event: Event, state: dict) -> None: async def poke_(bot: Bot, event: Event, state: dict) -> bool: return (event.detail_type == "notify" - and event.raw_event["sub_type"] == "poke" # type: ignore + and event.raw_event["sub_type"] == "poke" and event.sub_type == "notice" and int( - event.self_id) == event.raw_event["target_id"] # type: ignore + event.self_id) == event.raw_event["target_id"] ) -poke = on_notice(poke_, block=True) +poke = on_notice(rule=check_banlist() & poke_, block=True) poke.handle()(_poke) # 处理 进 / 退 群事件 -groupEvent = on_notice(rule=check_banlist()) +groupEvent = on_notice() @groupEvent.handle() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: - if event.raw_event["notice_type"] == "group_increase": # type: ignore + if event.raw_event["notice_type"] == "group_increase": await groupEvent.finish( - f'好欸!事新人[CQ:at,qq={event.raw_event["user_id"]}]' # type: ignore - ) # type: ignore + f'好欸!事新人[CQ:at,qq={event.raw_event["user_id"]}]' + ) await groupEvent.finish("在下 ATRI,你可以叫我 亚托莉 或 アトリ !~w") - elif event.raw_event[ # type: ignore + elif event.raw_event[ "notice_type"] == "group_decrease": await groupEvent.finish( - f'[{event.raw_event["operator_id"]}] 离开了我们...' # type: ignore + f'[{event.raw_event["operator_id"]}] 离开了我们...' ) @@ -119,13 +117,11 @@ async def _(bot: Bot, event: Event, state: dict) -> None: # file_PO = Path( # '.') / 'ATRI' / 'plugins' / 'plugin_chat' / 'public_opinion.json' - # @groupEvent.handle() # type: ignore # async def _(bot: Bot, event: Event, state: dict) -> None: # with open(file_PO, 'r') as f: # data = json.load(f) - # 口臭一下 fxxkMe = on_command('口臭一下', aliases={'口臭', '骂我'}, diff --git a/ATRI/plugins/plugin_test/__init__.py b/ATRI/plugins/plugin_test/__init__.py index 6455d95..a83052d 100644 --- a/ATRI/plugins/plugin_test/__init__.py +++ b/ATRI/plugins/plugin_test/__init__.py @@ -16,7 +16,7 @@ from pathlib import Path from random import sample import nonebot -from nonebot.plugin import on_command, on_message +from nonebot.plugin import on_command from nonebot.permission import SUPERUSER from nonebot.adapters.cqhttp import Bot, Event diff --git a/ATRI/plugins/plugin_utils/__init__.py b/ATRI/plugins/plugin_utils/__init__.py index 3c813cb..4435b81 100644 --- a/ATRI/plugins/plugin_utils/__init__.py +++ b/ATRI/plugins/plugin_utils/__init__.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 # -*- encoding: utf-8 -*- - ''' @File : __init__.py @Time : 2020/11/07 14:20:08 @@ -12,6 +11,7 @@ __author__ = 'kyomotoi' import os +import re import json import random from pathlib import Path @@ -23,8 +23,12 @@ from datetime import datetime, timedelta from nonebot.plugin import on_command from nonebot.adapters.cqhttp import Bot, Event +from utils.utils_error import errorRepo from utils.utils_rule import check_banlist, check_switch +from .roll import roll_dice +from .genshin import GetInfo, JsonAnalysis + file = Path('.') / 'ATRI' / 'data' / 'data_IDcard' / 'main.bin' @@ -61,9 +65,9 @@ def numberID(area: int, sex: int, birth: int) -> str: return fullCode -plugin_name = "one-key-adult" +plugin_name_0 = "one-key-adult" generateID = on_command("我要转大人,一天打25小时游戏", - rule=check_banlist() & check_switch(plugin_name)) + rule=check_banlist() & check_switch(plugin_name_0)) @generateID.handle() # type: ignore @@ -87,3 +91,60 @@ async def _(bot: Bot, event: Event, state: dict) -> None: msg0 += " 2、不适用于网易和腾讯。" await generateID.finish(msg0) + + +rollD = on_command("roll", rule=check_banlist()) + + [email protected]() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: + args = str(event.message).strip() + + if args: + state['resu'] = args + + [email protected]("resu", + prompt="roll 参数不能为空~!\ndemo:1d10 或 2d10+2d10") # type: ignore +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_dice(resu)) + + +plugin_name_1 = 'genshin-search' +genshinInfo = on_command('genshin', + rule=check_banlist() & check_switch(plugin_name_1)) + + [email protected]() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: + args = str(event.message).strip() + + if args: + state['uid'] = args + + [email protected]('uid', prompt='请告诉咱需要查询的UID,暂时只支持国服嗷~(') # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: + uid = str(state['uid']) + + if (len(uid) == 9 and uid[0] == '1'): + await bot.send(event, '别急,在搜索了!') + uid_info = '' + + try: + uid_info = JsonAnalysis(GetInfo(uid)) + except: + await genshinInfo.finish(errorRepo("数据请求错误,原因可能为ID输入错误或不存在")) + + msg0 = f'{uid} Genshin Info:\n' + msg0 += uid_info + await genshinInfo.finish(msg0) + + else: + await genshinInfo.finish('UID检查未通过,请确保此ID为9位数或者是否为国服ID~!') diff --git a/ATRI/plugins/plugin_utils/genshin.py b/ATRI/plugins/plugin_utils/genshin.py new file mode 100644 index 0000000..d8bcf2f --- /dev/null +++ b/ATRI/plugins/plugin_utils/genshin.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python3 +# -*- encoding: utf-8 -*- +''' +@File : genshin.py +@Time : 2020/11/07 22:34:58 +@Author : Kyomotoi +@Contact : [email protected] +@Github : https://github.com/Kyomotoi +@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +@Docs : Fork from https://github.com/Womsxd/YuanShen_User_Info +''' +__author__ = 'kyomotoi' + +import json +import time +import string +import random +import hashlib +import requests + + +def md5(text: str) -> str: + """text 转 md5""" + md5 = hashlib.md5() + md5.update(text.encode()) + return md5.hexdigest() + + +def DSGet() -> str: + mhyVersion = "2.1.0" + n = md5(mhyVersion) + i = str(int(time.time())) + r = ''.join(random.sample(string.ascii_lowercase + string.digits, 6)) + c = md5("salt=" + n + "&t=" + i + "&r=" + r) + return i + "," + r + "," + c + + +def GetInfo(uid: str) -> str: + """请求API""" + req = requests.get( + url= + f"https://api-takumi.mihoyo.com/game_record/genshin/api/index?server=cn_gf01&role_id={uid}", + headers={ + 'Accept': 'application/json, text/plain, */*', + 'DS': DSGet(), + 'Origin': 'https://webstatic.mihoyo.com', + 'x-rpc-app_version': '2.1.0', + 'User-Agent': + 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.2.0', + 'x-rpc-client_type': '4', + 'Referer': + 'https://webstatic.mihoyo.com/app/community-game-records/index.html?v=6', + 'Accept-Encoding': 'gzip, deflate', + 'Accept-Language': 'zh-CN,en-US;q=0.8', + 'X-Requested-With': 'com.mihoyo.hyperion' + }) + return req.text + + +def JsonAnalysis(JsonText) -> str: + """解析数据""" + data = json.loads(JsonText) + + Character_Info = "Roles:\n" + Character_List = [] + Character_List = data["data"]["avatars"] + for i in Character_List: + if (i["element"] == "None"): + Character_Type = "无属性" + elif (i["element"] == "Anemo"): + Character_Type = "风属性" + elif (i["element"] == "Pyro"): + Character_Type = "火属性" + elif (i["element"] == "Geo"): + Character_Type = "岩属性" + elif (i["element"] == "Electro"): + Character_Type = "雷属性" + elif (i["element"] == "Cryo"): + Character_Type = "冰属性" + elif (i["element"] == "Hydro"): + Character_Type = "水属性" + else: + Character_Type = "草属性" + + if (i["name"] == "旅行者"): + if (i["image"].find("UI_AvatarIcon_PlayerGirl") != -1): + TempText = f'* {i["name"]}:\n' + TempText += f' - [萤——妹妹] {i["level"]}级 {Character_Type}\n' + + elif (i["image"].find("UI_AvatarIcon_PlayerBoy") != -1): + TempText = f'* {i["name"]}:\n' + TempText += f' - [空——哥哥] {i["level"]}级 {Character_Type}\n' + + else: + TempText = f'* {i["name"]}:\n' + TempText += f' - [性别判断失败] {i["level"]}级 {Character_Type}\n' + else: + TempText = f'* {i["name"]} {i["rarity"]}★角色:\n' + TempText += f' - {i["level"]}级 好感度({i["fetter"]})级 {Character_Type}\n' + + Character_Info = Character_Info + TempText + + a1 = data["data"]["stats"]["spiral_abyss"] + + Account_Info = 'Account Info:\n' + Account_Info += f'- 活跃天数:{data["data"]["stats"]["active_day_number"]} 天\n' + Account_Info += f'- 达成成就:{data["data"]["stats"]["achievement_number"]} 个\n' + Account_Info += f'- 获得角色:{data["data"]["stats"]["avatar_number"]}个\n' + Account_Info += f'- 深渊螺旋:{"没打" if (data["data"]["stats"]["spiral_abyss"] == "-") else f"打到了{a1}"}\n' + Account_Info += f'* 收集:\n' + Account_Info += f' - 风神瞳{data["data"]["stats"]["anemoculus_number"]}个 岩神瞳{data["data"]["stats"]["geoculus_number"]}个\n' + Account_Info += f'* 解锁:\n' + Account_Info += f' - 传送点{data["data"]["stats"]["way_point_number"]}个 秘境{data["data"]["stats"]["domain_number"]}个\n' + Account_Info += f'* 共开启宝箱:\n' + Account_Info += f' - 普通:{data["data"]["stats"]["common_chest_number"]}个 精致:{data["data"]["stats"]["exquisite_chest_number"]}个\n' + Account_Info += f' - 珍贵:{data["data"]["stats"]["luxurious_chest_number"]}个 华丽:{data["data"]["stats"]["precious_chest_number"]}个' + + print(Character_Info + "\r\n" + Account_Info) + return Character_Info + "\r\n" + Account_Info
\ No newline at end of file diff --git a/ATRI/plugins/plugin_utils/roll.py b/ATRI/plugins/plugin_utils/roll.py new file mode 100644 index 0000000..bf87aa3 --- /dev/null +++ b/ATRI/plugins/plugin_utils/roll.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# -*- encoding: utf-8 -*- +''' +@File : roll.py +@Time : 2020/11/07 15:56:02 +@Author : Kyomotoi +@Contact : [email protected] +@Github : https://github.com/Kyomotoi +@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi' + +import re +from random import randint + + +def roll_dice(par: str) -> str: + """掷骰子""" + result = 0 + proc = '' + proc_list = [] + p = par.split('+') + + # 计算每个单独的roll + for i in p: + args = re.findall(r"(\d{0,10})(?:(d)(\d{1,10}))", i) + args = list(args[0]) + + if not args[0]: + args[0] = 1 + + if int(args[0]) >= 5000 or int(args[2]) >= 5000: + return '阿..好大...' + + for a in range(1, int(args[0]) + 1): + rd = randint(1, int(args[2])) + result = result + rd + + if len(proc_list) <= 10: + proc_list.append(rd) + + if len(proc_list) == 10: + temp_list = [] + for i in proc_list: + if len(temp_list) == 9: + proc += str(i) + else: + proc += str(i) + '+' + temp_list.append(i) + + elif len(proc_list) >= 10: + proc += '太长了不展示了' + + else: + proc += str(result) + + result = f"{par}=({proc})={result}" + + return str(result) @@ -38,13 +38,10 @@ CONFIG_PATH = Path('.') / 'config.yml' config = load_yaml(CONFIG_PATH) config = config['bot'] -print(config) - # 初始化 nonebot.init(DEBUG=config['debug'], SUPERUSSERS=config['superusers'], NICKNAME=config['nickname'], - COMMAND_START=config['command_start'], COMMAND_SEP=config['command_sep']) app = nonebot.get_asgi() @@ -10,8 +10,10 @@ bot: superusers: [""] # 机器人昵称,建议不动 nickname: ["ATRI", "Atri", "atri", "亚托莉", "アトリ"] + # 命令触发头,建议不动,除非你知道你在做什么 - command_start: [""] + # - 请打开同目录下的 .dev 文件进行修改 + # 命令分离,建议不动,除非你知道你在做什么 command_sep: ["."] diff --git a/utils/utils_rule/__init__.py b/utils/utils_rule/__init__.py index 333fb5d..c1d0757 100644 --- a/utils/utils_rule/__init__.py +++ b/utils/utils_rule/__init__.py @@ -106,6 +106,7 @@ def check_switch(func_name: str) -> Rule: data_switch_all["pixiv-author-search"] = "True" data_switch_all["pixiv-rank"] = "True" data_switch_all["one-key-adult"] = "True" + data_switch_all["genshin-search"] = "True" file = open(file_switch_all, 'w') file.write(json.dumps(data_switch_all)) @@ -118,6 +119,8 @@ def check_switch(func_name: str) -> Rule: try: os.mkdir( Path('.') / 'ATRI' / 'data' / 'data_Group' / f'{group}') + except: + pass data_switch_alone["anime-setu"] = "True" data_switch_alone["anime-pic-search"] = "True" @@ -127,6 +130,7 @@ def check_switch(func_name: str) -> Rule: data_switch_alone["pixiv-author-search"] = "True" data_switch_alone["pixiv-rank"] = "True" data_switch_alone["one-key-adult"] = "True" + data_switch_alone["genshin-search"] = "True" file = open(file_switch_alone, 'w') file.write(json.dumps(data_switch_alone)) diff --git a/utils/utils_rule/switch.json b/utils/utils_rule/switch.json index 88bc6b9..c19bf91 100644 --- a/utils/utils_rule/switch.json +++ b/utils/utils_rule/switch.json @@ -1 +1 @@ -{"anime-setu": "True", "anime-pic-search": "True", "anime-vid-search": "True", "all-off-anime-setu": "True", "ai-face": "True", "pixiv-pic-search": "True", "pixiv-author-search": "True", "pixiv-rank": "True", "one-key-adult": "True"}
\ No newline at end of file +{"anime-setu": "True", "anime-pic-search": "True", "anime-vid-search": "True", "all-off-anime-setu": "True", "ai-face": "True", "pixiv-pic-search": "True", "pixiv-author-search": "True", "pixiv-rank": "True", "one-key-adult": "True", "genshin-search": "True"}
\ No newline at end of file diff --git a/utils/utils_switch/__init__.py b/utils/utils_switch/__init__.py index d4e73db..31abe16 100644 --- a/utils/utils_switch/__init__.py +++ b/utils/utils_switch/__init__.py @@ -23,7 +23,7 @@ def controlSwitch(func_name: str, :return: str ''' - file_switch_all = Path('.') / 'utils' / 'utils_switch' / 'switch.json' + file_switch_all = Path('.') / 'utils' / 'utils_rule' / 'switch.json' if group: file_switch_group = Path( diff --git a/utils/utils_switch/switch.json b/utils/utils_switch/switch.json deleted file mode 100644 index 9fb8cfa..0000000 --- a/utils/utils_switch/switch.json +++ /dev/null @@ -1 +0,0 @@ -{"anime-setu": "True", "anime-pic-search": "True", "anime-vid-search": "True", "all-off-anime-setu": "True", "ai-face": "True", "pixiv-pic-search": "True", "pixiv-author-search": "True", "pixiv-rank": "True"}
\ No newline at end of file |