From c29e5db7e4e04ee2d2a90e7f14da2897e4eed4c2 Mon Sep 17 00:00:00 2001 From: Lyan Guan Date: Wed, 18 Dec 2024 20:57:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E8=8C=83=20=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=A0=E9=99=A4=E8=BF=87=E6=97=A7=E6=88=BF=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_pjsekaihelper/.idea/.gitignore | 3 ++ nonebot_plugin_pjsekaihelper/.idea/.name | 1 + .../inspectionProfiles/Project_Default.xml | 21 ++++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++ nonebot_plugin_pjsekaihelper/.idea/misc.xml | 7 ++++ .../.idea/modules.xml | 8 +++++ .../.idea/nonebot_plugin_pjsekaihelper.iml | 12 +++++++ nonebot_plugin_pjsekaihelper/__init__.py | 32 +++++++++++-------- pyproject.toml | 6 ++-- 9 files changed, 78 insertions(+), 18 deletions(-) create mode 100644 nonebot_plugin_pjsekaihelper/.idea/.gitignore create mode 100644 nonebot_plugin_pjsekaihelper/.idea/.name create mode 100644 nonebot_plugin_pjsekaihelper/.idea/inspectionProfiles/Project_Default.xml create mode 100644 nonebot_plugin_pjsekaihelper/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 nonebot_plugin_pjsekaihelper/.idea/misc.xml create mode 100644 nonebot_plugin_pjsekaihelper/.idea/modules.xml create mode 100644 nonebot_plugin_pjsekaihelper/.idea/nonebot_plugin_pjsekaihelper.iml diff --git a/nonebot_plugin_pjsekaihelper/.idea/.gitignore b/nonebot_plugin_pjsekaihelper/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/nonebot_plugin_pjsekaihelper/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/nonebot_plugin_pjsekaihelper/.idea/.name b/nonebot_plugin_pjsekaihelper/.idea/.name new file mode 100644 index 0000000..93f5256 --- /dev/null +++ b/nonebot_plugin_pjsekaihelper/.idea/.name @@ -0,0 +1 @@ +__init__.py \ No newline at end of file diff --git a/nonebot_plugin_pjsekaihelper/.idea/inspectionProfiles/Project_Default.xml b/nonebot_plugin_pjsekaihelper/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..c35c807 --- /dev/null +++ b/nonebot_plugin_pjsekaihelper/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,21 @@ + + + + \ No newline at end of file diff --git a/nonebot_plugin_pjsekaihelper/.idea/inspectionProfiles/profiles_settings.xml b/nonebot_plugin_pjsekaihelper/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/nonebot_plugin_pjsekaihelper/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/nonebot_plugin_pjsekaihelper/.idea/misc.xml b/nonebot_plugin_pjsekaihelper/.idea/misc.xml new file mode 100644 index 0000000..db8786c --- /dev/null +++ b/nonebot_plugin_pjsekaihelper/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/nonebot_plugin_pjsekaihelper/.idea/modules.xml b/nonebot_plugin_pjsekaihelper/.idea/modules.xml new file mode 100644 index 0000000..5f8fe42 --- /dev/null +++ b/nonebot_plugin_pjsekaihelper/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/nonebot_plugin_pjsekaihelper/.idea/nonebot_plugin_pjsekaihelper.iml b/nonebot_plugin_pjsekaihelper/.idea/nonebot_plugin_pjsekaihelper.iml new file mode 100644 index 0000000..07abf20 --- /dev/null +++ b/nonebot_plugin_pjsekaihelper/.idea/nonebot_plugin_pjsekaihelper.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/nonebot_plugin_pjsekaihelper/__init__.py b/nonebot_plugin_pjsekaihelper/__init__.py index 48e067a..156c4bf 100644 --- a/nonebot_plugin_pjsekaihelper/__init__.py +++ b/nonebot_plugin_pjsekaihelper/__init__.py @@ -6,7 +6,7 @@ from nonebot import require from pathlib import Path -from nonebot.internal.params import ArgPlainText +from nonebot.params import ArgPlainText require("nonebot_plugin_localstore") import nonebot_plugin_localstore as store @@ -18,7 +18,6 @@ from nonebot.permission import SUPERUSER from nonebot.adapters.onebot.v11 import GroupMessageEvent, Bot, Event, MessageEvent, PrivateMessageEvent, MessageSegment -global room_data SUPERUSERS = get_driver().config.superusers __plugin_meta__ = PluginMetadata( @@ -30,11 +29,12 @@ homepage="https://github.com/Ant1816/nonebot-plugin-pjsekaihelper", extra={ "author": "Ant1", - "version": "1.0.13", + "version": "1.0.14", "priority": 10, }, ) +room_data = [] plugin_data_dir: Path = store.get_plugin_data_dir() ROOM_LIST_FILE: Path = store.get_plugin_data_file("room_list.json") @@ -43,19 +43,22 @@ def load_all_room(): + global room_data try: with open(ROOM_LIST_FILE, 'r', encoding='utf-8') as file: - globals()['room_data'] = json.load(file) + room_data = json.load(file) except FileNotFoundError: - globals()['room_data'] = [] - if globals()['room_data']: - for room in globals()['room_data']: - last = datetime.datetime.strptime(room["CreatedTime"], "%H:%M:%S") - if str(datetime.datetime.strptime(time.strftime('%H:%M:%S', time.localtime()), "%H:%M:%S") - last) >= '1800': - globals()['room_data'].remove(room) + room_data = [] + if room_data: + for room in room_data: + last = datetime.datetime.strptime(room["CreatedTime"], "%Y-%m-%d %H:%M:%S") + now = datetime.datetime.strptime(time.strftime('%Y-%m-%d %H:%M:%S'), "%Y-%m-%d %H:%M:%S") + duration = now - last + if duration.days > 0 or duration.seconds > 1800: + room_data.remove(room) with open(ROOM_LIST_FILE, 'w', encoding='utf-8') as file: - json.dump(globals()['room_data'], file, ensure_ascii=False, indent=2) - return globals()['room_data'] + json.dump(room_data, file, ensure_ascii=False, indent=2) + return room_data help_ = on_command("pjsk help", priority=10, block=True) @@ -90,7 +93,7 @@ async def handle_create_room(bot: Bot, event: GroupMessageEvent, args: Message = "RoomNumber": room_number, "Server": ServerInfo, "CreatedBy": event.get_user_id(), - "CreatedTime": time.strftime('%H:%M:%S', time.localtime()) + "CreatedTime": time.strftime('%Y-%m-%d %H:%M:%S') } new_room_data.append(new_room) else: @@ -141,7 +144,8 @@ async def handle_room_delete(bot: Bot, event: GroupMessageEvent, args: Message = @roomreset.handle() async def handle_room_reset(bot: Bot, event: GroupMessageEvent): + global room_data with open(ROOM_LIST_FILE, 'w', encoding='utf-8') as file: json.dump([], file, ensure_ascii=False, indent=2) - globals()['room_data'] = [] + room_data = [] await roomreset.finish("重置成功") diff --git a/pyproject.toml b/pyproject.toml index d2165c7..1768619 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nonebot-plugin-pjsekaihelper" -version = "1.0.13" +version = "1.0.14" description = "世界计划插件,拥有组建车队等功能,持续开发中" readme = "README.md" requires-python = ">=3.8" @@ -19,11 +19,9 @@ classifiers = [ ] dependencies = [ - "datetime", - "pathlib", "nonebot2>=2.3.0", "nonebot_plugin_localstore>=0.7.1", - "nonebot-adapter-onebot" + "nonebot-adapter-onebot>=2.1.0" ] [project.optional-dependencies]