async def on_thread_ready(self, thread, creator, category, initial_message): """Sends out menu to user""" menu_config = await self.db.find_one({'_id': 'config'}) if menu_config: message = DummyMessage(copy.copy(initial_message)) message.author = self.bot.modmail_guild.me message.content = menu_config['content'] #genesis = thread.recipient_genesis_message #await genesis.delete() msg, _ = await thread.reply(message, anonymous=True) for r in menu_config['options']: await msg.add_reaction(r) await asyncio.sleep(0.3) try: reaction, _ = await self.bot.wait_for( 'reaction_add', check=lambda r, u: r.message == msg and u == thread. recipient and str(r.emoji) in menu_config['options'], timeout=120) except asyncio.TimeoutError: message.content = 'No reaction recieved in menu... timing out' await thread.reply(message) else: alias = menu_config['options'][str(reaction.emoji)] ctxs = [] if alias is not None: ctxs = [] aliases = normalize_alias(alias) for alias in aliases: view = StringView(self.bot.prefix + alias) ctx_ = commands.Context(prefix=self.bot.prefix, view=view, bot=self.bot, message=message) ctx_.thread = thread discord.utils.find(view.skip_string, await self.bot.get_prefix()) ctx_.invoked_with = view.get_word().lower() ctx_.command = self.bot.all_commands.get( ctx_.invoked_with) ctxs += [ctx_] for ctx in ctxs: if ctx.command: old_checks = copy.copy(ctx.command.checks) ctx.command.checks = [ checks.has_permissions(PermissionLevel.INVALID) ] await self.bot.invoke(ctx) ctx.command.checks = old_checks continue
async def get_contexts(self, message, *, cls=commands.Context): """ Returns all invocation contexts from the message. Supports getting the prefix from database as well as command aliases. """ view = StringView(message.content) ctx = cls(prefix=self.prefix, view=view, bot=self, message=message) thread = await self.threads.find(channel=ctx.channel) if self._skip_check(message.author.id, self.user.id): return [ctx] prefixes = await self.get_prefix() invoked_prefix = discord.utils.find(view.skip_string, prefixes) if invoked_prefix is None: return [ctx] invoker = view.get_word().lower() # Check if there is any aliases being called. alias = self.aliases.get(invoker) if alias is not None: ctxs = [] aliases = normalize_alias( alias, message.content[len(f"{invoked_prefix}{invoker}"):]) if not aliases: logger.warning("Alias %s is invalid, removing.", invoker) self.aliases.pop(invoker) for alias in aliases: view = StringView(invoked_prefix + alias) ctx_ = cls(prefix=self.prefix, view=view, bot=self, message=message) ctx_.thread = thread discord.utils.find(view.skip_string, prefixes) ctx_.invoked_with = view.get_word().lower() ctx_.command = self.all_commands.get(ctx_.invoked_with) ctxs += [ctx_] return ctxs ctx.thread = thread ctx.invoked_with = invoker ctx.command = self.all_commands.get(invoker) return [ctx]