コード例 #1
0
    async def love_cmd(self, args, author, roles, dialogs):
        """ `*love joueur1 joueur2` : Rends les joueurs j1 et j2 amoureux """
        try:
            target1, target2 = unpack(args, "!love joueur1 joueur2")
            roles.check_has_player(target1)
            roles.check_has_player(target2)
            assert roles.get_name_by_id(author.user.id) not in [
                target1, target2
            ], dialogs.lovemaker.try_to_involve_himself.tell()
            assert not target1 == target2, dialogs.lovemaker.target1_is_target2.tell(
            )
        except Exception as e:
            await self.error(to=author, msg=e)
            return

        target1_name = target1
        target2_name = target2
        target1 = roles.get_role_by_name(target1_name)
        target2 = roles.get_role_by_name(target2_name)

        target1.loving = target2
        target2.loving = target1
        await target1.user.send(
            dialogs.lovemaker.in_love.tell(lover=target2_name,
                                           role=target2.role.upper()))
        await target2.user.send(
            dialogs.lovemaker.in_love.tell(lover=target1_name,
                                           role=target1.role.upper()))
        if (target1.role == WEREWOLF) ^ (target2.role == WEREWOLF):
            await target1.user.send(
                dialogs.lovemaker.new_goal.tell(lover=target2_name))
            await target2.user.send(
                dialogs.lovemaker.new_goal.tell(lover=target1_name))

        await self.end(roles, dialogs)
コード例 #2
0
    async def private_cmd(self, args, author, roles, dialogs):
        """ `*private unJoueur monMessage` : Envoi le message uniquement à ce joueur """
        try:
            target, *msg = unpack(args, "$private unJoueur *monMessage")
            assert len(args) >= 2, "Il manque un message !"
            assert roles.get_role_by_name(target), msgs.NO_SUCH_PLAYER % target
        except Exception as e:
            await self.error(to=author, msg=e)
            return

        await self.redirect(from_=roles.get_name_by_id(author.user.id),
                            to=roles.get_role_by_name(target),
                            msg=" ".join(msg))
コード例 #3
0
    async def voteforall_cmd(self, args, author, roles, dialogs):
        """ `*voteforall unJoueur : Force tous les joueurs à voter contre ce joueur"""
        try:
            target = unpack(args, "!voteforall unJoueur")
            roles.check_has_player(target)
            roles.check_is_admin(author)
        except Exception as e:
            await self.error(to=author, msg=e)
            return

        for user in roles.alive_players.players():
            self.votes[roles.get_name_by_id(user.id)] = target

        await self.end(roles, dialogs)
コード例 #4
0
    async def external_admin_cmd(self, args, author, roles, dialogs, session):
        """ `*admin unJoueur` : Change l'administrateur de la partie pour unJoueur """
        try:
            new_admin = unpack(args, '!admin unJoueur')
            roles.check_is_admin(author)
            assert roles.get_role_by_name(
                new_admin), msgs.NO_SUCH_PLAYER % new_admin
        except Exception as e:
            await self.error(author.user, str(e))
            return

        session.set_admin(roles.get_role_by_name(new_admin).user.id)
        await roles.everyone.send(msgs.ADMIN_SUCCESSFULLY_CHANGED %
                                  (roles.game_name, new_admin))
コード例 #5
0
ファイル: seeker_step.py プロジェクト: alphasaft/werewolf_bot
    async def see_cmd(self, args, author, roles, dialogs):
        """ `*see unJoueur` : Vous renvoie le role de ce joueur """
        try:
            target = unpack(args, "!see unJoueur")
            roles.check_has_player(target)
            assert target != roles.get_name_by_id(
                author.user.id), dialogs.seeker.try_to_see_herself.tell()
        except Exception as e:
            await self.error(to=author, msg=e)
            return

        target_role = roles.get_role_by_name(target)
        await author.send(
            dialogs.seeker.see_role.tell(target=target,
                                         role=target_role.role.upper()))
        await self.end(roles, dialogs)
