diff --git a/Paimon_Calendar/__init__.py b/Paimon_Calendar/__init__.py index 9413b42..abcde0f 100644 --- a/Paimon_Calendar/__init__.py +++ b/Paimon_Calendar/__init__.py @@ -1,10 +1,10 @@ -from nonebot import require, get_bot, on_command, logger +from nonebot import get_bot, on_command, logger from nonebot.adapters.onebot.v11 import MessageEvent, Message, MessageSegment from nonebot.params import CommandArg from nonebot.plugin import PluginMetadata from utils.file_handler import load_json, save_json -from utils.message_util import MessageBuild, get_message_id +from utils.message_util import get_message_id from .generate import * import re @@ -22,7 +22,7 @@ __plugin_meta__ = PluginMetadata( 'type': '原神Wiki', 'range': ['private', 'group', 'guild'], "author": "nicklly <1134741727@qq.com>", - "version": "1.0.0", + "version": "1.0.1", }, ) @@ -79,7 +79,7 @@ async def _(event: MessageEvent, msg: Message = CommandArg()): if not msg: im = await generate_day_schedule(server) - await calendar.finish( MessageSegment.image(im)) + await calendar.finish(MessageSegment.image(im)) else: push_data = load_json('calender_push.json') if msg.startswith(('开启', 'on', '打开')): diff --git a/Paimon_Calendar/draw.py b/Paimon_Calendar/draw.py index 2a37248..17fb842 100644 --- a/Paimon_Calendar/draw.py +++ b/Paimon_Calendar/draw.py @@ -1,8 +1,8 @@ from PIL import Image, ImageDraw, ImageFont -import os +from pathlib import Path -font_Path = res_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'res') -font = ImageFont.truetype(os.path.join(res_path, 'wqy-microhei.ttc'), 20) +res_path = Path(__file__).parent.parent / 'res' +font = ImageFont.truetype(str(res_path / 'wqy-microhei.ttc'), 20) width = 500 diff --git a/Paimon_Calendar/event.py b/Paimon_Calendar/event.py index 97224a1..4cbb9f4 100644 --- a/Paimon_Calendar/event.py +++ b/Paimon_Calendar/event.py @@ -1,4 +1,4 @@ -import os +from pathlib import Path from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta from utils.aiorequests import get @@ -8,8 +8,7 @@ import functools import re -res = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'Paimon_Calendar/template') - +res = Path(__file__).parent / 'template' # type 0 普通常驻任务深渊 1 新闻 2 蛋池 3 限时活动H5 event_data = { 'cn': [], @@ -172,7 +171,7 @@ async def load_event_cn(): 'forever': False, 'type': 3, 'color': '#580dda', - 'banner': res + '/sy.jpg' + 'banner': res / 'sy.jpg' }) event_data['cn'].append({ 'title': '「深境螺旋」· 下半段 ', @@ -181,7 +180,7 @@ async def load_event_cn(): 'forever': False, 'type': 3, 'color': '#580dda', - 'banner': res + '/sy.jpg' + 'banner': res / 'sy.jpg' }) i = i+1 diff --git a/Paimon_Calendar/generate.py b/Paimon_Calendar/generate.py index 0e44628..ba8e458 100644 --- a/Paimon_Calendar/generate.py +++ b/Paimon_Calendar/generate.py @@ -1,6 +1,6 @@ -import base64 -from io import BytesIO +from nonebot import require +require("nonebot_plugin_htmlrender") from nonebot_plugin_htmlrender import html_to_pic import jinja2 @@ -8,19 +8,11 @@ from .event import * from .draw import * body = [] -template_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'Paimon_Calendar/template') +template_path = Path(__file__).parent / 'template' env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path), enable_async=True) -def im2base64str(im): - io = BytesIO() - im.save(io, 'png') - base64_str = f"base64://{base64.b64encode(io.getvalue()).decode()}" - return base64_str - - async def generate_day_schedule(server='cn'): - events = await get_events(server, 0, 15) has_prediction = False """ 追加数据前先执行清除,以防数据叠加 """ @@ -35,10 +27,10 @@ async def generate_day_schedule(server='cn'): if event['start_days'] <= 0: time = '即将结束' if event["left_days"] == 0 else f'{str(event["left_days"])}天后结束' body.append({ - 'title': event['title'], - 'time': time, + 'title': event['title'], + 'time': time, 'online': f'{datetime.strftime(event["start"], r"%m-%d")} ~ {datetime.strftime(event["end"], r"%m-%d")}', - 'color': event['color'], + 'color': event['color'], 'banner': event['banner'] }) if has_prediction: @@ -46,14 +38,12 @@ async def generate_day_schedule(server='cn'): if event['start_days'] > 0: time = '即将开始' if event["start_days"] == 0 else f'{str(event["start_days"])}天后开始' body.append({ - 'title': event['title'], - 'time': time, + 'title': event['title'], + 'time': time, 'online': f'{datetime.strftime(event["start"], r"%m-%d")} ~ {datetime.strftime(event["end"], r"%m-%d")}', - 'color': event['color'], + 'color': event['color'], 'banner': event['banner'] }) content = await template.render_async(body=body, css_path=template_path) return await html_to_pic(content, wait=0, viewport={"width": 600, "height": 100}) - -