Skip to content

Commit

Permalink
refactor: handler types (#54)
Browse files Browse the repository at this point in the history
* refactor: handler types

* style: apply code style
  • Loading branch information
SaidBySolo authored Jan 10, 2024
1 parent 4ba2b43 commit ae90a35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions crenata/application/tree.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
from __future__ import annotations

from discord import Interaction
from discord._types import ClientT
from discord.app_commands.errors import AppCommandError
from discord.app_commands.tree import CommandTree

from crenata.application.client import Crenata
from crenata.application.error.handler import ErrorHandler


class CrenataCommandTree(CommandTree[ClientT]):
def __init__(self, client: ClientT, *, fallback_to_global: bool = True):
class CrenataCommandTree(CommandTree[Crenata]):
def __init__(self, client: Crenata, *, fallback_to_global: bool = True):
super().__init__(client, fallback_to_global=fallback_to_global)
self.error_handler: ErrorHandler[Crenata] = ErrorHandler()

self.error_handler: ErrorHandler[ClientT] = ErrorHandler()

def set_error_handler(self, handler: ErrorHandler[ClientT]) -> None:
def set_error_handler(self, handler: ErrorHandler[Crenata]) -> None:
self.error_handler = handler

async def on_error(
self, interaction: Interaction[ClientT], error: AppCommandError
self, interaction: Interaction[Crenata], error: AppCommandError
) -> None:
await self.error_handler.on_error(interaction, error)

async def interaction_check(self, interaction: Interaction[Crenata]) -> bool:
...
6 changes: 3 additions & 3 deletions crenata/application/view/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Optional
from typing import Optional

from discord import Interaction
from discord.interactions import Interaction
Expand All @@ -20,9 +20,9 @@ def __init__(
super().__init__(timeout=timeout)

self.executor_id = executor_id
self.error_handler: ErrorHandler[Any] = ErrorHandler()
self.error_handler = ErrorHandler()

def set_error_handler(self, handler: ErrorHandler[Any]) -> None:
def set_error_handler(self, handler: ErrorHandler) -> None:
self.error_handler = handler

async def interaction_check(self, interaction: Interaction) -> bool:
Expand Down

0 comments on commit ae90a35

Please sign in to comment.