summaryrefslogtreecommitdiff
path: root/ATRI/plugins/setu/data_source.py
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI/plugins/setu/data_source.py')
-rw-r--r--ATRI/plugins/setu/data_source.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/ATRI/plugins/setu/data_source.py b/ATRI/plugins/setu/data_source.py
index d8ad00e..0b8ae50 100644
--- a/ATRI/plugins/setu/data_source.py
+++ b/ATRI/plugins/setu/data_source.py
@@ -1,5 +1,6 @@
+import asyncio
from random import choice
-from nonebot.adapters.onebot.v11 import MessageSegment
+from nonebot.adapters.onebot.v11 import Bot, MessageSegment
from ATRI.service import Service
from ATRI.rule import is_in_service
@@ -17,9 +18,16 @@ DEFAULT_SETU = (
class Setu(Service):
def __init__(self):
Service.__init__(self, "涩图", "hso!", rule=is_in_service("涩图"))
-
+
@staticmethod
- async def random_setu() -> tuple:
+ def _use_proxy(url: str) -> str:
+ if ST.reverse_proxy:
+ return url.replace("i.pixiv.cat", ST.reverse_proxy_domain)
+ else:
+ return url
+
+ @classmethod
+ async def random_setu(cls) -> tuple:
"""
随机涩图.
"""
@@ -34,12 +42,12 @@ class Setu(Service):
p_id = data.get("pid", 88124144)
url: str = data["urls"].get("original", "ignore")
- setu = MessageSegment.image(use_proxy(url), timeout=114514)
+ setu = MessageSegment.image(cls._use_proxy(url), timeout=114514)
repo = f"Title: {title}\nPid: {p_id}"
return repo, setu
- @staticmethod
- async def tag_setu(tag: str) -> tuple:
+ @classmethod
+ async def tag_setu(cls, tag: str) -> tuple:
"""
指定tag涩图.
"""
@@ -56,7 +64,7 @@ class Setu(Service):
p_id = data.get("pid", 88124144)
url = data["urls"].get(
"original",
- use_proxy(DEFAULT_SETU),
+ cls._use_proxy(DEFAULT_SETU),
)
setu = MessageSegment.image(url, timeout=114514)
repo = f"Title: {title}\nPid: {p_id}"
@@ -70,8 +78,8 @@ class Setu(Service):
data = await detect_image(url, file_size)
return data
- @staticmethod
- async def scheduler() -> str:
+ @classmethod
+ async def scheduler(cls) -> str:
"""
每隔指定时间随机抽取一个群发送涩图.
格式:
@@ -88,15 +96,13 @@ class Setu(Service):
url = temp_data[0]["urls"].get(
"original",
- use_proxy(DEFAULT_SETU),
+ cls._use_proxy(DEFAULT_SETU),
)
setu = MessageSegment.image(url, timeout=114514)
repo = f"是{tag}哦~❤\n{setu}"
return repo
-
-def use_proxy(url: str) -> str:
- if ST.reverse_proxy:
- return url.replace("i.pixiv.cat", ST.reverse_proxy_domain)
- else:
- return url
+ @staticmethod
+ async def async_recall(bot: Bot, event_id):
+ await asyncio.sleep(30)
+ await bot.delete_msg(message_id=event_id)