mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-07 04:40:00 +08:00
update 0.0.6.0
This commit is contained in:
+50
-50
@@ -1,19 +1,18 @@
|
||||
from nonebot.adapters.cqhttp.message import Message
|
||||
from utils.utils import get_message_text, is_number
|
||||
from configs.config import PIX_OMEGA_PIXIV_RATIO, WITHDRAW_PIX_TIME
|
||||
from models.omega_pixiv_illusts import OmegaPixivIllusts
|
||||
from configs.config import Config
|
||||
from .model.omega_pixiv_illusts import OmegaPixivIllusts
|
||||
from utils.message_builder import image
|
||||
from utils.manager import withdraw_message_manager
|
||||
from services.log import logger
|
||||
from nonebot.adapters.cqhttp import (
|
||||
Bot,
|
||||
MessageEvent,
|
||||
GroupMessageEvent,
|
||||
PrivateMessageEvent,
|
||||
)
|
||||
from utils.manager import withdraw_message_manager
|
||||
from nonebot.typing import T_State
|
||||
from .data_source import get_image
|
||||
from models.pixiv import Pixiv
|
||||
from .model.pixiv import Pixiv
|
||||
from nonebot import on_command
|
||||
import random
|
||||
|
||||
@@ -55,54 +54,66 @@ __plugin_block_limit__ = {"rst": "您有PIX图片正在处理,请稍等..."}
|
||||
pix = on_command("pix", aliases={"PIX", "Pix"}, priority=5, block=True)
|
||||
|
||||
|
||||
PIX_RATIO = PIX_OMEGA_PIXIV_RATIO[0] / (
|
||||
PIX_OMEGA_PIXIV_RATIO[0] + PIX_OMEGA_PIXIV_RATIO[1]
|
||||
)
|
||||
OMEGA_RATIO = 1 - PIX_RATIO
|
||||
PIX_RATIO = None
|
||||
OMEGA_RATIO = None
|
||||
|
||||
|
||||
@pix.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
global PIX_RATIO, OMEGA_RATIO
|
||||
if PIX_RATIO is None:
|
||||
pix_omega_pixiv_ratio = Config.get_config("pix", "PIX_OMEGA_PIXIV_RATIO")
|
||||
PIX_RATIO = pix_omega_pixiv_ratio[0] / (
|
||||
pix_omega_pixiv_ratio[0] + pix_omega_pixiv_ratio[1]
|
||||
)
|
||||
OMEGA_RATIO = 1 - PIX_RATIO
|
||||
num = 1
|
||||
keyword = get_message_text(event.json())
|
||||
x = keyword.split(" ")
|
||||
if "-s" in x:
|
||||
x.remove("-s")
|
||||
nsfw_tag = 1
|
||||
elif "-r" in x:
|
||||
x.remove("-r")
|
||||
nsfw_tag = 2
|
||||
else:
|
||||
nsfw_tag = 0
|
||||
if nsfw_tag != 0 and str(event.user_id) not in bot.config.superusers:
|
||||
await pix.finish("你不能看这些噢,这些都是是留给管理员看的...")
|
||||
if len(x) > 1:
|
||||
if is_number(x[-1]):
|
||||
num = int(x[-1])
|
||||
if num > 10:
|
||||
if str(event.user_id) not in bot.config.superusers or (
|
||||
str(event.user_id) in bot.config.superusers and num > 30
|
||||
):
|
||||
num = random.randint(1, 10)
|
||||
await pix.send(f"太贪心了,就给你发 {num}张 好了")
|
||||
x = x[:-1]
|
||||
keyword = " ".join(x)
|
||||
pix_num = int(num * PIX_RATIO) + 15 if PIX_RATIO != 0 else 0
|
||||
omega_num = num - pix_num + 15
|
||||
if is_number(keyword):
|
||||
all_image = await Pixiv.query_images(uid=int(keyword))
|
||||
if num == 1:
|
||||
pix_num = 15
|
||||
omega_num = 15
|
||||
all_image = await Pixiv.query_images(
|
||||
uid=int(keyword), num=pix_num, r18=1 if nsfw_tag == 2 else 0
|
||||
) + await OmegaPixivIllusts.query_images(
|
||||
uid=int(keyword), num=omega_num, nsfw_tag=nsfw_tag
|
||||
)
|
||||
elif keyword.lower().startswith("pid"):
|
||||
pid = keyword.replace("pid", "").replace(":", "")
|
||||
pid = keyword.replace("pid", "").replace(":", "").replace(":", "")
|
||||
if not is_number(pid):
|
||||
await pix.finish("PID必须是数字...", at_sender=True)
|
||||
isr18 = 0 if isinstance(event, GroupMessageEvent) else 2
|
||||
nsfw_tag = 0 if isinstance(event, GroupMessageEvent) else None
|
||||
all_image = await Pixiv.query_images(pid=int(pid), r18=isr18)
|
||||
all_image = await Pixiv.query_images(
|
||||
pid=int(pid), r18=1 if nsfw_tag == 2 else 0
|
||||
)
|
||||
if not all_image:
|
||||
all_image = await OmegaPixivIllusts.query_images(
|
||||
pid=int(pid), nsfw_tag=nsfw_tag
|
||||
)
|
||||
else:
|
||||
x = keyword.split()
|
||||
if "-s" in x:
|
||||
x.remove("-s")
|
||||
nsfw_tag = 1
|
||||
elif "-r" in x:
|
||||
x.remove("-r")
|
||||
nsfw_tag = 2
|
||||
else:
|
||||
nsfw_tag = 0
|
||||
if nsfw_tag != 0 and str(event.user_id) not in bot.config.superusers:
|
||||
await pix.finish("你不能看这些噢,这些都是是留给管理员看的...")
|
||||
if len(x) > 1:
|
||||
if is_number(x[-1]):
|
||||
num = int(x[-1])
|
||||
if num > 10:
|
||||
if str(event.user_id) not in bot.config.superusers or (
|
||||
str(event.user_id) in bot.config.superusers and num > 30
|
||||
):
|
||||
num = random.randint(1, 10)
|
||||
await pix.send(f"太贪心了,就给你发 {num}张 好了")
|
||||
x = x[:-1]
|
||||
keyword = " ".join(x)
|
||||
pix_num = int(num * PIX_RATIO) + 15 if PIX_RATIO != 0 else 0
|
||||
omega_num = num - pix_num + 15
|
||||
tmp = await Pixiv.query_images(
|
||||
x, r18=1 if nsfw_tag == 2 else 0, num=pix_num
|
||||
) + await OmegaPixivIllusts.query_images(x, nsfw_tag=nsfw_tag, num=omega_num)
|
||||
@@ -124,14 +135,12 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
if isinstance(img, OmegaPixivIllusts):
|
||||
img_url = img.url
|
||||
author = img.uname
|
||||
print(img.nsfw_tag)
|
||||
elif isinstance(img, Pixiv):
|
||||
img_url = img.img_url
|
||||
author = img.author
|
||||
pid = img.pid
|
||||
title = img.title
|
||||
uid = img.uid
|
||||
# tags = img.tags
|
||||
_img = await get_image(img_url, event.user_id)
|
||||
if _img:
|
||||
msg_id = await pix.send(
|
||||
@@ -152,14 +161,5 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||
f" 查看PIX图库PID: {pid},下载图片出错"
|
||||
)
|
||||
withdraw_message(event, msg_id["message_id"])
|
||||
withdraw_message_manager.withdraw_message(event, msg_id, Config.get_config("pix", "WITHDRAW_PIX_MESSAGE"))
|
||||
|
||||
|
||||
def withdraw_message(event: MessageEvent, id_: int):
|
||||
if WITHDRAW_PIX_TIME[0]:
|
||||
if (
|
||||
(WITHDRAW_PIX_TIME[1] == 0 and isinstance(event, PrivateMessageEvent))
|
||||
or (WITHDRAW_PIX_TIME[1] == 1 and isinstance(event, GroupMessageEvent))
|
||||
or WITHDRAW_PIX_TIME[1] == 2
|
||||
):
|
||||
withdraw_message_manager.append((id_, WITHDRAW_PIX_TIME[0]))
|
||||
|
||||
Reference in New Issue
Block a user