Skip to content

fix: let unload_extension() pop regex pattern listeners #1683

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
Merged
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
17 changes: 13 additions & 4 deletions interactions/models/internal/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import inspect
import typing
from typing import Awaitable, Dict, List, TYPE_CHECKING, Callable, Coroutine, Optional
import re

import interactions.models.internal as models
import interactions.api.events as events
Expand Down Expand Up @@ -154,12 +155,20 @@ def drop(self) -> None:
for func in self._commands:
if isinstance(func, models.ModalCommand):
for listener in func.listeners:
# noinspection PyProtectedMember
self.bot._modal_callbacks.pop(listener)
if isinstance(listener, re.Pattern):
# noinspection PyProtectedMember
self.bot._regex_modal_callbacks.pop(listener)
else:
# noinspection PyProtectedMember
self.bot._modal_callbacks.pop(listener)
elif isinstance(func, models.ComponentCommand):
for listener in func.listeners:
# noinspection PyProtectedMember
self.bot._component_callbacks.pop(listener)
if isinstance(listener, re.Pattern):
# noinspection PyProtectedMember
self.bot._regex_component_callbacks.pop(listener)
else:
# noinspection PyProtectedMember
self.bot._component_callbacks.pop(listener)
elif isinstance(func, models.InteractionCommand):
for scope in func.scopes:
if self.bot.interactions_by_scope.get(scope):
Expand Down