2021-05-20 19:34:27 +08:00
|
|
|
|
from nonebot import on_command, on_regex
|
2021-10-03 14:24:07 +08:00
|
|
|
|
from .query_resource import get_resource_type_list, query_resource, init, check_resource_exists
|
2021-06-30 19:50:55 +08:00
|
|
|
|
from utils.utils import get_message_text, scheduler
|
2021-07-30 21:21:51 +08:00
|
|
|
|
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent, Message
|
2021-05-20 19:34:27 +08:00
|
|
|
|
from nonebot.typing import T_State
|
|
|
|
|
|
from services.log import logger
|
2021-09-05 02:21:38 +08:00
|
|
|
|
from configs.config import NICKNAME
|
2021-08-17 23:17:08 +08:00
|
|
|
|
from nonebot.permission import SUPERUSER
|
2021-05-20 19:34:27 +08:00
|
|
|
|
import re
|
2021-07-30 21:21:51 +08:00
|
|
|
|
|
2021-05-20 19:34:27 +08:00
|
|
|
|
try:
|
|
|
|
|
|
import ujson as json
|
|
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
2021-10-03 14:24:07 +08:00
|
|
|
|
__zx_plugin_name__ = "原神资源查询"
|
|
|
|
|
|
__plugin_usage__ = """
|
|
|
|
|
|
usage:
|
|
|
|
|
|
不需要打开网页,就能帮你生成资源图片
|
|
|
|
|
|
指令:
|
|
|
|
|
|
原神资源查询 [资源名称]
|
|
|
|
|
|
原神资源列表
|
|
|
|
|
|
[资源名称]在哪
|
|
|
|
|
|
哪有[资源名称]
|
|
|
|
|
|
""".strip()
|
|
|
|
|
|
__plugin_superuser_usage__ = """
|
|
|
|
|
|
usage:
|
|
|
|
|
|
更新原神资源信息
|
|
|
|
|
|
指令:
|
|
|
|
|
|
更新原神资源信息
|
|
|
|
|
|
""".strip()
|
|
|
|
|
|
__plugin_des__ = "原神大地图资源速速查看"
|
|
|
|
|
|
__plugin_cmd__ = ["原神资源查询 [资源名称]", "原神资源列表", "[资源名称]在哪/哪有[资源名称]", "更新原神资源信息 [_superuser]"]
|
|
|
|
|
|
__plugin_type__ = ("原神相关",)
|
|
|
|
|
|
__plugin_version__ = 0.1
|
|
|
|
|
|
__plugin_author__ = "HibiKier"
|
|
|
|
|
|
__plugin_settings__ = {
|
|
|
|
|
|
"level": 5,
|
|
|
|
|
|
"default_status": True,
|
|
|
|
|
|
"limit_superuser": False,
|
|
|
|
|
|
"cmd": ["原神资源查询", "原神资源列表"],
|
|
|
|
|
|
}
|
2022-02-09 20:05:49 +08:00
|
|
|
|
__plugin_block_limit__ = {
|
|
|
|
|
|
"rst": "您有资源正在查询!"
|
|
|
|
|
|
}
|
2021-06-15 10:57:08 +08:00
|
|
|
|
|
2021-10-03 14:24:07 +08:00
|
|
|
|
qr = on_command("原神资源查询", aliases={"原神资源查找"}, priority=5, block=True)
|
2021-05-20 19:34:27 +08:00
|
|
|
|
qr_lst = on_command("原神资源列表", priority=5, block=True)
|
2021-10-03 14:24:07 +08:00
|
|
|
|
rex_qr = on_regex(".*?(在哪|在哪里|哪有|哪里有).*?", priority=5, block=True)
|
|
|
|
|
|
update_info = on_command("更新原神资源信息", permission=SUPERUSER, priority=1, block=True)
|
2021-05-20 19:34:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@qr.handle()
|
|
|
|
|
|
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
|
|
|
|
|
resource_name = get_message_text(event.json())
|
2021-10-03 14:24:07 +08:00
|
|
|
|
if check_resource_exists(resource_name):
|
|
|
|
|
|
await qr.send("正在生成位置....")
|
|
|
|
|
|
resource = await query_resource(resource_name)
|
|
|
|
|
|
await qr.send(Message(resource), at_sender=True)
|
|
|
|
|
|
logger.info(
|
|
|
|
|
|
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
|
|
|
|
|
f" 查询原神材料:" + resource_name
|
|
|
|
|
|
)
|
|
|
|
|
|
else:
|
|
|
|
|
|
await qr.send(f"未查找到 {resource_name} 资源,可通过 “原神资源列表” 获取全部资源名称..")
|
2021-05-20 19:34:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@rex_qr.handle()
|
|
|
|
|
|
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
|
|
|
|
|
msg = get_message_text(event.json())
|
2021-07-30 21:21:51 +08:00
|
|
|
|
if msg.find("在哪") != -1:
|
|
|
|
|
|
rs = re.search("(.*)在哪.*?", msg)
|
|
|
|
|
|
resource_name = rs.group(1) if rs else ""
|
2021-05-20 19:34:27 +08:00
|
|
|
|
else:
|
2021-07-30 21:21:51 +08:00
|
|
|
|
rs = re.search(".*?(哪有|哪里有)(.*)", msg)
|
|
|
|
|
|
resource_name = rs.group(2) if rs else ""
|
2021-10-03 14:24:07 +08:00
|
|
|
|
if check_resource_exists(resource_name):
|
|
|
|
|
|
await qr.send("正在生成位置....")
|
|
|
|
|
|
resource = await query_resource(resource_name)
|
|
|
|
|
|
if resource:
|
|
|
|
|
|
await rex_qr.send(Message(resource), at_sender=True)
|
|
|
|
|
|
logger.info(
|
|
|
|
|
|
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
|
|
|
|
|
f" 查询原神材料:" + resource_name
|
|
|
|
|
|
)
|
2021-05-20 19:34:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@qr_lst.handle()
|
|
|
|
|
|
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
2021-07-30 21:21:51 +08:00
|
|
|
|
txt = get_resource_type_list()
|
2021-05-20 19:34:27 +08:00
|
|
|
|
txt_list = txt.split("\n")
|
2021-09-05 02:21:38 +08:00
|
|
|
|
if isinstance(event, GroupMessageEvent):
|
|
|
|
|
|
mes_list = []
|
2021-05-20 19:34:27 +08:00
|
|
|
|
for txt in txt_list:
|
|
|
|
|
|
data = {
|
|
|
|
|
|
"type": "node",
|
|
|
|
|
|
"data": {
|
2021-09-05 02:21:38 +08:00
|
|
|
|
"name": f"这里是{NICKNAME}酱",
|
2021-05-20 19:34:27 +08:00
|
|
|
|
"uin": f"{bot.self_id}",
|
2021-07-30 21:21:51 +08:00
|
|
|
|
"content": txt,
|
|
|
|
|
|
},
|
2021-05-20 19:34:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
mes_list.append(data)
|
|
|
|
|
|
await bot.send_group_forward_msg(group_id=event.group_id, messages=mes_list)
|
|
|
|
|
|
else:
|
2021-07-30 21:21:51 +08:00
|
|
|
|
rst = ""
|
2021-05-20 19:34:27 +08:00
|
|
|
|
for i in range(len(txt_list)):
|
2021-07-30 21:21:51 +08:00
|
|
|
|
rst += txt_list[i] + "\n"
|
2021-05-20 19:34:27 +08:00
|
|
|
|
if i % 5 == 0:
|
|
|
|
|
|
if rst:
|
|
|
|
|
|
await qr_lst.send(rst)
|
2021-07-30 21:21:51 +08:00
|
|
|
|
rst = ""
|
|
|
|
|
|
|
2021-05-20 19:34:27 +08:00
|
|
|
|
|
2021-07-30 21:21:51 +08:00
|
|
|
|
@update_info.handle()
|
|
|
|
|
|
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
|
|
|
|
|
await init(True)
|
2021-10-03 14:24:07 +08:00
|
|
|
|
await update_info.send("更新原神资源信息完成...")
|
2021-05-20 19:34:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@scheduler.scheduled_job(
|
2021-10-03 14:24:07 +08:00
|
|
|
|
"cron",
|
2021-05-20 19:34:27 +08:00
|
|
|
|
hour=5,
|
|
|
|
|
|
minute=1,
|
|
|
|
|
|
)
|
|
|
|
|
|
async def _():
|
|
|
|
|
|
try:
|
2021-07-30 21:21:51 +08:00
|
|
|
|
await init()
|
2021-10-03 14:24:07 +08:00
|
|
|
|
logger.info(f"每日更新原神材料信息成功!")
|
2021-05-20 19:34:27 +08:00
|
|
|
|
except Exception as e:
|
2021-10-03 14:24:07 +08:00
|
|
|
|
logger.error(f"每日更新原神材料信息错误:{e}")
|