summaryrefslogtreecommitdiff
path: root/ATRI
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI')
-rw-r--r--ATRI/config.py6
-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
-rw-r--r--ATRI/utils/limit.py5
8 files changed, 92 insertions, 10 deletions
diff --git a/ATRI/config.py b/ATRI/config.py
index 07af8f3..cce33aa 100644
--- a/ATRI/config.py
+++ b/ATRI/config.py
@@ -25,6 +25,7 @@ class Config(BaseConfig):
command_sep: set = set(config.get('command_sep', ['.']))
session_expire_timeout: timedelta = timedelta(
config.get('session_expire_timeout', 2))
+ session_exciting_time: int = int(config.get('session_exciting_time', 60))
class NetworkPost:
config: dict = config['NetworkPost']
@@ -45,6 +46,11 @@ class Config(BaseConfig):
passing_rate: float = float(config.get('passing_rate', 0.8))
host: str = config.get('host', '127.0.0.1')
port: int = int(config.get('port', 5000))
+
+ class SauceNAO:
+ config: dict = config['SauceNAO']
+
+ key: str = config.get('key', '')
RUNTIME_CONFIG = {
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
diff --git a/ATRI/utils/limit.py b/ATRI/utils/limit.py
index 06b1f35..778b090 100644
--- a/ATRI/utils/limit.py
+++ b/ATRI/utils/limit.py
@@ -1,7 +1,7 @@
import datetime
from random import choice
-from ATRI.config import config
+from ATRI.config import Config
from ATRI.service import Service as sv
from .list import count_list, del_list_aim
from .apscheduler import scheduler, DateTrigger
@@ -24,6 +24,7 @@ def del_list(user: str) -> None:
global exciting_user
exciting_user = del_list_aim(exciting_user, user)
+
async def is_too_exciting(user: int, group: int,
times: int, repo: bool) -> bool:
global exciting_user
@@ -37,7 +38,7 @@ async def is_too_exciting(user: int, group: int,
else:
if count_list(exciting_user_temp, user) == times:
delta = datetime.timedelta(
- seconds=config["BotSelfConfig"]["session_exciting_time"])
+ seconds=Config.BotSelfConfig.session_exciting_time)
trigger = DateTrigger(
run_date=datetime.datetime.now() + delta)