Skip to content

Commit 12b5b9c

Browse files
committed
Implemented autocomplete support at addon
1 parent 6303752 commit 12b5b9c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

dico_command/addon.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import typing
22
from .command import Command
33
try:
4-
from dico_interaction import InteractionCommand, ComponentCallback
4+
from dico_interaction import InteractionCommand, ComponentCallback, AutoComplete
55
except ImportError:
66
InteractionCommand = None
77
ComponentCallback = None
8+
AutoComplete = None
89

910
if typing.TYPE_CHECKING:
1011
from .bot import Bot
@@ -48,6 +49,7 @@ def __init__(self, bot: "Bot"):
4849
self.listeners: typing.List[Listener] = [x for x in resp if isinstance(x, Listener)]
4950
self.interactions: typing.List["InteractionCommand"] = [x for x in resp if InteractionCommand is not None and isinstance(x, InteractionCommand)]
5051
self.callbacks: typing.List["ComponentCallback"] = [x for x in resp if ComponentCallback is not None and isinstance(x, ComponentCallback)]
52+
self.autocompletes: typing.List["AutoComplete"] = [x for x in resp if AutoComplete is not None and isinstance(x, AutoComplete)]
5153
self.on_load()
5254

5355
def __str__(self):

dico_command/bot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def load_addons(self, *addons: typing.Type["Addon"]):
160160
for cc in loaded.callbacks:
161161
cc.register_self_or_cls(loaded)
162162
self.interaction.add_callback(cc)
163+
for ac in loaded.autocompletes:
164+
ac.register_self_or_cls(loaded)
165+
self.interaction.add_autocomplete(ac)
163166

164167
def unload_addons(self, *addons: typing.Union[str, typing.Type["Addon"]]):
165168
for x in addons:
@@ -179,6 +182,8 @@ def unload_addons(self, *addons: typing.Union[str, typing.Type["Addon"]]):
179182
self.interaction.remove_command(t)
180183
for cc in addon.callbacks:
181184
self.interaction.remove_callback(cc)
185+
for ac in addon.autocompletes:
186+
self.interaction.remove_autocomplete(ac)
182187
addon.on_unload()
183188

184189
def load_module(self, import_path: str):

0 commit comments

Comments
 (0)