Skip to content

Commit

Permalink
adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
MeetWq committed Aug 15, 2024
1 parent 444ae47 commit c914b5f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
4 changes: 4 additions & 0 deletions nonebot_plugin_memes_api/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ class ArgParserMismatch(ArgMismatch):

class ArgModelMismatch(ArgMismatch):
pass


class MemeFeedback(MemeGeneratorException):
pass
18 changes: 3 additions & 15 deletions nonebot_plugin_memes_api/matchers/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
from nonebot_plugin_userinfo import ImageSource, UserInfo, get_user_info

from ..config import memes_config
from ..exception import (
ArgMismatch,
MemeGeneratorException,
TextOrNameNotEnough,
TextOverLength,
)
from ..exception import MemeGeneratorException
from ..manager import meme_manager
from ..recorder import record_meme_generation
from ..request import MemeInfo, generate_meme
Expand Down Expand Up @@ -77,15 +72,8 @@ async def process(
meme_key=meme.key, images=images, texts=texts, args=args
)
await record_meme_generation(session, meme.key)
except TextOverLength:
await matcher.finish("文字长度过长")
except ArgMismatch:
await matcher.finish("参数解析错误")
except TextOrNameNotEnough:
await matcher.finish("文字或名字数量不足")
except MemeGeneratorException:
logger.warning(traceback.format_exc())
await matcher.finish("出错了,请稍后再试")
except MemeGeneratorException as e:
await matcher.finish(e.message)

msg = UniMessage()
if show_info:
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_memes_api/matchers/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,6 @@ def fmt_time(time: datetime) -> str:
)
output = await plot_duration_counts(duration_counts, title)
else:
title = f"{humanized}表情调用统计"
title = f"{humanized}表情调用统计(总调用次数为 {sum(key_counts.values())}"
output = await plot_key_and_duration_counts(key_counts, duration_counts, title)
await UniMessage.image(raw=output).send()
5 changes: 4 additions & 1 deletion nonebot_plugin_memes_api/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ArgModelMismatch,
ArgParserMismatch,
ImageNumberMismatch,
MemeFeedback,
MemeGeneratorException,
NoSuchMeme,
OpenImageFailed,
Expand Down Expand Up @@ -72,7 +73,9 @@ async def send_request(
return resp.text
elif 520 <= status_code < 600:
message = resp.json()["detail"]
if status_code == 551:
if 560 <= status_code < 570:
raise MemeFeedback(message)
elif status_code == 551:
raise ArgParserMismatch(message)
elif status_code == 552:
raise ArgModelMismatch(message)
Expand Down
16 changes: 8 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot_plugin_memes_api"
version = "0.4.5"
version = "0.4.6"
description = "Nonebot2 plugin for making memes"
authors = ["meetwq <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit c914b5f

Please sign in to comment.