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 Dec 18, 2023
1 parent 320989b commit 59d46ff
Show file tree
Hide file tree
Showing 19 changed files with 28 additions and 30 deletions.
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
2 changes: 1 addition & 1 deletion 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
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
1 change: 0 additions & 1 deletion handlers/decorators/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class OsuEvent:

handlers = {}

def __new__(cls):
Expand Down
1 change: 0 additions & 1 deletion handlers/decorators/http.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class HttpEvent:

handlers = {}

def __new__(cls):
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
8 changes: 4 additions & 4 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 @@ -234,7 +234,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 +316,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
3 changes: 2 additions & 1 deletion 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 @@ -146,7 +147,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
1 change: 0 additions & 1 deletion objects/BanchoObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class Message:

__slots__ = ("sender", "to", "body", "client_id", "when")

def __init__(self, sender: str = "", to: str = "", body: str = "", client_id: int = 0):
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
3 changes: 1 addition & 2 deletions 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 Expand Up @@ -206,7 +206,6 @@ def CreateBanchoPacket(


class PacketBuilder:

# server packet: 5
@staticmethod
def UserID(user_id: int) -> bytes:
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 59d46ff

Please sign in to comment.