summaryrefslogtreecommitdiff
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
parentbebb0ecf8497755ce5be5d28884ed5d9e1eb3c79 (diff)
downloadATRI-de0426304d77ae9cbb9ffccac142176b0f1900de.tar.gz
ATRI-de0426304d77ae9cbb9ffccac142176b0f1900de.tar.bz2
ATRI-de0426304d77ae9cbb9ffccac142176b0f1900de.zip
[Update]
-rw-r--r--ATRI/plugins/plugin_admin/__init__.py191
-rw-r--r--ATRI/plugins/plugin_anime/__init__.py2
-rw-r--r--ATRI/plugins/plugin_chat/__init__.py80
-rw-r--r--ATRI/plugins/plugin_sqlite/__init__.py146
-rw-r--r--ATRI/plugins/plugin_test/__init__.py11
5 files changed, 309 insertions, 121 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")
diff --git a/ATRI/plugins/plugin_anime/__init__.py b/ATRI/plugins/plugin_anime/__init__.py
index f267aeb..ffe2be2 100644
--- a/ATRI/plugins/plugin_anime/__init__.py
+++ b/ATRI/plugins/plugin_anime/__init__.py
@@ -274,7 +274,7 @@ async def _(bot: Bot, event: Event, state: dict) -> None:
if msg:
pass
else:
- msg0 = "-==Setu Type Control System==-\n"
+ msg0 = "-==ATRI Setu Type Control System==-\n"
msg0 += "**Tips: For SUPERUSERS**\n"
msg0 += "┌Usage: setu-type {type}\n"
msg0 += "└Type:\n"
diff --git a/ATRI/plugins/plugin_chat/__init__.py b/ATRI/plugins/plugin_chat/__init__.py
index 8f4fd32..d30bd2e 100644
--- a/ATRI/plugins/plugin_chat/__init__.py
+++ b/ATRI/plugins/plugin_chat/__init__.py
@@ -10,16 +10,20 @@
'''
__author__ = 'kyomotoi'
+import json
+from pathlib import Path
from random import choice
from nonebot.log import logger
-from nonebot.permission import GROUP_ADMIN, GROUP_OWNER, SUPERUSER
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event
from nonebot.plugin import on_command, on_message, on_notice
+from utils.utils_times import countX
+from utils.utils_error import errorRepo
from utils.utils_banList import banList
from utils.utils_history import saveMessage
+from utils.utils_request import request_api_text
# 收集 bot 所在群的聊天记录
@@ -95,13 +99,12 @@ poke = on_notice(poke_, block=True)
poke.handle()(_poke)
-# 处理进 / 退 裙事件
+# 处理 进 / 退 群事件
groupEvent = on_notice()
@groupEvent.handle() # type: ignore
async def _(bot: Bot, event: Event, state: dict) -> None:
group = str(event.group_id)
- print(event.raw_event)
if banList(group):
if event.raw_event["notice_type"] == "group_increase":
@@ -112,4 +115,73 @@ async def _(bot: Bot, event: Event, state: dict) -> None:
await groupEvent.finish(f'[{event.raw_event["operator_id"]}] 离开了我们...')
-# 舆情监听系统 \ No newline at end of file
+# 舆情监听系统
+listenPublicOpinion = on_message()
+file_PO = Path('.') / 'ATRI' / 'plugins' / 'plugin_chat' / 'public_opinion.json'
+
[email protected]() # type: ignore
+async def _(bot: Bot, event: Event, state: dict) -> None:
+ with open(file_PO, 'r') as f:
+ data = json.load(f)
+
+
+# 口臭一下
+fxxkMe = on_command('口臭一下', aliases={'口臭', '骂我'}, rule=to_me())
+list_M = []
+
[email protected]() # type: ignore
+async def _(bot: Bot, event: Event, state: dict) -> None:
+ user = str(event.user_id)
+ group = str(event.group_id)
+ global list_M
+
+ if banList(user, group):
+ if countX(list_M, user) >= 3:
+ await fxxkMe.finish("不是??你这么想被咱骂的嘛??被咱骂就这么舒服的吗?!该......你该不会是.....M吧!")
+
+ elif countX(list_M, user) >= 6:
+ await fxxkMe.finish("给我适可而止阿!?")
+ list_M = list(set(list_M))
+
+ else:
+ list_M.append(user)
+ URL = "https://nmsl.shadiao.app/api.php?level=min&lang=zh_cn"
+ msg = ""
+
+ try:
+ msg = request_api_text(URL)
+ except:
+ await fxxkMe.finish(errorRepo("请求错误"))
+
+ await fxxkMe.finish(msg)
+
+
+# Hitokoto
+hitokoto = on_command('一言', aliases={'抑郁一下', '网抑云'}, rule=to_me())
+list_Y = []
+
[email protected]() # type: ignore
+async def _(bot: Bot, event: Event, state: dict) -> None:
+ user = str(event.user_id)
+ group = str(event.group_id)
+ global list_Y
+
+ if banList(user, group):
+ if countX(list_Y, user) >= 3:
+ await hitokoto.finish("额......需要咱安慰一下嘛~?")
+
+ elif countX(list_Y, user) >= 6:
+ await hitokoto.finish("如果心里感到难受就赶快去睡觉奥!别再憋自己了!")
+ list_Y = list(set(list_Y))
+
+ else:
+ list_Y.append(user)
+ URL = "https://api.imjad.cn/hitokoto/?cat=a&charset=utf-8&length=50&encode=json&fun=sync&source="
+ info = {}
+
+ try:
+ info = json.loads(request_api_text(URL))
+ except:
+ await hitokoto.finish(errorRepo("请求错误"))
+
+ await hitokoto.finish(info["hitokoto"])
diff --git a/ATRI/plugins/plugin_sqlite/__init__.py b/ATRI/plugins/plugin_sqlite/__init__.py
index 42ea60c..1663026 100644
--- a/ATRI/plugins/plugin_sqlite/__init__.py
+++ b/ATRI/plugins/plugin_sqlite/__init__.py
@@ -22,12 +22,38 @@ from utils.utils_error import errorRepo
from utils.utils_request import aio_get_bytes
-UploadSetu = on_command('setu', permission=SUPERUSER)
+SetuData = on_command('setu', permission=SUPERUSER)
+
[email protected]() # type: ignore
+async def _(bot: Bot, event: Event, state: dict) -> None:
+ msg0 = "-==ATRI Setu Data System==-\n"
+ msg0 += "Upload:\n"
+ msg0 += " - setu [type] [pid]\n"
+ msg0 += " * type: normal, nearR18 r18\n"
+ msg0 += "Delete:\n"
+ msg0 += " - setu-delete [pid]"
+ await SetuData.finish(msg0)
+
+
+UploadSetu = on_command('setu-upload', permission=SUPERUSER)
@UploadSetu.handle() # type: ignore
async def _(bot: Bot, event: Event, state: dict) -> None:
msg = str(event.message).strip().split(' ')
+ if msg[0] and msg[1]:
+ pass
+ else:
+ msg0 = "请检查格式奥~!\n"
+ msg0 += "setu-upload [type] [pid]\n"
+ msg0 += "type: normal, nearR18, r18"
+ await UploadSetu.finish(msg0)
+
+ if msg[0] not in ["noraml", "nearR18", "nearr18", "r18", "R18"]:
+ msg0 = "请检查类型~!\n"
+ msg0 += "type: normal, nearR18, r18"
+ await UploadSetu.finish(msg0)
+
s_type = msg[0]
pid = msg[1]
@@ -42,7 +68,7 @@ async def _(bot: Bot, event: Event, state: dict) -> None:
info = info["response"][0]
title = info["title"]
tags = info["tags"]
- account = info["account"]
+ account = info["user"]["account"]
name = info["user"]["name"]
u_id = info["user"]["id"]
user_link = f'https://www.pixiv.net/users/' + f'{u_id}'
@@ -50,61 +76,71 @@ async def _(bot: Bot, event: Event, state: dict) -> None:
data_setu = (f'{pid}', f'{title}', f'{tags}', f'{account}', f'{name}', f'{u_id}', f'{user_link}', f'{img}')
- if s_type == "normal":
- if os.path.exists('ATRI/data/data_Sqlite/setu/normal.db'):
- print('数据文件存在!')
- else:
- await bot.send(event, '数据库不存在,将开始构建...')
- await bot.send(event, '开始构建数据库!')
- con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'normal.db')
- cur = con.cursor()
- cur.execute('CREATE TABLE normal(pid PID, title TITLE, tags TAGS, account ACCOUNT, name NAME, u_id UID, user_link USERLINK, img IMG, UNIQUE(pid, title, tags, account, name, u_id, user_link, img))')
- con.commit()
- cur.close()
- await bot.send(event, '完成')
-
- con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'normal.db')
- cur = con.cursor()
- cur.execute('INSERT INTO normal(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', data_setu)
- con.commit()
- con.close()
-
- elif s_type == "nearr18":
- if os.path.exists('ATRI/data/data_Sqlite/setu/nearR18.db'):
- print('数据文件存在!')
- else:
- await bot.send(event, '数据库不存在,将开始构建...')
- await bot.send(event, '开始构建数据库!')
- con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'nearR18.db')
- cur = con.cursor()
- cur.execute('CREATE TABLE nearR18(pid PID, title TITLE, tags TAGS, account ACCOUNT, name NAME, u_id UID, user_link USERLINK, img IMG, UNIQUE(pid, title, tags, account, name, u_id, user_link, img))')
- con.commit()
- cur.close()
- await bot.send(event, '完成')
-
- con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'nearR18.db')
+ if s_type == "nearr18":
+ s_type = "nearR18"
+ elif s_type == "R18":
+ s_type = "r18"
+ else:
+ pass
+
+ if os.path.exists(f'ATRI/data/data_Sqlite/setu/{s_type}.db'):
+ print('数据文件存在!')
+ else:
+ await DeleteSetu.finish("数据库都不在添加🔨!?罢了我现创一个")
+ con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / f'{s_type}.db')
cur = con.cursor()
- cur.execute('INSERT INTO nearR18(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', data_setu)
+ cur.execute(f'CREATE TABLE {s_type}(pid PID, title TITLE, tags TAGS, account ACCOUNT, name NAME, u_id UID, user_link USERLINK, img IMG, UNIQUE(pid, title, tags, account, name, u_id, user_link, img))')
con.commit()
- con.close()
+ cur.close()
+ await bot.send(event, '完成')
+
+ con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / f'{s_type}.db')
+ cur = con.cursor()
+ cur.execute(f'INSERT INTO {s_type}(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', data_setu)
+ con.commit()
+ cur.close()
+
+ await UploadSetu.finish(f"数据上传完成~!\n涩图库[{s_type}]涩图 +1")
+
+
+DeleteSetu = on_command('setu-delete', permission=SUPERUSER)
+
[email protected]() # type: ignore
+async def _(bot: Bot, event: Event, state: dict) -> None:
+ msg = str(event.message).strip().split(' ')
- elif s_type == "r18":
- if os.path.exists('ATRI/data/data_Sqlite/setu/r18.db'):
- print('数据文件存在!')
- else:
- await bot.send(event, '数据库不存在,将开始构建...')
- await bot.send(event, '开始构建数据库!')
- con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'r18.db')
- cur = con.cursor()
- cur.execute('CREATE TABLE r18(pid PID, title TITLE, tags TAGS, account ACCOUNT, name NAME, u_id UID, user_link USERLINK, img IMG, UNIQUE(pid, title, tags, account, name, u_id, user_link, img))')
- con.commit()
- cur.close()
- await bot.send(event, '完成')
+ if msg[0] and msg[1]:
+ pass
+ else:
+ msg0 = "请检查格式奥~!\n"
+ msg0 += "setu-delete [type] [pid]\n"
+ msg0 += "type: normal, nearR18, r18"
+ await DeleteSetu.finish(msg0)
+
+ if msg[0] not in ["noraml", "nearR18", "nearr18", "r18", "R18"]:
+ msg0 = "请检查类型~!\n"
+ msg0 += "type: normal, nearR18, r18"
+ await UploadSetu.finish(msg0)
+
+ s_type = msg[0]
+ pid = msg[1]
+
+ if s_type == "nearr18":
+ s_type = "nearR18"
+ elif s_type == "R18":
+ s_type = "r18"
+ else:
+ pass
+
+ if os.path.exists(f'ATRI/data/data_Sqlite/setu/{s_type}.db'):
+ print('数据文件存在!')
+ else:
+ await DeleteSetu.finish("数据库都不在删🔨!?")
- con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'r18.db')
- cur = con.cursor()
- cur.execute('INSERT INTO r18(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', data_setu)
- con.commit()
- con.close()
+ con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / f'{s_type}.db')
+ cur = con.cursor()
+ cur.execute(f'DELETE FROM {s_type} WHERE pid = {pid}')
+ con.commit()
+ con.close()
- await UploadSetu.finish(f"数据上传完成~!\n涩图库[{s_type}]涩图 +1")
+ await UploadSetu.finish(f"数据删除完成~!\n涩图库[{s_type}]涩图 -1")
diff --git a/ATRI/plugins/plugin_test/__init__.py b/ATRI/plugins/plugin_test/__init__.py
index 5a6fe96..8ff0a28 100644
--- a/ATRI/plugins/plugin_test/__init__.py
+++ b/ATRI/plugins/plugin_test/__init__.py
@@ -16,7 +16,7 @@ from pathlib import Path
from random import sample
import nonebot
-from nonebot.plugin import on_command
+from nonebot.plugin import on_command, on_message
from nonebot.permission import SUPERUSER
from nonebot.adapters.cqhttp import Bot, Event
@@ -44,4 +44,11 @@ testBot = on_command('获取bot', permission=SUPERUSER)
@testBot.handle() # type: ignore
async def _(bot: Bot, event: Event, state: dict) -> None:
test_bot = nonebot.get_bots()
- print(test_bot, type(test_bot.keys())) \ No newline at end of file
+ print(test_bot, type(test_bot.keys()))
+
+testPrivate = on_message()
+
[email protected]() # type: ignore
+async def _(bot: Bot, event: Event, state: dict) -> None:
+ if event.user_id == "1172294279":
+ await bot.send(event, "123") \ No newline at end of file