Skip to content

Commit

Permalink
feat:suno 作曲
Browse files Browse the repository at this point in the history
  • Loading branch information
fanxuankai committed Jun 3, 2024
1 parent 6341b5c commit 27e2064
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions plugins/suno/suno.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ def on_handle_context(self, e_context: EventContext):
enabled = self.config.get("enabled")
if content.startswith(plugin_prefix) and enabled:
content = content.replace(plugin_prefix, "", 1)
ids = self.request_suno(content.strip())
reply = Reply()
reply.type = ReplyType.TEXT
e_context["reply"] = reply
if ids:
msg = "\n".join(ids)
reply.content = f"正在努力作曲中,请稍后点击链接试听吧!\n{msg}"
else:
try:
ids = self.request_suno(content.strip())
if ids:
msg = "\n".join(ids)
reply.content = f"正在努力作曲中,请稍后点击链接试听吧!\n{msg}"
else:
reply.content = "作曲失败,请稍后重试吧!"
except Exception as e:
logger.error(f"[Suno] error, msg={e}")
reply.content = "作曲失败,请稍后重试吧!"
e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑

Expand All @@ -65,12 +69,14 @@ def request_suno(self, content):
res = res.json()
logger.debug(f"[Suno] res={res}")
ids = []
for clip in res.get("clips"):
ids.append(self.config.get("share_link") + "/" + clip.get("id"))
clips = res.get("clips")
if clips:
for clip in res.get("clips"):
ids.append(self.config.get("share_link") + "/" + clip.get("id"))
return ids
else:
res_json = res.json()
logger.error(f"[Suno] error, status_code={res.status_code}, msg={res_json.get('message')}")
logger.error(f"[Suno] error, status_code={res.status_code}, msg={res_json.get('detail')}")
return []

def get_help_text(self, **kwargs):
Expand Down

0 comments on commit 27e2064

Please sign in to comment.