mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-01 17:49:58 +08:00
x
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
from .music_163 import get_song_id, get_song_info
|
||||
from nonebot.adapters.onebot.v11 import Bot, Event, GroupMessageEvent, Message
|
||||
from nonebot.params import CommandArg
|
||||
from nonebot.typing import T_State
|
||||
from services.log import logger
|
||||
from nonebot import on_command
|
||||
|
||||
|
||||
__zx_plugin_name__ = "点歌"
|
||||
__plugin_usage__ = """
|
||||
usage:
|
||||
在线点歌
|
||||
指令:
|
||||
点歌 [歌名]
|
||||
""".strip()
|
||||
__plugin_des__ = "为你点播了一首曾经的歌"
|
||||
__plugin_cmd__ = ["点歌 [歌名]"]
|
||||
__plugin_type__ = ("一些工具",)
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = "HibiKier"
|
||||
__plugin_settings__ = {
|
||||
"level": 5,
|
||||
"default_status": True,
|
||||
"limit_superuser": False,
|
||||
"cmd": ["点歌"],
|
||||
}
|
||||
|
||||
|
||||
music = on_command("点歌", priority=5, block=True)
|
||||
|
||||
|
||||
@music.handle()
|
||||
async def handle_first_receive(state: T_State, arg: Message = CommandArg()):
|
||||
args = arg.extract_plain_text().strip()
|
||||
if args:
|
||||
state["song_name"] = args
|
||||
|
||||
|
||||
@music.got("song_name", prompt="歌名是?")
|
||||
async def _(bot: Bot, event: Event, state: T_State):
|
||||
song = state["song_name"]
|
||||
song_id = await get_song_id(song)
|
||||
if not song_id:
|
||||
await music.finish("没有找到这首歌!", at_sender=True)
|
||||
for _ in range(3):
|
||||
song_content = [{"type": "music", "data": {"type": 163, "id": song_id}}]
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||
f" 点歌 :{song}"
|
||||
)
|
||||
await music.finish(song_content)
|
||||
else:
|
||||
await music.finish("网易云繁忙...")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ class GenshinCountManager(DrawCountManager):
|
||||
# print(self._data)
|
||||
user: GenshinCountManager.UserCount = self._data[key]
|
||||
if user.count - user.five_index == 90:
|
||||
user.five_index = user.count
|
||||
user.five_index = 90
|
||||
return 5
|
||||
if user.count - user.four_index == 10:
|
||||
user.four_index = user.count
|
||||
|
||||
@@ -37,7 +37,7 @@ async def _(event: GroupMessageEvent):
|
||||
img = ""
|
||||
msg = ""
|
||||
if (DATA_PATH / "custom_welcome_msg" / f"{event.group_id}.jpg").exists():
|
||||
img = image(abspath=DATA_PATH / "custom_welcome_msg" / f"{event.group_id}.jpg")
|
||||
img = image(DATA_PATH / "custom_welcome_msg" / f"{event.group_id}.jpg")
|
||||
custom_welcome_msg_json = (
|
||||
DATA_PATH / "custom_welcome_msg" / "custom_welcome_msg.json"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
from .music_163 import get_song_id, get_song_info
|
||||
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, Message
|
||||
from nonebot.params import CommandArg
|
||||
from nonebot.typing import T_State
|
||||
from services.log import logger
|
||||
from nonebot import on_command
|
||||
from utils.message_builder import music
|
||||
|
||||
|
||||
__zx_plugin_name__ = "点歌"
|
||||
__plugin_usage__ = """
|
||||
usage:
|
||||
在线点歌
|
||||
指令:
|
||||
点歌 [歌名]
|
||||
""".strip()
|
||||
__plugin_des__ = "为你点播了一首曾经的歌"
|
||||
__plugin_cmd__ = ["点歌 [歌名]"]
|
||||
__plugin_type__ = ("一些工具",)
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = "HibiKier"
|
||||
__plugin_settings__ = {
|
||||
"level": 5,
|
||||
"default_status": True,
|
||||
"limit_superuser": False,
|
||||
"cmd": ["点歌"],
|
||||
}
|
||||
|
||||
|
||||
music_handler = on_command("点歌", priority=5, block=True)
|
||||
|
||||
|
||||
@music_handler.handle()
|
||||
async def handle_first_receive(state: T_State, arg: Message = CommandArg()):
|
||||
if args := arg.extract_plain_text().strip():
|
||||
state["song_name"] = args
|
||||
|
||||
|
||||
@music_handler.got("song_name", prompt="歌名是?")
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
song = state["song_name"]
|
||||
song_id = await get_song_id(song)
|
||||
if not song_id:
|
||||
await music_handler.finish("没有找到这首歌!", at_sender=True)
|
||||
await music_handler.send(music("163", song_id))
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||
f" 点歌 :{song}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+41
-41
@@ -1,41 +1,41 @@
|
||||
from utils.http_utils import AsyncHttpx
|
||||
import json
|
||||
|
||||
|
||||
headers = {"referer": "http://music.163.com"}
|
||||
cookies = {"appver": "2.0.2"}
|
||||
|
||||
|
||||
async def search_song(song_name: str):
|
||||
"""
|
||||
搜索歌曲
|
||||
:param song_name: 歌名
|
||||
"""
|
||||
r = await AsyncHttpx.post(
|
||||
f"http://music.163.com/api/search/get/",
|
||||
data={"s": song_name, "limit": 1, "type": 1, "offset": 0},
|
||||
)
|
||||
if r.status_code != 200:
|
||||
return None
|
||||
return json.loads(r.text)
|
||||
|
||||
|
||||
async def get_song_id(song_name: str) -> int:
|
||||
""" """
|
||||
r = await search_song(song_name)
|
||||
try:
|
||||
return r["result"]["songs"][0]["id"]
|
||||
except KeyError:
|
||||
return 0
|
||||
|
||||
|
||||
async def get_song_info(songId: int):
|
||||
"""
|
||||
获取歌曲信息
|
||||
"""
|
||||
r = await AsyncHttpx.post(
|
||||
f"http://music.163.com/api/song/detail/?id={songId}&ids=%5B{songId}%5D",
|
||||
)
|
||||
if r.status_code != 200:
|
||||
return None
|
||||
return json.loads(r.text)
|
||||
from utils.http_utils import AsyncHttpx
|
||||
import json
|
||||
|
||||
|
||||
headers = {"referer": "http://music.163.com"}
|
||||
cookies = {"appver": "2.0.2"}
|
||||
|
||||
|
||||
async def search_song(song_name: str):
|
||||
"""
|
||||
搜索歌曲
|
||||
:param song_name: 歌名
|
||||
"""
|
||||
r = await AsyncHttpx.post(
|
||||
f"http://music.163.com/api/search/get/",
|
||||
data={"s": song_name, "limit": 1, "type": 1, "offset": 0},
|
||||
)
|
||||
if r.status_code != 200:
|
||||
return None
|
||||
return json.loads(r.text)
|
||||
|
||||
|
||||
async def get_song_id(song_name: str) -> int:
|
||||
""" """
|
||||
r = await search_song(song_name)
|
||||
try:
|
||||
return r["result"]["songs"][0]["id"]
|
||||
except KeyError:
|
||||
return 0
|
||||
|
||||
|
||||
async def get_song_info(songId: int):
|
||||
"""
|
||||
获取歌曲信息
|
||||
"""
|
||||
r = await AsyncHttpx.post(
|
||||
f"http://music.163.com/api/song/detail/?id={songId}&ids=%5B{songId}%5D",
|
||||
)
|
||||
if r.status_code != 200:
|
||||
return None
|
||||
return json.loads(r.text)
|
||||
@@ -1,9 +1,8 @@
|
||||
from io import BytesIO
|
||||
from random import choice
|
||||
from nonebot import on_regex
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent
|
||||
from utils.utils import get_message_at, get_user_avatar
|
||||
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, Message
|
||||
from utils.utils import get_message_at, get_user_avatar, get_message_text
|
||||
from utils.message_builder import image
|
||||
from utils.image_utils import BuildImage
|
||||
from nonebot.params import RegexGroup
|
||||
@@ -28,14 +27,14 @@ __plugin_settings__ = {
|
||||
}
|
||||
|
||||
one_friend = on_regex(
|
||||
"^我.*?朋友.*?(想问问|说|让我问问|想问|让我问|想知道|让我帮他问问|让我帮他问|让我帮忙问|让我帮忙问问|问)(.*)",
|
||||
"^我.*?朋友.*?[想问问|说|让我问问|想问|让我问|想知道|让我帮他问问|让我帮他问|让我帮忙问|让我帮忙问问|问](.*)",
|
||||
priority=4,
|
||||
block=True,
|
||||
)
|
||||
|
||||
|
||||
@one_friend.handle()
|
||||
async def _(bot: Bot, event: GroupMessageEvent, state: T_State, reg_group: Tuple[Any, ...] = RegexGroup()):
|
||||
async def _(bot: Bot, event: GroupMessageEvent, reg_group: Tuple[Any, ...] = RegexGroup()):
|
||||
qq = get_message_at(event.json())
|
||||
if not qq:
|
||||
qq = choice(
|
||||
@@ -51,7 +50,7 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State, reg_group: Tuple
|
||||
qq = qq[0]
|
||||
at_user = await bot.get_group_member_info(group_id=event.group_id, user_id=qq)
|
||||
user_name = at_user["card"] or at_user["nickname"]
|
||||
msg = reg_group[1]
|
||||
msg = get_message_text(Message(reg_group[0])).strip()
|
||||
if not msg:
|
||||
msg = "都不知道问什么"
|
||||
msg = msg.replace("他", "我").replace("她", "我").replace("它", "我")
|
||||
|
||||
@@ -235,10 +235,10 @@ async def get_image(img_url: str, user_id: int) -> Optional[str]:
|
||||
img_url = old_img_url
|
||||
continue
|
||||
async with aiofiles.open(
|
||||
TEMP_PATH / f"pix_{user_id}_{img_url[-10:-4]}.jpg", "wb"
|
||||
TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg", "wb"
|
||||
) as f:
|
||||
await f.write(response.content)
|
||||
return TEMP_PATH / f"pix_{user_id}_{img_url[-10:-4]}.jpg"
|
||||
return TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg"
|
||||
except TimeoutError:
|
||||
logger.warning(f"PIX:{img_url} 图片下载超时...")
|
||||
pass
|
||||
|
||||
+39
-18
@@ -1,15 +1,10 @@
|
||||
from utils.utils import is_number
|
||||
from configs.config import Config
|
||||
from ._model.omega_pixiv_illusts import OmegaPixivIllusts
|
||||
from utils.message_builder import image
|
||||
from utils.message_builder import image, custom_forward_msg
|
||||
from utils.manager import withdraw_message_manager
|
||||
from services.log import logger
|
||||
from nonebot.adapters.onebot.v11 import (
|
||||
Bot,
|
||||
MessageEvent,
|
||||
GroupMessageEvent,
|
||||
Message
|
||||
)
|
||||
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, Message
|
||||
from nonebot.params import CommandArg
|
||||
from ._data_source import get_image
|
||||
from ._model.pixiv import Pixiv
|
||||
@@ -49,6 +44,13 @@ __plugin_settings__ = {
|
||||
"cmd": ["pix", "Pix", "PIX", "pIx"],
|
||||
}
|
||||
__plugin_block_limit__ = {"rst": "您有PIX图片正在处理,请稍等..."}
|
||||
__plugin_configs__ = {
|
||||
"MAX_ONCE_NUM2FORWARD": {
|
||||
"value": None,
|
||||
"help": "单次发送的图片数量达到指定值时转发为合并消息",
|
||||
"default_value": None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pix = on_command("pix", aliases={"PIX", "Pix"}, priority=5, block=True)
|
||||
@@ -64,12 +66,12 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
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]
|
||||
pix_omega_pixiv_ratio[0] + pix_omega_pixiv_ratio[1]
|
||||
)
|
||||
OMEGA_RATIO = 1 - PIX_RATIO
|
||||
num = 1
|
||||
keyword = arg.extract_plain_text().strip()
|
||||
x = keyword.split(" ")
|
||||
x = keyword.split()
|
||||
if "-s" in x:
|
||||
x.remove("-s")
|
||||
nsfw_tag = 1
|
||||
@@ -80,12 +82,15 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
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 n := len(x) == 1 and is_number(x[0]):
|
||||
num = int(x[-1])
|
||||
keyword = ""
|
||||
elif n > 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
|
||||
str(event.user_id) in bot.config.superusers and num > 30
|
||||
):
|
||||
num = random.randint(1, 10)
|
||||
await pix.send(f"太贪心了,就给你发 {num}张 好了")
|
||||
@@ -125,11 +130,12 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
tmp_.append(x.pid)
|
||||
if not all_image:
|
||||
await pix.finish(f"未在图库中找到与 {keyword} 相关Tag/UID/PID的图片...", at_sender=True)
|
||||
msg_list = []
|
||||
for _ in range(num):
|
||||
img_url = None
|
||||
author = None
|
||||
if not all_image:
|
||||
await pix.finish("坏了...发完了,没图了...")
|
||||
# if not all_image:
|
||||
# await pix.finish("坏了...发完了,没图了...")
|
||||
img = random.choice(all_image)
|
||||
all_image.remove(img)
|
||||
if isinstance(img, OmegaPixivIllusts):
|
||||
@@ -144,7 +150,7 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
_img = await get_image(img_url, event.user_id)
|
||||
if _img:
|
||||
if Config.get_config("pix", "SHOW_INFO"):
|
||||
msg_id = await pix.send(
|
||||
msg_list.append(
|
||||
Message(
|
||||
f"title:{title}\n"
|
||||
f"author:{author}\n"
|
||||
@@ -153,16 +159,31 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
)
|
||||
)
|
||||
else:
|
||||
msg_id = await pix.send(image(_img))
|
||||
msg_list.append(image(_img))
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||
f" 查看PIX图库PID: {pid}"
|
||||
)
|
||||
else:
|
||||
msg_id = await pix.send(f"下载图片似乎出了一点问题,PID:{pid}")
|
||||
msg_list.append("这张图似乎下载失败了")
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||
f" 查看PIX图库PID: {pid},下载图片出错"
|
||||
)
|
||||
withdraw_message_manager.withdraw_message(event, msg_id, Config.get_config("pix", "WITHDRAW_PIX_MESSAGE"))
|
||||
|
||||
if (
|
||||
Config.get_config("pix", "MAX_ONCE_NUM2FORWARD")
|
||||
and num >= Config.get_config("pix", "MAX_ONCE_NUM2FORWARD")
|
||||
and isinstance(event, GroupMessageEvent)
|
||||
):
|
||||
msg_id = await bot.send_group_forward_msg(
|
||||
group_id=event.group_id, messages=custom_forward_msg(msg_list, bot.self_id)
|
||||
)
|
||||
withdraw_message_manager.withdraw_message(
|
||||
event, msg_id, Config.get_config("pix", "WITHDRAW_PIX_MESSAGE")
|
||||
)
|
||||
else:
|
||||
for msg in msg_list:
|
||||
msg_id = await pix.send(msg)
|
||||
withdraw_message_manager.withdraw_message(
|
||||
event, msg_id, Config.get_config("pix", "WITHDRAW_PIX_MESSAGE")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user