Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
HibiKier committed Mar 1, 2022
1 parent 53b375b commit 12f5580
Show file tree
Hide file tree
Showing 542 changed files with 173 additions and 152 deletions.
2 changes: 1 addition & 1 deletion __version__
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__: v0.1.4.1
__version__: v0.1.4
11 changes: 11 additions & 0 deletions basic_plugins/hooks/other_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
from nonebot.message import run_preprocessor, IgnoredException
from nonebot.typing import T_State
from ._utils import status_message_manager
from utils.image_utils import text2image
from typing import Dict, Any
from nonebot.adapters.onebot.v11 import (
Bot,
MessageEvent,
PrivateMessageEvent,
GroupMessageEvent,
)
import re


# 为什么AI会自己和自己聊天
Expand Down Expand Up @@ -38,3 +41,11 @@ async def _(matcher: Matcher, bot: Bot, event: MessageEvent, state: T_State):
status_message_manager.delete(event.user_id)
raise IgnoredException("有命令就别说话了")

# @Bot.on_calling_api
# async def handle_api_call(bot: Bot, api: str, data: Dict[str, Any]):
# if api in ["send_msg", "send_group_msg", "send_private_msg"]:
# msg = str(data["message"])
# if (r := re.search("\[\[To_Img\|?(.*?)]]", msg)) or (r := re.search("[[To_Img\|?(.*?)[[")):



14 changes: 2 additions & 12 deletions basic_plugins/hooks/task_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,10 @@ async def handle_api_call(bot: Bot, api: str, data: Dict[str, Any]):
or api == "send_group_msg"
)
and (
(
r := re.search(
"^\[\[_task\|(.*)]]",
data["message"].strip()
if isinstance(data["message"], str)
else str(data["message"]["text"]).strip(),
)
)
(r := re.search("^\[\[_task\|(.*)]]", str(data["message"]["text"]).strip()))
or (
r := re.search(
"^[[_task\|(.*)]]",
data["message"].strip()
if isinstance(data["message"], str)
else str(data["message"]["text"]).strip(),
"^[[_task\|(.*)]]", str(data["message"]["text"]).strip()
)
)
)
Expand Down
58 changes: 0 additions & 58 deletions plugins/c_song/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/draw_card/count_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def check(self, key: int) -> Optional[int]:
# 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
Expand Down
Empty file added plugins/draw_card/rule.py
Empty file.
2 changes: 1 addition & 1 deletion plugins/group_welcome_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
54 changes: 54 additions & 0 deletions plugins/music/__init__.py
Original file line number Diff line number Diff line change
@@ -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}"
)




82 changes: 41 additions & 41 deletions plugins/c_song/music_163.py → plugins/music/music_163.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 5 additions & 6 deletions plugins/one_friend/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,14 +27,14 @@
}

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(
Expand All @@ -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("它", "我")
Expand Down
4 changes: 2 additions & 2 deletions plugins/pix_gallery/_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 12f5580

Please sign in to comment.