diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e5a07a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/dist +__pycache__ +/.idea \ No newline at end of file diff --git a/README.md b/README.md index f7d76c7..5405e25 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,8 @@ pip install nonebot-plugin-calc24 - 24点 关闭连续模式:关闭连续模式 ## 更新 +### 2024-08-02 +- 更改插件的模式储存方式 ### 2024-05-26 - 更新模式切换判断 - └ 缺点:插件在自己或bot重启后会默认关闭连续模式 diff --git a/nonebot_plugin_calc24/__init__.py b/nonebot_plugin_calc24/__init__.py index d7abcf0..592de2f 100644 --- a/nonebot_plugin_calc24/__init__.py +++ b/nonebot_plugin_calc24/__init__.py @@ -6,6 +6,9 @@ from nonebot.typing import T_State from nonebot.plugin import PluginMetadata from .xj_calc24 import xj_calc24 +from .file_handle import file_handle + +file_handle = file_handle() class_calc24 = xj_calc24() @@ -17,10 +20,11 @@ homepage="https://github.com/ajdgg/nonebot-plugin-calc24", ) +pattern_data = file_handle.file_reading("calc24-data.json", "pattern") _timers = {} _continuous_mode = {} -_continuous_mode['pattern'] = False +_continuous_mode['pattern'] = pattern_data _calc24_session = {} _original_array = {} @@ -43,10 +47,12 @@ async def handle_first_receive(bot: Bot, event: Event, state: T_State, args=Comm await calc24.finish("连续模式已是开启了哦") else: _continuous_mode['pattern'] = True + file_handle.file_change('calc24-data.json', 'pattern', True) await calc24.finish("连续模式开启") elif Plugin_status == '退出连续模式' or Plugin_status == '关闭连续模式': if _continuous_mode['pattern']: _continuous_mode['pattern'] = False + file_handle.file_change("calc24-data.json", "pattern", False) await calc24.finish("连续模式关闭") else: await calc24.finish("连续模式已是关闭的哦") diff --git a/nonebot_plugin_calc24/calc24-data.json b/nonebot_plugin_calc24/calc24-data.json index 9d70fde..e34e978 100644 --- a/nonebot_plugin_calc24/calc24-data.json +++ b/nonebot_plugin_calc24/calc24-data.json @@ -1,4 +1,5 @@ { + "pattern": false, "data": [ [ 1, diff --git a/nonebot_plugin_calc24/file_handle.py b/nonebot_plugin_calc24/file_handle.py index b127053..3b61a52 100644 --- a/nonebot_plugin_calc24/file_handle.py +++ b/nonebot_plugin_calc24/file_handle.py @@ -1,4 +1,5 @@ from pathlib import Path +from typing import Union import json @@ -20,7 +21,7 @@ def file_reading(self, file: str, key: str): except Exception as e: print(f"An error occurred: {e}") - def file_change(self, file: str, key: str, value: str): + def file_change(self, file: str, key: str, value: Union[str, int, float, bool, list]): try: json_file_path_change = file_path(file) with json_file_path_change.open('r', encoding='utf-8') as f: