Exemplo n.º 1
0
    async def _quit(ctx):
        try:
            bot.check_has_joined_game(ctx.author.id)
            bot.check_can_confirm(ctx.author)
            assert not bot.is_active(bot.which_game(
                ctx.author.id)), msgs.CANNOT_QUIT_IN_GAME
        except Exception as e:
            await ctx.channel.send(e)
            return

        game_name = bot.which_game(ctx.author.id)

        if bot.get_admin(game_name) == ctx.author:
            await ctx.channel.send(msgs.CONFIRM_FOR_GAME_DESTRUCTION %
                                   game_name)
            confirm = await bot.confirm(ctx.author, "game quit (admin)")

            if confirm is None:
                return

            elif confirm:
                bot.delete_game(game_name)
                logger.debug("Game %s was deleted by its owner %s" %
                             (game_name, ctx.author.name))
                await ctx.channel.send(msgs.GAME_SUCCESSFULLY_DELETED %
                                       game_name)

        else:
            bot.quit_game(ctx.author.id)
            logger.debug("%s quited the game %s" %
                         (ctx.author.name, bot.which_game(ctx.author.id)))
            await ctx.channel.send(msgs.GAME_SUCCESSFULLY_QUITED % game_name)
Exemplo n.º 2
0
    async def _list(ctx):
        games = bot.get_opened_games()
        if games:
            await ctx.channel.send(embed=msgs.OPENED_GAMES_LIST.build(
                games="\n- ".join(games)))
        else:
            await ctx.channel.send(embed=msgs.NO_OPENED_GAME.build())

        logger.debug("Error")
Exemplo n.º 3
0
 async def next_step(self, roles, dialogs):
     """Go to next step when the previous one is over"""
     if not self._cur < len(self._steps) - 1:
         self._generate_turn()
     self._cur += 1
     self._check_game_is_over(roles)
     logger.debug(
         "Step %s has ended, starting step %s" % (self._steps[self._cur-1], self.current_step.__class__.__name__)
     )
     await self.current_step.start(roles, dialogs)
Exemplo n.º 4
0
    async def join(ctx, game_name=None):
        try:
            bot.check_parameter(game_name, "game join unePartie", "unePartie")
            bot.check_game_exists(game_name)
            bot.check_is_alone(ctx.author.id)
            bot.check_game_is_available(game_name)
        except Exception as e:
            await ctx.channel.send(e)
            return

        await bot.join_game(game_name, ctx.author)

        logger.debug("%s joined the game named %s " %
                     (ctx.author.name, game_name))
        await ctx.channel.send(msgs.SUCCESSFULLY_JOINED % game_name)
Exemplo n.º 5
0
    async def new(ctx, game_name=None, *too):
        try:
            bot.check_parameter(game_name, "game new nomDeLaPartie",
                                "nomDeLaPartie")
            bot.check_name_is_available(game_name)
            bot.check_is_alone(ctx.author.id)
            bot.check_not_too_much_parameters(too, "game new nomDeLaPartie")
        except Exception as e:
            await ctx.channel.send(e)
            return

        bot.add_game(game_name, ctx.author, home_channel=ctx.channel)
        logger.debug("%s created a game named %s" %
                     (ctx.author.name, game_name))
        await ctx.channel.send(msgs.SUCCESSFULLY_CREATED %
                               (game_name, game_name))
Exemplo n.º 6
0
    async def react(self,
                    cmd,
                    args,
                    author,
                    roles,
                    dialogs,
                    session,
                    disable_checks=False):
        """Reacts to a command, such as $kill or $vote."""

        if not disable_checks:
            if not (author.alive or cmd in ALLTIMES_CMDS):
                await self.error(to=author, msg=msgs.DEAD_USER_INVOKES_CMD)
                return

            if not (self.is_current_role(author) or cmd in ALLTIMES_CMDS):
                await author.send(msgs.WRONG_ROLE)
                return

        try:
            if hasattr(self, cmd + '_cmd'):
                await getattr(self, cmd + '_cmd')(args, author, roles, dialogs)
            elif hasattr(self, 'external_' + cmd + '_cmd'):
                await getattr(self,
                              'external_' + cmd + '_cmd')(args, author, roles,
                                                          dialogs, session)
            else:
                await self.command_not_found(cmd, author)

        except Exception as e:
            fmt = "'%s %s' command invocation raised a(n) %s :\n\n%s\n%s\n" % (
                cmd,
                " ".join(args),
                e.__class__.__name__,
                "".join(traceback.format_tb(e.__traceback__)),
                str(e) or "[no further info]",
            )

            logger.error(fmt)
            await self.error(to=author, msg=msgs.COMMAND_HAS_RAISED % cmd)

        else:
            logger.debug(
                "La commande de jeu '%s' vient d'être invoquée avec succès par %s"
                % (cmd, author.user.name))
Exemplo n.º 7
0
    async def kick(ctx, player: str = None):
        player = get_id(player)
        try:
            bot.check_parameter(player, "!game kick unJoueur", "unJoueur")
            bot.check_has_joined_game(ctx.author.id)
            bot.check_has_joined_game(player, bot.which_game(ctx.author.id))
            bot.check_is_game_admin(ctx.author.id)
            if player == ctx.author.id:
                raise NameError(msgs.CANNOT_KICK_YOURSELF)
        except Exception as e:
            await ctx.channel.send(e)
            return

        _game = bot.which_game(player)
        bot.quit_game(player)
        logger.debug("%s was kicked of the game %s" %
                     (ctx.author.name, bot.which_game(ctx.author.id)))
        await ctx.channel.send(msgs.SUCCESSFULLY_KICKED_FROM_GAME %
                               (make_mention(player), _game))
Exemplo n.º 8
0
    async def start(ctx, *too):
        try:
            bot.check_not_too_much_parameters(too, "!game start")
            bot.check_has_joined_game(ctx.author.id)
            bot.check_is_game_admin(ctx.author.id)
            bot.check_can_launch(bot.which_game(ctx.author.id))
        except Exception as e:
            await ctx.channel.send(e)
            return

        async with ctx.channel.typing():
            game_name = bot.which_game(ctx.author.id)
            category = get(ctx.guild.categories, name=EXPEDITIONS_CATEGORY)
            bot.voice_channels[
                game_name] = await ctx.guild.create_voice_channel(
                    game_name, category=category, reason="Heberge les débats")
            members = [
                member.mention for member in bot.get_game_members(game_name)
            ]
            await bot.launch_game(game_name)
            logger.debug("Game %s was started by its owner %s" %
                         (game_name, ctx.author.name))
            await ctx.channel.send(embed=msgs.GAME_START.build(
                members="\n- ".join(members)))
Exemplo n.º 9
0
async def on_message(msg):
    if not msg.author.bot:
        logger.debug("'%s' was sended by %s" %
                     (msg.content, msg.author.display_name))

    if msg.author == bot.user:
        return  # We don't want the bot to reply to itself !

    if type(msg.channel) is discord.DMChannel:
        if bot.devmode:
            try:
                await bot.devtool.process_commands(msg)
            except BaseException:
                msg = bot.devtool.transform_msg(msg)
                logger.debug("Message author was truncated for %s" %
                             msg.author.name)
            else:
                return

        logger.debug("Reacting to the message...")
        await bot.react(msg)
    elif msg.content.strip().startswith(consts.PREFIX):
        logger.debug("Processing the message as a command...")
        await bot.process_commands(msg)
Exemplo n.º 10
0
 def _generate_turn(self):
     """Create a new turn : night + day"""
     logger.debug("A new game turn was generated")
     self._steps.extend(self._turn or [])