Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #277 from Lunarmagpie/on_ready_bug
Browse files Browse the repository at this point in the history
🐛 fix on_ready middleware
  • Loading branch information
zunda-arrow authored Nov 30, 2021
2 parents 98b7d71 + 558a1a3 commit e26e563
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
22 changes: 10 additions & 12 deletions pincer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def execute_event(calls: List[Coro], *args, **kwargs):
if should_pass_cls(call):
call_args = (
ChatCommandHandler.managers[call.__module__],
*args
*(arg for arg in args if arg is not None)
)

ensure_future(call(*call_args, **kwargs))
Expand Down Expand Up @@ -495,12 +495,11 @@ async def handle_middleware(
if next_call is None:
raise RuntimeError(f"Middleware `{key}` has not been registered.")

return (
(next_call, ret_object)
if next_call.startswith("on_")
else await self.handle_middleware(
payload, next_call, *arguments, **params
)
if next_call.startswith("on_"):
return (next_call, ret_object)

return await self.handle_middleware(
payload, next_call, *arguments, **params
)

async def execute_error(
Expand Down Expand Up @@ -547,12 +546,11 @@ async def process_event(self, name: str, payload: GatewayDispatch):
what specifically happened.
"""
try:
key, ret_object = await self.handle_middleware(payload, name)

self.event_mgr.process_events(key, ret_object)
key, args = await self.handle_middleware(payload, name)
self.event_mgr.process_events(key, args)

if calls := self.get_event_coro(key):
self.execute_event(calls, ret_object)
self.execute_event(calls, args)

except Exception as e:
await self.execute_error(e)
Expand Down Expand Up @@ -665,7 +663,7 @@ async def get_guild_template(self, code: str) -> GuildTemplate:
"""
return GuildTemplate.from_dict(
construct_client_dict(
self,
self,
await self.http.get(f"guilds/templates/{code}")
)
)
Expand Down
2 changes: 1 addition & 1 deletion pincer/objects/guild/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from enum import IntEnum
from typing import AsyncGenerator, overload, TYPE_CHECKING

from .channel import Channel
from ...exceptions import UnavailableGuildError
from ...utils.api_object import APIObject
from ...utils.conversion import construct_client_dict, remove_none
Expand All @@ -17,7 +18,6 @@

from .audit_log import AuditLog
from .ban import Ban
from .channel import Channel
from .invite import Invite
from .member import GuildMember
from .features import GuildFeature
Expand Down
6 changes: 5 additions & 1 deletion pincer/utils/event_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ def matches_event(self, event_name: str, event_value: Any):
return False

if self.check:
return self.check(event_value)
if event_value is not None:
return self.check(event_value)
else:
# Certain middleware do not have an event_value
return self.check()

return True

Expand Down

0 comments on commit e26e563

Please sign in to comment.