Skip to content

Commit

Permalink
💡更新模式的记忆存储
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdgg committed Aug 1, 2024
1 parent e1a6f2a commit 790daa9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dist
__pycache__
/.idea
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pip install nonebot-plugin-calc24
- 24点 关闭连续模式:关闭连续模式

## 更新
### 2024-08-02
- 更改插件的模式储存方式
### 2024-05-26
- 更新模式切换判断
- └ 缺点:插件在自己或bot重启后会默认关闭连续模式
Expand Down
8 changes: 7 additions & 1 deletion nonebot_plugin_calc24/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand All @@ -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 = {}

Expand All @@ -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("连续模式已是关闭的哦")
Expand Down
1 change: 1 addition & 0 deletions nonebot_plugin_calc24/calc24-data.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"pattern": false,
"data": [
[
1,
Expand Down
3 changes: 2 additions & 1 deletion nonebot_plugin_calc24/file_handle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import Union
import json


Expand All @@ -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:
Expand Down

0 comments on commit 790daa9

Please sign in to comment.