summaryrefslogtreecommitdiff
path: root/ATRI
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI')
-rw-r--r--ATRI/__init__.py77
-rw-r--r--ATRI/check.py111
-rw-r--r--ATRI/plugins/plugin_anime/__init__.py30
-rw-r--r--ATRI/plugins/plugin_anime/data_source.py1
-rw-r--r--ATRI/plugins/plugin_anime/sepi_list.json1
-rw-r--r--ATRI/plugins/plugin_chat/__init__.py61
-rw-r--r--ATRI/plugins/plugin_chat/drifting_bottle.json2
-rw-r--r--ATRI/utils/utils_rule/__init__.py46
-rw-r--r--ATRI/utils/utils_rule/ban_list_group.json1
-rw-r--r--ATRI/utils/utils_rule/switch.json2
-rw-r--r--ATRI/utils/utils_textcheck/__init__.py2
11 files changed, 55 insertions, 279 deletions
diff --git a/ATRI/__init__.py b/ATRI/__init__.py
deleted file mode 100644
index c795e29..0000000
--- a/ATRI/__init__.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/env python3
-# -*- encoding: utf-8 -*-
-'''
-@File : __init__.py
-@Time : 2020/11/21 09:53:07
-@Author : Kyomotoi
-@Contact : [email protected]
-@Github : https://github.com/Kyomotoi
-@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
-'''
-__author__ = 'kyomotoi'
-
-from .check import checkATRI
-
-checkATRI().chechConfig()
-checkATRI().checkRely()
-
-import time
-import nonebot
-import datetime
-from pathlib import Path
-from .utils.utils_yml import load_yaml
-from nonebot.log import default_format, logger
-
-COPYRIGHT = (r"""====================[ATRI | アトリ]====================
-* Mirai + NoneBot2 + Python
-* Copyright © 2018-2020 Kyomotoi,All Rights Reserved
-* Project: https://github.com/Kyomotoi/ATRI
-* Blog: blog.lolihub.icu
-=======================================================""")
-print(COPYRIGHT)
-time.sleep(1)
-
-CONFIG_PATH = Path('.') / 'config.yml'
-config = load_yaml(CONFIG_PATH)
-config = config['bot']
-
-LOGGER_INFO_PATH = Path(
- '.'
-) / 'logs' / 'info' / f"{datetime.datetime.now().strftime('%Y%m%d-%H%M%S')}-INFO.log"
-LOGGER_ERROR_PATH = Path(
- '.'
-) / 'logs' / 'error' / f"{datetime.datetime.now().strftime('%Y%m%d-%H%M%S')}-ERROR.log"
-
-_app = None
-
-
-class Service:
- def init(self) -> None:
- global _app
- logger.info('ATRI is initializing...')
- nonebot.init(debug=bool(config['debug']),
- superusers=set(config['superusers']),
- nickname=set(config['nickname']),
- command_start=set(config['command_start']),
- command_sep=set(config['command_sep']))
-
- _app = nonebot.get_asgi()
-
- nonebot.load_plugins('ATRI/plugins')
-
- logger.add(LOGGER_INFO_PATH,
- rotation='10 MB',
- diagnose=False,
- level='INFO',
- format=default_format)
- logger.add(LOGGER_ERROR_PATH,
- rotation='10 MB',
- diagnose=False,
- level='ERROR',
- format=default_format)
-
- def run(self) -> None:
- logger.info("Running ATRI...")
- nonebot.get_driver().run(app='ATRI:_app', # type: ignore
- host=config['host'],
- port=config['port'])
diff --git a/ATRI/check.py b/ATRI/check.py
deleted file mode 100644
index 8be8c5c..0000000
--- a/ATRI/check.py
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/usr/bin/env python3
-# -*- encoding: utf-8 -*-
-'''
-@File : check.py
-@Time : 2020/11/07 14:30:34
-@Author : Kyomotoi
-@Contact : [email protected]
-@Github : https://github.com/Kyomotoi
-@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
-'''
-__author__ = 'kyomotoi'
-
-import os
-import sys
-import time
-import pkg_resources
-
-rely_list = ''.join(f'{rely}' for rely in pkg_resources.working_set)
-need_rely_list = ['pathlib', 'pyyaml', 'rich']
-for rely in need_rely_list:
- if rely not in rely_list:
- os.system(f'pip3 install {rely}')
-
-from pathlib import Path
-from rich.progress import Progress
-from .utils.utils_yml import load_yaml
-
-CONFIG_PATH = Path('.') / 'config.yml'
-config = load_yaml(CONFIG_PATH)
-
-
-class checkATRI():
- """运行前检查必要条件"""
- def chechConfig(self) -> None:
- """检查配置文件是否填写完整"""
- len_config = len(config) + len(config['bot']) + len(
- config['api']) + len(config['html'])
-
- with Progress() as progress:
- task = progress.add_task("[cyan]Checking Config...",
- total=len_config)
-
- while not progress.finished:
- # 检查基本配置
- bot = config['bot']
- for key in bot:
- if key == 'debug':
- if bot['debug'] != 0:
- print('DEBUG now is open.')
- progress.update(task, advance=1)
- time.sleep(0.1)
- else:
- if not bot[key]:
- print(f"Can't load [{key}] from config.yml")
- time.sleep(5)
- sys.exit(0)
-
- else:
- progress.update(task, advance=1)
- time.sleep(0.1)
-
- # 检查接口配置
- api = config['api']
- for key in api:
- if not api[key]:
- print(f"Can't load [{key}] from config.yml")
- time.sleep(5)
- sys.exit(0)
- else:
- progress.update(task, advance=1)
- time.sleep(0.1)
-
- # 检查网页配置
- html = config['html']
- for key in html:
- if not html[key]:
- print(f"Can't load [{key}] from config.yml")
- time.sleep(5)
- sys.exit(0)
- else:
- progress.update(task, advance=1)
- time.sleep(0.1)
-
- def checkRely(self) -> None:
- '''
- 检查依赖是否完整
- 如不完整自动安装
- 别吐槽 暴 力
- '''
- rely_list = [
- 'nonebot2', 'nonebot2[scheduler]', 'nonebot2[test]', 'nltk',
- 'requests', 'pillow', 'psutil'
- ]
- rely_len = len(rely_list)
-
- with Progress() as progress:
- task = progress.add_task("[cyan]Checking Rely...", total=rely_len)
-
- while not progress.finished:
- for rely in rely_list:
- if rely not in rely_list:
- try:
- os.system(f'pip3 install {rely}')
- except:
- print(
- "Can't install package {rely}. Please use Google/Bing search error repo and fix it by yourself."
- )
- time.sleep(5)
- sys.exit(0)
- progress.update(task, advance=1)
- time.sleep(0.1)
diff --git a/ATRI/plugins/plugin_anime/__init__.py b/ATRI/plugins/plugin_anime/__init__.py
index c51e73f..9bed2b7 100644
--- a/ATRI/plugins/plugin_anime/__init__.py
+++ b/ATRI/plugins/plugin_anime/__init__.py
@@ -18,6 +18,7 @@ from random import randint
from datetime import datetime, timedelta
from apscheduler.triggers.date import DateTrigger
+from nonebot.rule import Rule
from nonebot.log import logger
from nonebot.sched import scheduler
from nonebot.typing import Bot, Event
@@ -199,19 +200,20 @@ async def _(bot: Bot, event: Event, state: dict) -> None:
plugin_name_2 = "anime-setu"
key_LoliconAPI = config['api']['LoliconAPI']
-setu_type = 1 # setu-type: 1(local), 2(url: https://api.lolicon.app/#/setu) default: 1(local)
+setu_type = 2 # setu-type: 1(local), 2(url: https://api.lolicon.app/#/setu)
SP_temp_list = []
SP_list = []
-SEPI_PATH = Path('.') / 'ATRI' / 'plugins' / 'plugin_anime' / 'sepi_list.json'
-async def check_sepi(bot: Bot, event: Event, state: dict) -> bool:
+def check_sepi() -> Rule:
"""检查目标是否是涩批"""
- if event.user_id in SP_list:
- await bot.send(event, "你可少冲点吧!涩批!哼唧")
- return False
- else:
- return True
+ async def _check_sepi(bot: Bot, event: Event, state: dict) -> bool:
+ if event.user_id in SP_list:
+ await bot.send(event, "你可少冲点吧!涩批!哼唧")
+ return False
+ else:
+ return True
+ return Rule(_check_sepi)
def add_sepi(user: int) -> None:
"""将目标移入涩批名单"""
@@ -226,7 +228,7 @@ def del_sepi(user: int) -> None:
setu = on_regex(
r"来[点丶张份副个幅][涩色瑟][图圖]|[涩色瑟][图圖]来|[涩色瑟][图圖][gkd|GKD|搞快点]|[gkd|GKD|搞快点][涩色瑟][图圖]",
- rule=check_banlist() & check_switch(plugin_name_2, False) & check_sepi)
+ rule=check_banlist() & check_switch(plugin_name_2, False) & check_sepi())
@setu.handle()
@@ -235,6 +237,7 @@ async def _(bot: Bot, event: Event, state: dict) -> None:
user = event.user_id
group = event.group_id
res = randint(1, 5)
+ print(1)
if countX(SP_temp_list, user) == 5:
add_sepi(user) # type: ignore
@@ -249,9 +252,12 @@ async def _(bot: Bot, event: Event, state: dict) -> None:
if setu_type == 1:
- con = sqlite3.connect(
- Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' /
- 'nearR18.db')
+ DATA_PATH = Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'nearR18.db'
+
+ if not DATA_PATH.is_file():
+ await setu.finish("数据库...她是空的!!!")
+
+ con = sqlite3.connect(DATA_PATH)
cur = con.cursor()
msg = cur.execute('SELECT * FROM nearR18 ORDER BY RANDOM() limit 1;')
diff --git a/ATRI/plugins/plugin_anime/data_source.py b/ATRI/plugins/plugin_anime/data_source.py
index 21f7d74..a479a0e 100644
--- a/ATRI/plugins/plugin_anime/data_source.py
+++ b/ATRI/plugins/plugin_anime/data_source.py
@@ -47,6 +47,7 @@ def resultRepo(user: str, key: str, img_url: str):
try:
task = SauceNAO(key)
data = task.search(img_url)
+ print(data)
except Exception:
return errorRepo('请求数据失败')
diff --git a/ATRI/plugins/plugin_anime/sepi_list.json b/ATRI/plugins/plugin_anime/sepi_list.json
index 9e26dfe..e69de29 100644
--- a/ATRI/plugins/plugin_anime/sepi_list.json
+++ b/ATRI/plugins/plugin_anime/sepi_list.json
@@ -1 +0,0 @@
-{} \ No newline at end of file
diff --git a/ATRI/plugins/plugin_chat/__init__.py b/ATRI/plugins/plugin_chat/__init__.py
index d2c3250..83afc62 100644
--- a/ATRI/plugins/plugin_chat/__init__.py
+++ b/ATRI/plugins/plugin_chat/__init__.py
@@ -82,7 +82,7 @@ async def _poke(bot: Bot, event: Event, state: dict) -> None:
msg = choice([
"你再戳!", "?再戳试试?", "别戳了别戳了再戳就坏了555", "我爪巴爪巴,球球别再戳了", "你戳你🐎呢?!",
"那...那里...那里不能戳...绝对...", "(。´・ω・)ん?", "有事恁叫我,别天天一个劲戳戳戳!", "欸很烦欸!你戳🔨呢",
- "?"
+ "?", "差不多得了😅", "欺负咱这好吗?这不好", "我希望你耗子尾汁"
])
await pokehah.finish(msg)
@@ -273,21 +273,21 @@ async def _(bot: Bot, event: Event, state: dict) -> None:
await hitokoto.finish(info["hitokoto"])
-# laughFunny = on_command('来句笑话', rule=check_banlist())
+laughFunny = on_command('来句笑话', rule=check_banlist())
-# @laughFunny.handle() #type: ignore
-# async def _(bot: Bot, event: Event, state: dict) -> None:
-# name = event.sender['nickname']
-# result = []
[email protected]() #type: ignore
+async def _(bot: Bot, event: Event, state: dict) -> None:
+ name = event.sender['nickname']
+ result = []
-# LAUGH_FILE = Path('.') / 'ATRI' / 'plugins' / 'plugin_chat' / 'laugh.txt'
+ LAUGH_FILE = Path('.') / 'ATRI' / 'plugins' / 'plugin_chat' / 'laugh.txt'
-# with open(LAUGH_FILE, 'r', encoding='utf-8') as f:
-# for line in f:
-# result.append(line.strip('\n'))
+ with open(LAUGH_FILE, 'r', encoding='utf-8') as f:
+ for line in f:
+ result.append(line.strip('\n'))
-# resu = choice(result)
-# print(resu%name)
+ resu = choice(result)
+ await laughFunny.finish(resu.replace("%name", name))
# 扔漂流瓶
plugin_name = 'drifting-bottle'
@@ -405,29 +405,30 @@ async def _(bot: Bot, event: Event, state: dict) -> None:
# 舆情监听
-#publicOpinion = on_message(rule=check_banlist(True))
-#ban_temp_list = []
+publicOpinion = on_message(rule=check_banlist())
+ban_temp_list = []
-#@publicOpinion.handle()
-#async def _(bot: Bot, event: Event, state: dict) -> None:
- #global ban_temp_list
- #msg = str(event.message)
- #user = str(event.user_id)
+async def _(bot: Bot, event: Event, state: dict) -> None:
+ global ban_temp_list
+ msg = str(event.message)
+ user = str(event.user_id)
# 检查是否满足条件
- #if countX(ban_temp_list,
- #user) == Textcheck().get_times(str(Textcheck().check(msg))):
- #ban_temp_list = list(set(ban_temp_list))
- #ban(user)
+ if countX(ban_temp_list,
+ user) == Textcheck().get_times(str(Textcheck().check(msg))):
+ ban_temp_list = list(set(ban_temp_list))
+ ban(user)
+ await publicOpinion.finish(Textcheck().check(msg))
- #if Textcheck().check(msg) == "False":
- #return
+ if Textcheck().check(msg) == "False":
+ return
- #if Textcheck().check(msg):
- #if user in master:
- #await publicOpinion.finish("主人你给我注意点阿?!你这可是在死亡边缘试探呢!!")
+ if Textcheck().check(msg):
+ if user in master:
+ await publicOpinion.finish("主人你给我注意点阿?!你这可是在死亡边缘试探呢!!")
- #ban_temp_list.append(int(user))
+ ban_temp_list.append(int(user))
- #await publicOpinion.finish(Textcheck().check(msg))
+ await publicOpinion.finish(Textcheck().check(msg))
diff --git a/ATRI/plugins/plugin_chat/drifting_bottle.json b/ATRI/plugins/plugin_chat/drifting_bottle.json
index 9e26dfe..8a57a22 100644
--- a/ATRI/plugins/plugin_chat/drifting_bottle.json
+++ b/ATRI/plugins/plugin_chat/drifting_bottle.json
@@ -1 +1 @@
-{} \ No newline at end of file
+{"1": [1172294279, 516729280, "\u6ca1\u5565\uff0c\u9001\u4e00\u5f20\u6da9\u56fe8[CQ:image,file=542e3acdfba13430d61b084fb07a2812.image,url=http://gchat.qpic.cn/gchatpic_new/1172294279/516729280-3085694275-542E3ACDFBA13430D61B084FB07A2812/0?term=2]"]} \ No newline at end of file
diff --git a/ATRI/utils/utils_rule/__init__.py b/ATRI/utils/utils_rule/__init__.py
index dcaeedc..cddf93e 100644
--- a/ATRI/utils/utils_rule/__init__.py
+++ b/ATRI/utils/utils_rule/__init__.py
@@ -13,12 +13,11 @@ __author__ = 'kyomotoi'
import os
import json
from pathlib import Path
-from typing import Optional
from nonebot.rule import Rule
from nonebot.typing import Bot, Event
-def check_banlist(for_group: Optional[bool] = False) -> Rule:
+def check_banlist() -> Rule:
'''
检查目标是否存在于封禁名单
@@ -27,62 +26,21 @@ def check_banlist(for_group: Optional[bool] = False) -> Rule:
async def _chech_banlist(bot: Bot, event: Event, state: dict) -> bool:
# 获取目标信息
user = str(event.user_id)
- group = str(event.group_id)
# 名单目录
BAN_LIST_USER_PATH = Path(
'.') / 'ATRI' / 'utils' / 'utils_rule' / 'ban_list_user.json'
- BAN_LIST_GROUP_PATH = Path(
- '.') / 'ATRI' / 'utils' / 'utils_rule' / 'ban_list_group.json'
# 检查文件是否存在,如不存在,自动创建并写入默认值
if not BAN_LIST_USER_PATH.is_file():
with open(BAN_LIST_USER_PATH, 'w') as f:
f.write(json.dumps({}))
- if not BAN_LIST_GROUP_PATH.is_file():
- with open(BAN_LIST_GROUP_PATH, 'w') as f:
- f.write(json.dumps({}))
-
# 读取文件
with open(BAN_LIST_USER_PATH, 'r') as f:
data_user = json.load(f)
- with open(BAN_LIST_GROUP_PATH, 'r') as f:
- data_group = json.load(f)
-
- # 判断目标
- if not for_group:
- if user:
- if user not in data_user:
- if group:
- if group not in data_group:
- return True
- else:
- return False
- else:
- return True
- else:
- return False
-
- elif group:
- if group not in data_group:
- if user:
- if user not in data_user:
- return True
- else:
- return False
- else:
- return True
- else:
- return False
- else:
- return False
- else:
- if group not in data_group:
- return True
- else:
- return False
+ return user not in data_user
return Rule(_chech_banlist)
diff --git a/ATRI/utils/utils_rule/ban_list_group.json b/ATRI/utils/utils_rule/ban_list_group.json
deleted file mode 100644
index 9e26dfe..0000000
--- a/ATRI/utils/utils_rule/ban_list_group.json
+++ /dev/null
@@ -1 +0,0 @@
-{} \ No newline at end of file
diff --git a/ATRI/utils/utils_rule/switch.json b/ATRI/utils/utils_rule/switch.json
index 1717be3..d7ac35e 100644
--- a/ATRI/utils/utils_rule/switch.json
+++ b/ATRI/utils/utils_rule/switch.json
@@ -1 +1 @@
-{"anime-setu": "False", "anime-pic-search": "True", "anime-vid-search": "True", "all-off-anime-setu": "True", "pixiv-pic-search": "True", "pixiv-author-search": "True", "pixiv-rank": "True", "one-key-adult": "True", "genshin-search": "True", "drifting-bottle": "True"} \ No newline at end of file
+{"anime-setu": "True", "anime-pic-search": "True", "anime-vid-search": "True", "all-off-anime-setu": "True", "pixiv-pic-search": "True", "pixiv-author-search": "True", "pixiv-rank": "True", "one-key-adult": "True", "genshin-search": "True", "drifting-bottle": "True"} \ No newline at end of file
diff --git a/ATRI/utils/utils_textcheck/__init__.py b/ATRI/utils/utils_textcheck/__init__.py
index 531bf69..be1553e 100644
--- a/ATRI/utils/utils_textcheck/__init__.py
+++ b/ATRI/utils/utils_textcheck/__init__.py
@@ -55,6 +55,6 @@ class Textcheck:
def get_times(self, word: str) -> Optional[int]:
if word not in self.data:
- return 0
+ return 11451406000721114514
else:
return self.data[word][1]