diff --git a/Paimon_Calendar/__init__.py b/Paimon_Calendar/__init__.py index 1ba9d7b..4a78f44 100644 --- a/Paimon_Calendar/__init__.py +++ b/Paimon_Calendar/__init__.py @@ -82,7 +82,7 @@ async def _(event: MessageEvent, msg: Message = CommandArg()): im = await generate_day_schedule(server) await calendar.finish(MessageSegment.image(im)) else: - push_data = load_json('calender_push.json') + push_data = load_json(Path() / 'data' / 'LittlePaimon' / 'calender_push.json') if msg.startswith(('开启', 'on', '打开')): # 添加定时推送任务 time_str = re.search(r'(\d{1,2}):(\d{2})', msg) @@ -101,7 +101,7 @@ async def _(event: MessageEvent, msg: Message = CommandArg()): if scheduler.get_job('genshin_calendar_' + push_id): scheduler.remove_job("genshin_calendar_" + push_id) - save_json(push_data, 'calender_push.json') + save_json(push_data, Path() / 'data' / 'LittlePaimon' / 'calender_push.json') scheduler.add_job( func=send_calendar, @@ -122,7 +122,7 @@ async def _(event: MessageEvent, msg: Message = CommandArg()): del push_data[str(get_message_id(event))] if scheduler.get_job("genshin_calendar_" + str(get_message_id(event))): scheduler.remove_job("genshin_calendar_" + str(get_message_id(event))) - save_json(push_data, 'calender_push.json') + save_json(push_data, Path() / 'data' / 'LittlePaimon' / 'calender_push.json') await calendar.finish('原神日程推送已关闭', at_sender=True) elif msg.startswith(('状态', 'status', 'setting')): if str(get_message_id(event)) not in push_data: @@ -137,7 +137,7 @@ async def _(event: MessageEvent, msg: Message = CommandArg()): # 自动推送任务 -for push_id, push_data in load_json('calender_push.json').items(): +for push_id, push_data in load_json(Path() / 'data' / 'LittlePaimon' / 'calender_push.json').items(): scheduler.add_job( func=send_calendar, trigger='cron', diff --git a/Paimon_CloudGenshin/__init__.py b/Paimon_CloudGenshin/__init__.py index 01402db..9ab04e8 100644 --- a/Paimon_CloudGenshin/__init__.py +++ b/Paimon_CloudGenshin/__init__.py @@ -2,6 +2,7 @@ import json import re import uuid from typing import Union +from pathlib import Path from littlepaimon_utils.files import load_json, save_json from nonebot import on_command, require, get_bot, logger @@ -56,12 +57,12 @@ async def _handle(event: Union[GroupMessageEvent, MessageEvent], match: Matcher, async def _(event: Union[GroupMessageEvent, MessageEvent], choice: str = ArgPlainText('choice')): if choice == '是': user_id = str(event.user_id) - data = load_json('user_data.json') + data = load_json(Path() / 'data' / 'LittlePaimon' / 'CloudGenshin.json') del data[user_id] if scheduler.get_job('cloud_genshin_' + user_id): scheduler.remove_job("cloud_genshin_" + user_id) - save_json(data, 'user_data.json') + save_json(data, Path() / 'data' / 'LittlePaimon' / 'CloudGenshin.json') await rm_cloud_ys.finish('token已解绑并取消自动签到~', at_sender=True) elif choice == '否': @@ -103,7 +104,7 @@ async def auto_sign_cgn(user_id, data): async def _(event: Union[GroupMessageEvent, MessageEvent], msg: Message = CommandArg(), uuid=uuid): param = msg.extract_plain_text().strip() user_id = str(event.user_id) - data = load_json('user_data.json') + data = load_json(Path() / 'data' / 'LittlePaimon' / 'CloudGenshin.json') action = re.search(r'(?P(信息|info)|(绑定|bind))', param) @@ -137,7 +138,7 @@ async def _(event: Union[GroupMessageEvent, MessageEvent], msg: Message = Comman scheduler.remove_job("cloud_genshin_" + user_id) """ 保存数据 """ - save_json(data, 'user_data.json') + save_json(data, Path() / 'data' / 'LittlePaimon' / 'CloudGenshin.json') """ 添加推送任务 """ scheduler.add_job( func=auto_sign_cgn, @@ -173,7 +174,7 @@ async def _(event: Union[GroupMessageEvent, MessageEvent], msg: Message = Comman await cloud_ys.finish('参数错误!', at_sender=True) -for user_id, data in load_json('user_data.json').items(): +for user_id, data in load_json(Path() / 'data' / 'LittlePaimon' / 'CloudGenshin.json').items(): scheduler.add_job( func=auto_sign_cgn, trigger='cron', diff --git a/Paimon_Plugins/news.py b/Paimon_Plugins/news.py index 1f9df2a..93d60c7 100644 --- a/Paimon_Plugins/news.py +++ b/Paimon_Plugins/news.py @@ -1,5 +1,5 @@ import re - +from pathlib import Path from littlepaimon_utils import aiorequests from littlepaimon_utils.files import load_json, save_json from nonebot import on_command, require, get_bot, logger @@ -37,15 +37,15 @@ scheduler = require('nonebot_plugin_apscheduler').scheduler async def news60s_pic_handler(event: MessageEvent, msg: Message = CommandArg()): msg = msg.extract_plain_text().strip() if not msg: - url = 'https://api.iyk0.com/60s/' - res = await aiorequests.get(url=url) - res = res.json() - await news60s_pic.finish(MessageSegment.image(file=res['imageUrl'])) + # url = 'https://api.iyk0.com/60s/' + # res = await aiorequests.get(url=url) + # res = res.json() + await news60s_pic.finish(MessageSegment.image(file='https://api.03c3.cn/zb/')) elif msg.startswith(('开启', 'on', '打开')): # 匹配msg中的xx:xx时间 time_str = re.search(r'(\d{1,2}):(\d{2})', msg) if time_str: - push_data = load_json('news60s_push.json') + push_data = load_json(Path() / 'data' / 'LittlePaimon' / 'news60s_push.json') push_id = str(get_message_id(event)) push_data[push_id] = { 'type': event.message_type, @@ -66,20 +66,20 @@ async def news60s_pic_handler(event: MessageEvent, msg: Message = CommandArg()): push_data[str(get_message_id(event))]), misfire_grace_time=10 ) - save_json(push_data, 'news60s_push.json') + save_json(push_data, Path() / 'data' / 'LittlePaimon' / 'news60s_push.json') await news60s_pic.finish('开启60s读世界推送成功', at_sender=True) else: await news60s_pic.finish('请给出正确的时间,格式为12:00', at_sender=True) elif msg.startswith(('关闭', 'off', 'close')): - push_data = load_json('news60s_push.json') + push_data = load_json(Path() / 'data' / 'LittlePaimon' / 'news60s_push.json') if str(get_message_id(event)) in push_data: del push_data[str(get_message_id(event))] if scheduler.get_job('60sNews' + str(get_message_id(event))): scheduler.remove_job('60sNews' + str(get_message_id(event))) - save_json(push_data, 'news60s_push.json') + save_json(push_data, Path() / 'data' / 'LittlePaimon' / 'news60s_push.json') await news60s_pic.finish('关闭60s读世界推送成功', at_sender=True) elif msg.startswith(('状态', 'status', 'setting')): - push_data = load_json('news60s_push.json') + push_data = load_json(Path() / 'data' / 'LittlePaimon' / 'news60s_push.json') if str(get_message_id(event)) not in push_data: await news60s_pic.finish('当前会话未开启60秒读世界订阅', at_sender=True) else: @@ -91,25 +91,25 @@ async def news60s_pic_handler(event: MessageEvent, msg: Message = CommandArg()): async def news60s_push_task(push_id, push_data: dict): try: - url = 'https://api.iyk0.com/60s/' - res = await aiorequests.get(url=url) - res = res.json() + # url = 'https://api.iyk0.com/60s/' + # res = await aiorequests.get(url=url) + # res = res.json() if push_data['type'] == 'private': api = 'send_private_msg' - data = {'user_id': push_id, 'message': MessageSegment.image(file=res['imageUrl'])} + data = {'user_id': push_id, 'message': MessageSegment.image(file='https://api.03c3.cn/zb/')} elif push_data['type'] == 'guild': api = 'send_guild_channel_msg' - data = {'guild_id': push_id, 'channel_id': push_data['channel_id'], 'message': MessageSegment.image(file=res['imageUrl'])} + data = {'guild_id': push_id, 'channel_id': push_data['channel_id'], 'message': MessageSegment.image(file='https://api.03c3.cn/zb/')} else: api = 'send_group_msg' - data = {'group_id': push_id, 'message': MessageSegment.image(file=res['imageUrl'])} + data = {'group_id': push_id, 'message': MessageSegment.image(file='https://api.03c3.cn/zb/')} await get_bot().call_api(api, **data) logger.info(f'{push_data["type"]}的{push_id}的60秒读世界推送成功') except Exception as e: logger.exception(f'{push_data["type"]}的{push_id}的60秒读世界推送失败:{e}') -for push_id, push_data in load_json('news60s_push.json').items(): +for push_id, push_data in load_json(Path() / 'data' / 'LittlePaimon' / 'news60s_push.json').items(): scheduler.add_job( func=news60s_push_task, trigger='cron', diff --git a/README.md b/README.md index 90f9095..4290f6d 100644 --- a/README.md +++ b/README.md @@ -59,23 +59,23 @@ ## 丨更新日志 > README只展示最近更新,全部更新日志详见[这里](https://github.com/CMHopeSunshine/LittlePaimon/blob/nonebot2/UPDATE_LOG.md) -+ 6.30 - - `ysd`支持查看`钟离、胡桃、雷电将军`的伤害计算(~~如果不准请反馈~~) -+ 7.1 - - 伤害计算新增`魈` + 7.3 - 重构部分代码 - - **修改了插件加载方式** - - 如果你此前是在`bot.py`中使用`nonebot.load_plugins("LittlePaimon")`方式加载插件,请在更新后将`load_plugins`改为`load_plugin`,也就是去掉`s` + - ~~修改了插件加载方式~~ + - 不改了,回档了,依旧是用`nonebot.load_plugins` - **修改静态资源和用户数据目录** - 理论上会**自动迁移**,但`git pull`更新可能会将资源删除,所以最好**手动迁移,同时备份** - 1、将派蒙的`res`文件夹改名`LittlePaimon`,移到nonebot根目录的`resources`中(没有`resources`就新建一个) - 2、将派蒙的`user_data`文件夹移到nonebot根目录的`data/LittlePaimon`目录中(同理,没有就新建) - 静态资源改为启动时自动下载 - - 上传至`pypi` - - 意味着你可以通过pip等包管理工具来下载派蒙,例子见下面的部署方法 - - 上面的修改基本上都是为了上传`pypi`,以及减少仓库体积 - + - ~~上传至`pypi`~~ + - ~~意味着你可以通过pip等包管理工具来下载派蒙,例子见下面的部署方法~~ + - ~~上面的修改基本上都是为了上传`pypi`,以及减少仓库体积~~ + - pip安装的话加载时存在导包问题,无法正确加载,~~算了吧~~ ++ 7.4 + - 回档部分7.3的修改 + - 修复`60秒早报`接口bug + ## 丨功能列表 详见我的博客[功能列表](https://blog.cherishmoon.fun/posts/nonebot2funclist.html)
@@ -98,26 +98,12 @@ # 2、编辑bot.py,在load_from_toml下方添加一句 - nonebot.load_plugin("LittlePaimon") + nonebot.load_plugins("LittlePaimon") # 3、进入LittlePaimon目录,安装依赖 cd LittlePaimon pip install -r requirements.txt ``` - - - pip方式 - - ```bash - # 在nonebot目录运行: - - # 1、pip方式 - pip install littlepaimon - # 如果你使用poetry进行环境管理,可以: - poetry add littlepaimon - - # 2、编辑pyproject.toml,在[tool.nonebot]下方的plugins里加入LittlePaimon - plugins = ["其他插件xxxx", "LittlePaimon"] - ``` ### 我不熟悉NoneBot2 **详细部署教程:** diff --git a/UPDATE_LOG.md b/UPDATE_LOG.md index 8bb1b76..d21036a 100644 --- a/UPDATE_LOG.md +++ b/UPDATE_LOG.md @@ -63,13 +63,17 @@ - 伤害计算新增`魈` + 7.3 - 重构部分代码 - - **修改了插件加载方式** - - 如果你此前是在`bot.py`中使用`nonebot.load_plugins("LittlePaimon")`方式加载插件,请在更新后将`load_plugins`改为`load_plugin`,也就是去掉`s` + - ~~修改了插件加载方式~~ + - 不改了,回档了,依旧是用`nonebot.load_plugins` - **修改静态资源和用户数据目录** - 理论上会**自动迁移**,但`git pull`更新可能会将资源删除,所以最好**手动迁移,同时备份** - 1、将派蒙的`res`文件夹改名`LittlePaimon`,移到nonebot根目录的`resources`中(没有`resources`就新建一个) - 2、将派蒙的`user_data`文件夹移到nonebot根目录的`data/LittlePaimon`目录中(同理,没有就新建) - 静态资源改为启动时自动下载 - - 上传至`pypi` - - 意味着你可以通过pip等包管理工具来下载派蒙,例子见下面的部署方法 - - 上面的修改基本上都是为了上传`pypi`,以及减少仓库体积 \ No newline at end of file + - ~~上传至`pypi`~~ + - ~~意味着你可以通过pip等包管理工具来下载派蒙,例子见下面的部署方法~~ + - ~~上面的修改基本上都是为了上传`pypi`,以及减少仓库体积~~ + - pip安装的话加载时存在导包问题,无法正确加载,~~算了吧~~ ++ 7.4 + - 回档部分7.3的修改 + - 修复`60秒早报`接口bug diff --git a/__init__.py b/__init__.py index 8be10a2..4305142 100644 --- a/__init__.py +++ b/__init__.py @@ -1,14 +1,11 @@ import asyncio import hashlib -import os.path import shutil from pathlib import Path from littlepaimon_utils.files import load_json, download from nonebot import get_driver, logger -from nonebot import load_plugins -load_plugins(os.path.dirname(__file__)) driver = get_driver()