summaryrefslogtreecommitdiff
path: root/ATRI/plugins/setu.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2020-08-11 00:08:59 +0800
committerKyomotoi <[email protected]>2020-08-11 00:08:59 +0800
commit892ae018b1b9ab52f3ee4b751893d70bd81ea777 (patch)
tree70312fbfb92d9569b33d047179ed7ac374c6aaf4 /ATRI/plugins/setu.py
parent97bf675947264bbf1b39e595e8286751616f27c2 (diff)
downloadATRI-892ae018b1b9ab52f3ee4b751893d70bd81ea777.tar.gz
ATRI-892ae018b1b9ab52f3ee4b751893d70bd81ea777.tar.bz2
ATRI-892ae018b1b9ab52f3ee4b751893d70bd81ea777.zip
[Update]
Diffstat (limited to 'ATRI/plugins/setu.py')
-rw-r--r--ATRI/plugins/setu.py83
1 files changed, 62 insertions, 21 deletions
diff --git a/ATRI/plugins/setu.py b/ATRI/plugins/setu.py
index b178fef..8c2f29e 100644
--- a/ATRI/plugins/setu.py
+++ b/ATRI/plugins/setu.py
@@ -1,17 +1,19 @@
# -*- coding:utf-8 -*-
+import os
import time
import json
+from random import choice, randint
+from pathlib import Path
import nonebot
from nonebot import on_command, CommandSession
-from nonebot import NLPSession
-from nonebot.natural_language import NLPResult
-from nonebot.plugin import on_natural_language
+from nonebot import MessageSegment
+import config # type: ignore
from ATRI.modules import response # type: ignore
bot = nonebot.get_bot()
-master = bot.config.SUPERUSERS
+master = config.MASTER()
apikey = bot.config.LOLICONAPI # type: ignore
URL = 'https://api.lolicon.app/setu/'
@@ -20,12 +22,13 @@ SETU_REPLY = """Title: {title}
Pid: {pid}
{setu}
---------------
-完成时间:{time}s"""
+Complete time:{time}s"""
-@on_command('setu', aliases = ['图来', '涩图', '涩图来'], only_to_me = False)
+@on_command('setu', patterns = (r"来[点丶张份副个幅][涩色瑟][图圖]|[涩色瑟][图圖]来|[涩色瑟][图圖][gkd|GKD|搞快点]|[gkd|GKD|搞快点][涩色瑟][图圖]|[图圖]来|[我你她他它]想要[点丶张份副][涩色瑟][图圖]|我想要[1一][张份幅副个只][涩色瑟][图圖]|[我你她他它]想[看|look][涩涩|色色]的东西"), only_to_me = False)
async def setu(session: CommandSession):
- with open('ATRI/plugins/switch/switch.json', 'r') as f:
+ group = session.event.group_id
+ with open(Path('.') / 'ATRI' / 'plugins' / 'switch' / 'switch.json', 'r') as f:
data = json.load(f)
if data["setu"] == 0:
@@ -37,21 +40,59 @@ async def setu(session: CommandSession):
"num": "1"
}
- dc = json.loads(response.request_api_params(URL, values))
- end = time.perf_counter()
+ res = randint(1,10)
+ if 1 <= res <= 9:
+ res = randint(1,4)
+ if 1 <= res <= 3:
+ try:
+ dc = json.loads(response.request_api_params(URL, values))
+ title = dc["data"][0]["title"]
+ pid = dc["data"][0]["pid"]
+ setu = dc["data"][0]["url"] #b64.b64_str_img_url(dc["data"][0]["url"])
+ except:
+ await session.send('失败了失败了失败了失...')
+ return
+
- await session.send(
- SETU_REPLY.format(
- title=dc["data"][0]["title"],
- pid=dc["data"][0]["pid"],
- setu=dc["data"][0]["url"],
- time = round(end - start, 3)
+ res = randint(1,3)
+ if 1 <= res <= 2:
+ end = time.perf_counter()
+ await session.send(
+ SETU_REPLY.format(
+ title = title,
+ pid = pid,
+ setu = dc["data"][0]["url"],
+ time = round(end - start, 3)
+ )
+ )
+
+ elif res == 3:
+ await session.send('我找到涩图了!但我发给主人了ο(=•ω<=)ρ⌒☆')
+ end = time.perf_counter()
+ await bot.send_private_msg( # type: ignore
+ user_id = master,
+ message = f"主人,从群{group}来的涩图!热乎着!\nTitle: {title}\nPid: {pid}\n{setu}\nComplete time: {round(end - start, 3)}"
+ )
+
+ elif res == 4:
+ img = choice(
+ [
+ 'SP.jpg', 'SP1.jpg', 'SP2.jpg'
+ ]
+ )
+ img = Path('.') / 'ATRI' / 'data' / 'emoji' / f'{img}'
+ img = os.path.abspath(img)
+ await session.send(f'[CQ:image,file=file:///{img}]')
+
+
+ elif res == 10:
+ img = choice(
+ [
+ 'GDZ.png', 'SHZY1.jpg', 'SHZY2.jpg', 'SHZY3.jpg', 'SHZY4.jpg', 'SHZY5.jpg', 'SHZY6.jpg'
+ ]
)
- )
+ img = Path('.') / 'ATRI' / 'data' / 'img' / 'niceIMG' / f'{img}'
+ await session.send(f'[CQ:image,file=file:///{img}]')
else:
- await session.send('该功能已被禁用...')
-
-@on_natural_language(['涩图', '色图'], only_to_me = False)
-async def _(session: NLPSession):
- return NLPResult(60.0, ('setu'), None) \ No newline at end of file
+ await session.send('该功能已被禁用...') \ No newline at end of file