Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 18, 2024
1 parent 294506c commit ca86f4a
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 43 deletions.
1 change: 1 addition & 0 deletions blob.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This file contains context features :sip:
"""

import os
from typing import Dict

Expand Down
4 changes: 2 additions & 2 deletions bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions bot/commands/multiplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 "",
Expand Down
1 change: 1 addition & 0 deletions bot/commands/tillerino.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"RX": Mods.Relax,
}


# pylint: disable=consider-using-f-string
async def get_pp_message(
token: "Player",
Expand Down
2 changes: 1 addition & 1 deletion handlers/eventhandlers/41-update-match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion handlers/eventhandlers/47-match-score-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion handlers/eventhandlers/56-match-failed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions handlers/eventhandlers/93-tournament-match-info-request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 9 additions & 7 deletions handlers/httphandlers/main_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions irc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
NAME = "kuriso!irc"
WHITE_SPACE = re.compile(r"\r?\n")


# Custom Bancho IRC exception.
class BanchoIRCException(Exception):
"""Custom expection."""
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion objects/BotPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion objects/IRCPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions objects/Player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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""
6 changes: 3 additions & 3 deletions objects/TokenStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()],
Expand Down
2 changes: 1 addition & 1 deletion packets/Builder/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions pubsub_listeners.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Hard-coded
"""

import asyncio
import traceback

Expand Down
4 changes: 2 additions & 2 deletions registrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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(
Expand Down

0 comments on commit ca86f4a

Please sign in to comment.