Skip to content

5.12.1 #1677

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

Merged
5 commits merged into from
May 6, 2024
Merged

5.12.1 #1677

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
2 changes: 2 additions & 0 deletions interactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
cooldown,
Cooldown,
CooldownSystem,
CronTrigger,
CustomEmoji,
CustomEmojiConverter,
DateTrigger,
Expand Down Expand Up @@ -433,6 +434,7 @@
"cooldown",
"Cooldown",
"CooldownSystem",
"CronTrigger",
"SlidingWindowSystem",
"ExponentialBackoffSystem",
"LeakyBucketSystem",
Expand Down
5 changes: 5 additions & 0 deletions interactions/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ def __init__(
self.async_startup_tasks: list[tuple[Callable[..., Coroutine], Iterable[Any], dict[str, Any]]] = []
"""A list of coroutines to run during startup"""

self._add_command_hook: list[Callable[[Callable], Any]] = []

# callbacks
if global_pre_run_callback:
if asyncio.iscoroutinefunction(global_pre_run_callback):
Expand Down Expand Up @@ -1416,6 +1418,9 @@ def add_command(self, func: Callable) -> None:
else:
self.logger.debug(f"Added callback: {func.callback.__name__}")

for hook in self._add_command_hook:
hook(func)

self.dispatch(CallbackAdded(callback=func, extension=func.extension if hasattr(func, "extension") else None))

def _gather_callbacks(self) -> None:
Expand Down
17 changes: 9 additions & 8 deletions interactions/ext/hybrid_commands/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,22 @@ def __init__(
self.client = cast(prefixed.PrefixedInjectedClient, client)
self.ext_command_list: dict[str, list[str]] = {}

self.client.add_listener(self.add_hybrid_command.copy_with_binding(self))
self.client.add_listener(self.handle_ext_unload.copy_with_binding(self))

self.client._add_command_hook.append(self._add_hybrid_command)

self.client.hybrid = self

@listen("on_callback_added")
async def add_hybrid_command(self, event: CallbackAdded):
if (
not isinstance(event.callback, HybridSlashCommand)
or not event.callback.callback
or event.callback._dummy_base
):
async def add_hybrid_command(self, event: CallbackAdded) -> None:
# just here for backwards compatability since it was accidentially public, don't rely on it
self._add_hybrid_command(event.callback)

def _add_hybrid_command(self, callback: Callable):
if not isinstance(callback, HybridSlashCommand) or not callback.callback or callback._dummy_base:
return

cmd = event.callback
cmd = callback
prefixed_transform = slash_to_prefixed(cmd)

if self.use_slash_command_msg:
Expand Down
17 changes: 6 additions & 11 deletions interactions/ext/prefixed_commands/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from interactions.api.events.internal import (
CommandError,
CommandCompletion,
CallbackAdded,
ExtensionUnload,
)
from interactions.client.client import Client
Expand Down Expand Up @@ -90,13 +89,13 @@ def __init__(
self.client.prefixed = self

self._dispatch_prefixed_commands = self._dispatch_prefixed_commands.copy_with_binding(self)
self._register_command = self._register_command.copy_with_binding(self)
self._handle_ext_unload = self._handle_ext_unload.copy_with_binding(self)

self.client.add_listener(self._dispatch_prefixed_commands)
self.client.add_listener(self._register_command)
self.client.add_listener(self._handle_ext_unload)

self.client._add_command_hook.append(self._register_command)

async def generate_prefixes(self, client: Client, msg: Message) -> str | list[str]:
"""
Generates a list of prefixes a prefixed command can have based on the client and message.
Expand Down Expand Up @@ -229,17 +228,13 @@ def remove_command(self, name: str, delete_parent_if_empty: bool = False) -> Opt

return command

@listen("callback_added")
async def _register_command(self, event: CallbackAdded) -> None:
def _register_command(self, callback: Callable) -> None:
"""Registers a prefixed command, if there is one given."""
if not isinstance(event.callback, PrefixedCommand):
if not isinstance(callback, PrefixedCommand):
return

cmd = event.callback
cmd.extension = event.extension

if not cmd.is_subcommand:
self.add_command(cmd)
if not callback.is_subcommand:
self.add_command(callback)

@listen("extension_unload")
async def _handle_ext_unload(self, event: ExtensionUnload) -> None:
Expand Down
2 changes: 2 additions & 0 deletions interactions/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
cooldown,
Cooldown,
CooldownSystem,
CronTrigger,
SlidingWindowSystem,
ExponentialBackoffSystem,
LeakyBucketSystem,
Expand Down Expand Up @@ -380,6 +381,7 @@
"cooldown",
"Cooldown",
"CooldownSystem",
"CronTrigger",
"SlidingWindowSystem",
"ExponentialBackoffSystem",
"LeakyBucketSystem",
Expand Down
6 changes: 6 additions & 0 deletions interactions/models/discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,12 @@ class AuditLogEventType(CursedIntEnum):
BLOCKED_PHISHING_LINK = 180
SERVER_GUIDE_CREATE = 190
SERVER_GUIDE_UPDATE = 191
VOICE_CHANNEL_STATUS_CREATE = 192
VOICE_CHANNEL_STATUS_DELETE = 193
CLYDE_AI_PROFILE_UPDATE = 194
GUILD_SCHEDULED_EVENT_EXCEPTION_CREATE = 200
GUILD_SCHEDULED_EVENT_EXCEPTION_UPDATE = 201
GUILD_SCHEDULED_EVENT_EXCEPTION_DELETE = 202


class AutoModTriggerType(CursedIntEnum):
Expand Down
3 changes: 2 additions & 1 deletion interactions/models/internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
from .protocols import Converter
from .extension import Extension
from .wait import Wait
from .tasks import BaseTrigger, DateTrigger, IntervalTrigger, OrTrigger, Task, TimeTrigger
from .tasks import BaseTrigger, DateTrigger, IntervalTrigger, OrTrigger, Task, TimeTrigger, CronTrigger

__all__ = (
"ActiveVoiceState",
Expand Down Expand Up @@ -132,6 +132,7 @@
"cooldown",
"Cooldown",
"CooldownSystem",
"CronTrigger",
"SlidingWindowSystem",
"ExponentialBackoffSystem",
"LeakyBucketSystem",
Expand Down
4 changes: 2 additions & 2 deletions interactions/models/internal/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .triggers import BaseTrigger, IntervalTrigger, DateTrigger, TimeTrigger, OrTrigger
from .triggers import BaseTrigger, IntervalTrigger, DateTrigger, TimeTrigger, OrTrigger, CronTrigger
from .task import Task

__all__ = ("BaseTrigger", "IntervalTrigger", "DateTrigger", "TimeTrigger", "OrTrigger", "Task")
__all__ = ("BaseTrigger", "IntervalTrigger", "DateTrigger", "TimeTrigger", "OrTrigger", "CronTrigger", "Task")
2 changes: 1 addition & 1 deletion interactions/models/internal/tasks/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from croniter import croniter

__all__ = ("BaseTrigger", "IntervalTrigger", "DateTrigger", "TimeTrigger", "OrTrigger")
__all__ = ("BaseTrigger", "IntervalTrigger", "DateTrigger", "TimeTrigger", "OrTrigger", "CronTrigger")


class BaseTrigger(ABC):
Expand Down
Loading
Loading