コード例 #6
0
ファイル: guard_step.py プロジェクト: alphasaft/werewolf_bot
    async def protect_cmd(self, args, author, roles, dialogs):
        """ `*protect unJoueur` : protège ce joueur """
        try:
            target = unpack(args, "$protect unJoueur")
            roles.check_has_player(target)
            assert roles.get_role_by_name(
                target) != author, dialogs.guard.try_to_protect_himself.tell()
            assert author.protected_player != target, dialogs.guard.same_target.tell(
                target=target)
        except Exception as e:
            await self.error(to=author, msg=str(e))
            return

        roles.protect(target)
        author.protected_player = target
        await author.send(dialogs.guard.done.tell(target=target))
        await self.end(roles, dialogs)
コード例 #7
0
ファイル: witch_step.py プロジェクト: alphasaft/werewolf_bot
    async def kill_cmd(self, args, author, roles, dialogs):
        """ `*kill unJoueur` : Utilise votre potion de mort pour tuer ce joueur """
        try:
            target = unpack(args, "!kill unJoueur")
            roles.check_has_player(target)
            assert roles.witch.death_potion, dialogs.witch.empty_death_potion.tell()
            assert target != roles.get_name_by_id(author.user.id), dialogs.witch.try_to_kill_herself.tell()
        except Exception as e:
            await self.error(to=author, msg=e)
            return

        author.use_death_potion()
        try:
            roles.wound(target)
            await roles.witch.send(dialogs.witch.kill.tell(target=target))
        except ProtectedPlayer:
            await roles.witch.send(dialogs.witch.target_protected.tell(target=target))
        await self.end(roles, dialogs)
コード例 #8
0
    async def external_kick_cmd(self, args, author, roles, dialogs, session):
        """ `*kick unJoueur` : Kick ce joueur de la partie """
        try:
            kicked = unpack(args, '!kick unJoueur')
            roles.check_is_admin(author)
            assert roles.get_role_by_name(kicked), msgs.NO_SUCH_PLAYER % kicked
        except Exception as e:
            await self.error(author.user, str(e))
            return

        await self.info(
            to=roles.everyone,
            msg="%s a été kické(e) de la partie. Il/elle était %s" %
            (kicked, roles.get_role_by_name(kicked).role))

        await roles.kill(kicked)
        session.remove_player(roles.get_role_by_name(kicked).id)
        await self.on_player_quit(roles, dialogs)
コード例 #9
0
ファイル: witch_step.py プロジェクト: alphasaft/werewolf_bot
    async def resurrect_cmd(self, args, author, roles, dialogs):
        """ `*resurrect (unJoueur)` : Ressucite  ce joueur, ou vous avec `$resurrect` """
        if not args:
            await self.resurrect_self(author, roles, dialogs)
            return

        try:
            target = unpack(args, "!resurrect unJoueur")
            assert not (target == roles.get_name_by_id(author.user.id) and not author.injured), dialogs.witch.try_to_resurrect_herself.tell()
            roles.check_has_player(target, injured=True)
            assert roles.witch.resurrect_potion, dialogs.witch.empty_resurrect_potion.tell()
        except Exception as e:
            await self.error(to=author, msg=e)
            return

        author.use_resurrect_potion()
        roles.heal(target)
        await roles.witch.user.send(dialogs.witch.resurrect.tell(target=target))
        await self.end(roles, dialogs)
