From a736347826340cdb430dba93a2460a756637af12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 16 Dec 2023 16:01:00 +0800 Subject: [PATCH 01/22] mai alias case insensitive --- modules/maimai/libraries/maimaidx_api_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/maimai/libraries/maimaidx_api_data.py b/modules/maimai/libraries/maimaidx_api_data.py index 21f707b6..3d82bbd4 100644 --- a/modules/maimai/libraries/maimaidx_api_data.py +++ b/modules/maimai/libraries/maimaidx_api_data.py @@ -75,7 +75,7 @@ async def get_alias(msg, sid): async def search_by_alias(msg, input_): result = [] - input_ = input_.replace("_", " ").strip() + input_ = input_.replace("_", " ").strip().lower() res = (await total_list.get()).filter(title=input_) for s in res: result.append(s['id']) @@ -89,7 +89,7 @@ async def search_by_alias(msg, input_): data = json.load(file) for sid, alias in data.items(): - if input_ in alias: + if input_ in alias.lower(): if sid in result: result.remove(sid) result.append(sid) # 此处的列表是歌曲 ID 列表 From ca02e08106b2b8e11fc14d42f1bf7f11e7f12623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 16 Dec 2023 16:03:46 +0800 Subject: [PATCH 02/22] fix --- modules/maimai/libraries/maimaidx_api_data.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/maimai/libraries/maimaidx_api_data.py b/modules/maimai/libraries/maimaidx_api_data.py index 3d82bbd4..55fd41f6 100644 --- a/modules/maimai/libraries/maimaidx_api_data.py +++ b/modules/maimai/libraries/maimaidx_api_data.py @@ -88,8 +88,9 @@ async def search_by_alias(msg, input_): with open(file_path, 'r') as file: data = json.load(file) - for sid, alias in data.items(): - if input_ in alias.lower(): + for sid, aliases in data.items(): + if input_ in aliases: + aliases = [alias.lower() for alias in aliases] if sid in result: result.remove(sid) result.append(sid) # 此处的列表是歌曲 ID 列表 From 423cb2a0a7663dd3805413b7513c888c809f346e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 16 Dec 2023 16:06:01 +0800 Subject: [PATCH 03/22] . --- modules/maimai/libraries/maimaidx_api_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/maimai/libraries/maimaidx_api_data.py b/modules/maimai/libraries/maimaidx_api_data.py index 55fd41f6..3c512f19 100644 --- a/modules/maimai/libraries/maimaidx_api_data.py +++ b/modules/maimai/libraries/maimaidx_api_data.py @@ -89,8 +89,8 @@ async def search_by_alias(msg, input_): data = json.load(file) for sid, aliases in data.items(): + aliases = [alias.lower() for alias in aliases] if input_ in aliases: - aliases = [alias.lower() for alias in aliases] if sid in result: result.remove(sid) result.append(sid) # 此处的列表是歌曲 ID 列表 From 26346effc143803cfec431ad2680a59a68f1ed05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 16 Dec 2023 16:19:02 +0800 Subject: [PATCH 04/22] rename toggle 2 setup --- modules/core/locales/en_us.json | 18 +++++++++--------- modules/core/locales/zh_cn.json | 18 +++++++++--------- modules/core/locales/zh_tw.json | 18 +++++++++--------- modules/core/utils.py | 20 ++++++++++---------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/modules/core/locales/en_us.json b/modules/core/locales/en_us.json index 40e838d3..fb35d06d 100644 --- a/modules/core/locales/en_us.json +++ b/modules/core/locales/en_us.json @@ -30,9 +30,9 @@ "core.help.prefix.list": "View custom command prefixes.", "core.help.prefix.remove": "Remove custom command prefix.", "core.help.prefix.reset": "Reset custom command prefix.", - "core.help.toggle.check": "Toggles whether to display command check prompts.", - "core.help.toggle.typing": "Toggle whether to display input prompts.", - "core.help.toggle.timeoffset": "Set the time offset.", + "core.help.setup.check": "setups whether to display command check prompts.", + "core.help.setup.typing": "setup whether to display input prompts.", + "core.help.setup.timeoffset": "Set the time offset.", "core.help.version": "View bot version.", "core.help.whoami": "Get the ID of the user account that sent the command inside the bot.", "core.message.abuse.ban.success": "Successfully banned ${user}.", @@ -154,12 +154,12 @@ "core.message.set.invalid": "Invalid ID format.", "core.message.set.module.success": "The following modules were successfully configured for the object: ", "core.message.superuser.invalid": "Invalid ID format. The format should be \"${target}|\".", - "core.message.toggle.check.disable": "Check prompt disabled.", - "core.message.toggle.check.enable": "Check prompt enabled.", - "core.message.toggle.timeoffset.invalid": "Invalid time offset.", - "core.message.toggle.timeoffset.success": "The time offset has been set to UTC${offset}.", - "core.message.toggle.typing.disable": "Input prompt disabled.", - "core.message.toggle.typing.enable": "Input prompt enabled.", + "core.message.setup.check.disable": "Check prompt disabled.", + "core.message.setup.check.enable": "Check prompt enabled.", + "core.message.setup.timeoffset.invalid": "Invalid time offset.", + "core.message.setup.timeoffset.success": "The time offset has been set to UTC${offset}.", + "core.message.setup.typing.disable": "Input prompt disabled.", + "core.message.setup.typing.enable": "Input prompt enabled.", "core.message.update.failed": "Failed to fetch update from GitHub. Please try again later.", "core.message.version": "Current bot version: ${commit}", "core.message.version.unknown": "Unable to get version. This instance may not be deployed using Git.", diff --git a/modules/core/locales/zh_cn.json b/modules/core/locales/zh_cn.json index df8dbe12..d9066d00 100644 --- a/modules/core/locales/zh_cn.json +++ b/modules/core/locales/zh_cn.json @@ -30,9 +30,9 @@ "core.help.prefix.list": "查看自定义命令前缀列表。", "core.help.prefix.remove": "移除自定义命令前缀。", "core.help.prefix.reset": "重置自定义命令前缀。", - "core.help.toggle.check": "切换是否展示命令错字检查提示。", - "core.help.toggle.typing": "切换是否展示输入提示。", - "core.help.toggle.timeoffset": "设置时间偏移量。", + "core.help.setup.check": "切换是否展示命令错字检查提示。", + "core.help.setup.typing": "切换是否展示输入提示。", + "core.help.setup.timeoffset": "设置时间偏移量。", "core.help.version": "查看机器人的版本号。", "core.help.whoami": "获取发送命令的账号在机器人内部的 ID。", "core.message.abuse.ban.success": "成功封禁 ${user}。", @@ -154,12 +154,12 @@ "core.message.set.invalid": "ID 格式错误。", "core.message.set.module.success": "成功为对象配置了以下模块:", "core.message.superuser.invalid": "ID 格式错误,格式应为“${target}|<用户 ID>”。", - "core.message.toggle.check.disable": "已关闭错字检查提示。", - "core.message.toggle.check.enable": "已开启错字检查提示。", - "core.message.toggle.timeoffset.invalid": "无效的时间偏移量。", - "core.message.toggle.timeoffset.success": "已将时间偏移量设定为 UTC${offset}。", - "core.message.toggle.typing.disable": "已关闭输入提示。", - "core.message.toggle.typing.enable": "已开启输入提示。", + "core.message.setup.check.disable": "已关闭错字检查提示。", + "core.message.setup.check.enable": "已开启错字检查提示。", + "core.message.setup.timeoffset.invalid": "无效的时间偏移量。", + "core.message.setup.timeoffset.success": "已将时间偏移量设定为 UTC${offset}。", + "core.message.setup.typing.disable": "已关闭输入提示。", + "core.message.setup.typing.enable": "已开启输入提示。", "core.message.update.failed": "尝试从 GitHub 获取更新失败,请稍后重试。", "core.message.version": "当前机器人版本号:${commit}", "core.message.version.unknown": "无法获取版本号。此实例可能没有使用 Git 进行部署。", diff --git a/modules/core/locales/zh_tw.json b/modules/core/locales/zh_tw.json index d8cdda66..0d508f3c 100644 --- a/modules/core/locales/zh_tw.json +++ b/modules/core/locales/zh_tw.json @@ -30,9 +30,9 @@ "core.help.prefix.list": "檢視自訂指令前綴列表。", "core.help.prefix.remove": "移除自訂指令前綴。", "core.help.prefix.reset": "重設自訂指令前綴。", - "core.help.toggle.check": "切換是否顯示指令錯誤檢查提醒。", - "core.help.toggle.typing": "切換是否顯示輸入提醒。", - "core.help.toggle.timeoffset": "設定時間偏移量。", + "core.help.setup.check": "切換是否顯示指令錯誤檢查提醒。", + "core.help.setup.typing": "切換是否顯示輸入提醒。", + "core.help.setup.timeoffset": "設定時間偏移量。", "core.help.version": "檢視機器人的版本號。", "core.help.whoami": "取得傳送指令的帳戶在機器人內部的 ID。", "core.message.abuse.ban.success": "成功封鎖 ${user}。", @@ -154,12 +154,12 @@ "core.message.set.invalid": "ID 格式錯誤。", "core.message.set.module.success": "成功為物件配置了以下模組:", "core.message.superuser.invalid": "ID 格式錯誤,格式應為「${target}|<使用者 ID>」。", - "core.message.toggle.check.disable": "已停用指令錯誤檢查提醒。", - "core.message.toggle.check.enable": "已啟用指令錯誤檢查提醒。", - "core.message.toggle.timeoffset.invalid": "無效的時間偏移量。", - "core.message.toggle.timeoffset.success": "已將時間偏移量設定為 UTC${offset}。", - "core.message.toggle.typing.disable": "已停用輸入提醒。", - "core.message.toggle.typing.enable": "已啟用輸入提醒。", + "core.message.setup.check.disable": "已停用指令錯誤檢查提醒。", + "core.message.setup.check.enable": "已啟用指令錯誤檢查提醒。", + "core.message.setup.timeoffset.invalid": "無效的時間偏移量。", + "core.message.setup.timeoffset.success": "已將時間偏移量設定為 UTC${offset}。", + "core.message.setup.typing.disable": "已停用輸入提醒。", + "core.message.setup.typing.enable": "已啟用輸入提醒。", "core.message.update.failed": "嘗試從 GitHub 取得更新失敗,請稍後重試。", "core.message.version": "目前機器人版本號:${commit}", "core.message.version.unknown": "無法取得版本號。此實例可能沒有使用 Git 進行部署。", diff --git a/modules/core/utils.py b/modules/core/utils.py index e27544d8..e9daf0c1 100644 --- a/modules/core/utils.py +++ b/modules/core/utils.py @@ -171,33 +171,33 @@ async def _(msg: Bot.MessageSession): disable_secret_check=True) -tog = module('toggle', base=True, required_admin=True) +setup = module('setup', base=True, required_admin=True, desc=) -@tog.command('typing {{core.help.toggle.typing}}') +@setup.command('typing {{core.help.setup.typing}}') async def _(msg: Bot.MessageSession): target = BotDBUtil.SenderInfo(msg.target.sender_id) state = target.query.disable_typing if not state: target.edit('disable_typing', True) - await msg.finish(msg.locale.t('core.message.toggle.typing.disable')) + await msg.finish(msg.locale.t('core.message.setup.typing.disable')) else: target.edit('disable_typing', False) - await msg.finish(msg.locale.t('core.message.toggle.typing.enable')) + await msg.finish(msg.locale.t('core.message.setup.typing.enable')) -@tog.command('check {{core.help.toggle.check}}') +@setup.command('check {{core.help.setup.check}}') async def _(msg: Bot.MessageSession): state = msg.options.get('typo_check') if state: msg.data.edit_option('typo_check', False) - await msg.finish(msg.locale.t('core.message.toggle.check.enable')) + await msg.finish(msg.locale.t('core.message.setup.check.enable')) else: msg.data.edit_option('typo_check', True) - await msg.finish(msg.locale.t('core.message.toggle.check.disable')) + await msg.finish(msg.locale.t('core.message.setup.check.disable')) -@tog.command('timeoffset {{core.help.toggle.timeoffset}}') +@setup.command('timeoffset {{core.help.setup.timeoffset}}') async def _(msg: Bot.MessageSession, offset: str): try: tstr_split = [int(part) for part in offset.split(':')] @@ -211,9 +211,9 @@ async def _(msg: Bot.MessageSession, offset: str): if hour > 12 or minute >= 60: raise ValueError except ValueError: - await msg.finish(msg.locale.t('core.message.toggle.timeoffset.invalid')) + await msg.finish(msg.locale.t('core.message.setup.timeoffset.invalid')) msg.data.edit_option('timezone_offset', offset) - await msg.finish(msg.locale.t('core.message.toggle.timeoffset.success', offset=offset)) + await msg.finish(msg.locale.t('core.message.setup.timeoffset.success', offset=offset)) mute = module('mute', base=True, required_admin=True, desc='{core.help.mute}') From 201513f6b121feba7c0a2da40acd669f1c93c865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 16 Dec 2023 16:33:30 +0800 Subject: [PATCH 05/22] fix --- modules/core/locales/en_us.json | 2 +- modules/core/locales/zh_cn.json | 2 +- modules/core/locales/zh_tw.json | 2 +- modules/core/utils.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/core/locales/en_us.json b/modules/core/locales/en_us.json index fb35d06d..486b8b7c 100644 --- a/modules/core/locales/en_us.json +++ b/modules/core/locales/en_us.json @@ -1,5 +1,5 @@ { - "core.help.admin": "Commands available to group administrators.", + "core.help.admin.desc": "Commands available to group administrators.", "core.help.admin.add": "Set members as bot administrators, implement the function of managing the robot without setting members as group administrators. It's no longer needed to set up it when you are already a group administrator.", "core.help.admin.ban": "Limit someone to use bot in the group.", "core.help.admin.list": "View all bot administrators.", diff --git a/modules/core/locales/zh_cn.json b/modules/core/locales/zh_cn.json index d9066d00..ace8cf6b 100644 --- a/modules/core/locales/zh_cn.json +++ b/modules/core/locales/zh_cn.json @@ -1,5 +1,5 @@ { - "core.help.admin": "一些群组管理员可使用的命令。", + "core.help.admin.desc": "一些群组管理员可使用的命令。", "core.help.admin.add": "设置成员为机器人管理员。以实现不设置成员为群组管理员的状況下管理机器人的效果。已是群组管理员无需设置此项目。", "core.help.admin.ban": "限制某人在本群使用机器人。", "core.help.admin.list": "查看所有机器人管理员。", diff --git a/modules/core/locales/zh_tw.json b/modules/core/locales/zh_tw.json index 0d508f3c..d901588e 100644 --- a/modules/core/locales/zh_tw.json +++ b/modules/core/locales/zh_tw.json @@ -1,5 +1,5 @@ { - "core.help.admin": "一些群組管理員可使用的指令。", + "core.help.admin.desc": "一些群組管理員可使用的指令。", "core.help.admin.add": "設定成員為機器人管理員,以實現不設定成員為群組管理員的狀況下管理機器人的效果。已是群組管理員無須設定此指令。", "core.help.admin.ban": "限制某人在此群組使用機器人。", "core.help.admin.list": "檢視所有機器人管理員。", diff --git a/modules/core/utils.py b/modules/core/utils.py index e9daf0c1..5211b316 100644 --- a/modules/core/utils.py +++ b/modules/core/utils.py @@ -70,7 +70,7 @@ async def _(msg: Bot.MessageSession): await msg.finish(result) -admin = module('admin', base=True, required_admin=True, desc='{core.help.admin}') +admin = module('admin', base=True, required_admin=True, desc='{core.help.admin.desc}') @admin.command([ @@ -171,7 +171,7 @@ async def _(msg: Bot.MessageSession): disable_secret_check=True) -setup = module('setup', base=True, required_admin=True, desc=) +setup = module('setup', base=True, required_admin=True, desc='{core.help.setup.desc}') @setup.command('typing {{core.help.setup.typing}}') From 3e57f9d4fd388c3b1a1f8a5505c55029bf1d132e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 16 Dec 2023 16:50:02 +0800 Subject: [PATCH 06/22] update core locales --- modules/core/locales/en_us.json | 9 +++++---- modules/core/locales/zh_cn.json | 9 +++++---- modules/core/locales/zh_tw.json | 7 ++++--- modules/core/utils.py | 21 ++++++++++----------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/modules/core/locales/en_us.json b/modules/core/locales/en_us.json index 486b8b7c..d6a7e53c 100644 --- a/modules/core/locales/en_us.json +++ b/modules/core/locales/en_us.json @@ -1,7 +1,7 @@ { - "core.help.admin.desc": "Commands available to group administrators.", "core.help.admin.add": "Set members as bot administrators, implement the function of managing the robot without setting members as group administrators. It's no longer needed to set up it when you are already a group administrator.", "core.help.admin.ban": "Limit someone to use bot in the group.", + "core.help.admin.desc": "Commands available to group administrators.", "core.help.admin.list": "View all bot administrators.", "core.help.admin.remove": "Remove bot administrator from member.", "core.help.admin.unban": "Remove limit someone to use bot in the group.", @@ -11,7 +11,7 @@ "core.help.alias.remove": "Remove custom command alias.", "core.help.alias.reset": "Reset custom command alias.", "core.help.leave": "Let the bot leave the group.", - "core.help.locale": "View bot running language.", + "core.help.locale.l": "View & Set the bot running language.", "core.help.locale.set": "Set bot running language.", "core.help.module.disable": "Disable single/multiple module(s).", "core.help.module.disable_all": "Disable all modules.", @@ -31,8 +31,9 @@ "core.help.prefix.remove": "Remove custom command prefix.", "core.help.prefix.reset": "Reset custom command prefix.", "core.help.setup.check": "setups whether to display command check prompts.", - "core.help.setup.typing": "setup whether to display input prompts.", + "core.help.setup.desc": "Set up bot actions.", "core.help.setup.timeoffset": "Set the time offset.", + "core.help.setup.typing": "setup whether to display input prompts.", "core.help.version": "View bot version.", "core.help.whoami": "Get the ID of the user account that sent the command inside the bot.", "core.message.abuse.ban.success": "Successfully banned ${user}.", @@ -153,13 +154,13 @@ "core.message.set.help.option.success": "The following parameters were set for the object: ${k} -> ${v}", "core.message.set.invalid": "Invalid ID format.", "core.message.set.module.success": "The following modules were successfully configured for the object: ", - "core.message.superuser.invalid": "Invalid ID format. The format should be \"${target}|\".", "core.message.setup.check.disable": "Check prompt disabled.", "core.message.setup.check.enable": "Check prompt enabled.", "core.message.setup.timeoffset.invalid": "Invalid time offset.", "core.message.setup.timeoffset.success": "The time offset has been set to UTC${offset}.", "core.message.setup.typing.disable": "Input prompt disabled.", "core.message.setup.typing.enable": "Input prompt enabled.", + "core.message.superuser.invalid": "Invalid ID format. The format should be \"${target}|\".", "core.message.update.failed": "Failed to fetch update from GitHub. Please try again later.", "core.message.version": "Current bot version: ${commit}", "core.message.version.unknown": "Unable to get version. This instance may not be deployed using Git.", diff --git a/modules/core/locales/zh_cn.json b/modules/core/locales/zh_cn.json index ace8cf6b..477f8dc8 100644 --- a/modules/core/locales/zh_cn.json +++ b/modules/core/locales/zh_cn.json @@ -1,7 +1,7 @@ { - "core.help.admin.desc": "一些群组管理员可使用的命令。", "core.help.admin.add": "设置成员为机器人管理员。以实现不设置成员为群组管理员的状況下管理机器人的效果。已是群组管理员无需设置此项目。", "core.help.admin.ban": "限制某人在本群使用机器人。", + "core.help.admin.desc": "一些群组管理员可使用的命令。", "core.help.admin.list": "查看所有机器人管理员。", "core.help.admin.remove": "取消成员的机器人管理员。", "core.help.admin.unban": "解除对某人在本群使用机器人的限制。", @@ -11,7 +11,7 @@ "core.help.alias.remove": "移除自定义命令别名。", "core.help.alias.reset": "重置自定义命令别名。", "core.help.leave": "使机器人离开群组。", - "core.help.locale": "查看机器人运行语言。", + "core.help.locale": "查看或设置机器人运行语言。", "core.help.locale.set": "设置机器人运行语言。", "core.help.module.disable": "关闭一个/多个模块。", "core.help.module.disable_all": "关闭所有模块。", @@ -31,8 +31,9 @@ "core.help.prefix.remove": "移除自定义命令前缀。", "core.help.prefix.reset": "重置自定义命令前缀。", "core.help.setup.check": "切换是否展示命令错字检查提示。", - "core.help.setup.typing": "切换是否展示输入提示。", + "core.help.setup.desc": "设置机器人行为。", "core.help.setup.timeoffset": "设置时间偏移量。", + "core.help.setup.typing": "切换是否展示输入提示。", "core.help.version": "查看机器人的版本号。", "core.help.whoami": "获取发送命令的账号在机器人内部的 ID。", "core.message.abuse.ban.success": "成功封禁 ${user}。", @@ -153,13 +154,13 @@ "core.message.set.help.option.success": "成功为对象设置了以下参数:${k} -> ${v}", "core.message.set.invalid": "ID 格式错误。", "core.message.set.module.success": "成功为对象配置了以下模块:", - "core.message.superuser.invalid": "ID 格式错误,格式应为“${target}|<用户 ID>”。", "core.message.setup.check.disable": "已关闭错字检查提示。", "core.message.setup.check.enable": "已开启错字检查提示。", "core.message.setup.timeoffset.invalid": "无效的时间偏移量。", "core.message.setup.timeoffset.success": "已将时间偏移量设定为 UTC${offset}。", "core.message.setup.typing.disable": "已关闭输入提示。", "core.message.setup.typing.enable": "已开启输入提示。", + "core.message.superuser.invalid": "ID 格式错误,格式应为“${target}|<用户 ID>”。", "core.message.update.failed": "尝试从 GitHub 获取更新失败,请稍后重试。", "core.message.version": "当前机器人版本号:${commit}", "core.message.version.unknown": "无法获取版本号。此实例可能没有使用 Git 进行部署。", diff --git a/modules/core/locales/zh_tw.json b/modules/core/locales/zh_tw.json index d901588e..faec99bc 100644 --- a/modules/core/locales/zh_tw.json +++ b/modules/core/locales/zh_tw.json @@ -1,7 +1,7 @@ { - "core.help.admin.desc": "一些群組管理員可使用的指令。", "core.help.admin.add": "設定成員為機器人管理員,以實現不設定成員為群組管理員的狀況下管理機器人的效果。已是群組管理員無須設定此指令。", "core.help.admin.ban": "限制某人在此群組使用機器人。", + "core.help.admin.desc": "一些群組管理員可使用的指令。", "core.help.admin.list": "檢視所有機器人管理員。", "core.help.admin.remove": "取消成員的機器人管理員。", "core.help.admin.unban": "解除對某人在此群組使用機器人的限制。", @@ -31,8 +31,9 @@ "core.help.prefix.remove": "移除自訂指令前綴。", "core.help.prefix.reset": "重設自訂指令前綴。", "core.help.setup.check": "切換是否顯示指令錯誤檢查提醒。", - "core.help.setup.typing": "切換是否顯示輸入提醒。", + "core.help.setup.desc": "設定機器人行動", "core.help.setup.timeoffset": "設定時間偏移量。", + "core.help.setup.typing": "切換是否顯示輸入提醒。", "core.help.version": "檢視機器人的版本號。", "core.help.whoami": "取得傳送指令的帳戶在機器人內部的 ID。", "core.message.abuse.ban.success": "成功封鎖 ${user}。", @@ -153,13 +154,13 @@ "core.message.set.help.option.success": "成功為物件設定了以下參數:${k} -> ${v}", "core.message.set.invalid": "ID 格式錯誤。", "core.message.set.module.success": "成功為物件配置了以下模組:", - "core.message.superuser.invalid": "ID 格式錯誤,格式應為「${target}|<使用者 ID>」。", "core.message.setup.check.disable": "已停用指令錯誤檢查提醒。", "core.message.setup.check.enable": "已啟用指令錯誤檢查提醒。", "core.message.setup.timeoffset.invalid": "無效的時間偏移量。", "core.message.setup.timeoffset.success": "已將時間偏移量設定為 UTC${offset}。", "core.message.setup.typing.disable": "已停用輸入提醒。", "core.message.setup.typing.enable": "已啟用輸入提醒。", + "core.message.superuser.invalid": "ID 格式錯誤,格式應為「${target}|<使用者 ID>」。", "core.message.update.failed": "嘗試從 GitHub 取得更新失敗,請稍後重試。", "core.message.version": "目前機器人版本號:${commit}", "core.message.version.unknown": "無法取得版本號。此實例可能沒有使用 Git 進行部署。", diff --git a/modules/core/utils.py b/modules/core/utils.py index 5211b316..a37ac9c9 100644 --- a/modules/core/utils.py +++ b/modules/core/utils.py @@ -15,10 +15,10 @@ from database import BotDBUtil jwt_secret = Config('jwt_secret') -ver = module('version', base=True, desc='{core.help.version}') +ver = module('version', base=True) -@ver.command() +@ver.command('{{core.help.version}}') async def bot_version(msg: Bot.MessageSession): if Info.version: await msg.finish(msg.locale.t('core.message.version', commit=Info.version[0:6])) @@ -26,12 +26,12 @@ async def bot_version(msg: Bot.MessageSession): await msg.finish(msg.locale.t('core.message.version.unknown')) -ping = module('ping', base=True, desc='{core.help.ping}') +ping = module('ping', base=True) started_time = datetime.now() -@ping.command() +@ping.command('{{core.help.ping}}') async def _(msg: Bot.MessageSession): checkpermisson = msg.check_super_user() result = "Pong!" @@ -216,10 +216,10 @@ async def _(msg: Bot.MessageSession, offset: str): await msg.finish(msg.locale.t('core.message.setup.timeoffset.success', offset=offset)) -mute = module('mute', base=True, required_admin=True, desc='{core.help.mute}') +mute = module('mute', base=True, required_admin=True) -@mute.command() +@mute.command('{{core.help.mute}}') async def _(msg: Bot.MessageSession): state = msg.data.switch_mute() if state: @@ -233,11 +233,10 @@ leave = module( base=True, required_admin=True, available_for='QQ|Group', - alias='dismiss', - desc='{core.help.leave}') + alias='dismiss') -@leave.command() +@leave.command('{{core.help.leave}}') async def _(msg: Bot.MessageSession): confirm = await msg.wait_confirm(msg.locale.t('core.message.confirm')) if confirm: @@ -245,10 +244,10 @@ async def _(msg: Bot.MessageSession): await msg.call_api('set_group_leave', group_id=msg.session.target) -token = module('token', base=True, desc='{core.help.token}') +token = module('token', base=True) -@token.command('') +@token.command(' {{core.help.token}}') async def _(msg: Bot.MessageSession): await msg.finish(jwt.encode({ 'exp': datetime.utcnow() + timedelta(seconds=60 * 60 * 24 * 7), # 7 days From f3ffde25448e5c4c48ea7c1244c0914d5944e044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 16 Dec 2023 19:24:36 +0800 Subject: [PATCH 07/22] Update --- modules/maimai/__init__.py | 14 +++++++------- modules/maimai/libraries/maimaidx_api_data.py | 2 +- modules/maimai/libraries/maimaidx_project.py | 8 ++++---- modules/maimai/regex.py | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/maimai/__init__.py b/modules/maimai/__init__.py index b5ada1ef..4b303309 100644 --- a/modules/maimai/__init__.py +++ b/modules/maimai/__init__.py @@ -1,4 +1,4 @@ -from core.builtins import command_prefix +from core.builtins import command_prefix import traceback from config import Config @@ -59,7 +59,7 @@ async def _(msg: Bot.MessageSession, constant: float, constant_max: float = None result_set = await base_level_q(constant) s = msg.locale.t("maimai.message.base", constant=round(constant, 1)) + "\n" for elem in result_set: - s += f"{elem[0]}\u200B. {elem[1]}{' (DX)' if elem[5] == 'DX' else ''} {elem[3]} {elem[4]} ({elem[2]})\n" + s += f"{elem[0]}\u200B. {elem[1]}{msg.locale.t('message.brackets', msg='DX') if elem[5] == 'DX' else ''} {elem[3]} {elem[4]} ({elem[2]})\n" if len(result_set) == 0: await msg.finish(msg.locale.t("maimai.message.music_not_found")) elif len(result_set) > 200: @@ -94,7 +94,7 @@ async def _(msg: Bot.MessageSession, level: str): result_set = await diff_level_q(level) s = msg.locale.t("maimai.message.level", level=level) + "\n" for elem in result_set: - s += f"{elem[0]}\u200B. {elem[1]}{' (DX)' if elem[5] == 'DX' else ''} {elem[3]} {elem[4]} ({elem[2]})\n" + s += f"{elem[0]}\u200B. {elem[1]}{msg.locale.t('message.brackets', msg='DX') if elem[5] == 'DX' else ''} {elem[3]} {elem[4]} ({elem[2]})\n" if len(result_set) == 0: await msg.finish(msg.locale.t("maimai.message.music_not_found")) elif len(result_set) <= 10: @@ -130,7 +130,7 @@ async def _(msg: Bot.MessageSession, keyword: str): else: search_result = msg.locale.t("maimai.message.search", keyword=name) + "\n" for music in sorted(res, key=lambda i: int(i['id'])): - search_result += f"{music['id']}\u200B. {music['title']}{' (DX)' if music['type'] == 'DX' else ''}\n" + search_result += f"{music['id']}\u200B. {music['title']}{msg.locale.t('message.brackets', msg='DX') if music['type'] == 'DX' else ''}\n" if len(res) <= 10: await msg.finish([Plain(search_result.strip())]) else: @@ -187,7 +187,7 @@ async def _(msg: Bot.MessageSession, id_or_alias: str, diff: str = None): res = msg.locale.t("maimai.message.song.prompt") + "\n" for sid in sorted(sid_list, key=int): s = (await total_list.get()).by_id(sid) - res += f"{s['id']}\u200B. {s['title']}{' (DX)' if s['type'] == 'DX' else ''}\n" + res += f"{s['id']}\u200B. {s['title']}{msg.locale.t('message.brackets', msg='DX') if s['type'] == 'DX' else ''}\n" await msg.finish(res.strip()) else: sid = str(sid_list[0]) @@ -250,7 +250,7 @@ async def _(msg: Bot.MessageSession, id_or_alias: str, username: str = None): res = msg.locale.t("maimai.message.song.prompt") + "\n" for sid in sorted(sid_list, key=int): s = (await total_list.get()).by_id(sid) - res += f"{s['id']}\u200B. {s['title']}{' (DX)' if s['type'] == 'DX' else ''}\n" + res += f"{s['id']}\u200B. {s['title']}{msg.locale.t('message.brackets', msg='DX') if s['type'] == 'DX' else ''}\n" await msg.finish(res.strip()) else: sid = str(sid_list[0]) @@ -443,7 +443,7 @@ async def _(msg: Bot.MessageSession, diff: str, sid: str, scoreline: float): b2t_2550_great_prop = "{:.4f}".format(break_2550_reduce / total_score * 100) b2t_2000_great = "{:.3f}".format(break_2000_reduce / 100) # 一个 TAP GREAT 减少 100 分 b2t_2000_great_prop = "{:.4f}".format(break_2000_reduce / total_score * 100) - await msg.finish(f'''{music['title']}{' (DX)' if music['type'] == 'DX' else ''} {diff_label[diff_index]} + await msg.finish(f'''{music['title']}{msg.locale.t('message.brackets', msg='DX') if music['type'] == 'DX' else ''} {diff_label[diff_index]} {msg.locale.t('maimai.message.scoreline', scoreline=scoreline, tap_great=tap_great, diff --git a/modules/maimai/libraries/maimaidx_api_data.py b/modules/maimai/libraries/maimaidx_api_data.py index 3c512f19..94fcbe10 100644 --- a/modules/maimai/libraries/maimaidx_api_data.py +++ b/modules/maimai/libraries/maimaidx_api_data.py @@ -46,7 +46,7 @@ async def update_covers(): async def get_info(music: Music, *details): - info = [Plain(f"{music.id}\u200B. {music.title}{' (DX)' if music['type'] == 'DX' else ''}")] + info = [Plain(f"{music.id}\u200B. {music.title}{msg.locale.t('message.brackets', msg='DX') if music['type'] == 'DX' else ''}")] try: img = f"https://www.diving-fish.com/covers/{get_cover_len5_id(music.id)}.png" await get_url(img, 200, attempt=1, fmt='read') diff --git a/modules/maimai/libraries/maimaidx_project.py b/modules/maimai/libraries/maimaidx_project.py index 32386a8f..678dc899 100644 --- a/modules/maimai/libraries/maimaidx_project.py +++ b/modules/maimai/libraries/maimaidx_project.py @@ -233,7 +233,7 @@ async def get_level_process(msg, payload, process, goal): elif goal in syncRank: if verlist[record_index]['fs']: self_record = syncRank[sync_rank.index(verlist[record_index]['fs'])] - output += f"{s[0]}\u200B. {s[1]}{' (DX)' if s[5] == 'DX' else ''} {s[2]} {s[3]} {self_record}\n" + output += f"{s[0]}\u200B. {s[1]}{msg.locale.t('message.brackets', msg='DX') if s[5] == 'DX' else ''} {s[2]} {s[3]} {self_record}\n" if len(song_remain) > 10: # 若剩余歌曲大于10个则使用图片形式 get_img = True else: @@ -260,7 +260,7 @@ async def get_score_list(msg, payload, level): output_lines = [] for s in enumerate(sorted(song_list, key=lambda i: i['achievements'], reverse=True)): # 根据成绩排序 music = (await total_list.get()).by_id(str(s[1]['id'])) - output = f"{music.id}\u200B. {music.title}{' (DX)' if music.type == 'DX' else ''} {diffs[s[1]['level_index']]} {music.ds[s[1]['level_index']]} {s[1]['achievements']}%" + output = f"{music.id}\u200B. {music.title}{msg.locale.t('message.brackets', msg='DX') if music.type == 'DX' else ''} {diffs[s[1]['level_index']]} {music.ds[s[1]['level_index']]} {s[1]['achievements']}%" if s[1]["fc"] and s[1]["fs"]: output += f" {combo_conversion.get(s[1]['fc'], '')} {sync_conversion.get(s[1]['fs'], '')}" elif s[1]["fc"] or s[1]["fs"]: @@ -425,7 +425,7 @@ async def get_plate_process(msg, payload, plate): elif goal == '舞舞': if verlist[record_index]['fs']: self_record = syncRank[sync_rank.index(verlist[record_index]['fs'])] - output += f"{s[0]}\u200B. {s[1]}{' (DX)' if s[5] == 'DX' else ''} {s[2]} {s[3]} {self_record}".strip() + '\n' + output += f"{s[0]}\u200B. {s[1]}{msg.locale.t('message.brackets', msg='DX') if s[5] == 'DX' else ''} {s[2]} {s[3]} {self_record}".strip() + '\n' if len(song_remain_difficult) > 10: # 若剩余歌曲大于10个则使用图片形式 get_img = True else: @@ -450,7 +450,7 @@ async def get_plate_process(msg, payload, plate): elif goal == '舞舞': if verlist[record_index]['fs']: self_record = syncRank[sync_rank.index(verlist[record_index]['fs'])] - output += f"{m.id}\u200B. {m.title}{' (DX)' if m.type == 'DX' else ''} {diffs[s[1]]} {m.ds[s[1]]} {self_record}".strip( + output += f"{m.id}\u200B. {m.title}{msg.locale.t('message.brackets', msg='DX') if m.type == 'DX' else ''} {diffs[s[1]]} {m.ds[s[1]]} {self_record}".strip( ) + '\n' if len(song_remain) > 10: # 若剩余歌曲大于10个则使用图片形式 get_img = True diff --git a/modules/maimai/regex.py b/modules/maimai/regex.py index 7d7aaa00..50153dcd 100644 --- a/modules/maimai/regex.py +++ b/modules/maimai/regex.py @@ -57,7 +57,7 @@ async def _(msg: Bot.MessageSession): res = msg.locale.t("maimai.message.song.prompt") + "\n" for sid in sorted(sid_list, key=int): s = (await total_list.get()).by_id(sid) - res += f"{s['id']}\u200B. {s['title']}{' (DX)' if s['type'] == 'DX' else ''}\n" + res += f"{s['id']}\u200B. {s['title']}{msg.locale.t('message.brackets', msg='DX') if s['type'] == 'DX' else ''}\n" await msg.finish(res.strip()) else: music = (await total_list.get()).by_id(str(sid_list[0])) @@ -86,7 +86,7 @@ async def _(msg: Bot.MessageSession): res = msg.locale.t("maimai.message.song.prompt") + "\n" for sid in sorted(sid_list, key=int): s = (await total_list.get()).by_id(sid) - res += f"{s['id']}\u200B. {s['title']}{' (DX)' if s['type'] == 'DX' else ''}\n" + res += f"{s['id']}\u200B. {s['title']}{msg.locale.t('message.brackets', msg='DX') if s['type'] == 'DX' else ''}\n" await msg.finish(res.strip()) else: sid = str(sid_list[0]) @@ -113,7 +113,7 @@ async def _(msg: Bot.MessageSession): music = (await total_list.get()).by_id(sid) if not music: await msg.finish(msg.locale.t("maimai.message.music_not_found")) - title = f"{music['id']}\u200B. {music['title']}{' (DX)' if music['type'] == 'DX' else ''}" + title = f"{music['id']}\u200B. {music['title']}{msg.locale.t('message.brackets', msg='DX') if music['type'] == 'DX' else ''}" alias = await get_alias(msg, sid) if len(alias) == 0: await msg.finish(msg.locale.t("maimai.message.alias.alias_not_found")) From 6f90915a2c83beda759509df0a683fad5bc6b1b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 16 Dec 2023 19:34:50 +0800 Subject: [PATCH 08/22] fix --- modules/maimai/__init__.py | 12 ++++++------ modules/maimai/libraries/maimaidx_api_data.py | 4 ++-- modules/maimai/regex.py | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/maimai/__init__.py b/modules/maimai/__init__.py index 4b303309..bca3ffe6 100644 --- a/modules/maimai/__init__.py +++ b/modules/maimai/__init__.py @@ -150,7 +150,7 @@ async def _(msg: Bot.MessageSession, sid: str): if not music: await msg.finish(msg.locale.t("maimai.message.music_not_found")) - title = await get_info(music, cover=False) + title = await get_info(msg, music, cover=False) alias = await get_alias(msg, sid) if len(alias) == 0: await msg.finish(msg.locale.t("maimai.message.alias.alias_not_found")) @@ -225,7 +225,7 @@ async def _(msg: Bot.MessageSession, id_or_alias: str, diff: str = None): touch=chart['notes'][3], brk=chart['notes'][4], charter=chart['charter']) - await msg.finish(await get_info(music, Plain(message))) + await msg.finish(await get_info(msg, music, Plain(message))) else: message = msg.locale.t( "maimai.message.song", @@ -234,7 +234,7 @@ async def _(msg: Bot.MessageSession, id_or_alias: str, diff: str = None): bpm=music['basic_info']['bpm'], version=music['basic_info']['from'], level='/'.join((str(ds) for ds in music['ds']))) - await msg.finish(await get_info(music, Plain(message))) + await msg.finish(await get_info(msg, music, Plain(message))) @mai.command('info [] {{maimai.help.info}}') @@ -268,7 +268,7 @@ async def _(msg: Bot.MessageSession, id_or_alias: str, username: str = None): output = await get_player_score(msg, payload, sid) - await msg.finish(await get_info(music, Plain(output))) + await msg.finish(await get_info(msg, music, Plain(output))) @mai.command('plate [] {{maimai.help.plate}}') @@ -403,7 +403,7 @@ async def _(msg: Bot.MessageSession, dx_type: str = None): await msg.finish(msg.locale.t("maimai.message.music_not_found")) else: music = music_data.random() - await msg.finish(await get_info(music, Plain(f"\n{'/'.join(str(ds) for ds in music.ds)}"))) + await msg.finish(await get_info(msg, music, Plain(f"\n{'/'.join(str(ds) for ds in music.ds)}"))) except ValueError: await msg.finish(msg.locale.t("maimai.message.random.error")) @@ -411,7 +411,7 @@ async def _(msg: Bot.MessageSession, dx_type: str = None): @mai.command('random {{maimai.help.random}}') async def _(msg: Bot.MessageSession): music = (await total_list.get()).random() - await msg.finish(await get_info(music, Plain(f"\n{'/'.join(str(ds) for ds in music.ds)}"))) + await msg.finish(await get_info(msg, music, Plain(f"\n{'/'.join(str(ds) for ds in music.ds)}"))) @mai.command('scoreline {{maimai.help.scoreline}}') diff --git a/modules/maimai/libraries/maimaidx_api_data.py b/modules/maimai/libraries/maimaidx_api_data.py index 94fcbe10..384050c2 100644 --- a/modules/maimai/libraries/maimaidx_api_data.py +++ b/modules/maimai/libraries/maimaidx_api_data.py @@ -3,7 +3,7 @@ import shutil import ujson as json -from core.builtins import Plain, Image +from core.builtins import Bot, Plain, Image from core.logger import Logger from core.utils.cache import random_cache_path from core.utils.http import get_url, post_url, download_to_cache @@ -45,7 +45,7 @@ async def update_covers(): return True -async def get_info(music: Music, *details): +async def get_info(msg: Bot.MessageSession, music: Music, *details): info = [Plain(f"{music.id}\u200B. {music.title}{msg.locale.t('message.brackets', msg='DX') if music['type'] == 'DX' else ''}")] try: img = f"https://www.diving-fish.com/covers/{get_cover_len5_id(music.id)}.png" diff --git a/modules/maimai/regex.py b/modules/maimai/regex.py index 50153dcd..3ba975dc 100644 --- a/modules/maimai/regex.py +++ b/modules/maimai/regex.py @@ -64,7 +64,7 @@ async def _(msg: Bot.MessageSession): if not music: await msg.finish(msg.locale.t("maimai.message.music_not_found")) - await msg.finish(await get_info(music, Plain(msg.locale.t("maimai.message.song", + await msg.finish(await get_info(msg, music, Plain(msg.locale.t("maimai.message.song", artist=music['basic_info']['artist'], genre=music['basic_info']['genre'], bpm=music['basic_info']['bpm'], @@ -104,7 +104,7 @@ async def _(msg: Bot.MessageSession): output = await get_player_score(msg, payload, sid) - await msg.finish(await get_info(music, Plain(output))) + await msg.finish(await get_info(msg, music, Plain(output))) @mai_regex.regex(re.compile(r"(?:id)?(\d+)\s?有什(?:么别|麼別)名", flags=re.I), desc='{maimai.help.maimai_regex.alias}') @@ -145,7 +145,7 @@ async def _(msg: Bot.MessageSession): await msg.finish(msg.locale.t("maimai.message.music_not_found")) else: music = music_data.random() - await msg.finish(await get_info(music, Plain(f"\n{'/'.join(str(ds) for ds in music.ds)}"))) + await msg.finish(await get_info(msg, music, Plain(f"\n{'/'.join(str(ds) for ds in music.ds)}"))) except ValueError: await msg.finish(msg.locale.t("maimai.message.random.error")) From 9d21227ce57027659673754142c675870d459383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 12:25:24 +0800 Subject: [PATCH 09/22] update --- modules/bugtracker/bugtracker.py | 2 +- modules/cytoid/profile.py | 2 +- modules/cytoid/rating.py | 2 +- modules/github/repo.py | 2 +- modules/github/user.py | 2 +- modules/maimai/libraries/maimai_best_50.py | 4 ++-- modules/maimai/libraries/maimaidx_api_data.py | 8 ++++---- modules/wolframalpha/__init__.py | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/bugtracker/bugtracker.py b/modules/bugtracker/bugtracker.py index ec75e1cc..ff985d47 100644 --- a/modules/bugtracker/bugtracker.py +++ b/modules/bugtracker/bugtracker.py @@ -60,7 +60,7 @@ async def bugtracker_get(session, mojira_id: str, nolink=False): json_url = 'https://bugs.mojang.com/rest/api/2/issue/' + id_ get_json = await get_url(json_url, 200) except ValueError as e: - if str(e).startswith('401'): + if e.args == (401,): await session.finish(session.locale.t("bugtracker.message.get_failed")) if mojira_id not in spx_cache: get_spx = await get_url('https://bugs.guangyaostore.com/translations', 200) diff --git a/modules/cytoid/profile.py b/modules/cytoid/profile.py index 2464ca24..0f163db6 100644 --- a/modules/cytoid/profile.py +++ b/modules/cytoid/profile.py @@ -17,7 +17,7 @@ async def cytoid_profile(msg: Bot.MessageSession): try: profile = json.loads(await get_url(profile_url, status_code=200)) except ValueError as e: - if str(e).startswith('404'): + if e.args == (404,): await msg.finish(msg.locale.t('cytoid.message.user_not_found')) raise e uid = profile['user']['uid'] diff --git a/modules/cytoid/rating.py b/modules/cytoid/rating.py index 8c9c8d54..7b1a5d62 100644 --- a/modules/cytoid/rating.py +++ b/modules/cytoid/rating.py @@ -210,7 +210,7 @@ async def get_rating(msg: Bot.MessageSession, uid, query_type): # shutil.rmtree(workdir) return {'status': True, 'path': savefilename} except Exception as e: - if str(e).startswith('404'): + if e.args == (404,): await msg.finish(msg.locale.t("cytoid.message.user_not_found")) traceback.print_exc() return {'status': False, 'text': msg.locale.t("error") + str(e)} diff --git a/modules/github/repo.py b/modules/github/repo.py index 773800fc..c0e87b96 100644 --- a/modules/github/repo.py +++ b/modules/github/repo.py @@ -66,6 +66,6 @@ Created {time_diff(result['created_at'])} ago | Updated {time_diff(result['updat asyncio.create_task(download()) except ValueError as e: - if str(e).startswith('404'): + if e.args == (404,): await msg.finish(msg.locale.t("github.message.repo.not_found")) traceback.print_exc() diff --git a/modules/github/user.py b/modules/github/user.py index 2ef88adb..4c6413b4 100644 --- a/modules/github/user.py +++ b/modules/github/user.py @@ -43,6 +43,6 @@ Account Created {time_diff(result['created_at'])} ago | Latest activity {time_di await msg.finish(message) except ValueError as e: - if str(e).startswith('404'): + if e.args == (404,): await msg.finish(msg.locale.t("github.message.repo.not_found")) traceback.print_exc() diff --git a/modules/maimai/libraries/maimai_best_50.py b/modules/maimai/libraries/maimai_best_50.py index ac3d7ad4..5cdcf1da 100644 --- a/modules/maimai/libraries/maimai_best_50.py +++ b/modules/maimai/libraries/maimai_best_50.py @@ -400,12 +400,12 @@ async def generate(msg, payload) -> Tuple[Optional[Image.Image], bool]: status_code=200, headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json') except ValueError as e: - if str(e).startswith('400'): + if e.args == (400,): if "qq" in payload: await msg.finish(msg.locale.t("maimai.message.user_unbound")) else: await msg.finish(msg.locale.t("maimai.message.user_not_found")) - elif str(e).startswith('403'): + elif e.args == (403,): await msg.finish(msg.locale.t("maimai.message.forbidden")) else: raise diff --git a/modules/maimai/libraries/maimaidx_api_data.py b/modules/maimai/libraries/maimaidx_api_data.py index 384050c2..b9621f82 100644 --- a/modules/maimai/libraries/maimaidx_api_data.py +++ b/modules/maimai/libraries/maimaidx_api_data.py @@ -106,12 +106,12 @@ async def get_record(msg, payload): status_code=200, headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json') except Exception as e: - if str(e).startswith('400'): + if e.args == (400,): if "qq" in payload: await msg.finish(msg.locale.t("maimai.message.user_unbound")) else: await msg.finish(msg.locale.t("maimai.message.user_not_found")) - elif str(e).startswith('403'): + elif e.args == (403,): await msg.finish(msg.locale.t("maimai.message.forbidden")) else: raise @@ -126,12 +126,12 @@ async def get_plate(msg, payload): status_code=200, headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json') except Exception as e: - if str(e).startswith('400'): + if e.args == (400,): if "qq" in payload: await msg.finish(msg.locale.t("maimai.message.user_unbound")) else: await msg.finish(msg.locale.t("maimai.message.user_not_found")) - elif str(e).startswith('403'): + elif e.args == (403,): await msg.finish(msg.locale.t("maimai.message.forbidden")) else: raise diff --git a/modules/wolframalpha/__init__.py b/modules/wolframalpha/__init__.py index 3d7f8ac1..802b1f70 100644 --- a/modules/wolframalpha/__init__.py +++ b/modules/wolframalpha/__init__.py @@ -38,7 +38,7 @@ async def _(msg: Bot.MessageSession): os.remove(img_path) await msg.finish([BImage(output)]) except ValueError as e: - if str(e).startswith('501'): + if e.args == (501,): await msg.finish(msg.locale.t('wolframalpha.message.incomprehensible')) @@ -57,5 +57,5 @@ async def _(msg: Bot.MessageSession): await msg.finish(rickroll(msg)) await msg.finish(data) except ValueError as e: - if str(e).startswith('501'): + if e.args == (501'): await msg.finish(msg.locale.t('wolframalpha.message.incomprehensible')) From d9d1934686de23567bf5a035e8a628682a672dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 12:40:56 +0800 Subject: [PATCH 10/22] update --- modules/bugtracker/bugtracker.py | 2 +- modules/core/locales/en_us.json | 4 ++-- modules/core/locales/zh_cn.json | 2 +- modules/core/locales/zh_tw.json | 2 +- modules/core/utils.py | 11 +++-------- modules/cytoid/profile.py | 4 +--- modules/github/repo.py | 5 ++--- modules/github/user.py | 4 ++-- modules/maimai/libraries/maimai_best_50.py | 4 ++-- modules/maimai/libraries/maimaidx_api_data.py | 8 ++++---- modules/wolframalpha/__init__.py | 4 ++-- 11 files changed, 21 insertions(+), 29 deletions(-) diff --git a/modules/bugtracker/bugtracker.py b/modules/bugtracker/bugtracker.py index ff985d47..ec75e1cc 100644 --- a/modules/bugtracker/bugtracker.py +++ b/modules/bugtracker/bugtracker.py @@ -60,7 +60,7 @@ async def bugtracker_get(session, mojira_id: str, nolink=False): json_url = 'https://bugs.mojang.com/rest/api/2/issue/' + id_ get_json = await get_url(json_url, 200) except ValueError as e: - if e.args == (401,): + if str(e).startswith('401'): await session.finish(session.locale.t("bugtracker.message.get_failed")) if mojira_id not in spx_cache: get_spx = await get_url('https://bugs.guangyaostore.com/translations', 200) diff --git a/modules/core/locales/en_us.json b/modules/core/locales/en_us.json index d6a7e53c..13f0fbdd 100644 --- a/modules/core/locales/en_us.json +++ b/modules/core/locales/en_us.json @@ -11,8 +11,8 @@ "core.help.alias.remove": "Remove custom command alias.", "core.help.alias.reset": "Reset custom command alias.", "core.help.leave": "Let the bot leave the group.", - "core.help.locale.l": "View & Set the bot running language.", - "core.help.locale.set": "Set bot running language.", + "core.help.locale.desc": "Control bot language.", + "core.help.locale.set": "Set the bot running languages.", "core.help.module.disable": "Disable single/multiple module(s).", "core.help.module.disable_all": "Disable all modules.", "core.help.module.enable": "Enable single/multiple module(s).", diff --git a/modules/core/locales/zh_cn.json b/modules/core/locales/zh_cn.json index 477f8dc8..c4a92dd4 100644 --- a/modules/core/locales/zh_cn.json +++ b/modules/core/locales/zh_cn.json @@ -11,7 +11,7 @@ "core.help.alias.remove": "移除自定义命令别名。", "core.help.alias.reset": "重置自定义命令别名。", "core.help.leave": "使机器人离开群组。", - "core.help.locale": "查看或设置机器人运行语言。", + "core.help.locale.desc": "控制机器人语言。", "core.help.locale.set": "设置机器人运行语言。", "core.help.module.disable": "关闭一个/多个模块。", "core.help.module.disable_all": "关闭所有模块。", diff --git a/modules/core/locales/zh_tw.json b/modules/core/locales/zh_tw.json index faec99bc..ae8d7ec3 100644 --- a/modules/core/locales/zh_tw.json +++ b/modules/core/locales/zh_tw.json @@ -11,7 +11,7 @@ "core.help.alias.remove": "移除自訂指令別名。", "core.help.alias.reset": "重設自訂指令別名。", "core.help.leave": "使機器人離開群組。", - "core.help.locale": "檢視機器人使用的語言。", + "core.help.locale.desc": "控制機器人語言。", "core.help.locale.set": "設定機器人使用的語言。", "core.help.module.disable": "停用一個/多個模組。", "core.help.module.disable_all": "停用所有模組。", diff --git a/modules/core/utils.py b/modules/core/utils.py index a37ac9c9..e185e1f9 100644 --- a/modules/core/utils.py +++ b/modules/core/utils.py @@ -125,10 +125,10 @@ async def config_ban(msg: Bot.MessageSession): await msg.finish(msg.locale.t("core.message.admin.ban.not_yet")) -locale = module('locale', base=True) +locale = module('locale', base=True, desc='{core.help.locale.desc}') -@locale.command('{{core.help.locale}}') +@locale.command() async def _(msg: Bot.MessageSession): avaliable_lang = msg.locale.t("message.delimiter").join(get_available_locales()) await msg.finish( @@ -228,12 +228,7 @@ async def _(msg: Bot.MessageSession): await msg.finish(msg.locale.t('core.message.mute.disable')) -leave = module( - 'leave', - base=True, - required_admin=True, - available_for='QQ|Group', - alias='dismiss') +leave = module('leave', base=True, required_admin=True, available_for='QQ|Group', alias='dismiss') @leave.command('{{core.help.leave}}') diff --git a/modules/cytoid/profile.py b/modules/cytoid/profile.py index 0f163db6..e0cafe3c 100644 --- a/modules/cytoid/profile.py +++ b/modules/cytoid/profile.py @@ -1,5 +1,3 @@ -import ujson as json - from core.builtins import Bot, Image, Plain from core.utils.http import get_url from .dbutils import CytoidBindInfoManager @@ -17,7 +15,7 @@ async def cytoid_profile(msg: Bot.MessageSession): try: profile = json.loads(await get_url(profile_url, status_code=200)) except ValueError as e: - if e.args == (404,): + if str(e).startswith('404'): await msg.finish(msg.locale.t('cytoid.message.user_not_found')) raise e uid = profile['user']['uid'] diff --git a/modules/github/repo.py b/modules/github/repo.py index c0e87b96..cd4eba14 100644 --- a/modules/github/repo.py +++ b/modules/github/repo.py @@ -1,5 +1,4 @@ -import asyncio -import traceback +traceback from core.builtins import Bot, Image, Plain, Url from core.dirty_check import rickroll @@ -66,6 +65,6 @@ Created {time_diff(result['created_at'])} ago | Updated {time_diff(result['updat asyncio.create_task(download()) except ValueError as e: - if e.args == (404,): + if str(e).startswith('404'): await msg.finish(msg.locale.t("github.message.repo.not_found")) traceback.print_exc() diff --git a/modules/github/user.py b/modules/github/user.py index 4c6413b4..795de680 100644 --- a/modules/github/user.py +++ b/modules/github/user.py @@ -1,4 +1,4 @@ -import traceback +eback from core.builtins import Url, Bot from core.dirty_check import rickroll @@ -43,6 +43,6 @@ Account Created {time_diff(result['created_at'])} ago | Latest activity {time_di await msg.finish(message) except ValueError as e: - if e.args == (404,): + if str(e).startswith('404'): await msg.finish(msg.locale.t("github.message.repo.not_found")) traceback.print_exc() diff --git a/modules/maimai/libraries/maimai_best_50.py b/modules/maimai/libraries/maimai_best_50.py index 5cdcf1da..ac3d7ad4 100644 --- a/modules/maimai/libraries/maimai_best_50.py +++ b/modules/maimai/libraries/maimai_best_50.py @@ -400,12 +400,12 @@ async def generate(msg, payload) -> Tuple[Optional[Image.Image], bool]: status_code=200, headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json') except ValueError as e: - if e.args == (400,): + if str(e).startswith('400'): if "qq" in payload: await msg.finish(msg.locale.t("maimai.message.user_unbound")) else: await msg.finish(msg.locale.t("maimai.message.user_not_found")) - elif e.args == (403,): + elif str(e).startswith('403'): await msg.finish(msg.locale.t("maimai.message.forbidden")) else: raise diff --git a/modules/maimai/libraries/maimaidx_api_data.py b/modules/maimai/libraries/maimaidx_api_data.py index b9621f82..384050c2 100644 --- a/modules/maimai/libraries/maimaidx_api_data.py +++ b/modules/maimai/libraries/maimaidx_api_data.py @@ -106,12 +106,12 @@ async def get_record(msg, payload): status_code=200, headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json') except Exception as e: - if e.args == (400,): + if str(e).startswith('400'): if "qq" in payload: await msg.finish(msg.locale.t("maimai.message.user_unbound")) else: await msg.finish(msg.locale.t("maimai.message.user_not_found")) - elif e.args == (403,): + elif str(e).startswith('403'): await msg.finish(msg.locale.t("maimai.message.forbidden")) else: raise @@ -126,12 +126,12 @@ async def get_plate(msg, payload): status_code=200, headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json') except Exception as e: - if e.args == (400,): + if str(e).startswith('400'): if "qq" in payload: await msg.finish(msg.locale.t("maimai.message.user_unbound")) else: await msg.finish(msg.locale.t("maimai.message.user_not_found")) - elif e.args == (403,): + elif str(e).startswith('403'): await msg.finish(msg.locale.t("maimai.message.forbidden")) else: raise diff --git a/modules/wolframalpha/__init__.py b/modules/wolframalpha/__init__.py index 802b1f70..3d7f8ac1 100644 --- a/modules/wolframalpha/__init__.py +++ b/modules/wolframalpha/__init__.py @@ -38,7 +38,7 @@ async def _(msg: Bot.MessageSession): os.remove(img_path) await msg.finish([BImage(output)]) except ValueError as e: - if e.args == (501,): + if str(e).startswith('501'): await msg.finish(msg.locale.t('wolframalpha.message.incomprehensible')) @@ -57,5 +57,5 @@ async def _(msg: Bot.MessageSession): await msg.finish(rickroll(msg)) await msg.finish(data) except ValueError as e: - if e.args == (501'): + if str(e).startswith('501'): await msg.finish(msg.locale.t('wolframalpha.message.incomprehensible')) From 1acdec57b4b295decac46944d00e23ca4dc67f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 12:45:16 +0800 Subject: [PATCH 11/22] update locale --- modules/github/__init__.py | 2 +- modules/github/locales/en_us.json | 3 ++- modules/github/locales/zh_cn.json | 3 ++- modules/github/locales/zh_tw.json | 1 + modules/github/repo.py | 2 -- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/github/__init__.py b/modules/github/__init__.py index 9c254ef7..5726a1d3 100644 --- a/modules/github/__init__.py +++ b/modules/github/__init__.py @@ -2,7 +2,7 @@ from core.builtins import Bot from core.component import module from modules.github import repo, user, search -github = module('github', alias='gh', developers=['Dianliang233']) +github = module('github', alias='gh', developers=['Dianliang233'], desc='{github.help.desc}') @github.handle(' {{github.help}}') diff --git a/modules/github/locales/en_us.json b/modules/github/locales/en_us.json index 18a4153e..56d59924 100644 --- a/modules/github/locales/en_us.json +++ b/modules/github/locales/en_us.json @@ -1,11 +1,12 @@ { + "github.help.desc": "Github query tool.", "github.help": "Trying to automatically identifying and distinguishing repo/user.", "github.help.repo": "Getting GitHub repository information.", "github.help.search": "Searching repositories on GitHub.", "github.help.user": "Getting GitHub user or organization information.", "github.message.repo.not_found": "The repository does not exist, please check your input.", "github.message.search": "Successfully to search for ${result} results:", - "github.message.search.none": "搜索成功,未找到结果。", + "github.message.search.none": "No results found.", "github.message.search.more_information": "Truncated due to chat limits; ${more_result} more results may not be shown.", "github.message.search.not_found": "The repository cannot be found; please check your input.", "github.message.user.not_found": "The user cannot be found; please check your input." diff --git a/modules/github/locales/zh_cn.json b/modules/github/locales/zh_cn.json index 9375af76..d9a04780 100644 --- a/modules/github/locales/zh_cn.json +++ b/modules/github/locales/zh_cn.json @@ -1,12 +1,13 @@ { "github.help": "尝试自动识别并区分 repo/user。", + "github.help.desc": "GitHub 查询工具。", "github.help.repo": "获取 GitHub 存储库信息。", "github.help.search": "搜索 GitHub 上的存储库。", "github.help.user": "获取 GitHub 用户或组织信息。", "github.message.repo.not_found": "此存储库不存在,请检查输入。", "github.message.search": "搜索成功,共 ${result} 条结果:", - "github.message.search.none": "搜索成功,未找到结果。", "github.message.search.more_information": "另有 ${more_result} 条结果未显示。", + "github.message.search.none": "搜索成功,未找到结果。", "github.message.search.not_found": "未找到存储库,请检查输入。", "github.message.user.not_found": "查无此人,请检查输入。" } \ No newline at end of file diff --git a/modules/github/locales/zh_tw.json b/modules/github/locales/zh_tw.json index 90bb1b08..92bb1374 100644 --- a/modules/github/locales/zh_tw.json +++ b/modules/github/locales/zh_tw.json @@ -1,4 +1,5 @@ { + "github.help.desc": "GitHub 查詢工具。", "github.help": "嘗試自動辨識並區分 repo/user。", "github.help.repo": "取得 Github 儲存庫資訊。", "github.help.search": "搜尋 Github 上的儲存庫。", diff --git a/modules/github/repo.py b/modules/github/repo.py index cd4eba14..e3bb5a27 100644 --- a/modules/github/repo.py +++ b/modules/github/repo.py @@ -1,5 +1,3 @@ -traceback - from core.builtins import Bot, Image, Plain, Url from core.dirty_check import rickroll from core.utils.http import get_url, download_to_cache From 969ae525d39154ffdd294c779f9a588c143ab2ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 12:56:21 +0800 Subject: [PATCH 12/22] fix --- modules/github/locales/zh_cn.json | 1 - modules/github/repo.py | 2 ++ modules/github/user.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/github/locales/zh_cn.json b/modules/github/locales/zh_cn.json index d9a04780..08ad53e9 100644 --- a/modules/github/locales/zh_cn.json +++ b/modules/github/locales/zh_cn.json @@ -6,7 +6,6 @@ "github.help.user": "获取 GitHub 用户或组织信息。", "github.message.repo.not_found": "此存储库不存在,请检查输入。", "github.message.search": "搜索成功,共 ${result} 条结果:", - "github.message.search.more_information": "另有 ${more_result} 条结果未显示。", "github.message.search.none": "搜索成功,未找到结果。", "github.message.search.not_found": "未找到存储库,请检查输入。", "github.message.user.not_found": "查无此人,请检查输入。" diff --git a/modules/github/repo.py b/modules/github/repo.py index e3bb5a27..bed4fea7 100644 --- a/modules/github/repo.py +++ b/modules/github/repo.py @@ -1,3 +1,5 @@ +import traceback + from core.builtins import Bot, Image, Plain, Url from core.dirty_check import rickroll from core.utils.http import get_url, download_to_cache diff --git a/modules/github/user.py b/modules/github/user.py index 795de680..2ef88adb 100644 --- a/modules/github/user.py +++ b/modules/github/user.py @@ -1,4 +1,4 @@ -eback +import traceback from core.builtins import Url, Bot from core.dirty_check import rickroll From e0540d33bc3fd621e690beed9e910322c3b4bc9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 12:56:45 +0800 Subject: [PATCH 13/22] . --- modules/github/locales/zh_cn.json | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/github/locales/zh_cn.json b/modules/github/locales/zh_cn.json index 08ad53e9..d9a04780 100644 --- a/modules/github/locales/zh_cn.json +++ b/modules/github/locales/zh_cn.json @@ -6,6 +6,7 @@ "github.help.user": "获取 GitHub 用户或组织信息。", "github.message.repo.not_found": "此存储库不存在,请检查输入。", "github.message.search": "搜索成功,共 ${result} 条结果:", + "github.message.search.more_information": "另有 ${more_result} 条结果未显示。", "github.message.search.none": "搜索成功,未找到结果。", "github.message.search.not_found": "未找到存储库,请检查输入。", "github.message.user.not_found": "查无此人,请检查输入。" From e253aee131753de928fb2b46b26ea019ea8063c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 13:59:18 +0800 Subject: [PATCH 14/22] Update mai rating --- modules/maimai/__init__.py | 78 ++++++++++++++----- modules/maimai/libraries/maimai_best_50.py | 33 +------- modules/maimai/libraries/maimaidx_api_data.py | 11 ++- modules/maimai/libraries/maimaidx_project.py | 20 +++-- modules/maimai/locales/en_us.json | 4 +- modules/maimai/locales/zh_cn.json | 6 +- modules/maimai/locales/zh_tw.json | 6 +- modules/maimai/regex.py | 2 +- 8 files changed, 88 insertions(+), 72 deletions(-) diff --git a/modules/maimai/__init__.py b/modules/maimai/__init__.py index bca3ffe6..a9440c11 100644 --- a/modules/maimai/__init__.py +++ b/modules/maimai/__init__.py @@ -1,4 +1,4 @@ -from core.builtins import command_prefix +import math import traceback from config import Config @@ -162,10 +162,10 @@ async def _(msg: Bot.MessageSession, sid: str): @mai.command('b50 [] {{maimai.help.b50}}') async def _(msg: Bot.MessageSession, username: str = None): - if username is None and msg.target.sender_from == "QQ": + if not username and msg.target.sender_from == "QQ": payload = {'qq': msg.session.sender, 'b50': True} else: - if username is None: + if not username: await msg.finish(msg.locale.t("maimai.message.no_username")) payload = {'username': username, 'b50': True} img = await generate(msg, payload) @@ -273,10 +273,10 @@ async def _(msg: Bot.MessageSession, id_or_alias: str, username: str = None): @mai.command('plate [] {{maimai.help.plate}}') async def _(msg: Bot.MessageSession, plate: str, username: str = None): - if username is None and msg.target.sender_from == "QQ": + if not username and msg.target.sender_from == "QQ": payload = {'qq': msg.session.sender} else: - if username is None: + if not username: await msg.finish(msg.locale.t("maimai.message.no_username")) payload = {'username': username} @@ -313,10 +313,10 @@ async def _(msg: Bot.MessageSession, level: str, goal: str, username: str = None "FDX", "FDX+"] - if username is None and msg.target.sender_from == "QQ": + if not username and msg.target.sender_from == "QQ": payload = {'qq': msg.session.sender} else: - if username is None: + if not username: await msg.finish(msg.locale.t("maimai.message.no_username")) payload = {'username': username} @@ -325,10 +325,10 @@ async def _(msg: Bot.MessageSession, level: str, goal: str, username: str = None if level_num < 8: await msg.finish(msg.locale.t("maimai.message.process.less_than_8")) else: - await msg.finish(msg.locale.t("maimai.message.process.error.goal_invalid")) + await msg.finish(msg.locale.t("maimai.message.level_invalid")) if goal.upper() not in goal_list: - await msg.finish(msg.locale.t("maimai.message.process.error.goal_invalid")) + await msg.finish(msg.locale.t("maimai.message.goal_invalid")) output, get_img = await get_level_process(msg, payload, level, goal) @@ -341,10 +341,10 @@ async def _(msg: Bot.MessageSession, level: str, goal: str, username: str = None @mai.command('rank [] {{maimai.help.rank}}') async def _(msg: Bot.MessageSession, username: str = None): - if username is None and msg.target.sender_from == "QQ": + if not username and msg.target.sender_from == "QQ": payload = {'qq': msg.session.sender} else: - if username is None: + if not username: await msg.finish(msg.locale.t("maimai.message.no_username")) payload = {'username': username} @@ -353,10 +353,10 @@ async def _(msg: Bot.MessageSession, username: str = None): @mai.command('scorelist [] {{maimai.help.scorelist}}') async def _(msg: Bot.MessageSession, level: str, username: str = None): - if username is None and msg.target.sender_from == "QQ": + if not username and msg.target.sender_from == "QQ": payload = {'qq': msg.session.sender} else: - if username is None: + if not username: await msg.finish(msg.locale.t("maimai.message.no_username")) payload = {'username': username} @@ -414,8 +414,8 @@ async def _(msg: Bot.MessageSession): await msg.finish(await get_info(msg, music, Plain(f"\n{'/'.join(str(ds) for ds in music.ds)}"))) -@mai.command('scoreline {{maimai.help.scoreline}}') -async def _(msg: Bot.MessageSession, diff: str, sid: str, scoreline: float): +@mai.command('scoreline {{maimai.help.scoreline}}') +async def _(msg: Bot.MessageSession, diff: str, sid: str, score: float): try: if not sid.isdigit(): if sid[:2].lower() == "id": @@ -434,7 +434,7 @@ async def _(msg: Bot.MessageSession, diff: str, sid: str, scoreline: float): bonus_score = total_score * 0.01 / brk # 奖励分 break_2550_reduce = bonus_score * 0.25 # 一个 BREAK 2550 减少 25% 奖励分 break_2000_reduce = bonus_score * 0.6 + 500 # 一个 BREAK 2000 减少 500 基础分和 60% 奖励分 - reduce = 101 - scoreline # 理论值与给定完成率的差,以百分比计 + reduce = 101 - score # 理论值与给定完成率的差,以百分比计 if reduce <= 0 or reduce >= 101: raise ValueError tap_great = "{:.2f}".format(total_score * reduce / 10000) # 一个 TAP GREAT 减少 100 分 @@ -445,7 +445,7 @@ async def _(msg: Bot.MessageSession, diff: str, sid: str, scoreline: float): b2t_2000_great_prop = "{:.4f}".format(break_2000_reduce / total_score * 100) await msg.finish(f'''{music['title']}{msg.locale.t('message.brackets', msg='DX') if music['type'] == 'DX' else ''} {diff_label[diff_index]} {msg.locale.t('maimai.message.scoreline', - scoreline=scoreline, + scoreline=score, tap_great=tap_great, tap_great_prop=tap_great_prop, brk=brk, @@ -457,6 +457,48 @@ async def _(msg: Bot.MessageSession, diff: str, sid: str, scoreline: float): await msg.finish(msg.locale.t('maimai.message.scoreline.error', prefix=command_prefix[0])) +@mai.command('rating [] {{maimai.help.rating}}') +async def _(msg: Bot.MessageSession, base: float, score: float): + if base > 15 or base < 0: + await msg.finish(msg.locale.t('maimai.message.base_invalid')) + if score: + await msg.finish(computeRa(base, score)) +# else: +# ... + +def computeRa(base: float, achievement: float) -> int: + if achievement < 50: + baseRa = 7.0 + elif achievement < 60: + baseRa = 8.0 + elif achievement < 70: + baseRa = 9.6 + elif achievement < 75: + baseRa = 11.2 + elif achievement < 80: + baseRa = 12.0 + elif achievement < 90: + baseRa = 13.6 + elif achievement < 94: + baseRa = 15.2 + elif achievement < 97: + baseRa = 16.8 + elif achievement < 98: + baseRa = 20.0 + elif achievement < 99: + baseRa = 20.3 + elif achievement < 99.5: + baseRa = 20.8 + elif achievement < 100: + baseRa = 21.1 + elif achievement < 100.5: + baseRa = 21.6 + else: + baseRa = 22.4 + + return math.floor(base * (min(100.5, achievement) / 100) * baseRa) + + @mai.command('update', required_superuser=True) async def _(msg: Bot.MessageSession): if await update_alias() and await update_covers(): @@ -465,7 +507,7 @@ async def _(msg: Bot.MessageSession): await msg.finish(msg.locale.t("failed")) -@mai.schedule(CronTrigger.from_crontab('0 */12 * * *')) +@mai.schedule(CronTrigger.from_crontab('0 0 * * *')) async def _(): Logger.info('Updating maimai alias...') try: diff --git a/modules/maimai/libraries/maimai_best_50.py b/modules/maimai/libraries/maimai_best_50.py index ac3d7ad4..bfdb40e1 100644 --- a/modules/maimai/libraries/maimai_best_50.py +++ b/modules/maimai/libraries/maimai_best_50.py @@ -7,6 +7,7 @@ from PIL import Image, ImageDraw, ImageFont, ImageFilter from core.builtins import ErrorMessage from core.utils.http import post_url +from modules.maimai import computeRa from .maimaidx_music import get_cover_len5_id, TotalList total_list = TotalList() @@ -361,38 +362,6 @@ class DrawBest(object): return self.img -def computeRa(ds: float, achievement: float) -> int: - baseRa = 22.4 - if achievement < 50: - baseRa = 7.0 - elif achievement < 60: - baseRa = 8.0 - elif achievement < 70: - baseRa = 9.6 - elif achievement < 75: - baseRa = 11.2 - elif achievement < 80: - baseRa = 12.0 - elif achievement < 90: - baseRa = 13.6 - elif achievement < 94: - baseRa = 15.2 - elif achievement < 97: - baseRa = 16.8 - elif achievement < 98: - baseRa = 20.0 - elif achievement < 99: - baseRa = 20.3 - elif achievement < 99.5: - baseRa = 20.8 - elif achievement < 100: - baseRa = 21.1 - elif achievement < 100.5: - baseRa = 21.6 - - return math.floor(ds * (min(100.5, achievement) / 100) * baseRa) - - async def generate(msg, payload) -> Tuple[Optional[Image.Image], bool]: try: resp = await post_url('https://www.diving-fish.com/api/maimaidxprober/query/player', diff --git a/modules/maimai/libraries/maimaidx_api_data.py b/modules/maimai/libraries/maimaidx_api_data.py index 384050c2..ae2e2c57 100644 --- a/modules/maimai/libraries/maimaidx_api_data.py +++ b/modules/maimai/libraries/maimaidx_api_data.py @@ -1,5 +1,6 @@ import os import shutil +import traceback import ujson as json @@ -105,7 +106,7 @@ async def get_record(msg, payload): data=json.dumps(payload), status_code=200, headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json') - except Exception as e: + except ValueError as e: if str(e).startswith('400'): if "qq" in payload: await msg.finish(msg.locale.t("maimai.message.user_unbound")) @@ -114,7 +115,8 @@ async def get_record(msg, payload): elif str(e).startswith('403'): await msg.finish(msg.locale.t("maimai.message.forbidden")) else: - raise + traceback.print_exc() + return data @@ -125,7 +127,7 @@ async def get_plate(msg, payload): data=json.dumps(payload), status_code=200, headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json') - except Exception as e: + except ValueError as e: if str(e).startswith('400'): if "qq" in payload: await msg.finish(msg.locale.t("maimai.message.user_unbound")) @@ -134,5 +136,6 @@ async def get_plate(msg, payload): elif str(e).startswith('403'): await msg.finish(msg.locale.t("maimai.message.forbidden")) else: - raise + traceback.print_exc() + return data diff --git a/modules/maimai/libraries/maimaidx_project.py b/modules/maimai/libraries/maimaidx_project.py index 678dc899..5b44f2b5 100644 --- a/modules/maimai/libraries/maimaidx_project.py +++ b/modules/maimai/libraries/maimaidx_project.py @@ -89,19 +89,21 @@ sync_rank = list(sync_conversion.keys()) # Sync字典的键(API内显示) async def get_rank(msg, payload): - player_data = await get_record(msg, payload) + time = msg.ts2strftime(datetime.now().timestamp(), timezone=False) - username = player_data['username'] url = f"https://www.diving-fish.com/api/maimaidxprober/rating_ranking" rank_data = await get_url(url, 200, fmt='json') - sorted_data = sorted(rank_data, key=lambda x: x['ra'], reverse=True) # 根据rating排名并倒序 + rank_data = sorted(rank_data, key=lambda x: x['ra'], reverse=True) # 根据rating排名并倒序 + + player_data = await get_record(msg, payload) + username = player_data['username'] rating = 0 rank = None total_rating = 0 - total_rank = len(sorted_data) + total_rank = len(rank_data) - for i, scoreboard in enumerate(sorted_data): + for i, scoreboard in enumerate(rank_data): if scoreboard['username'] == username: rank = i + 1 rating = scoreboard['ra'] @@ -112,10 +114,6 @@ async def get_rank(msg, payload): average_rating = total_rating / total_rank surpassing_rate = (total_rank - rank) / total_rank * 100 - time = msg.ts2strftime(datetime.now().timestamp(), timezone=False) - - formatted_average_rating = "{:.4f}".format(average_rating) - formatted_surpassing_rate = "{:.2f}".format(surpassing_rate) await msg.finish(msg.locale.t('maimai.message.rank', time=time, @@ -123,8 +121,8 @@ async def get_rank(msg, payload): user=username, rating=rating, rank=rank, - average_rating=formatted_average_rating, - surpassing_rate=formatted_surpassing_rate)) + average_rating="{:.4f}".format(average_rating), + surpassing_rate="{:.2f}".format(surpassing_rate))) async def get_player_score(msg, payload, input_id): diff --git a/modules/maimai/locales/en_us.json b/modules/maimai/locales/en_us.json index 124a9fce..157f70f1 100644 --- a/modules/maimai/locales/en_us.json +++ b/modules/maimai/locales/en_us.json @@ -30,8 +30,10 @@ "maimai.message.chart_not_found": "未找到符合要求的谱面。", "maimai.message.error.non_digital": "发生错误:歌曲 ID 必须为数字!", "maimai.message.forbidden": "此用户禁止了其他人获取数据。", + "maimai.message.goal_invalid": "无效的目标评级,请检查输入。", "maimai.message.info.no_record": "未游玩过此谱面", "maimai.message.level": "以下为 ${level} 级的曲目列表:", + "maimai.message.level_invalid": "无效的等级,请检查输入。", "maimai.message.music_not_found": "未找到符合要求的歌曲。", "maimai.message.no_username": "请提供用户名!", "maimai.message.plate": "您的${plate}剩余进度如下:\nBasic 剩余 ${song_remain_basic} 首,\nAdvanced 剩余 ${song_remain_advanced} 首,\nExpert 剩余 ${song_remain_expert} 首,\nMaster 剩余 ${song_remain_master} 首", @@ -44,8 +46,6 @@ "maimai.message.plate.remaster": ",\nRe:MASTER 剩余 ${song_remain_remaster} 首", "maimai.message.process": "您还有 ${song_remain} 首 ${process} 级曲目没有达成 ${goal}。", "maimai.message.process.completed": "您已达成 ${process} 级曲目全谱面 ${goal}。", - "maimai.message.process.error.goal_invalid": "发生错误:无效的目标评级,请检查输入。", - "maimai.message.process.error.level_invalid": "发生错误:无效的等级,请检查输入。", "maimai.message.process.last": "您的 ${process} 级歌曲全谱面 ${goal} 剩余曲目如下:", "maimai.message.process.less_than_8": "歌曲等级必须大于 8 级。", "maimai.message.random.error": "发生错误:随机歌曲失败,请检查输入。", diff --git a/modules/maimai/locales/zh_cn.json b/modules/maimai/locales/zh_cn.json index 1ce3253c..79ae1c82 100644 --- a/modules/maimai/locales/zh_cn.json +++ b/modules/maimai/locales/zh_cn.json @@ -18,6 +18,7 @@ "maimai.help.random": "随机一首歌曲。", "maimai.help.random.filter": "随机一首指定条件的歌曲,输入为“*”则表示无条件。", "maimai.help.rank": "查看用户在查分器上的分数排行。", + "maimai.help.rating": "根据定数计算 Rating。", "maimai.help.scoreline": "查询歌曲的分数线。", "maimai.help.scorelist": "查看用户在对应等级的分数列表。", "maimai.help.search": "根据歌名(或一部分)搜索歌曲。", @@ -27,11 +28,14 @@ "maimai.message.alias.file_not_found": "未找到别名文件,请使用“${prefix}maimai update”初始化文件。", "maimai.message.base": "以下为定数 ${constant} 的曲目列表:", "maimai.message.base.range": "以下为定数 ${constant}-${constant_max} 的曲目列表:", + "maimai.message.base_invalid": "无效的定数,请检查输入。", "maimai.message.chart_not_found": "未找到符合要求的谱面。", "maimai.message.error.non_digital": "发生错误:歌曲 ID 必须为数字!", "maimai.message.forbidden": "此用户禁止了其他人获取数据。", + "maimai.message.goal_invalid": "无效的目标评级,请检查输入。", "maimai.message.info.no_record": "未游玩过此谱面", "maimai.message.level": "以下为 ${level} 级的曲目列表:", + "maimai.message.level_invalid": "无效的等级,请检查输入。", "maimai.message.music_not_found": "未找到符合要求的歌曲。", "maimai.message.no_username": "请提供用户名!", "maimai.message.plate": "您的${plate}剩余进度如下:\nBasic 剩余 ${song_remain_basic} 首,\nAdvanced 剩余 ${song_remain_advanced} 首,\nExpert 剩余 ${song_remain_expert} 首,\nMaster 剩余 ${song_remain_master} 首", @@ -44,8 +48,6 @@ "maimai.message.plate.remaster": ",\nRe:MASTER 剩余 ${song_remain_remaster} 首", "maimai.message.process": "您还有 ${song_remain} 首 ${process} 级曲目没有达成 ${goal}。", "maimai.message.process.completed": "您已达成 ${process} 级曲目全谱面 ${goal}。", - "maimai.message.process.error.goal_invalid": "发生错误:无效的目标评级,请检查输入。", - "maimai.message.process.error.level_invalid": "发生错误:无效的等级,请检查输入。", "maimai.message.process.last": "您的 ${process} 级歌曲全谱面 ${goal} 剩余曲目如下:", "maimai.message.process.less_than_8": "歌曲等级必须大于 8 级。", "maimai.message.random.error": "发生错误:随机歌曲失败,请检查输入。", diff --git a/modules/maimai/locales/zh_tw.json b/modules/maimai/locales/zh_tw.json index 6c753b7a..87feee00 100644 --- a/modules/maimai/locales/zh_tw.json +++ b/modules/maimai/locales/zh_tw.json @@ -18,6 +18,7 @@ "maimai.help.random": "隨機一首歌曲。", "maimai.help.random.filter": "隨機一首指定條件的歌曲,輸入「*」則表示無條件。", "maimai.help.rank": "查看使用者在查分器上的分數排行。", + "maimai.help.rating": "依據定數計算 Rating。", "maimai.help.scoreline": "查詢歌曲的分數線。", "maimai.help.scorelist": "查看使用者在對應等級的分數列表。", "maimai.help.search": "依據歌名(或一部分)搜尋歌曲。", @@ -27,11 +28,14 @@ "maimai.message.alias.file_not_found": "未找到別名檔案,請使用「${prefix}maimai update」初始化檔案。", "maimai.message.base": "以下為定數 ${constant} 的曲目列表:", "maimai.message.base.range": "以下為定數 ${constant}-${constant_max} 的曲目列表:", + "maimai.message.base_invalid": "無效的定數,請校對輸入。", "maimai.message.chart_not_found": "未找到符合要求的譜面。", "maimai.message.error.non_digital": "發生錯誤:歌曲 ID 必須為數字!", "maimai.message.forbidden": "此使用者禁止了其他人取得資料。", + "maimai.message.goal_invalid": "無效的目標評級,請校對輸入。", "maimai.message.info.no_record": "未遊玩過此譜面", "maimai.message.level": "以下為難度 ${level} 的曲目列表:", + "maimai.message.level_invalid": "無效的等級,請校對輸入。", "maimai.message.music_not_found": "未找到符合要求的歌曲。", "maimai.message.no_username": "請提供使用者名稱!", "maimai.message.plate": "您的${plate}剩餘進度如下:\nBasic 剩餘 ${song_remain_basic} 首,\nAdvanced 剩餘 ${song_remain_advanced} 首,\nExpert 剩餘 ${song_remain_expert} 首,\nMaster 剩餘 ${song_remain_master} 首", @@ -44,8 +48,6 @@ "maimai.message.plate.remaster": ",Re:MASTER 剩餘 ${song_remain_remaster} 首", "maimai.message.process": "您還有 ${song_remain} 首 ${process} 級曲目沒有達成 ${goal}。", "maimai.message.process.completed": "您已達成 ${process} 級曲目全譜面 ${goal}。", - "maimai.message.process.error.goal_invalid": "發生錯誤:無效的目標評級,請校對輸入。", - "maimai.message.process.error.level_invalid": "發生錯誤:無效的等級,請校對輸入。", "maimai.message.process.last": "您的 ${process} 級歌曲全譜面 ${goal} 剩餘曲目如下:", "maimai.message.process.less_than_8": "歌曲等級必須大於 8 級。", "maimai.message.random.error": "發生錯誤:無法隨機歌曲,請校對輸入。", diff --git a/modules/maimai/regex.py b/modules/maimai/regex.py index 3ba975dc..aa63ef45 100644 --- a/modules/maimai/regex.py +++ b/modules/maimai/regex.py @@ -213,7 +213,7 @@ async def _(msg: Bot.MessageSession): return if goal.upper() not in goal_list: - await msg.finish(msg.locale.t("maimai.message.process.error.goal_invalid")) + await msg.finish(msg.locale.t("maimai.message.goal_invalid")) output, get_img = await get_level_process(msg, payload, level, goal) From fe1ab784c0d6de9c224e7e43fa3fb401af79a830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 14:02:51 +0800 Subject: [PATCH 15/22] fix --- modules/maimai/__init__.py | 67 +++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/modules/maimai/__init__.py b/modules/maimai/__init__.py index a9440c11..5da4a2d4 100644 --- a/modules/maimai/__init__.py +++ b/modules/maimai/__init__.py @@ -40,6 +40,39 @@ def get_diff(diff): return level +def computeRa(base: float, achievement: float) -> int: + if achievement < 50: + baseRa = 7.0 + elif achievement < 60: + baseRa = 8.0 + elif achievement < 70: + baseRa = 9.6 + elif achievement < 75: + baseRa = 11.2 + elif achievement < 80: + baseRa = 12.0 + elif achievement < 90: + baseRa = 13.6 + elif achievement < 94: + baseRa = 15.2 + elif achievement < 97: + baseRa = 16.8 + elif achievement < 98: + baseRa = 20.0 + elif achievement < 99: + baseRa = 20.3 + elif achievement < 99.5: + baseRa = 20.8 + elif achievement < 100: + baseRa = 21.1 + elif achievement < 100.5: + baseRa = 21.6 + else: + baseRa = 22.4 + + return math.floor(base * (min(100.5, achievement) / 100) * baseRa) + + mai = module('maimai', recommend_modules='maimai_regex', developers=['mai-bot', 'OasisAkari', 'DoroWolf'], alias='mai', support_languages=['zh_cn'], desc='{maimai.help.desc}') @@ -457,7 +490,7 @@ async def _(msg: Bot.MessageSession, diff: str, sid: str, score: float): await msg.finish(msg.locale.t('maimai.message.scoreline.error', prefix=command_prefix[0])) -@mai.command('rating [] {{maimai.help.rating}}') +@mai.command('rating {{maimai.help.rating}}') async def _(msg: Bot.MessageSession, base: float, score: float): if base > 15 or base < 0: await msg.finish(msg.locale.t('maimai.message.base_invalid')) @@ -466,38 +499,6 @@ async def _(msg: Bot.MessageSession, base: float, score: float): # else: # ... -def computeRa(base: float, achievement: float) -> int: - if achievement < 50: - baseRa = 7.0 - elif achievement < 60: - baseRa = 8.0 - elif achievement < 70: - baseRa = 9.6 - elif achievement < 75: - baseRa = 11.2 - elif achievement < 80: - baseRa = 12.0 - elif achievement < 90: - baseRa = 13.6 - elif achievement < 94: - baseRa = 15.2 - elif achievement < 97: - baseRa = 16.8 - elif achievement < 98: - baseRa = 20.0 - elif achievement < 99: - baseRa = 20.3 - elif achievement < 99.5: - baseRa = 20.8 - elif achievement < 100: - baseRa = 21.1 - elif achievement < 100.5: - baseRa = 21.6 - else: - baseRa = 22.4 - - return math.floor(base * (min(100.5, achievement) / 100) * baseRa) - @mai.command('update', required_superuser=True) async def _(msg: Bot.MessageSession): From d8de389335aa0f92c7a1a2e6bece3636c909804b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 14:05:26 +0800 Subject: [PATCH 16/22] fix --- modules/maimai/__init__.py | 65 +++++++++++----------- modules/maimai/libraries/maimai_best_50.py | 34 ++++++++++- 2 files changed, 65 insertions(+), 34 deletions(-) diff --git a/modules/maimai/__init__.py b/modules/maimai/__init__.py index 5da4a2d4..822d7db8 100644 --- a/modules/maimai/__init__.py +++ b/modules/maimai/__init__.py @@ -40,39 +40,6 @@ def get_diff(diff): return level -def computeRa(base: float, achievement: float) -> int: - if achievement < 50: - baseRa = 7.0 - elif achievement < 60: - baseRa = 8.0 - elif achievement < 70: - baseRa = 9.6 - elif achievement < 75: - baseRa = 11.2 - elif achievement < 80: - baseRa = 12.0 - elif achievement < 90: - baseRa = 13.6 - elif achievement < 94: - baseRa = 15.2 - elif achievement < 97: - baseRa = 16.8 - elif achievement < 98: - baseRa = 20.0 - elif achievement < 99: - baseRa = 20.3 - elif achievement < 99.5: - baseRa = 20.8 - elif achievement < 100: - baseRa = 21.1 - elif achievement < 100.5: - baseRa = 21.6 - else: - baseRa = 22.4 - - return math.floor(base * (min(100.5, achievement) / 100) * baseRa) - - mai = module('maimai', recommend_modules='maimai_regex', developers=['mai-bot', 'OasisAkari', 'DoroWolf'], alias='mai', support_languages=['zh_cn'], desc='{maimai.help.desc}') @@ -499,6 +466,38 @@ async def _(msg: Bot.MessageSession, base: float, score: float): # else: # ... +def computeRa(base: float, achievement: float) -> int: + if achievement < 50: + baseRa = 7.0 + elif achievement < 60: + baseRa = 8.0 + elif achievement < 70: + baseRa = 9.6 + elif achievement < 75: + baseRa = 11.2 + elif achievement < 80: + baseRa = 12.0 + elif achievement < 90: + baseRa = 13.6 + elif achievement < 94: + baseRa = 15.2 + elif achievement < 97: + baseRa = 16.8 + elif achievement < 98: + baseRa = 20.0 + elif achievement < 99: + baseRa = 20.3 + elif achievement < 99.5: + baseRa = 20.8 + elif achievement < 100: + baseRa = 21.1 + elif achievement < 100.5: + baseRa = 21.6 + else: + baseRa = 22.4 + + return math.floor(base * (min(100.5, achievement) / 100) * baseRa) + @mai.command('update', required_superuser=True) async def _(msg: Bot.MessageSession): diff --git a/modules/maimai/libraries/maimai_best_50.py b/modules/maimai/libraries/maimai_best_50.py index bfdb40e1..87727f14 100644 --- a/modules/maimai/libraries/maimai_best_50.py +++ b/modules/maimai/libraries/maimai_best_50.py @@ -7,7 +7,6 @@ from PIL import Image, ImageDraw, ImageFont, ImageFilter from core.builtins import ErrorMessage from core.utils.http import post_url -from modules.maimai import computeRa from .maimaidx_music import get_cover_len5_id, TotalList total_list = TotalList() @@ -362,6 +361,39 @@ class DrawBest(object): return self.img +def computeRa(ds: float, achievement: float) -> int: + if achievement < 50: + baseRa = 7.0 + elif achievement < 60: + baseRa = 8.0 + elif achievement < 70: + baseRa = 9.6 + elif achievement < 75: + baseRa = 11.2 + elif achievement < 80: + baseRa = 12.0 + elif achievement < 90: + baseRa = 13.6 + elif achievement < 94: + baseRa = 15.2 + elif achievement < 97: + baseRa = 16.8 + elif achievement < 98: + baseRa = 20.0 + elif achievement < 99: + baseRa = 20.3 + elif achievement < 99.5: + baseRa = 20.8 + elif achievement < 100: + baseRa = 21.1 + elif achievement < 100.5: + baseRa = 21.6 + else: + baseRa = 22.4 + + return math.floor(ds * (min(100.5, achievement) / 100) * baseRa) + + async def generate(msg, payload) -> Tuple[Optional[Image.Image], bool]: try: resp = await post_url('https://www.diving-fish.com/api/maimaidxprober/query/player', From 33e0cb528ec8cd35437904f461043006a0ba2c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 14:07:48 +0800 Subject: [PATCH 17/22] update --- modules/maimai/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/maimai/__init__.py b/modules/maimai/__init__.py index 822d7db8..a30b0858 100644 --- a/modules/maimai/__init__.py +++ b/modules/maimai/__init__.py @@ -462,7 +462,7 @@ async def _(msg: Bot.MessageSession, base: float, score: float): if base > 15 or base < 0: await msg.finish(msg.locale.t('maimai.message.base_invalid')) if score: - await msg.finish(computeRa(base, score)) + await msg.finish(Plain[computeRa(base, score)]) # else: # ... From e4e776e21e84539aca95cb3558d529e0f8ff7a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 14:11:18 +0800 Subject: [PATCH 18/22] fix wssb --- modules/maimai/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/maimai/__init__.py b/modules/maimai/__init__.py index a30b0858..98885e66 100644 --- a/modules/maimai/__init__.py +++ b/modules/maimai/__init__.py @@ -462,9 +462,7 @@ async def _(msg: Bot.MessageSession, base: float, score: float): if base > 15 or base < 0: await msg.finish(msg.locale.t('maimai.message.base_invalid')) if score: - await msg.finish(Plain[computeRa(base, score)]) -# else: -# ... + await msg.finish([Plain(computeRa(base, score))]) def computeRa(base: float, achievement: float) -> int: if achievement < 50: From 8b15fe4d7bf813c7b8b74eee7f687957a146f751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 14:22:16 +0800 Subject: [PATCH 19/22] . --- modules/maimai/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/maimai/__init__.py b/modules/maimai/__init__.py index 98885e66..87e66ddb 100644 --- a/modules/maimai/__init__.py +++ b/modules/maimai/__init__.py @@ -459,7 +459,7 @@ async def _(msg: Bot.MessageSession, diff: str, sid: str, score: float): @mai.command('rating {{maimai.help.rating}}') async def _(msg: Bot.MessageSession, base: float, score: float): - if base > 15 or base < 0: + if base > 15 or base < 1: await msg.finish(msg.locale.t('maimai.message.base_invalid')) if score: await msg.finish([Plain(computeRa(base, score))]) From ed3cb8d630113ed50850edd29a76d94f8259cdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 14:27:36 +0800 Subject: [PATCH 20/22] upd --- modules/maimai/__init__.py | 4 +--- modules/maimai/locales/zh_cn.json | 3 +-- modules/maimai/locales/zh_tw.json | 3 +-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/modules/maimai/__init__.py b/modules/maimai/__init__.py index 87e66ddb..21263c25 100644 --- a/modules/maimai/__init__.py +++ b/modules/maimai/__init__.py @@ -459,10 +459,8 @@ async def _(msg: Bot.MessageSession, diff: str, sid: str, score: float): @mai.command('rating {{maimai.help.rating}}') async def _(msg: Bot.MessageSession, base: float, score: float): - if base > 15 or base < 1: - await msg.finish(msg.locale.t('maimai.message.base_invalid')) if score: - await msg.finish([Plain(computeRa(base, score))]) + await msg.finish([Plain(max(0, computeRa(base, score)))]) def computeRa(base: float, achievement: float) -> int: if achievement < 50: diff --git a/modules/maimai/locales/zh_cn.json b/modules/maimai/locales/zh_cn.json index 79ae1c82..d2183f51 100644 --- a/modules/maimai/locales/zh_cn.json +++ b/modules/maimai/locales/zh_cn.json @@ -28,7 +28,6 @@ "maimai.message.alias.file_not_found": "未找到别名文件,请使用“${prefix}maimai update”初始化文件。", "maimai.message.base": "以下为定数 ${constant} 的曲目列表:", "maimai.message.base.range": "以下为定数 ${constant}-${constant_max} 的曲目列表:", - "maimai.message.base_invalid": "无效的定数,请检查输入。", "maimai.message.chart_not_found": "未找到符合要求的谱面。", "maimai.message.error.non_digital": "发生错误:歌曲 ID 必须为数字!", "maimai.message.forbidden": "此用户禁止了其他人获取数据。", @@ -54,7 +53,7 @@ "maimai.message.rank": "截至 ${time},\n查分器共有 ${total_rank} 名用户,平均分数为 ${average_rating}。\n${user} 的分数为 ${rating},排名为 #${rank},\n已经超越了 ${surpassing_rate}% 的玩家。", "maimai.message.scoreline": "分数线 ${scoreline}% 允许的最多 TAP GREAT 数量为 ${tap_great}(每个-${tap_great_prop}%),\nBREAK 2550(一共 ${brk} 个)等价于 ${b2t_2550_great} 个 TAP GREAT(-${b2t_2550_great_prop}%),\nBREAK 2000(一共 ${brk} 个)等价于 ${b2t_2000_great} 个 TAP GREAT(-${b2t_2000_great_prop}%)", "maimai.message.scoreline.error": "发生错误:计算结果失败,请检查输入。", - "maimai.message.scorelist": "以下为 ${user} 的 ${level} 级分数列表:", + "maimai.message.scorelist": "以下为 ${user} 的 ${level} 级成绩列表:", "maimai.message.search": "“${keyword}”的搜索结果:", "maimai.message.song": "艺术家:${artist}\n分类:${genre}\nBPM:${bpm}\n版本:${version}\n难度:${level}", "maimai.message.song.dx": "${diff} ${level} (${ds})\nTAP:${tap}\nHOLD:${hold}\nSLIDE:${slide}\nTOUCH:${touch}\nBREAK:${brk}\n谱师:${charter}", diff --git a/modules/maimai/locales/zh_tw.json b/modules/maimai/locales/zh_tw.json index 87feee00..40c8dd19 100644 --- a/modules/maimai/locales/zh_tw.json +++ b/modules/maimai/locales/zh_tw.json @@ -28,7 +28,6 @@ "maimai.message.alias.file_not_found": "未找到別名檔案,請使用「${prefix}maimai update」初始化檔案。", "maimai.message.base": "以下為定數 ${constant} 的曲目列表:", "maimai.message.base.range": "以下為定數 ${constant}-${constant_max} 的曲目列表:", - "maimai.message.base_invalid": "無效的定數,請校對輸入。", "maimai.message.chart_not_found": "未找到符合要求的譜面。", "maimai.message.error.non_digital": "發生錯誤:歌曲 ID 必須為數字!", "maimai.message.forbidden": "此使用者禁止了其他人取得資料。", @@ -54,7 +53,7 @@ "maimai.message.rank": "截至 ${time},\n查分器共有 ${total_rank} 名使用者,平均分數為 ${average_rating},\n${user} 的分數為 ${rating},排名為 #${rank},\n已經超越了 ${surpassing_rate}% 的玩家。", "maimai.message.scoreline": "分數線 ${scoreline}% 允許的最多 TAP GREAT 數量為 ${tap_great}(每個-${tap_great_prop}%)。\nBREAK 2550(一共 ${brk} 個)相當於 ${b2t_2550_great} 個 TAP GREAT(-${b2t_2550_great_prop}%),\nBREAK 2000(一共 ${brk} 個)相當於 ${b2t_2000_great} 個 TAP GREAT(-${b2t_2000_great_prop}%)", "maimai.message.scoreline.error": "發生錯誤:無法計算結果,請校對輸入。", - "maimai.message.scorelist": "以下為 ${user} 的 ${level} 級分數列表:", + "maimai.message.scorelist": "以下為 ${user} 的 ${level} 級成績列表:", "maimai.message.search": "「${keyword}」的搜尋結果:", "maimai.message.song": "藝術家:${artist}\n分類:${genre}\nBPM:${bpm}\n版本:${version}\n難度:${level}", "maimai.message.song.dx": "${diff} ${level} (${ds})\nTAP:${tap}\nHOLD:${hold}\nSLIDE:${slide}\nTOUCH:${touch}\nBREAK:${brk}\n譜師:${charter}", From b9499faaf96ad7601b8c608342e972de51f1c995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 21:17:18 +0800 Subject: [PATCH 21/22] Update slash commands --- bots/discord/slash/arcaea.py | 34 ++++---------------- bots/discord/slash/{bug.py => bugtracker.py} | 7 ++-- bots/discord/slash/cytoid.py | 14 ++++---- bots/discord/slash/mcplayer.py | 8 ++--- bots/discord/slash/mcv.py | 13 +++++--- bots/discord/slash/server.py | 4 +-- bots/discord/slash/tweet.py | 8 ++--- modules/arcaea/locales/en_us.json | 2 +- modules/cytoid/locales/en_us.json | 2 +- modules/github/__init__.py | 2 +- modules/github/locales/en_us.json | 12 +++---- modules/server/__init__.py | 6 ++-- 12 files changed, 47 insertions(+), 65 deletions(-) rename bots/discord/slash/{bug.py => bugtracker.py} (57%) diff --git a/bots/discord/slash/arcaea.py b/bots/discord/slash/arcaea.py index 1eca2d4e..5ef7b7e3 100644 --- a/bots/discord/slash/arcaea.py +++ b/bots/discord/slash/arcaea.py @@ -3,48 +3,26 @@ import discord from bots.discord.client import client from bots.discord.slash_parser import slash_parser -arcaea = client.create_group("arcaea", "查询arcaea的相关信息") +arcaea = client.create_group("arcaea", "Queries about Arcaea.") - -@arcaea.command(description="查询best30列表") -async def b30(ctx: discord.ApplicationContext): - await slash_parser(ctx, "b30") - - -@arcaea.command(description="查询最近游玩记录") -async def info(ctx: discord.ApplicationContext): - await slash_parser(ctx, "info") - - -@arcaea.command(description="绑定账户") -@discord.option(name="friendcode", description="好友代码") -async def bind(ctx: discord.ApplicationContext, friendcode: str): - await slash_parser(ctx, f"bind {friendcode}") - - -@arcaea.command(description="取消绑定账户") -async def unbind(ctx: discord.ApplicationContext): - await slash_parser(ctx, "unbind") - - -@arcaea.command(description="获取最新版本的arcaea安卓版链接") +@arcaea.command(description="Get the latest version of game apk.") async def download(ctx: discord.ApplicationContext): await slash_parser(ctx, "download") -@arcaea.command(description="随机一首歌曲") +@arcaea.command(description="Random a song.") async def random(ctx: discord.ApplicationContext): await slash_parser(ctx, "random") -rank = arcaea.create_subgroup("rank", "查询arcaea日排行榜的相关信息") +rank = arcaea.create_subgroup("rank", "View the current daily rank of Arcaea songs.") -@rank.command(description="查询arcaea免费包当前日排行榜") +@rank.command(description="View the current rank of the free packs.") async def free(ctx: discord.ApplicationContext): await slash_parser(ctx, "rank free") -@rank.command(description="查询arcaea收费包当前日排行榜") +@rank.command(description="View the current rank of the paid packs.") async def paid(ctx: discord.ApplicationContext): await slash_parser(ctx, "rank paid") diff --git a/bots/discord/slash/bug.py b/bots/discord/slash/bugtracker.py similarity index 57% rename from bots/discord/slash/bug.py rename to bots/discord/slash/bugtracker.py index a44b9162..1050bfd5 100644 --- a/bots/discord/slash/bug.py +++ b/bots/discord/slash/bugtracker.py @@ -6,10 +6,9 @@ from bots.discord.slash_parser import slash_parser async def auto_search(ctx: discord.AutocompleteContext): if ctx.options["mojiraid"] == '': - return ['MC-', 'MCPE-', 'MCD-', 'MCL-', 'REALMS-', 'WEB-', 'MCCE-'] + return ['BDS-', 'MCPE-', 'MCD-', 'MCL-', 'MCLG-', 'REALMS-', 'MC-', 'WEB-'] - -@client.command(description="查询一个已记录在Mojira上的bug信息") +@client.command(description="Query the corresponding ticket on Mojira.") @discord.option(name="mojiraid", autocomplete=auto_search) -async def bug(ctx: discord.ApplicationContext, mojiraid: str): +async def bugtracker(ctx: discord.ApplicationContext, mojiraid: str): await slash_parser(ctx, mojiraid) diff --git a/bots/discord/slash/cytoid.py b/bots/discord/slash/cytoid.py index 40545a52..f0bc3b8c 100644 --- a/bots/discord/slash/cytoid.py +++ b/bots/discord/slash/cytoid.py @@ -3,30 +3,30 @@ import discord from bots.discord.client import client from bots.discord.slash_parser import slash_parser -cytoid = client.create_group("cytoid", "查询Cytoid的相关信息") +cytoid = client.create_group("cytoid", "Query about Cytoid.") -@cytoid.command(description="查询Best30列表") +@cytoid.command(description="Query the Best 30 list.") async def b30(ctx: discord.ApplicationContext): await slash_parser(ctx, "b30") -@cytoid.command(description="查询Recent30列表") +@cytoid.command(description="Query the Recent 30 list.") async def r30(ctx: discord.ApplicationContext): await slash_parser(ctx, "r30") -@cytoid.command(description="查询个人信息") +@cytoid.command(description="Query user profile.") async def profile(ctx: discord.ApplicationContext): await slash_parser(ctx, "profile") -@cytoid.command(description="绑定用户") -@discord.option(name="username", description="用户名") +@cytoid.command(description="Bind user.") +@discord.option(name="username", description="Your Cytoid username.") async def bind(ctx: discord.ApplicationContext, username: str): await slash_parser(ctx, f"bind {username}") -@cytoid.command(description="取消绑定用户") +@cytoid.command(description="Unbind user.") async def unbind(ctx: discord.ApplicationContext): await slash_parser(ctx, "unbind") diff --git a/bots/discord/slash/mcplayer.py b/bots/discord/slash/mcplayer.py index 7be0d948..babaeed3 100644 --- a/bots/discord/slash/mcplayer.py +++ b/bots/discord/slash/mcplayer.py @@ -4,7 +4,7 @@ from bots.discord.client import client from bots.discord.slash_parser import slash_parser -@client.slash_command(description="获取一个Minecraft玩家的信息") -@discord.option(name="player", description="玩家名") -async def mcplayer(ctx: discord.ApplicationContext, player: str): - await slash_parser(ctx, player) +@client.slash_command(description="Get Minecraft player information.") +@discord.option(name="username_or_uuid", description="The name or UUID of Minecraft player.") +async def mcplayer(ctx: discord.ApplicationContext, username_or_uuid: str): + await slash_parser(ctx, username_or_uuid) diff --git a/bots/discord/slash/mcv.py b/bots/discord/slash/mcv.py index f1a0fbbf..b41cd91a 100644 --- a/bots/discord/slash/mcv.py +++ b/bots/discord/slash/mcv.py @@ -4,21 +4,26 @@ from bots.discord.client import client from bots.discord.slash_parser import slash_parser -@client.slash_command(description="获取Minecraft Java版的最新版本信息") +@client.slash_command(description="Get the latest version of Minecraft: Java Edition in the launcher.") async def mcv(ctx: discord.ApplicationContext): await slash_parser(ctx, '') -@client.slash_command(description="获取Minecraft基岩版的最新版本信息") +@client.slash_command(description="Get the latest version of Minecraft: Bedrock Edition on Mojira.") async def mcbv(ctx: discord.ApplicationContext): await slash_parser(ctx, '') -@client.slash_command(description="获取Minecraft Dungeons的最新版本信息") +@client.slash_command(description="Get the latest version of Minecraft Dungeons on Mojira.") async def mcdv(ctx: discord.ApplicationContext): await slash_parser(ctx, '') -@client.slash_command(description="获取Minecraft教育版的最新版本信息") +@client.slash_command(description="Get the latest version of Minecraft: Education Edition in Windows Edition.") async def mcev(ctx: discord.ApplicationContext): await slash_parser(ctx, '') + + +@client.slash_command(description="Get the latest version of Minecraft Legends on Mojira.") +async def mclgv(ctx: discord.ApplicationContext): + await slash_parser(ctx, '') \ No newline at end of file diff --git a/bots/discord/slash/server.py b/bots/discord/slash/server.py index b3dbb12b..02ea118c 100644 --- a/bots/discord/slash/server.py +++ b/bots/discord/slash/server.py @@ -10,7 +10,7 @@ async def auto_search(ctx: discord.AutocompleteContext): return [ctx.options["address"]] -@client.slash_command(description="获取一个Minecraft服务器的信息") -@discord.option(name="address", description="服务器地址", autocomplete=auto_search) +@client.slash_command(description="Get Minecraft: Java/Bedrock Edition server motd.") +@discord.option(name="address", description="The server address.", autocomplete=auto_search) async def server(ctx: discord.ApplicationContext, address: str): await slash_parser(ctx, address) diff --git a/bots/discord/slash/tweet.py b/bots/discord/slash/tweet.py index e6ce7841..e8893841 100644 --- a/bots/discord/slash/tweet.py +++ b/bots/discord/slash/tweet.py @@ -3,10 +3,10 @@ import discord from bots.discord.client import client from bots.discord.slash_parser import slash_parser -tweet = client.create_group("tweet", "获取推文摘要") +tweet = client.create_group("tweet", "Get tweet image from tweet ID or link.") @tweet.command() -@discord.option(name="tweetid", description="推文ID") -async def get(ctx: discord.ApplicationContext, tweetid: str): - await slash_parser(ctx, tweetid) +@discord.option(name="tweet", description="The tweet ID or tweet link.") +async def get(ctx: discord.ApplicationContext, tweet: str): + await slash_parser(ctx, tweet) diff --git a/modules/arcaea/locales/en_us.json b/modules/arcaea/locales/en_us.json index 4a7512d2..5927004c 100644 --- a/modules/arcaea/locales/en_us.json +++ b/modules/arcaea/locales/en_us.json @@ -2,7 +2,7 @@ "arcaea.help.calc": "Calculate the single Potential based on scores and rating.", "arcaea.help.desc": "Queries about Arcaea.", "arcaea.help.download": "Get the latest version of game apk.", - "arcaea.help.random": "Random a track.", + "arcaea.help.random": "Random a song.", "arcaea.help.rank.free": "View the current rank of the free packs.", "arcaea.help.rank.paid": "View the current rank of the paid packs.", "arcaea.message.download": "Current latest version is ${version}.\nDownload: ${url}", diff --git a/modules/cytoid/locales/en_us.json b/modules/cytoid/locales/en_us.json index c4d08391..19b67f9a 100644 --- a/modules/cytoid/locales/en_us.json +++ b/modules/cytoid/locales/en_us.json @@ -1,7 +1,7 @@ { "cytoid.help.b30": "Query the Best 30 list of Cytoid user. ", "cytoid.help.bind": "Bind Cytoid user.", - "cytoid.help.desc": "Query Cytoid related content.", + "cytoid.help.desc": "Query about Cytoid.", "cytoid.help.profile": "Query user profile.", "cytoid.help.r30": "Query the Recent 30 list of Cytoid user. ", "cytoid.help.unbind": "Unbind user.", diff --git a/modules/github/__init__.py b/modules/github/__init__.py index 5726a1d3..e68b54bc 100644 --- a/modules/github/__init__.py +++ b/modules/github/__init__.py @@ -18,7 +18,7 @@ async def _(msg: Bot.MessageSession): await repo.repo(msg) -@github.handle(('user {{github.help.user}}')) +@github.handle('user {{github.help.user}}') async def _(msg: Bot.MessageSession): await user.user(msg) diff --git a/modules/github/locales/en_us.json b/modules/github/locales/en_us.json index 56d59924..ac7f9c39 100644 --- a/modules/github/locales/en_us.json +++ b/modules/github/locales/en_us.json @@ -1,13 +1,13 @@ { "github.help.desc": "Github query tool.", "github.help": "Trying to automatically identifying and distinguishing repo/user.", - "github.help.repo": "Getting GitHub repository information.", - "github.help.search": "Searching repositories on GitHub.", - "github.help.user": "Getting GitHub user or organization information.", - "github.message.repo.not_found": "The repository does not exist, please check your input.", + "github.help.repo": "Get GitHub repository information.", + "github.help.search": "Search repositories on GitHub.", + "github.help.user": "Get GitHub user or organization information.", + "github.message.repo.not_found": "The repository does not exist. Please check your input.", "github.message.search": "Successfully to search for ${result} results:", "github.message.search.none": "No results found.", "github.message.search.more_information": "Truncated due to chat limits; ${more_result} more results may not be shown.", - "github.message.search.not_found": "The repository cannot be found; please check your input.", - "github.message.user.not_found": "The user cannot be found; please check your input." + "github.message.search.not_found": "The repository cannot be found. Please check your input.", + "github.message.user.not_found": "The user cannot be found. Please check your input." } \ No newline at end of file diff --git a/modules/server/__init__.py b/modules/server/__init__.py index f3509512..96d188ae 100644 --- a/modules/server/__init__.py +++ b/modules/server/__init__.py @@ -9,13 +9,13 @@ from .server import server s = module('server', alias='s', developers=['_LittleC_', 'OasisAkari']) -@s.command(' [-r] [-p] {{server.help}}', +@s.command(' [-r] [-p] {{server.help}}', options_desc={'-r': '{server.help.option.r}', '-p': '{server.help.option.p}'}) async def main(msg: Bot.MessageSession): gather_list = [] - match_object = re.match(r'(.*)[\s:](.*)', msg.parsed_msg[""], re.M | re.I) + match_object = re.match(r'(.*)[\s:](.*)', msg.parsed_msg[""], re.M | re.I) is_local_ip = False - server_address = msg.parsed_msg[""] + server_address = msg.parsed_msg[""] if match_object: server_address = match_object.group(1) From 954bfdbbc3a570954a2dc1db83427ca8e8ca437f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sun, 17 Dec 2023 21:28:30 +0800 Subject: [PATCH 22/22] fix --- modules/mcbbs_news/mcbbs_news.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mcbbs_news/mcbbs_news.py b/modules/mcbbs_news/mcbbs_news.py index 8a1f07ab..05636893 100644 --- a/modules/mcbbs_news/mcbbs_news.py +++ b/modules/mcbbs_news/mcbbs_news.py @@ -15,7 +15,7 @@ async def news(msg): if web_render: use_local = True if web_render_local else False api = (web_render_local if use_local else web_render) + 'source?url=' + api - html = await get_url(api, 200) + html = await get_url(api, 200, request_private_ip=True) Logger.debug(html) bs = BeautifulSoup(html, 'html.parser') results = bs.select('#threadlisttableid > tbody[id^="normalthread_"]')