1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
import asyncio
from nonebot.adapters.onebot.v11 import Bot, MessageSegment
from ATRI import conf
from ATRI.utils import request
from .nsfw_checker import detect_image, init_model
LOLICON_URL = "https://api.lolicon.app/setu/v2"
DEFAULT_SETU = (
"https://i.pixiv.cat/img-original/img/2021/02/28/22/44/49/88124144_p0.jpg"
)
class Setu:
@staticmethod
def _use_proxy(url: str) -> str:
if conf.Setu.reverse_proxy:
return url.replace("i.pixiv.cat", conf.Setu.reverse_proxy_domain)
else:
return url
@classmethod
async def random_setu(cls) -> tuple:
"""
随机涩图.
"""
res = await request.get(LOLICON_URL)
data: dict = res.json()
temp_data: dict = data.get("data", list())
if not temp_data:
return "涩批爬", None
data: dict = temp_data[0]
title = data.get("title", "木陰のねこ")
p_id = data.get("pid", 88124144)
url: str = data["urls"].get("original", "ignore")
setu = MessageSegment.image(cls._use_proxy(url), timeout=114514)
repo = f"Title: {title}\nPid: {p_id}"
return repo, setu
@classmethod
async def tag_setu(cls, tag: str) -> tuple:
"""
指定tag涩图.
"""
url = LOLICON_URL + f"?tag={tag}"
res = await request.get(url)
data: dict = res.json()
temp_data: dict = data.get("data", list())
if not temp_data:
return f"没有 {tag} 的涩图呢...", None
data = temp_data[0]
title = data.get("title", "木陰のねこ")
p_id = data.get("pid", 88124144)
url = data["urls"].get(
"original",
cls._use_proxy(DEFAULT_SETU),
)
setu = MessageSegment.image(url, timeout=114514)
repo = f"Title: {title}\nPid: {p_id}"
return repo, setu
@staticmethod
async def detecter(url: str, file_size: int) -> float:
"""
涩值检测.
"""
data = await detect_image(url, file_size)
return data
@staticmethod
async def async_recall(bot: Bot, event_id):
await asyncio.sleep(30)
await bot.delete_msg(message_id=event_id)
from ATRI import driver
driver().on_startup(init_model)
|