2022-07-16 05:31:56 +08:00
|
|
|
|
from typing import Tuple, Any
|
|
|
|
|
|
|
2022-07-29 19:50:21 +08:00
|
|
|
|
from nonebot import on_regex
|
2022-07-16 05:31:56 +08:00
|
|
|
|
from nonebot.params import RegexGroup
|
2023-02-22 17:51:51 +08:00
|
|
|
|
from configs.path_config import TEMP_PATH
|
2022-02-19 18:20:19 +08:00
|
|
|
|
from nonebot.adapters.onebot.v11 import Bot, MessageEvent
|
2023-02-22 17:51:51 +08:00
|
|
|
|
import time
|
|
|
|
|
|
from utils.http_utils import AsyncHttpx
|
2021-07-30 21:21:51 +08:00
|
|
|
|
from utils.message_builder import image
|
2021-11-23 21:44:59 +08:00
|
|
|
|
from services.log import logger
|
2021-11-29 13:09:47 +08:00
|
|
|
|
from utils.manager import withdraw_message_manager
|
|
|
|
|
|
from configs.config import Config
|
2021-05-20 19:21:05 +08:00
|
|
|
|
|
2021-10-03 14:24:07 +08:00
|
|
|
|
__zx_plugin_name__ = "coser"
|
|
|
|
|
|
__plugin_usage__ = """
|
|
|
|
|
|
usage:
|
|
|
|
|
|
三次元也不戳,嘿嘿嘿
|
|
|
|
|
|
指令:
|
2022-07-16 05:31:56 +08:00
|
|
|
|
?N连cos/coser
|
|
|
|
|
|
示例:cos
|
|
|
|
|
|
示例:5连cos (单次请求张数小于9)
|
2021-10-03 14:24:07 +08:00
|
|
|
|
""".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-11-29 13:09:47 +08:00
|
|
|
|
__plugin_configs__ = {
|
|
|
|
|
|
"WITHDRAW_COS_MESSAGE": {
|
|
|
|
|
|
"value": (0, 1),
|
|
|
|
|
|
"help": "自动撤回,参1:延迟撤回色图时间(秒),0 为关闭 | 参2:监控聊天类型,0(私聊) 1(群聊) 2(群聊+私聊)",
|
|
|
|
|
|
"default_value": (0, 1),
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
2021-05-20 19:21:05 +08:00
|
|
|
|
|
2023-02-22 17:51:51 +08:00
|
|
|
|
cos_img_path = TEMP_PATH / "cos"
|
2022-08-21 18:32:24 +08:00
|
|
|
|
coser = on_regex(r"^(\d)?连?(cos|COS|coser|括丝)$", priority=5, block=True)
|
2021-05-20 19:21:05 +08:00
|
|
|
|
|
2022-07-28 16:48:45 +08:00
|
|
|
|
# 纯cos,较慢:https://picture.yinux.workers.dev
|
|
|
|
|
|
# 比较杂,有福利姬,较快:https://api.jrsgslb.cn/cos/url.php?return=img
|
2023-02-22 17:51:51 +08:00
|
|
|
|
url = "https://picture.yinux.workers.dev"
|
2021-05-20 19:21:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@coser.handle()
|
2022-08-21 18:32:24 +08:00
|
|
|
|
async def _(event: MessageEvent, reg_group: Tuple[Any, ...] = RegexGroup()):
|
2022-07-16 05:31:56 +08:00
|
|
|
|
num = reg_group[0] or 1
|
|
|
|
|
|
for _ in range(int(num)):
|
2023-02-22 17:51:51 +08:00
|
|
|
|
path = cos_img_path / f'{int(time.time())}.jpeg'
|
2022-07-16 05:31:56 +08:00
|
|
|
|
try:
|
2023-02-22 17:51:51 +08:00
|
|
|
|
await AsyncHttpx.download_file(url, path)
|
|
|
|
|
|
msg_id = await coser.send(image(path))
|
2022-07-16 05:31:56 +08:00
|
|
|
|
withdraw_message_manager.withdraw_message(
|
|
|
|
|
|
event,
|
|
|
|
|
|
msg_id["message_id"],
|
|
|
|
|
|
Config.get_config("coser", "WITHDRAW_COS_MESSAGE"),
|
|
|
|
|
|
)
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
await coser.send("你cos给我看!")
|
|
|
|
|
|
logger.error(f"coser 发送了未知错误 {type(e)}:{e}")
|