Skip to content

Commit

Permalink
give up
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Apr 5, 2024
1 parent 33d8680 commit d9e8704
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
13 changes: 10 additions & 3 deletions nonebot_plugin_multincm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,24 @@ async def cache_song(song: BaseSong, session: Optional[str] = None):


async def send_song(song: BaseSong):
await cache_song(song)

bot = cast(Bot, current_bot.get())
matcher = current_matcher.get()

try:
await matcher.send(await song.to_card_message(int(bot.self_id)))
msg = await song.to_card_message(int(bot.self_id))
except Exception:
logger.exception(f"Generate {song.calling} card failed")
await matcher.finish(f"生成{song.calling}卡片失败,请检查后台输出")

try:
await matcher.send(msg)
except ActionFailed:
logger.warning(f"Send {song.calling} card failed")
logger.opt(exception=True).debug("Stacktrace")
await matcher.send(f"发送卡片失败\n{await song.get_url()}")

await cache_song(song)


async def get_class_from_link_type(type_name: str) -> Type[SongOrPlaylist]:
if type_name not in LINK_TYPES:
Expand Down
17 changes: 14 additions & 3 deletions nonebot_plugin_multincm/card_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,35 @@ class CardDict(TypedDict):
MUSIC_CARD_TEMPLATE: CardDict = json.loads(MUSIC_CARD_TEMPLATE_PATH.read_text("u8"))


def construct_music_card(
async def sign_card(card_json: str) -> str:
# placeholder
return card_json


async def construct_music_card(
*,
uin: int,
desc: str,
jump_url: str,
music_url: str,
preview: str,
title: str,
) -> CardDict:
sign: bool = True,
) -> str:
data = MUSIC_CARD_TEMPLATE.copy()
# ctime = int(time.time())
# config = data["config"]
extra = data["extra"]
meta = data["meta"]["music"]
# config["ctime"] = ctime
extra["uin"] = uin
# meta["ctime"] = ctime
meta["desc"] = desc
meta["jumpUrl"] = jump_url
meta["musicUrl"] = music_url
meta["preview"] = preview
meta["title"] = title
meta["uin"] = uin
data["prompt"] = f"[分享]{title}"
return data
card_json = json.dumps(data)
return await sign_card(card_json) if sign else card_json
2 changes: 1 addition & 1 deletion nonebot_plugin_multincm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ConfigModel(BaseModel):
ncm_upload_folder_name: str = "MultiNCM"
ncm_enable_record: bool = False
ncm_download_locally: bool = False
ncm_use_json_segment: bool = True
ncm_use_json_segment: bool = False

@field_validator("ncm_upload_folder_name")
def validate_upload_folder_name(cls, v: str) -> str: # noqa: N805
Expand Down
16 changes: 7 additions & 9 deletions nonebot_plugin_multincm/providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,13 @@ async def to_card_message(self, uin: int) -> Message:
MessageSegment(
"json",
{
"data": json.dumps(
construct_music_card(
uin=uin,
desc=content,
jump_url=url,
music_url=playable_url,
preview=cover_url,
title=name,
),
"data": await construct_music_card(
uin=uin,
desc=content,
jump_url=url,
music_url=playable_url,
preview=cover_url,
title=name,
),
},
)
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_multincm/res/card_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"config": {
"ctime": 1712281916,
"forward": 1,
"token": "25f70581889bb7ec6a3bbe30df32a438",
"token": "da6b069da1e2982db3e386233f68d76d",
"type": "normal"
},
"extra": {
Expand Down

0 comments on commit d9e8704

Please sign in to comment.