From e60824b1a490e1694af42407528e35cdafda151f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 23:19:01 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- blob.py | 1 + bot/bot.py | 4 ++-- bot/commands/multiplayer.py | 12 ++++++------ bot/commands/tillerino.py | 1 + handlers/eventhandlers/41-update-match.py | 2 +- handlers/eventhandlers/47-match-score-update.py | 2 +- handlers/eventhandlers/56-match-failed.py | 2 +- .../93-tournament-match-info-request.py | 12 ++++++------ handlers/httphandlers/main_handler.py | 16 +++++++++------- index.py | 2 +- irc/server.py | 11 +++++++---- loops.py | 4 ++-- objects/BotPlayer.py | 2 +- objects/IRCPlayer.py | 2 +- objects/Player.py | 8 ++++---- objects/TokenStorage.py | 6 +++--- packets/Builder/index.py | 2 +- pubsub_listeners.py | 1 + registrator.py | 4 ++-- 19 files changed, 51 insertions(+), 43 deletions(-) diff --git a/blob.py b/blob.py index 9ab9025..55be552 100755 --- a/blob.py +++ b/blob.py @@ -1,6 +1,7 @@ """ This file contains context features :sip: """ + import os from typing import Dict diff --git a/bot/bot.py b/bot/bot.py index 19287a3..6795c51 100755 --- a/bot/bot.py +++ b/bot/bot.py @@ -56,7 +56,7 @@ async def connect(cls) -> bool: token.parse_friends(), token.update_stats(), token.parse_country(), # we don't needed ip, we are bots - ] + ], ) u_panel = PacketBuilder.UserPresence(token) @@ -139,7 +139,7 @@ async def proceed_command(cls, message: "Message") -> bool: message.body = message.body.strip() cmd, func_command = None, None - for (k, func) in cls.commands.items(): + for k, func in cls.commands.items(): if message.body.startswith(k): cmd, func_command = k, func break diff --git a/bot/commands/multiplayer.py b/bot/commands/multiplayer.py index 12519fc..b96e624 100755 --- a/bot/commands/multiplayer.py +++ b/bot/commands/multiplayer.py @@ -417,7 +417,7 @@ async def mp_set(args: List[str], player: "Player", __): MatchTeamTypes(match_team_type) == MatchTeamTypes.TagTeamVs or match_team_type == MatchTeamTypes.TeamVs ): - for (i, slot) in enumerate(player.match.slots): + for i, slot in enumerate(player.match.slots): if slot.team == SlotTeams.Neutral: slot.team = SlotTeams.Red if i % 2 == 1 else SlotTeams.Blue else: @@ -661,11 +661,11 @@ async def mp_settings(_, player: "Player", __): empty = False # pylint: disable=consider-using-f-string msg += "* [{team}] <{status}> ~ {username}{mods}\n".format( - team="red" - if slot.team == SlotTeams.Red - else "blue" - if slot.team == SlotTeams.Blue - else "!! no team !!", + team=( + "red" + if slot.team == SlotTeams.Red + else "blue" if slot.team == SlotTeams.Blue else "!! no team !!" + ), status=readable_status, username=slot.token.name, mods=f" (+ {new_utils.readable_mods(slot.mods)})" if slot.mods > 0 else "", diff --git a/bot/commands/tillerino.py b/bot/commands/tillerino.py index 4757d42..12dfdce 100755 --- a/bot/commands/tillerino.py +++ b/bot/commands/tillerino.py @@ -46,6 +46,7 @@ "RX": Mods.Relax, } + # pylint: disable=consider-using-f-string async def get_pp_message( token: "Player", diff --git a/handlers/eventhandlers/41-update-match.py b/handlers/eventhandlers/41-update-match.py index 1d255e5..fb4e67b 100755 --- a/handlers/eventhandlers/41-update-match.py +++ b/handlers/eventhandlers/41-update-match.py @@ -40,7 +40,7 @@ async def update_match(data: bytes, token: "Player"): new_match["team_type"] == MatchTeamTypes.TagTeamVs or new_match["team_type"] == MatchTeamTypes.TeamVs ): - for (i, slot) in enumerate(match.slots): + for i, slot in enumerate(match.slots): if slot.team == SlotTeams.Neutral: slot.team = SlotTeams.Red if i % 2 == 1 else SlotTeams.Blue else: diff --git a/handlers/eventhandlers/47-match-score-update.py b/handlers/eventhandlers/47-match-score-update.py index 0f4a1e7..80c57ff 100755 --- a/handlers/eventhandlers/47-match-score-update.py +++ b/handlers/eventhandlers/47-match-score-update.py @@ -19,7 +19,7 @@ async def match_score_update(packet_data: bytes, token: "Player"): match = token.match slotInd = -1 - for (ind, slot) in enumerate(match.slots): + for ind, slot in enumerate(match.slots): if slot.token == token: slotInd = ind break diff --git a/handlers/eventhandlers/56-match-failed.py b/handlers/eventhandlers/56-match-failed.py index 0dd3e08..2277d68 100755 --- a/handlers/eventhandlers/56-match-failed.py +++ b/handlers/eventhandlers/56-match-failed.py @@ -17,7 +17,7 @@ async def player_failed(_, token: "Player"): match = token.match slot_ind = -1 - for (ind, slot) in enumerate(match.slots): + for ind, slot in enumerate(match.slots): if slot.token == token: slot_ind = ind break diff --git a/handlers/eventhandlers/93-tournament-match-info-request.py b/handlers/eventhandlers/93-tournament-match-info-request.py index 72267fe..6eb12df 100755 --- a/handlers/eventhandlers/93-tournament-match-info-request.py +++ b/handlers/eventhandlers/93-tournament-match-info-request.py @@ -32,17 +32,17 @@ async def refresh_user_stats(packet_data: bytes, token: "Player"): old_token, ) # remove our actual manager form additional clients token.token = manager_token # moving manager token to additional token - manager_obj.additional_clients[ - manager_token - ] = token # add this token to additional clients + manager_obj.additional_clients[manager_token] = ( + token # add this token to additional clients + ) Context.players.store_by_token.pop( manager_token, ) # remove our additional client from manager accounts manager_obj.token = old_token # assign our pseudo additional client to manager - Context.players.store_by_token[ - old_token - ] = manager_obj # store this token, like it should be + Context.players.store_by_token[old_token] = ( + manager_obj # store this token, like it should be + ) token = manager_obj # for next code part diff --git a/handlers/httphandlers/main_handler.py b/handlers/httphandlers/main_handler.py index 743b261..d47f016 100755 --- a/handlers/httphandlers/main_handler.py +++ b/handlers/httphandlers/main_handler.py @@ -53,7 +53,7 @@ async def main_handler(request: Request): # packets recieve with memoryview(await request.body()) as packets: raw_bytes = KurisoPacketReader(packets) - response = bytes() + response = b'' while not raw_bytes.EOF(): packet_id = raw_bytes.read_u_int_16() _ = raw_bytes.read_int_8() # empty byte @@ -204,9 +204,11 @@ async def main_handler(request: Request): privileges=user_data["privileges"], utc_offset=time_offset, pm_private=pm_private, - silence_end=0 - if user_data["silence_end"] - int(time.time()) < 0 - else user_data["silence_end"] - int(time.time()), + silence_end=( + 0 + if user_data["silence_end"] - int(time.time()) < 0 + else user_data["silence_end"] - int(time.time()) + ), is_tourneymode=False, ip=request.client.host, ) @@ -234,7 +236,7 @@ async def main_handler(request: Request): player.parse_friends(), player.update_stats(), player.parse_country(request.client.host), - ] + ], ) if "ppy.sh" in request.url.netloc and not (player.is_admin or player.is_tournament_stuff): @@ -316,10 +318,10 @@ async def main_handler(request: Request): Context.channels["#osu"].join_channel(player), Context.channels["#announce"].join_channel(player), Context.channels["#english"].join_channel(player), - ] + ], ) - for (_, chan) in Context.channels.items(): + for _, chan in Context.channels.items(): if not chan.temp_channel and chan.can_read: start_bytes += PacketBuilder.ChannelAvailable(chan) diff --git a/index.py b/index.py index c1c057e..ed4a271 100755 --- a/index.py +++ b/index.py @@ -73,7 +73,7 @@ async def main(): redis_values["password"] = Config.config["redis"]["password"] redis_pool = await aioredis.from_url( - f"redis://{Config.config['redis']['host']}", **redis_values + f"redis://{Config.config['redis']['host']}", **redis_values, ) Context.redis = redis_pool diff --git a/irc/server.py b/irc/server.py index bf81e5b..3b77aec 100644 --- a/irc/server.py +++ b/irc/server.py @@ -23,6 +23,7 @@ NAME = "kuriso!irc" WHITE_SPACE = re.compile(r"\r?\n") + # Custom Bancho IRC exception. class BanchoIRCException(Exception): """Custom expection.""" @@ -105,9 +106,11 @@ async def login(self, irc_token: str = ""): "privileges": start_data["privileges"], "utc_offset": 0, "pm_private": False, - "silence_end": 0 - if start_data["silence_end"] - int(time.time()) < 0 - else start_data["silence_end"] - int(time.time()), + "silence_end": ( + 0 + if start_data["silence_end"] - int(time.time()) < 0 + else start_data["silence_end"] - int(time.time()) + ), "is_tourneymode": True, "ip": socket_ip, "irc": self, @@ -146,7 +149,7 @@ async def login(self, irc_token: str = ""): player.parse_friends(), player.update_stats(), player.parse_country(), - ] + ], ) logger.klog(f"<{start_data['username']}> logged in, through irc!chat") diff --git a/loops.py b/loops.py index d41b5b3..d8626da 100755 --- a/loops.py +++ b/loops.py @@ -14,12 +14,12 @@ async def clean_timeouts(): """ tasks = [] - for (_, user) in Context.players.store_by_token.items(): + for _, user in Context.players.store_by_token.items(): if user.is_bot: continue # ignore bot if hasattr(user, "additional_clients"): - for (_, sub_user) in user.additional_clients.items(): + for _, sub_user in user.additional_clients.items(): if int(time.time()) - sub_user.last_packet_unix > LAST_PACKET_TIMEOUT: logger.slog(f"[Player/{user.name}/subclient] was kicked during timeout") # simulate logout packet diff --git a/objects/BotPlayer.py b/objects/BotPlayer.py index f912a33..0582350 100755 --- a/objects/BotPlayer.py +++ b/objects/BotPlayer.py @@ -103,7 +103,7 @@ async def update_stats(self, selected_mode: GameModes = None) -> bool: async def logout(self) -> None: # leave channels - for (_, chan) in Context.channels.items(): + for _, chan in Context.channels.items(): if self.id in chan.users: await chan.leave_channel(self) diff --git a/objects/IRCPlayer.py b/objects/IRCPlayer.py index a0384ee..0b703cf 100644 --- a/objects/IRCPlayer.py +++ b/objects/IRCPlayer.py @@ -85,7 +85,7 @@ async def logout(self) -> None: await userHelper.deleteBanchoSession(self.id, self.ip) # leave channels - for (_, chan) in Context.channels.items(): + for _, chan in Context.channels.items(): if self.id in chan.users: await chan.leave_channel(self) diff --git a/objects/Player.py b/objects/Player.py index e2cc5bd..4a144ba 100755 --- a/objects/Player.py +++ b/objects/Player.py @@ -126,7 +126,7 @@ def __init__( self._match: Optional["Match"] = None - self.queue = bytes() # main thing + self.queue = b'' # main thing self.login_time = int(time.time()) self.last_packet_unix = int(time.time()) @@ -299,7 +299,7 @@ async def update_stats(self, selected_mode: GameModes = None) -> bool: ) self.stats[gm].update( - **{**task, **{"leaderboard_rank": int(position) + 1 if position else 0}} + **{**task, **{"leaderboard_rank": int(position) + 1 if position else 0}}, ) async def logout(self) -> None: @@ -319,7 +319,7 @@ async def logout(self) -> None: await self.spectating.remove_spectator(self) # leave channels - for (_, chan) in Context.channels.items(): + for _, chan in Context.channels.items(): if self.id in chan.users: await chan.leave_channel(self) @@ -534,7 +534,7 @@ def enqueue(self, b: bytes) -> None: def dequeue(self) -> Optional[bytes]: if self.queue: data = self.queue - self.queue = bytes() + self.queue = b'' return data return b"" diff --git a/objects/TokenStorage.py b/objects/TokenStorage.py index 8be3e05..9cf524e 100755 --- a/objects/TokenStorage.py +++ b/objects/TokenStorage.py @@ -39,7 +39,7 @@ def get_token( if token: if not self.store_by_token.get(token, None): # we can't find token, but probably it's additional client?! - for (_, user) in self.store_by_token.items(): + for _, user in self.store_by_token.items(): if hasattr(user, "additional_clients"): if token in user.additional_clients: return user.additional_clients.get(token, None) @@ -55,7 +55,7 @@ def get_token( def delete_token(self, token: "Player") -> bool: if token.is_tourneymode: - for (_, user) in self.store_by_token.items(): + for _, user in self.store_by_token.items(): if hasattr(user, "additional_clients"): if token.token in user.additional_clients: user.additional_clients.pop(token.token) @@ -84,7 +84,7 @@ def get_all_tokens( ] # just return all player instances additional_tokens = [] if not ignore_tournament_clients: - for (_, user) in self.store_by_token.items(): + for _, user in self.store_by_token.items(): if hasattr(user, "additional_clients"): additional_tokens.extend( [token for (_, token) in user.additional_clients.items()], diff --git a/packets/Builder/index.py b/packets/Builder/index.py index d82a59a..60db75a 100755 --- a/packets/Builder/index.py +++ b/packets/Builder/index.py @@ -166,7 +166,7 @@ def write_mp_match(self, arguments: List[Union["Match", bool]]) -> bool: # 2 - (data, osuType) @staticmethod def CreateBanchoPacket( - pid: Union[int, OsuPacketID], *args: Union[Tuple[Any, int]] + pid: Union[int, OsuPacketID], *args: Union[Tuple[Any, int]], ) -> bytes: # writing packet writer = KurisoPacketWriter() diff --git a/pubsub_listeners.py b/pubsub_listeners.py index 92bf68e..9787d9b 100755 --- a/pubsub_listeners.py +++ b/pubsub_listeners.py @@ -1,6 +1,7 @@ """ Hard-coded """ + import asyncio import traceback diff --git a/registrator.py b/registrator.py index a154172..56309bd 100755 --- a/registrator.py +++ b/registrator.py @@ -14,7 +14,7 @@ def load_handlers(app: Starlette): logger.wlog("[Handlers/Events] Loading handlers & events...") paths_to_import = {"handlers": ["httphandlers", "eventhandlers"]} - for (k, v) in paths_to_import.items(): + for k, v in paths_to_import.items(): sys.path.insert(0, k) for deep_path in v: sys.path.insert(0, f"{k}/{deep_path}") @@ -27,7 +27,7 @@ def load_handlers(app: Starlette): __import__(os.path.splitext(file)[0], None, None, [""]) handlers = [] - for (path, path_describe) in HttpEvent.handlers.items(): + for path, path_describe in HttpEvent.handlers.items(): logger.slog(f"[Handlers/Events] {path} registered!") handlers.append( Route(