From 70e629a7394b888dc47cab2798000550b4ebc7b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 14 Dec 2024 19:02:35 +0800 Subject: [PATCH] update style issue --- bot.py | 21 ++++++++++---------- bots/aiocqhttp/info.py | 2 +- bots/aiogram/info.py | 6 +++++- bots/discord/info.py | 2 +- bots/kook/info.py | 2 +- bots/matrix/info.py | 2 +- core/console/info.py | 2 +- core/scripts/config_generate.py | 3 +-- modules/ask/__init__.py | 2 +- modules/core/help.py | 2 +- modules/dice/process.py | 2 +- modules/maimai/libraries/maimaidx_apidata.py | 5 ++--- modules/maimai/maimai.py | 12 +++++------ modules/mcv/mcv.py | 10 +++++----- modules/oba/__init__.py | 2 +- modules/summary/__init__.py | 2 +- modules/twenty_four/__init__.py | 8 ++++---- modules/wiki/utils/ab.py | 2 +- modules/wiki/utils/wikilib.py | 2 +- 19 files changed, 45 insertions(+), 44 deletions(-) diff --git a/bot.py b/bot.py index 4d1dfc1b54..68756c5183 100644 --- a/bot.py +++ b/bot.py @@ -177,18 +177,17 @@ def restart_process(bot_name: str): for p in processes: if p.is_alive(): continue + if p.exitcode == 233: + Logger.warning(f'{p.pid} ({p.name}) exited with code 233, restart all bots.') + raise RestartBot else: - if p.exitcode == 233: - Logger.warning(f'{p.pid} ({p.name}) exited with code 233, restart all bots.') - raise RestartBot - else: - Logger.critical(f'Process {p.pid} ({p.name}) exited with code {p.exitcode}, please check the log.') - processes.remove(p) - p.terminate() - p.join() - p.close() - restart_process(p.name) - break + Logger.critical(f'Process {p.pid} ({p.name}) exited with code {p.exitcode}, please check the log.') + processes.remove(p) + p.terminate() + p.join() + p.close() + restart_process(p.name) + break if not processes: break diff --git a/bots/aiocqhttp/info.py b/bots/aiocqhttp/info.py index a80c5e2a2d..c3b2240e9a 100644 --- a/bots/aiocqhttp/info.py +++ b/bots/aiocqhttp/info.py @@ -7,4 +7,4 @@ target_guild_prefix = f'{client_name}|Guild' target_group_prefix = f'{client_name}|Group' target_private_prefix = f'{client_name}|Private' -target_prefix_list = [target_guild_prefix, target_group_prefix, target_private_prefix] \ No newline at end of file +target_prefix_list = [target_guild_prefix, target_group_prefix, target_private_prefix] diff --git a/bots/aiogram/info.py b/bots/aiogram/info.py index 37b8745159..80e4422936 100644 --- a/bots/aiogram/info.py +++ b/bots/aiogram/info.py @@ -4,4 +4,8 @@ sender_prefix_list = [sender_prefix] target_prefix = client_name -target_prefix_list = [f'{client_name}|Private', f'{client_name}|Group', f'{client_name}|Supergroup', f'{client_name}|Channel'] \ No newline at end of file +target_prefix_list = [ + f'{client_name}|Private', + f'{client_name}|Group', + f'{client_name}|Supergroup', + f'{client_name}|Channel'] diff --git a/bots/discord/info.py b/bots/discord/info.py index 3afb48d632..b323b8e5b7 100644 --- a/bots/discord/info.py +++ b/bots/discord/info.py @@ -6,4 +6,4 @@ target_channel_prefix = f'{client_name}|Channel' target_dm_channel_prefix = f'{client_name}|DM|Channel' target_slash_prefix = f'{client_name}|Slash' -target_prefix_list = [target_channel_prefix, target_dm_channel_prefix] \ No newline at end of file +target_prefix_list = [target_channel_prefix, target_dm_channel_prefix] diff --git a/bots/kook/info.py b/bots/kook/info.py index 7a436dc726..49fe9b3ba1 100644 --- a/bots/kook/info.py +++ b/bots/kook/info.py @@ -6,4 +6,4 @@ target_prefix = client_name target_group_prefix = f'{client_name}|Group' target_person_prefix = f'{client_name}|Person' -target_prefix_list = [target_group_prefix, target_person_prefix] \ No newline at end of file +target_prefix_list = [target_group_prefix, target_person_prefix] diff --git a/bots/matrix/info.py b/bots/matrix/info.py index d78c233857..406a3f5c20 100644 --- a/bots/matrix/info.py +++ b/bots/matrix/info.py @@ -4,4 +4,4 @@ sender_prefix_list = [sender_prefix] target_prefix = f'{client_name}|Room' -target_prefix_list = [target_prefix] \ No newline at end of file +target_prefix_list = [target_prefix] diff --git a/core/console/info.py b/core/console/info.py index 3f1ad946cb..6a008aa287 100644 --- a/core/console/info.py +++ b/core/console/info.py @@ -4,4 +4,4 @@ sender_prefix_list = [sender_prefix] target_prefix = f'{client_name}|Console' -target_prefix_list = [target_prefix] \ No newline at end of file +target_prefix_list = [target_prefix] diff --git a/core/scripts/config_generate.py b/core/scripts/config_generate.py index 427d61d95b..ca3c2372c3 100644 --- a/core/scripts/config_generate.py +++ b/core/scripts/config_generate.py @@ -106,8 +106,7 @@ def generate_config(dir_path, language): if isint(lang) and (langI := (int(lang) - 1)) in range(len(lang_list)): lang = list(lang_list.keys())[langI] break - else: - print('Invalid input, please try again.') + print('Invalid input, please try again.') generate_config(config_path, lang) diff --git a/modules/ask/__init__.py b/modules/ask/__init__.py index 7e03888232..c5dae3bebf 100644 --- a/modules/ask/__init__.py +++ b/modules/ask/__init__.py @@ -89,7 +89,7 @@ async def _(msg: Bot.MessageSession): ) if run.status == 'completed': break - elif run.status == 'failed': + if run.status == 'failed': if run.last_error.code == 'rate_limit_exceeded' and \ 'quota' not in run.last_error.message: Logger.warning(run.last_error.json()) diff --git a/modules/core/help.py b/modules/core/help.py index 1a08ef3bd9..e4ccad1fd6 100644 --- a/modules/core/help.py +++ b/modules/core/help.py @@ -325,7 +325,7 @@ async def help_generator(msg: Bot.MessageSession, continue if value.rss and not msg.Feature.rss: continue - elif not is_superuser and value.required_superuser or \ + if not is_superuser and value.required_superuser or \ not is_base_superuser and value.required_base_superuser: continue diff --git a/modules/dice/process.py b/modules/dice/process.py index 50eb1c948b..a463ed3703 100644 --- a/modules/dice/process.py +++ b/modules/dice/process.py @@ -108,7 +108,7 @@ def parse_dice_expression(msg: Bot.MessageSession, dices: str): try: if any(item.lower() == func for func in math_funcs): continue - elif 'A' in item: + if 'A' in item: dice_count += 1 dice_expr_list[j] = WODDice(msg, item) elif 'C' in item: diff --git a/modules/maimai/libraries/maimaidx_apidata.py b/modules/maimai/libraries/maimaidx_apidata.py index 74eb9038b4..2464bf4dc0 100644 --- a/modules/maimai/libraries/maimaidx_apidata.py +++ b/modules/maimai/libraries/maimaidx_apidata.py @@ -35,9 +35,8 @@ async def update_cover() -> bool: if Config('debug', False): Logger.error(f'Failed to download {id}.png') continue - else: - Logger.error(traceback.format_exc()) - return False + Logger.error(traceback.format_exc()) + return False return True diff --git a/modules/maimai/maimai.py b/modules/maimai/maimai.py index 79790ab7c8..6c0b182aca 100644 --- a/modules/maimai/maimai.py +++ b/modules/maimai/maimai.py @@ -631,12 +631,12 @@ async def _(msg: Bot.MessageSession, diff: str, sid: str, score: float): reduce = 101 - score # 理论值与给定完成率的差,以百分比计 if reduce <= 0 or reduce >= 101: raise ValueError - tap_great = "{:.2f}".format(total_score * reduce / 10000) # 一个 TAP GREAT 减少 100 分 - tap_great_prop = "{:.4f}".format(10000 / total_score) - b2t_2550_great = "{:.3f}".format(break_2550_reduce / 100) # 一个 TAP GREAT 减少 100 分 - 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) + tap_great = f"{(total_score * reduce / 10000):.2f}" # 一个 TAP GREAT 减少 100 分 + tap_great_prop = f"{(10000 / total_score):.4f}" + b2t_2550_great = f"{(break_2550_reduce / 100):.3f}" # 一个 TAP GREAT 减少 100 分 + b2t_2550_great_prop = f"{(break_2550_reduce / total_score * 100):.4f}" + b2t_2000_great = f"{(break_2000_reduce / 100):.3f}" # 一个 TAP GREAT 减少 100 分 + b2t_2000_great_prop = f"{(break_2000_reduce / total_score * 100):.4f}" await msg.finish(f'''{music['title']}{' (DX)' if music['type'] == 'DX' else ''} {diff_list[diff_index]} {msg.locale.t('maimai.message.scoreline', scoreline=score, diff --git a/modules/mcv/mcv.py b/modules/mcv/mcv.py index 835ed90ad4..9dd690eae2 100644 --- a/modules/mcv/mcv.py +++ b/modules/mcv/mcv.py @@ -29,7 +29,7 @@ async def mcv(msg: Bot.MessageSession): snapshot=data['latest']['snapshot'], release_time=msg.ts2strftime(time_release), snapshot_time=msg.ts2strftime(time_snapshot)) - except (ConnectionError, OSError): # Probably... + except ConnectionError: # Probably... message1 = msg.locale.t("mcv.message.mcv.launcher.failed") try: mojira = json.loads(await get_url('https://bugs.mojang.com/rest/api/2/project/10400/versions', 200)) @@ -64,7 +64,7 @@ async def mcbv(msg: Bot.MessageSession): pass try: data = json.loads(await get_url('https://bugs.mojang.com/rest/api/2/project/10200/versions', 200)) - except (ConnectionError, OSError): # Probably... + except ConnectionError: # Probably... return ErrorMessage('{mcv.message.error.server}', locale=msg.locale.locale, enable_report=False) beta = [] preview = [] @@ -93,7 +93,7 @@ async def mcbv(msg: Bot.MessageSession): async def mcdv(msg: Bot.MessageSession): try: data = json.loads(await get_url('https://bugs.mojang.com/rest/api/2/project/11901/versions', 200)) - except (ConnectionError, OSError): # Probably... + except ConnectionError: # Probably... return ErrorMessage('{mcv.message.error.server}', locale=msg.locale.locale, enable_report=False) release = [] for v in data: @@ -108,7 +108,7 @@ async def mcev(msg: Bot.MessageSession): Logger.debug(data) version = re.search(r'(?<=\[)(.*?)(?=])', data)[0] Logger.debug(version) - except (ConnectionError, OSError): # Probably... + except ConnectionError: # Probably... return ErrorMessage('{mcv.message.error.server}', locale=msg.locale.locale, enable_report=False) return msg.locale.t("mcv.message.mcev", version=version) @@ -116,7 +116,7 @@ async def mcev(msg: Bot.MessageSession): async def mclgv(msg: Bot.MessageSession): try: data = json.loads(await get_url('https://bugs.mojang.com/rest/api/2/project/12200/versions', 200)) - except (ConnectionError, OSError): # Probably... + except ConnectionError: # Probably... return ErrorMessage('{mcv.message.error.server}', locale=msg.locale.locale, enable_report=False) release = [] for v in data: diff --git a/modules/oba/__init__.py b/modules/oba/__init__.py index c596023377..33d9477bbc 100644 --- a/modules/oba/__init__.py +++ b/modules/oba/__init__.py @@ -16,7 +16,7 @@ def size_convert(value): size = 1024.0 for _, unit in enumerate(units): if (value / size) < 1: - return '%.2f%s' % (value, ' ' + unit) + return f'{value:.2f} {unit}' value /= size diff --git a/modules/summary/__init__.py b/modules/summary/__init__.py index 7265a9cd3d..a27a82c1af 100644 --- a/modules/summary/__init__.py +++ b/modules/summary/__init__.py @@ -45,7 +45,7 @@ async def _(msg: Bot.MessageSession): if await check_bool(''.join(texts)): await msg.finish(rickroll(msg)) - char_count = sum([len(i) for i in texts]) + char_count = sum(len(i) for i in texts) wait_msg = await msg.send_message( msg.locale.t('summary.message.waiting', count=char_count, time=round(char_count / 33.5, 1))) diff --git a/modules/twenty_four/__init__.py b/modules/twenty_four/__init__.py index 7e72d21ad5..12362958cf 100644 --- a/modules/twenty_four/__init__.py +++ b/modules/twenty_four/__init__.py @@ -61,25 +61,25 @@ async def find_solution(numbers): for perm in perms: for expr in exprs: # 穷举就完事了 - exp = '(({}{}{}){}{}){}{}'.format(perm[0], expr[0], perm[1], expr[1], perm[2], expr[2], perm[3]) + exp = f'(({perm[0]}{expr[0]}{perm[1]}){expr[1]}{perm[2]}){expr[2]}{perm[3]}' try: if (calc(exp) == 24 or 0 < 24 - calc(exp) < 1e-13): return exp except BaseException: pass - exp = '({}{}{}){}({}{}{})'.format(perm[0], expr[0], perm[1], expr[1], perm[2], expr[2], perm[3]) + exp = f'({perm[0]}{expr[0]}{perm[1]}){expr[1]}({perm[2]}{expr[2]}{perm[3]})' try: if (calc(exp) == 24 or 0 < 24 - calc(exp) < 1e-13): return exp except BaseException: pass - exp = '{}{}({}{}({}{}{}))'.format(perm[0], expr[0], perm[1], expr[1], perm[2], expr[2], perm[3]) + exp = f'{perm[0]}{expr[0]}({perm[1]}{expr[1]}({perm[2]}{expr[2]}{perm[3]}))' try: if (calc(exp) == 24 or 0 < 24 - calc(exp) < 1e-13): return exp except BaseException: pass - exp = '{}{}({}{}{}){}{}'.format(perm[0], expr[0], perm[1], expr[1], perm[2], expr[2], perm[3]) + exp = f'{perm[0]}{expr[0]}({perm[1]}{expr[1]}{perm[2]}){expr[2]}{perm[3]}' try: if (calc(exp) == 24 or 0 < 24 - calc(exp) < 1e-13): return exp diff --git a/modules/wiki/utils/ab.py b/modules/wiki/utils/ab.py index ec4962ac21..abf8453c23 100644 --- a/modules/wiki/utils/ab.py +++ b/modules/wiki/utils/ab.py @@ -1,7 +1,7 @@ from core.builtins import Url, Bot from core.dirty_check import check from modules.wiki.utils.time import strptime2ts -from modules.wiki.utils.wikilib import WikiLib, WikiInfo +from modules.wiki.utils.wikilib import WikiLib AB_LIMIT = 5 diff --git a/modules/wiki/utils/wikilib.py b/modules/wiki/utils/wikilib.py index 3a8ba6e0f4..73c1581138 100644 --- a/modules/wiki/utils/wikilib.py +++ b/modules/wiki/utils/wikilib.py @@ -213,7 +213,7 @@ async def check_wiki_available(self): api_match = self.url.split('//')[0] + api_match # Logger.info(api_match) wiki_api_link = api_match - except (TimeoutError, asyncio.TimeoutError): + except TimeoutError: return WikiStatus(available=False, value=False, message=self.locale.t( "wiki.message.utils.wikilib.get_failed.timeout")) except IndexError: