示例#1
0
    async def on_thread_ready(self, thread, creator, category, initial_message):
        """Sends out menu to user"""
        config = await self.db.find_one({'_id': 'config'}) or {}
        responses = {}
        if not config.get('questions'): return

        q_message = DummyMessage(copy.copy(initial_message))
        q_message.author = self.bot.modmail_guild.me

        for question in config['questions']:
            q_message.content = question
            await thread.reply(q_message)

            try:
                m = await self.user_resp(thread.recipient, thread.recipient, timeout=30)
            except asyncio.TimeoutError:
                await thread.close(closer=self.bot.modmail_guild.me, message='Closed due to inactivity and not responding to questions')
                return
            else:
                responses[question] = m.content

        await asyncio.sleep(1)
        em = discord.Embed(color=self.bot.main_color, timestamp=datetime.utcnow())
        for k, v in responses.items():
            em.add_field(name=k, value=v, inline=False)
        em.set_author(name=m.author.name, icon_url=m.author.avatar_url)
        message = await thread.channel.send(embed=em)
        await message.pin()

        q_message.content = 'Your thread is now passed over to the moderators.'
        await thread.reply(q_message)

        move_to = self.bot.get_channel(int(config['move_to']))
        await thread.channel.edit(category=move_to, sync_permissions=True)
示例#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
示例#3
0
 async def activate_auto_triggers():
     if initial_message:
         message = DummyMessage(copy.copy(initial_message))
         try:
             return await self.bot.trigger_auto_triggers(message, channel)
         except RuntimeError:
             pass