Skip to content

Commit

Permalink
优化代码规范 修复无法自动删除过旧房间
Browse files Browse the repository at this point in the history
  • Loading branch information
Ant1816 committed Dec 18, 2024
1 parent 46f48de commit c29e5db
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 18 deletions.
3 changes: 3 additions & 0 deletions nonebot_plugin_pjsekaihelper/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nonebot_plugin_pjsekaihelper/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions nonebot_plugin_pjsekaihelper/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions nonebot_plugin_pjsekaihelper/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 18 additions & 14 deletions nonebot_plugin_pjsekaihelper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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")

Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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("重置成功")
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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]
Expand Down

0 comments on commit c29e5db

Please sign in to comment.