예제 #1
0
    async def test_handle_check_failure_errors(self):
        """Should await `ctx.send` when error is check failure."""
        test_cases = ({
            "error": errors.BotMissingPermissions(MagicMock()),
            "call_ctx_send": True
        }, {
            "error": errors.BotMissingRole(MagicMock()),
            "call_ctx_send": True
        }, {
            "error": errors.BotMissingAnyRole(MagicMock()),
            "call_ctx_send": True
        }, {
            "error": errors.NoPrivateMessage(),
            "call_ctx_send": True
        }, {
            "error": InWhitelistCheckFailure(1234),
            "call_ctx_send": True
        }, {
            "error": ResponseCodeError(MagicMock()),
            "call_ctx_send": False
        })

        for case in test_cases:
            with self.subTest(error=case["error"],
                              call_ctx_send=case["call_ctx_send"]):
                self.ctx.reset_mock()
                await self.cog.handle_check_failure(self.ctx, case["error"])
                if case["call_ctx_send"]:
                    self.ctx.send.assert_awaited_once()
                else:
                    self.ctx.send.assert_not_awaited()
예제 #2
0
 async def predicate(ctx: Context):
     if ctx.guild is None:
         raise errors.NoPrivateMessage()
     ssbu_controller = ctx.bot.get_controller('ssbu')
     db = ctx.bot.db
     channel = await db.wrap_text_channel(ctx.channel)
     author = await db.wrap_member(ctx.author)
     return await ssbu_controller.is_organizer(channel, author)
예제 #3
0
 async def predicate(ctx: Context):
     if ctx.guild is None:
         raise errors.NoPrivateMessage()
     ssbu_controller = ctx.bot.get_controller('ssbu')
     db = ctx.bot.db
     guild = await db.wrap_guild(ctx.guild)
     author = await db.wrap_member(ctx.author)
     return await ssbu_controller.is_main_organizer(guild, author)
예제 #4
0
 def predicate(ctx):
     items = ((ExtFuncs.readVars(ctx.guild.id)).get('Roles')).get(roleObj)
     if not isinstance(ctx.channel, discord.abc.GuildChannel):
         raise errors.NoPrivateMessage()
     getter = functools.partial(discord.utils.get, ctx.author.roles)
     if any(
             getter(
                 id=item) is not None if isinstance(item, int) else getter(
                     name=item) is not None for item in items):
         return True
     raise errors.MissingAnyRole(items)