From 9aecb24ec725a183db6f27aca58c2e0e818274ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 27 May 2023 18:19:24 +0800 Subject: [PATCH] upd --- locales/zh_cn.json | 2 ++ modules/hitokoto/__init__.py | 2 +- modules/maimai/__init__.py | 27 +++++++++++++++++---------- modules/maimai/locales/zh_cn.json | 4 ++-- modules/random/__init__.py | 4 ++-- modules/random/locales/en_us.json | 2 -- modules/random/locales/zh_cn.json | 2 -- modules/random/locales/zh_tw.json | 2 -- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/locales/zh_cn.json b/locales/zh_cn.json index 3d40ab3f..6141b213 100644 --- a/locales/zh_cn.json +++ b/locales/zh_cn.json @@ -15,6 +15,8 @@ "error.message.paused": "群消息发送被服务器拦截,已暂停群消息发送,使用“${prefix}resume”恢复推送。", "error.module.helpdoc.invalid": "${module} 模块的帮助信息有误,请联系开发者处理。", "error.module.unbound": "模块 ${module} 未绑定任何命令且无简介,请联系开发者处理。", + "error.range.notnumber": "发生错误:无效的数字区间。", + "error.range.invalid": "发生错误:最小值不能大于最大值。", "error.prompt": "发生错误:${error_msg}\n错误汇报地址:", "error.prompt.noreport": "执行命令时发生错误:\n${err_msg}\n此问题并非机器人程序错误(API 请求出错等),请勿将此消息报告给机器人开发者。", "error.prompt.report": "执行命令时发生错误,请报告机器人开发者:\n${err_msg}\n错误汇报地址:", diff --git a/modules/hitokoto/__init__.py b/modules/hitokoto/__init__.py index 74bafe3e..ff403d56 100644 --- a/modules/hitokoto/__init__.py +++ b/modules/hitokoto/__init__.py @@ -17,7 +17,7 @@ async def _(msg: Bot.MessageSession): except AttributeError: set_type = None url = 'https://v1.hitokoto.cn/?' - if set_type is not None: + if not set_type: if set_type not in hitokoto_types: await msg.finish(msg.locale.t('hitokoto.message.error.type')) else: diff --git a/modules/maimai/__init__.py b/modules/maimai/__init__.py index ce2629c9..343dd82a 100644 --- a/modules/maimai/__init__.py +++ b/modules/maimai/__init__.py @@ -39,21 +39,28 @@ mai = module('maimai', developers=['mai-bot', 'OasisAkari'], alias=['mai'], @mai.handle('inner [] {{maimai.help.inner}}') async def _(msg: Bot.MessageSession): - if '' not in msg.parsed_msg: - result_set = await inner_level_q(float(msg.parsed_msg[''])) + try: + rating = float(msg.parsed_msg['']) + try: + rating_max = float(msg.parsed_msg.get('')) + except AttributeError: + rating_max = None + except ValueError: + return await msg.finish(msg.locale.t('error.range.notnumber')) + if rating > rating_max: + return await msg.finish(msg.locale.t('error.range.invalid')) + if not rating_max: + result_set = await inner_level_q(rating) + s = msg.locale.t("maimai.message.inner", rating=round(rating, 1)) + "\n" else: - result_set = await inner_level_q(float(msg.parsed_msg['']), float(msg.parsed_msg[''])) - s = "" + result_set = await inner_level_q(rating, rating_max) + s = msg.locale.t("maimai.message.inner.range", rating=round(rating, 1), rating_max=round(rating_max, 1)) + "\n" for elem in result_set: s += f"{elem[0]}. {elem[1]} {elem[3]} {elem[4]}({elem[2]})\n" if len(result_set) > 150: return await msg.finish(msg.locale.t("maimai.message.too_much", length=len(result_set))) - elif len(result_set) > 50: - img = text_to_image(s) - if img: - await msg.finish([BImage(img)]) - else: - await msg.finish(s.strip()) + img = text_to_image(s) + await msg.finish([BImage(img)]) diff --git a/modules/maimai/locales/zh_cn.json b/modules/maimai/locales/zh_cn.json index 0ee3e4c8..2db538c5 100644 --- a/modules/maimai/locales/zh_cn.json +++ b/modules/maimai/locales/zh_cn.json @@ -11,6 +11,6 @@ "maimai.message.forbidden": "此用户禁止了其他人获取数据。", "maimai.message.chart_not_found": "未找到该谱面。", "maimai.message.b50.waiting": "加载时间较长,请稍等……", - "maimai.message.inline": "以下为定数 ${rating} 的曲目列表:", - "maimai.message.inline.range": "以下为定数 ${rating}-${rating_max} 的曲目列表:" + "maimai.message.inner": "以下为定数 ${rating} 的曲目列表:", + "maimai.message.inner.range": "以下为定数 ${rating}-${rating_max} 的曲目列表:" } \ No newline at end of file diff --git a/modules/random/__init__.py b/modules/random/__init__.py index d176c77e..c08b6a02 100644 --- a/modules/random/__init__.py +++ b/modules/random/__init__.py @@ -15,9 +15,9 @@ async def _(msg: Bot.MessageSession): _min = int(msg.parsed_msg['']) _max = int(msg.parsed_msg['']) except ValueError: - return await msg.finish(msg.locale.t('random.message.number.error.invalid')) + return await msg.finish(msg.locale.t('error.range.notnumber')) if _min > _max: - return await msg.finish(msg.locale.t('random.message.number.error.out_of_range')) + return await msg.finish(msg.locale.t('error.range.invalid')) random = secrets.randbelow(_max - _min + 1) + _min await msg.finish('' + str(random)) diff --git a/modules/random/locales/en_us.json b/modules/random/locales/en_us.json index dcee24ad..3a09355b 100644 --- a/modules/random/locales/en_us.json +++ b/modules/random/locales/en_us.json @@ -9,7 +9,5 @@ "random.help.shuffle": "Shuffle the order of a given set.", "random.help.string": "生成随机字符串,默认为字母和数字组合。", "random.help.uuid": "Generate random UUID (v4).", - "random.message.number.error.invalid": "发生错误:无效的数字区间。", - "random.message.number.error.out_of_range": "发生错误:最小值大于最大值。", "random.message.string.error.invalid": "发生错误:长度必须为小于 100 的正整数。" } \ No newline at end of file diff --git a/modules/random/locales/zh_cn.json b/modules/random/locales/zh_cn.json index 764c7085..f5fcff5b 100644 --- a/modules/random/locales/zh_cn.json +++ b/modules/random/locales/zh_cn.json @@ -9,7 +9,5 @@ "random.help.shuffle": "打乱集合的顺序。", "random.help.string": "生成随机字符串,默认为字母和数字组合。", "random.help.uuid": "生成随机 UUID(v4)。", - "random.message.number.error.invalid": "发生错误:无效的数字区间。", - "random.message.number.error.out_of_range": "发生错误:最小值大于最大值。", "random.message.string.error.invalid": "发生错误:长度必须为小于 100 的正整数。" } \ No newline at end of file diff --git a/modules/random/locales/zh_tw.json b/modules/random/locales/zh_tw.json index fd216f45..287a6c29 100644 --- a/modules/random/locales/zh_tw.json +++ b/modules/random/locales/zh_tw.json @@ -9,7 +9,5 @@ "random.help.shuffle": "打亂集合的順序。", "random.help.string": "產生隨機字串,預設為字母或數字組合。", "random.help.uuid": "產生隨機 UUID(v4)。", - "random.message.number.error.invalid": "發生錯誤:無效的數字區間。", - "random.message.number.error.out_of_range": "發生錯誤:最小值大於最大值。", "random.message.string.error.invalid": "發生錯誤:長度必須為小於 100 的正整數。" } \ No newline at end of file