summaryrefslogtreecommitdiff
path: root/ATRI/plugins/LearnRepo.py
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI/plugins/LearnRepo.py')
-rw-r--r--ATRI/plugins/LearnRepo.py62
1 files changed, 20 insertions, 42 deletions
diff --git a/ATRI/plugins/LearnRepo.py b/ATRI/plugins/LearnRepo.py
index 1d79836..01c04c2 100644
--- a/ATRI/plugins/LearnRepo.py
+++ b/ATRI/plugins/LearnRepo.py
@@ -1,13 +1,12 @@
import json
-from random import randint
from datetime import datetime
from pathlib import Path
import nonebot
from nonebot import on_command
from nonebot import CommandSession
-import config # type: ignore
-from ATRI.modules.funcControl import checkNoob # type: ignore
+import config
+from ATRI.modules.error import errorBack
bot = nonebot.get_bot()
@@ -41,46 +40,25 @@ async def _(session: CommandSession):
await session.send('该词已存在~!')
else:
- data[f"{word}"] = [f"{repo}",prob]
- f = open(Path('.') / 'ATRI' / 'plugins' / 'LearnRepo' / 'LearnRepo.json', 'w')
- f.write(json.dumps(data))
- f.close()
- session.finish(f"学習しました!\nWord:[{word}]\nRepo:[{repo}]\nProbability:[{'%.2f%%' % (round(1 / prob , 1) * 100)}]")
-
+ try:
+ data[f"{word}"] = [f"{repo}",prob]
+ f = open(Path('.') / 'ATRI' / 'plugins' / 'LearnRepo' / 'LearnRepo.json', 'w')
+ f.write(json.dumps(data))
+ f.close()
+ session.finish(f"学習しました!\nWord:[{word}]\nRepo:[{repo}]\nProbability:[{'%.2f%%' % (round(1 / prob , 1) * 100)}]")
+ except:
+ session.finish(errorBack('写入失败'))
+
elif w_tpye == '删除词汇':
if word in data.keys():
- data.pop(f"{word}")
- f = open(Path('.') / 'ATRI' / 'plugins' / 'LearnRepo' / 'LearnRepo.json', 'w')
- f.write(json.dumps(data))
- f.close()
- await session.send(f'已成功从ATRI记忆模块中抹除[{word}]')
+ try:
+ data.pop(f"{word}")
+ f = open(Path('.') / 'ATRI' / 'plugins' / 'LearnRepo' / 'LearnRepo.json', 'w')
+ f.write(json.dumps(data))
+ f.close()
+ await session.send(f'已成功从ATRI记忆模块中抹除[{word}]')
+ except:
+ session.finish(errorBack('移除失败'))
else:
- session.finish(f'ATRI貌似没法从记忆中找到关键词[{word}]呢...')
-
-
[email protected]_message("group")
-async def repo(context):
- user = context["user_id"]
- group = context["group_id"]
- word = context["message"]
- if 0 <= now_time() < 5.5:
- pass
- else:
- if checkNoob(user, group):
- try:
- with open(Path('.') / 'ATRI' / 'plugins' / 'LearnRepo' / 'LearnRepo.json', 'r') as f:
- data = json.load(f)
- except:
- data = {}
-
- if str(word) in data.keys():
- lt = data[f"{word}"]
- msg = lt[0]
- prob = int(lt[1])
- res = randint(1,prob)
- if res == 1:
- await bot.send_msg(
- group_id = group,
- message = msg
- ) # type: ignore \ No newline at end of file
+ session.finish(f'ATRI貌似没法从记忆中找到关键词[{word}]呢...') \ No newline at end of file