Skip to content

Commit f795a32

Browse files
committed
Set up database text indexes on bot start
1 parent 3a69e74 commit f795a32

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

bot.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ def _load_extensions(self):
128128
cog = f'cogs.{file[:-3]}'
129129
print(f'Loading {cog}')
130130
self.load_extension(cog)
131+
132+
async def is_owner(self, user):
133+
allowed = [int(x) for x in str(self.config.get('owners', '0')).split(',')]
134+
return user.id in allowed
131135

132136
async def logout(self):
133137
await self.session.close()
@@ -250,7 +254,15 @@ async def on_connect(self):
250254
print(Fore.CYAN + 'Connected to gateway.')
251255

252256
await self.config.refresh()
257+
if self.db:
258+
await self.setup_indexes()
253259
self._connected.set()
260+
261+
async def setup_indexes(self):
262+
coll = self.db.logs
263+
if 'messages.content_text' not in await coll.index_information():
264+
print('Creating "text" index for "messages.content"')
265+
await coll.create_index([('messages.content', 'text')], sparse=True)
254266

255267
async def on_ready(self):
256268
"""Bot startup, sets uptime."""
@@ -397,6 +409,8 @@ async def get_context(self, message, *, cls=commands.Context):
397409

398410
if self._skip_check(message.author.id, self.user.id):
399411
return ctx
412+
413+
ctx.thread = await self.threads.find(channel=ctx.channel)
400414

401415
prefixes = await self.get_prefix()
402416

0 commit comments

Comments
 (0)