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

Commit

Permalink
Fix responses
Browse files Browse the repository at this point in the history
  • Loading branch information
norinorin committed Dec 9, 2021
1 parent b8d2a0d commit ff6859a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion kita/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, event: InteractionCreateEvent, handler: GatewayCommandHandler
self.handler = handler
self.last_message: Optional[Message] = None
self.command: Optional[ICommandCallback] = None
self.deferring = True
self.deferring = False

def set_command(self: ContextT, command: ICommandCallback) -> ContextT:
self.command = command
Expand Down
10 changes: 7 additions & 3 deletions kita/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ async def execute(self, ctx: Context) -> Optional[Message]:
interaction = ctx.interaction
res: Optional[Message] = None
if self.type == DEFER:
if ctx.deferring:
return None

await interaction.create_initial_response(
ResponseType.DEFERRED_MESSAGE_CREATE
)
ctx.n_message += 1
ctx.deferring = True
elif self.type == CREATE:
return None

if self.type == CREATE:
if ctx.deferring:
self.type = EDIT
return await self.execute(ctx)
Expand All @@ -78,7 +82,7 @@ async def execute(self, ctx: Context) -> Optional[Message]:
if ctx.deferring:
ctx.deferring = False

if ctx.n_message == 1:
if ctx.n_message < 2:
res = await interaction.edit_initial_response(*args, **kwargs)
else:
assert ctx.last_message is not None # can't be None
Expand Down
11 changes: 8 additions & 3 deletions nokari/extensions/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,12 @@ async def spotify_album(
ctx: Context = data(Context),
spotify_client: SpotifyClient = data(SpotifyClient),
album: str = "",
) -> None:
) -> Any:
yield defer()

if not album:
return await spotify_track(ctx, spotify_client, album=True)
yield spotify_track(ctx, spotify_client, album=True)
return

if not (spotify_album := await spotify_client.get_item(ctx, album, Album)):
return
Expand Down Expand Up @@ -455,6 +458,8 @@ def rtfd_hikari(
if not obj:
return respond(f"{HIKARI_BASE_URL}/hikari")

yield defer()

if not objects.objects:
yield objects.init_cache(ctx.app)

Expand All @@ -481,7 +486,7 @@ def rtfd_hikari(
)
)

return paginator.start()
yield paginator.start()


@initializer
Expand Down
7 changes: 4 additions & 3 deletions nokari/extensions/extras/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Callable, Dict, Type, TypeVar

import hikari
from black import traceback
from hikari.interactions.command_interactions import CommandInteraction
from hikari.messages import MessageFlag

Expand All @@ -18,7 +19,7 @@
)
from kita.events import CommandFailureEvent
from kita.extensions import listener
from kita.utils import find
from kita.utils import find, get_exc_info

_ExcT = TypeVar("_ExcT", bound=Exception)

Expand Down Expand Up @@ -78,9 +79,9 @@ async def on_error(event: CommandFailureEvent) -> None:
await event.context.respond(embed=embed, flags=MessageFlag.EPHEMERAL)

_LOGGER.error(
"Ignoring exception in command %s",
"Ignoring exception in command %s:\n%s",
event.context.command and event.context.command.__name__,
exc_info=error,
"".join(traceback.format_exception(*(get_exc_info(error)))),
)


Expand Down

0 comments on commit ff6859a

Please sign in to comment.