Example #1
0
    async def process_commands(self, message):
        if message.author.bot:
            return

        if isinstance(message.channel, discord.DMChannel):
            return await self.process_dm_modmail(message)

        if message.content.startswith(self.prefix):
            cmd = message.content[len(self.prefix):].strip()

            # Process snippets
            if cmd in self.snippets:
                thread = await self.threads.find(channel=message.channel)
                snippet = self.snippets[cmd]
                if thread:
                    snippet = self.formatter.format(snippet,
                                                    recipient=thread.recipient)
                message.content = f"{self.prefix}reply {snippet}"

        ctxs = await self.get_contexts(message)
        for ctx in ctxs:
            if ctx.command:
                if not any(1 for check in ctx.command.checks
                           if hasattr(check, "permission_level")):
                    logger.debug(
                        "Command %s has no permissions check, adding invalid level.",
                        ctx.command.qualified_name,
                    )
                    checks.has_permissions(PermissionLevel.INVALID)(
                        ctx.command)

                await self.invoke(ctx)
                continue

            thread = await self.threads.find(channel=ctx.channel)
            if thread is not None:
                try:
                    reply_without_command = strtobool(
                        self.config["reply_without_command"])
                except ValueError:
                    reply_without_command = self.config.remove(
                        "reply_without_command")

                if reply_without_command:
                    await thread.reply(message)
                else:
                    await self.api.append_log(message, type_="internal")
            elif ctx.invoked_with:
                exc = commands.CommandNotFound(
                    'Command "{}" is not found'.format(ctx.invoked_with))
                self.dispatch("command_error", ctx, exc)
Example #2
0
    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
Example #3
0
    async def process_commands(self, message):
        if message.author.bot:
            return

        if isinstance(message.channel, discord.DMChannel):
            return await self.process_dm_modmail(message)

        if message.content.startswith(self.prefix):
            cmd = message.content[len(self.prefix):].strip()

            # Process snippets
            if cmd in self.snippets:
                snippet = self.snippets[cmd]
                message.content = f"{self.prefix}freply {snippet}"

        ctxs = await self.get_contexts(message)
        for ctx in ctxs:
            if ctx.command:
                if not any(1 for check in ctx.command.checks
                           if hasattr(check, "permission_level")):
                    logger.debug(
                        "Il comando %s non ha il controllo permessi, aggiungo il livello 'invalid'.",
                        ctx.command.qualified_name,
                    )
                    checks.has_permissions(PermissionLevel.INVALID)(
                        ctx.command)

                await self.invoke(ctx)
                continue

            thread = await self.threads.find(channel=ctx.channel)
            if thread is not None:
                if self.config.get("anon_reply_without_command"):
                    await thread.reply(message, anonymous=True)
                elif self.config.get("reply_without_command"):
                    await thread.reply(message)
                else:
                    await self.api.append_log(message, type_="internal")
            elif ctx.invoked_with:
                exc = commands.CommandNotFound(
                    'Il comando "{}" non รจ stato trovato'.format(
                        ctx.invoked_with))
                self.dispatch("command_error", ctx, exc)
Example #4
0
    def __init__(self, bot):
        self.bot = bot
        self._original_help_command = bot.help_command
        self.bot.help_command = ModmailHelpCommand(
            verify_checks=False, command_attrs={"help": "Shows this help message."}
        )
        # Looks a bit ugly
        self.bot.help_command._command_impl = checks.has_permissions(
            PermissionLevel.REGULAR
        )(self.bot.help_command._command_impl)

        self.bot.help_command.cog = self

        # Class Variables
        self.presence = None

        # Tasks
        self.presence_task = self.bot.loop.create_task(self.loop_presence())
Example #5
0
    def cog_unload(self):
        self.bot.help_command = self._original_help_command

    @commands.group(invoke_without_command=True)
    @checks.has_permissions(PermissionLevel.OWNER)
    @utils.trigger_typing