Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: handler types #54

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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