2021-05-20 19:21:05 +08:00
|
|
|
|
from nonebot import on_command
|
|
|
|
|
|
from nonebot.typing import T_State
|
2021-07-30 21:21:51 +08:00
|
|
|
|
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
|
2021-05-20 19:21:05 +08:00
|
|
|
|
from services.log import logger
|
2021-09-05 02:21:38 +08:00
|
|
|
|
from asyncio.exceptions import TimeoutError
|
2021-07-30 21:21:51 +08:00
|
|
|
|
from utils.message_builder import image
|
2021-09-05 02:21:38 +08:00
|
|
|
|
from configs.path_config import IMAGE_PATH
|
2021-10-03 14:24:07 +08:00
|
|
|
|
from utils.utils import get_local_proxy
|
2021-09-05 02:21:38 +08:00
|
|
|
|
import aiohttp
|
|
|
|
|
|
import aiofiles
|
2021-05-20 19:21:05 +08:00
|
|
|
|
|
2021-10-03 14:24:07 +08:00
|
|
|
|
__zx_plugin_name__ = "coser"
|
|
|
|
|
|
__plugin_usage__ = """
|
|
|
|
|
|
usage:
|
|
|
|
|
|
三次元也不戳,嘿嘿嘿
|
|
|
|
|
|
指令:
|
|
|
|
|
|
cos/coser
|
|
|
|
|
|
""".strip()
|
|
|
|
|
|
__plugin_des__ = "三次元也不戳,嘿嘿嘿"
|
|
|
|
|
|
__plugin_cmd__ = ["cos/coser"]
|
|
|
|
|
|
__plugin_version__ = 0.1
|
|
|
|
|
|
__plugin_author__ = "HibiKier"
|
|
|
|
|
|
__plugin_settings__ = {
|
|
|
|
|
|
"level": 5,
|
|
|
|
|
|
"default_status": True,
|
|
|
|
|
|
"limit_superuser": False,
|
|
|
|
|
|
"cmd": ["cos", "coser", "括丝", "COS", "Cos", "cOS", "coS"],
|
|
|
|
|
|
}
|
2021-05-20 19:21:05 +08:00
|
|
|
|
|
2021-07-30 21:21:51 +08:00
|
|
|
|
coser = on_command(
|
|
|
|
|
|
"cos", aliases={"coser", "括丝", "COS", "Cos", "cOS", "coS"}, priority=5, block=True
|
|
|
|
|
|
)
|
2021-05-20 19:21:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
2021-10-03 14:24:07 +08:00
|
|
|
|
url = "http://ovooa.com/API/cosplay/api.php"
|
2021-05-20 19:21:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@coser.handle()
|
2021-07-30 21:21:51 +08:00
|
|
|
|
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
2021-09-05 02:21:38 +08:00
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
|
|
try:
|
|
|
|
|
|
for _ in range(3):
|
|
|
|
|
|
try:
|
2021-11-04 16:11:50 +08:00
|
|
|
|
async with session.get(url, proxy=get_local_proxy(), timeout=2, verify_ssl=False) as response:
|
2021-10-03 14:24:07 +08:00
|
|
|
|
_url = (await response.json())['text']
|
|
|
|
|
|
async with session.get(
|
|
|
|
|
|
_url, timeout=5, proxy=get_local_proxy(), verify_ssl=False
|
|
|
|
|
|
) as res:
|
2021-09-09 10:47:26 +08:00
|
|
|
|
if res.status == 200:
|
2021-10-03 14:24:07 +08:00
|
|
|
|
async with aiofiles.open(
|
|
|
|
|
|
f"{IMAGE_PATH}/temp/{event.user_id}_coser.jpg", "wb"
|
|
|
|
|
|
) as f:
|
2021-09-05 02:21:38 +08:00
|
|
|
|
await f.write(await res.read())
|
2021-09-09 10:47:26 +08:00
|
|
|
|
logger.info(
|
|
|
|
|
|
f"(USER {event.user_id}, "
|
|
|
|
|
|
f"GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
|
|
|
|
|
f" 发送COSER"
|
|
|
|
|
|
)
|
2021-10-03 14:24:07 +08:00
|
|
|
|
await coser.send(
|
|
|
|
|
|
image(f"{event.user_id}_coser.jpg", "temp")
|
|
|
|
|
|
)
|
2021-09-09 10:47:26 +08:00
|
|
|
|
break
|
2021-10-03 14:24:07 +08:00
|
|
|
|
except (TimeoutError, KeyError):
|
2021-09-05 02:21:38 +08:00
|
|
|
|
pass
|
2021-09-09 10:47:26 +08:00
|
|
|
|
else:
|
2021-10-03 14:24:07 +08:00
|
|
|
|
await coser.send("你cos给我看!")
|
2021-09-05 02:21:38 +08:00
|
|
|
|
except Exception as e:
|
2021-10-03 14:24:07 +08:00
|
|
|
|
await coser.send("发生了预料之外的错误..请稍后再试或联系管理员修复...")
|
|
|
|
|
|
logger.error(f"coser 发送了未知错误 {type(e)}:{e}")
|