summaryrefslogtreecommitdiff
path: root/ATRI/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI/plugins')
-rw-r--r--ATRI/plugins/anime-search/__init__.py11
-rw-r--r--ATRI/plugins/call-owner.py11
-rw-r--r--ATRI/plugins/essential.py16
-rw-r--r--ATRI/plugins/nsfw.py12
-rw-r--r--ATRI/plugins/saucenao/__init__.py12
-rw-r--r--ATRI/plugins/saucenao/data_source.py29
6 files changed, 83 insertions, 8 deletions
diff --git a/ATRI/plugins/anime-search/__init__.py b/ATRI/plugins/anime-search/__init__.py
index eb3dc56..9bf76cb 100644
--- a/ATRI/plugins/anime-search/__init__.py
+++ b/ATRI/plugins/anime-search/__init__.py
@@ -30,6 +30,17 @@ anime_search = sv.on_command(
rule=is_in_service('anime')
)
+@anime_search.args_parser # type: ignore
+async def _nsfw(bot: Bot, event: MessageEvent, state: T_State) -> None:
+ msg = str(event.message)
+ if msg == "算了":
+ await anime_search.finish('好吧')
+
+ if not msg:
+ await anime_search.reject('图呢?')
+ else:
+ state['msg'] = msg
+
@anime_search.handle()
async def _anime_search(bot: Bot,
event: MessageEvent,
diff --git a/ATRI/plugins/call-owner.py b/ATRI/plugins/call-owner.py
index 488e5a3..5384fdd 100644
--- a/ATRI/plugins/call-owner.py
+++ b/ATRI/plugins/call-owner.py
@@ -21,6 +21,17 @@ __doc__ = """
repo = sv.on_command(cmd="来杯红茶", docs=__doc__)
[email protected]_parser # type: ignore
+async def _nsfw(bot: Bot, event: MessageEvent, state: T_State) -> None:
+ msg = str(event.message)
+ if msg == "算了":
+ await repo.finish('好吧')
+
+ if not msg:
+ await repo.reject('话呢?')
+ else:
+ state['pic'] = msg
+
@repo.handle()
async def _repo(bot: Bot, event: MessageEvent, state: T_State) -> None:
msg = str(event.message).strip()
diff --git a/ATRI/plugins/essential.py b/ATRI/plugins/essential.py
index c48d540..be0d509 100644
--- a/ATRI/plugins/essential.py
+++ b/ATRI/plugins/essential.py
@@ -89,7 +89,7 @@ async def disconnect(bot) -> None:
@run_preprocessor # type: ignore
-async def _idk(matcher: Matcher,
+async def _check_block(matcher: Matcher,
bot: Bot,
event: MessageEvent,
state: T_State) -> None:
@@ -105,6 +105,7 @@ async def _idk(matcher: Matcher,
if not sv.BlockSystem.auth_group(group):
raise IgnoredException(f'Block group: {group}')
+
@run_preprocessor # type: ignore
async def _store_message(matcher: Matcher,
bot: Bot,
@@ -123,8 +124,8 @@ async def _store_message(matcher: Matcher,
try:
data = json.loads(path.read_bytes())
except:
- data = {}
- data[event.message_id] = {
+ data = dict()
+ data[str(event.message_id)] = {
"date": now_time,
"time": str(time.time()),
"post_type": str(event.post_type),
@@ -146,7 +147,7 @@ async def _store_message(matcher: Matcher,
"role": event.sender.role,
"title": event.sender.title
},
- "to_me": event.to_me
+ "to_me": str(event.to_me)
}
try:
with open(path, 'w', encoding='utf-8') as r:
@@ -160,7 +161,7 @@ async def _store_message(matcher: Matcher,
pass
if sv.BlockSystem.auth_group(group):
- return
+ raise IgnoredException(f'Block group: {group}')
else:
pass
@@ -178,7 +179,7 @@ async def _request_friend_event(bot, event: FriendRequestEvent) -> None:
try:
data = json.loads(path.read_bytes())
except:
- data = {}
+ data = dict()
data[event.flag] = {
"user_id": event.user_id,
"comment": event.comment
@@ -218,7 +219,7 @@ async def _request_group_event(bot, event: GroupRequestEvent) -> None:
try:
data = json.loads(path.read_bytes())
except:
- data = {}
+ data = dict()
data[event.flag] = {
"user_id": event.user_id,
"group_id": event.group_id,
@@ -361,7 +362,6 @@ async def _recall_event(bot: Bot, event: GroupRecallNoticeEvent) -> None:
f"{repo}"
)
- await bot.send(event, "咱看到惹~!")
for superuser in Config.BotSelfConfig.superusers:
await sv.NetworkPost.send_private_msg(
user_id=int(superuser),
diff --git a/ATRI/plugins/nsfw.py b/ATRI/plugins/nsfw.py
index 945edf6..dd3ac46 100644
--- a/ATRI/plugins/nsfw.py
+++ b/ATRI/plugins/nsfw.py
@@ -2,6 +2,7 @@ import re
import json
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent
+from nonebot.adapters.cqhttp.event import MessageEvent
from nonebot.typing import T_State
from ATRI.log import logger as log
@@ -66,6 +67,17 @@ nsfw_reading = sv.on_command(
rule=is_in_service('nsfw')
)
+@nsfw_reading.args_parser # type: ignore
+async def _nsfw(bot: Bot, event: MessageEvent, state: T_State) -> None:
+ msg = str(event.message)
+ if msg == "算了":
+ await nsfw_reading.finish('好吧')
+
+ if not msg:
+ await nsfw_reading.reject('图呢?')
+ else:
+ state['pic'] = msg
+
@nsfw_reading.handle()
async def _nsfw_r(bot: Bot,
event: GroupMessageEvent,
diff --git a/ATRI/plugins/saucenao/__init__.py b/ATRI/plugins/saucenao/__init__.py
new file mode 100644
index 0000000..c36fde1
--- /dev/null
+++ b/ATRI/plugins/saucenao/__init__.py
@@ -0,0 +1,12 @@
+from nonebot.adapters.cqhttp import Bot, MessageEvent
+
+from ATRI.service import Service as sv
+from ATRI.rule import is_in_service
+
+
+__doc__ = """
+以图搜图
+权限组:所有人
+用法:
+ 以图搜图 (pic)
+"""
diff --git a/ATRI/plugins/saucenao/data_source.py b/ATRI/plugins/saucenao/data_source.py
new file mode 100644
index 0000000..636c540
--- /dev/null
+++ b/ATRI/plugins/saucenao/data_source.py
@@ -0,0 +1,29 @@
+from ATRI.utils.request import post_bytes
+
+
+URL = "https://saucenao.com/search.php"
+
+
+class SauceNao:
+ def __init__(self,
+ api_key: str,
+ output_type=2,
+ testmode=0,
+ dbmask=None,
+ dbmaski=32768,
+ db=5,
+ numres=1) -> None:
+ params = dict()
+ params['api_key'] = api_key
+ params['output_type'] = output_type
+ params['testmode'] = testmode
+ params['dbmask'] = dbmask
+ params['dbmaski'] = dbmaski
+ params['db'] = db
+ params['numres'] = numres
+ self.params = params
+
+ async def search(self, url: str):
+ self.params['url'] = url
+ res = await post_bytes(url=URL, params=self.params)
+ return res