Skip to content
This repository has been archived by the owner on Dec 7, 2024. It is now read-only.

Commit

Permalink
tweak tip
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Dec 18, 2023
1 parent 70535ba commit ddc8e46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion nonebot_plugin_riffusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from . import __main__ as __main__ # noqa: E402
from .config import ConfigModel # noqa: E402

__version__ = "0.1.0"
__version__ = "0.1.0.post1"
__plugin_meta__ = PluginMetadata(
name="Riffusion",
description="你给歌词,AI 作曲",
Expand Down
29 changes: 14 additions & 15 deletions nonebot_plugin_riffusion/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from arclet.alconna import (
Alconna,
Arg,
ArgFlag,
Args,
Arparma,
ArparmaBehavior,
Expand Down Expand Up @@ -57,11 +56,6 @@ async def do():
asyncio.create_task(do())


class ReprStrOutBoundsBehave(OutBoundsBehave):
def __repr__(self) -> str:
return ";".join((x if isinstance(x, str) else str(x)) for x in self.args)


class RiffusionBehavior(ArparmaBehavior):
def operate(self, interface: Arparma):
style: Optional[str] = interface["style"]
Expand All @@ -71,19 +65,19 @@ def operate(self, interface: Arparma):

if style:
if prompt:
raise ReprStrOutBoundsBehave("不能同时指定 预设风格 Prompt 和 自定义 Prompt")
raise OutBoundsBehave("不能同时指定 预设风格 Prompt 和 自定义 Prompt")
if style not in PRESET_PROMPTS_MAP:
raise ReprStrOutBoundsBehave("预设风格不存在")
raise OutBoundsBehave("预设风格不存在")

if lyrics:
if random_lyrics:
raise ReprStrOutBoundsBehave("不能同时 使用随机歌词 和 指定歌词")
raise OutBoundsBehave("不能同时 使用随机歌词 和 指定歌词")
if not ENGLISH_REGEX.match(lyrics):
raise ReprStrOutBoundsBehave("歌词仅支持英文")
raise OutBoundsBehave("歌词仅支持英文")
if len(lyrics.split()) > 25:
raise ReprStrOutBoundsBehave("请将歌词限制在 25 词以内")
raise OutBoundsBehave("请将歌词限制在 25 词以内")
elif not random_lyrics: # and not lyrics
raise ReprStrOutBoundsBehave("请指定歌词,或使用随机歌词")
raise OutBoundsBehave("请指定歌词,或使用随机歌词")


cmd_riffusion = on_alconna(
Expand Down Expand Up @@ -115,10 +109,9 @@ def operate(self, interface: Arparma):
),
Args(
Arg(
"lyrics",
"lyrics?",
value=str,
notice="歌词(仅支持英文)",
flags=[ArgFlag.OPTIONAL],
),
),
meta=CommandMeta(
Expand All @@ -128,11 +121,17 @@ def operate(self, interface: Arparma):
behaviors=[RiffusionBehavior()],
),
aliases={"riff"},
auto_send_output=True,
skip_for_unmatch=False,
use_cmd_start=True,
)


@cmd_riffusion.handle()
async def _(matcher: AlconnaMatcher, parma: Arparma):
if parma.error_info:
await matcher.finish(f"{parma.error_info}\n使用指令 `riffusion -h` 查看帮助")


@cmd_riffusion.handle()
async def _(matcher: AlconnaMatcher, parma: Arparma):
style: Optional[str] = parma["style"]
Expand Down

0 comments on commit ddc8e46

Please sign in to comment.