コード例 #10
0
    async def kill_cmd(self, args, author, roles, dialogs):
        """ `*kill uneCible` : Propose de tuer ce joueur. Si tous les loups sont d'accord, il/elle sera tué(e)"""
        try:
            target = unpack(args, "!kill uneCible")
            assert author in roles.were_wolfs, "Vous n'êtes pas un loup-garou !"
            roles.check_has_player(target)
            assert roles.get_role_by_name(
                target
            ) not in roles.were_wolfs, dialogs.werewolf.try_to_kill_werewolf.tell(
            )
        except Exception as e:
            await self.error(to=author, msg=e)
            return

        if not self.targeted or self.targeted == target:
            self.agree_players.add(author)
            await self.info(
                to=author,
                msg=dialogs.werewolf.propose_target.tell(target=target))
            await self.info(to=roles.were_wolfs.exclude(author.user.id),
                            msg=dialogs.werewolf.get_target_proposition.tell(
                                from_player=roles.get_name_by_id(
                                    author.user.id),
                                target=target))

        else:
            await self.info(to=author,
                            msg=dialogs.werewolf.not_agree.tell(
                                old=self.targeted, new=target))
            await self.info(to=roles.were_wolfs.exclude(author.user.id),
                            msg=dialogs.werewolf.someone_doesnt_agree.tell(
                                from_player=roles.get_name_by_id(
                                    author.user.id),
                                old=self.targeted,
                                new=target))

            self.agree_players = {author}

        self.targeted = target
        if self.agree_players == roles.were_wolfs.only_alive():
            await self.end(roles, dialogs)
コード例 #11
0
    async def kill_cmd(self, args, author, roles, dialogs):
        """ `*kill unJoueur>` : Tue ce joueur. Vous mourrez après."""
        try:
            target = unpack(args, "!kill unJoueur>")
            assert target != roles.get_name_by_id(
                author.user.id), dialogs.hunter.try_to_kill_himself()
            roles.check_has_player(target)
        except Exception as e:
            await self.error(to=author, msg=e)
            return

        await roles.kill(target)
        await roles.hunter.user.send(
            dialogs.hunter.kill.tell(target=target,
                                     role=roles.get_role_by_name(target).role))
        await roles.everyone.exclude(roles.hunter.user.id).send(
            dialogs.hunter.die.tell(hunter=roles.get_name_by_id(
                roles.hunter.user.id),
                                    target=target,
                                    role=roles.get_role_by_name(target).role))
        await self.end(roles, dialogs)
コード例 #12
0
    async def nickname_cmd(self, args, author, roles: Roles, dialogs):
        """ `*nickname unPseudo` : Change votre pseudo pour unPseudo """

        try:
            new_nickname = unpack(args, "!nickname unPseudo")
            assert new_nickname.isalnum(
            ) and len(new_nickname) <= 15, msgs.INVALID_NICKNAME % new_nickname
            assert author not in self.confirmed, msgs.NICKNAME_ALREADY_CONFIRMED % roles.get_name_by_id(
                author.user.id)
            assert not roles.get_role_by_name(new_nickname), \
                msgs.NICKNAME_ALREADY_TAKEN % (new_nickname, roles.get_role_by_name(new_nickname).user.mention)
        except Exception as e:
            await self.error(to=author, msg=e)
            return

        if author in self.waiting_for_nicknames:
            self.waiting_for_nicknames.remove(author)

        roles.change_nickname(roles.get_name_by_id(author.user.id),
                              new_nickname)
        await self.info(to=author, msg=msgs.CHANGED_NICKNAME % new_nickname)
コード例 #13
0
    async def vote_cmd(self, args, author, roles, dialogs):
        """ `*vote unJoueur` : Dépose un vote contre ce joueur """
        try:
            target = unpack(args, "!vote unJoueur")
            roles.check_has_player(target)
            assert not self.votes.get(roles.get_name_by_id(
                author.user.id)), dialogs.everyone.has_already_voted.tell()
            assert not self.forced_targets or target in self.forced_targets, dialogs.everyone.invalid_vote_target.tell(
                authorized_targets=", ".join(self.forced_targets[:-1]) +
                " ou " + self.forced_targets[-1])
        except Exception as e:
            await self.error(to=author, msg=e)
            return

        self.votes[roles.get_name_by_id(author.user.id)] = target
        await self.info(to=roles.everyone,
                        msg=dialogs.everyone.has_voted.tell(
                            player=roles.get_name_by_id(author.user.id),
                            target=target))

        if set(
                roles.get_name_by_id(player.user.id)
                for player in roles.alive_players) == set(self.votes.keys()):
            await self.end(roles, dialogs)