summaryrefslogtreecommitdiff
path: root/ATRI/plugins/plugin_admin
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2020-10-31 20:01:36 +0800
committerKyomotoi <[email protected]>2020-10-31 20:01:36 +0800
commitde0426304d77ae9cbb9ffccac142176b0f1900de (patch)
tree9749f9b04cdb0d30cecced882c33c87eea77cd8e /ATRI/plugins/plugin_admin
parentbebb0ecf8497755ce5be5d28884ed5d9e1eb3c79 (diff)
downloadATRI-de0426304d77ae9cbb9ffccac142176b0f1900de.tar.gz
ATRI-de0426304d77ae9cbb9ffccac142176b0f1900de.tar.bz2
ATRI-de0426304d77ae9cbb9ffccac142176b0f1900de.zip
[Update]
Diffstat (limited to 'ATRI/plugins/plugin_admin')
-rw-r--r--ATRI/plugins/plugin_admin/__init__.py191
1 files changed, 132 insertions, 59 deletions
diff --git a/ATRI/plugins/plugin_admin/__init__.py b/ATRI/plugins/plugin_admin/__init__.py
index cacb667..571d83d 100644
--- a/ATRI/plugins/plugin_admin/__init__.py
+++ b/ATRI/plugins/plugin_admin/__init__.py
@@ -13,6 +13,7 @@ __author__ = 'kyomotoi'
import re
import json
from pathlib import Path
+from utils.utils_error import errorRepo
from nonebot.plugin import on_command
from nonebot.adapters.cqhttp import Bot, Event
@@ -81,69 +82,141 @@ async def _(bot: Bot, event: Event, state: dict) -> None:
await switch.finish("请检查拼写是否正确嗷~~!")
-# # 舆情监控系统
-# publicOpinion = on_command("舆情", permission=SUPERUSER|GROUP_ADMIN|GROUP_OWNER)
-# data_PO = Path('.') / 'ATRI' / 'plugins' / 'plugin_chat' / 'public_opinion.json'
-
-# @publicOpinion.handle() # type: ignore
-# async def _(bot: Bot, event: Event, state: dict) -> None:
-# user = str(event.user_id)
-# group = str(event.group_id)
-# msg = str(event.message).strip().split(' ')
-
-# if banList(user, group):
-# if msg[0] == '':
-# msg0 = "---=====ATRI POM System=====---\n"
-# msg0 += "Usage:\n"
-# msg0 += " - 舆情 [key] [times] [ban time(bot)] [repo]\n"
-# msg0 += "Tips:\n"
-# msg0 += " - 非 SUPERU 只能设置本群\n"
-# msg0 += " - SUPERU 需在后跟随 -a 以启用全局效果\n"
-# msg0 += " - 参数类型:\n"
-# msg0 += " * key: 关键词(将使用正则匹配)\n"
-# msg0 += " * times: 容忍次数(n>0, int)\n"
-# msg0 += " * ban time: bot对其失效时间(min, int)\n"
-# msg0 += " * repo: 触发后的关键词(可选),如为图片,键入 img"
-
-# await publicOpinion.finish(msg0)
-
-# key_word = msg[0]
-# remind = msg[1]
-# punish = msg[2]
-# repo = msg[3]
+# 舆情监控系统
+publicOpinion = on_command("舆情", permission=SUPERUSER|GROUP_ADMIN|GROUP_OWNER)
+data_PO = Path('.') / 'ATRI' / 'plugins' / 'plugin_chat' / 'public_opinion.json'
-# if key_word and remind and punish and repo:
-# if re.findall(r"/^\d{1,}$/", remind) and re.findall(r"/^\d{1,}$/", punish):
-# pass
[email protected]() # type: ignore
+async def _(bot: Bot, event: Event, state: dict) -> None:
+ user = str(event.user_id)
+ group = str(event.group_id)
+ msg = str(event.message).strip().split(' ')
-# else:
-# await publicOpinion.finish("非法字符!请注意(times, ban time)类型为int(阿拉伯数字)")
+ if banList(user, group):
+ if msg[0] == '':
+ msg0 = "---=====ATRI POM System=====---\n"
+ msg0 += "Usage:\n"
+ msg0 += " - 舆情 [key] [times] [ban time(bot)] [repo]\n"
+ msg0 += "Tips:\n"
+ msg0 += " - 非 SUPERU 只能设置本群\n"
+ msg0 += " - SUPERU 需在后跟随 -a 以启用全局效果\n"
+ msg0 += " - 参数类型:\n"
+ msg0 += " * key: 关键词(将使用正则匹配)\n"
+ msg0 += " * times: 容忍次数(n>0, int)\n"
+ msg0 += " * ban time: bot对其失效时间(min, int)\n"
+ msg0 += " * repo: 触发后的关键词(可选),如为图片,键入 img"
+
+ await publicOpinion.finish(msg0)
-# else:
-# await publicOpinion.finish("请键入完整信息!\n如需帮助,请键入 舆情")
+ if msg[0] and msg[1] and msg[2] and msg[3]:
+ pass
+ else:
+ msg0 = "请检查格式奥~!\n"
+ msg0 += "舆情 [key] [times] [ban time(bot)] [repo]\n"
+ msg0 += " * key: 关键词(将使用正则匹配)\n"
+ msg0 += " * times: 容忍次数(n>0, int)\n"
+ msg0 += " * ban time: bot对其失效时间(min, int)\n"
+ msg0 += " * repo: 触发后的关键词(可选),如为图片,键入 img"
+ await publicOpinion.finish(msg0)
+
+ key_word = msg[0]
+ remind = msg[1]
+ punish = msg[2]
+ repo = msg[3]
+
+ if key_word and remind and punish and repo:
+ if re.findall(r"/^\d{1,}$/", remind) and re.findall(r"/^\d{1,}$/", punish):
+ pass
+
+ else:
+ await publicOpinion.finish("非法字符!请注意(times, ban time)类型为int(阿拉伯数字)")
-# if repo == "img":
-# state["key_word"] = key_word
-# state["remind"] = remind
-# state["punish"] = punish
+ else:
+ await publicOpinion.finish("请键入完整信息!\n如需帮助,请键入 舆情")
+
+ if repo == "img":
+ state["key_word"] = key_word
+ state["remind"] = remind
+ state["punish"] = punish
-# else:
-# pass
-
-# @publicOpinion.got("repo", prompt="检测到 repo 类型为 img,请发送一张图片") # type: ignore
-# async def _(bot: Bot, event: Event, state: dict) -> None:
-# key_word = state["key_word"]
-# remind = state["remind"]
-# punish = state["punish"]
-# repo = state["repo"]
-
-# if "[CQ:image" not in repo:
-# await publicOpinion.reject("请发送一张图片而不是图片以外的东西~!(")
+ else:
+ try:
+ with open(data_PO, "r") as f:
+ data = json.load(f)
+ except:
+ data = {}
+
+ data[key_word] = [remind, punish, repo]
+
+ with open(data_PO, "w") as f:
+ f.write(json.dumps(data))
+ f.close()
+
+ msg0 = "舆情信息记录完成~!\n"
+ msg0 += f"Keyword: {key_word}\n"
+ msg0 += f"Times: {remind}\n"
+ msg0 += f"Ban time: {punish}\n"
+ msg0 += f"Repo: {repo}"
+
+ await publicOpinion.finish(msg0)
+
+
[email protected]("repo", prompt="检测到 repo 类型为 img,请发送一张图片") # type: ignore
+async def _(bot: Bot, event: Event, state: dict) -> None:
+ key_word = state["key_word"]
+ remind = state["remind"]
+ punish = state["punish"]
+ repo = state["repo"]
+
+ if "[CQ:image" not in repo:
+ await publicOpinion.reject("请发送一张图片而不是图片以外的东西~!(")
+
+ try:
+ with open(data_PO, "r") as f:
+ data = json.load(f)
+ except:
+ data = {}
+
+ data[key_word] = [remind, punish, repo]
+
+ with open(data_PO, "w") as f:
+ f.write(json.dumps(data))
+ f.close()
+
+ msg0 = "舆情信息记录完成~!\n"
+ msg0 += f"Keyword: {key_word}\n"
+ msg0 += f"Times: {remind}\n"
+ msg0 += f"Ban time: {punish}\n"
+ msg0 += f"Repo: {repo}"
+
+ await publicOpinion.finish(msg0)
+
+
+trackError = on_command('track', permission=SUPERUSER)
+file_error = Path('.') / 'ATRI' / 'data' / 'data_Error' / 'error.json'
+
[email protected]() # type: ignore
+async def _(bot: Bot, event: Event, state: dict) -> None:
+ track_id = str(event.message).strip()
+
+ if not track_id:
+ await trackError.finish("请告诉咱追踪ID嗷~!不然无法获取错误堆栈呢!!")
-# try:
-# with open(data_PO, "r") as f:
-# data = json.load(f)
-# except:
-# data = {}
+ data = {}
-# data[key_word] = [remind, punish, repo]
+ try:
+ with open(file_error, 'r') as f:
+ data = json.load(f)
+ except:
+ await trackError.finish(errorRepo("读取文件时错误"))
+
+ if track_id in data:
+ info_error = data[track_id]
+
+ msg0 = f"trackID: {track_id}\n"
+ msg0 =+ info_error
+
+ await trackError.finish(msg0)
+
+ else:
+ await trackError.finish("未发现该ID")