Skip to content

Commit 2077e33

Browse files
committed
Implement get_prefix which replaces the former weird get_pre method
1 parent f15a959 commit 2077e33

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

bot.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
class ModmailBot(commands.Bot):
5656

5757
def __init__(self):
58-
super().__init__(command_prefix=self.get_pre)
58+
super().__init__(command_prefix=None) # implemented in `get_prefix`
5959
self.version = __version__
6060
self.start_time = datetime.utcnow()
6161
self.threads = ThreadManager(self)
@@ -75,6 +75,9 @@ def __init__(self):
7575
self._add_commands()
7676
self.owner = None
7777

78+
async def get_prefix(self, message=None):
79+
return [self.prefix, f'<@{self.user.id}> ', f'<@!{self.user.id}> ']
80+
7881
def _add_commands(self):
7982
"""Adds commands automatically"""
8083
self.remove_command('help')
@@ -199,11 +202,6 @@ def recipient_color(self):
199202
else:
200203
return color
201204

202-
@staticmethod
203-
async def get_pre(bot, message): # TODO: there gotta be a better way
204-
"""Returns the prefix."""
205-
return [bot.prefix, f'<@{bot.user.id}> ', f'<@!{bot.user.id}> ']
206-
207205
async def on_connect(self):
208206
print(line)
209207
print(Fore.CYAN, end='')
@@ -343,8 +341,7 @@ async def get_context(self, message, *, cls=commands.Context):
343341
if self._skip_check(message.author.id, self.user.id):
344342
return ctx
345343

346-
# TODO: Can be replaced with await `self.get_pre(self, None)`?
347-
prefixes = [self.prefix, f'<@{bot.user.id}> ', f'<@!{bot.user.id}> ']
344+
prefixes = await self.get_prefix()
348345

349346
invoked_prefix = discord.utils.find(view.skip_string, prefixes)
350347
if invoked_prefix is None:

core/thread.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515

1616
class Thread:
17-
"""Represents a discord modmail thread"""
17+
"""Represents a discord Modmail thread"""
1818

1919
def __init__(self, manager, recipient):
2020
self.manager = manager
2121
self.bot = manager.bot
22+
# TODO: Why wouldn't there be recipient?
2223
self.id = recipient.id if recipient else None
24+
# TODO: recipient should not be bot
2325
self.recipient = recipient
2426
self.channel = None
2527
self.ready_event = asyncio.Event()

0 commit comments

Comments
 (0)