Beispiel #1
0
    def _turn_the_tides(self, tide):
        fence_sitters = Vote.fence_sitters()
        user = User("beginbot")
        vote = Vote("beginbot")

        for fence_sitter in fence_sitters:
            fs = User(fence_sitter)

            # Maybe in peace time, you should only lose a fraction of your
            # commands
            fs.remove_all_commands()
            if tide == "revolution":
                print(fs.bankrupt())

        revolutionaries = vote.revolutionaries()
        peace_keepers = vote.peace_keepers()

        revolutionary_sounds = list(
            chain.from_iterable(
                [User(user).commands() for user in revolutionaries]))

        peace_keeper_sounds = list(
            chain.from_iterable(
                [User(user).commands() for user in peace_keepers]))

        print(f"Revolutionaries: {revolutionaries}")
        print(f"Sounds: {revolutionary_sounds}\n")
        print(f"Peace Keepers: {peace_keepers}")
        print(f"Sounds: {peace_keeper_sounds}\n")

        BreakingNews(
            user=self.revolutionary,
            scope=f"@{self.revolutionary} triggered a {tide} coup",
            category=tide,
            revolutionaries=revolutionaries,
            peace_keepers=peace_keepers,
            fence_sitters=fence_sitters,
        ).save()

        if tide == "peace":
            power_users = peace_keepers
            weaklings = revolutionaries
            self._transfer_power(peace_keepers, revolutionaries,
                                 revolutionary_sounds)
            return "REVOLUTIONS WILL NOT BE TOLERATED, AND REVOLUTIONARIES WILL BE PUNISHED"

        if tide == "revolution":
            power_users = revolutionaries
            weaklings = peace_keepers

            # We need to remove all Revolution permissionns before
            for revolutionary in revolutionaries:
                print(User(revolutionary).remove_all_commands())

            self._transfer_power(
                revolutionaries,
                peace_keepers,
                peace_keeper_sounds + revolutionary_sounds,
            )
            return "THE REVOLUTION IS NOW!"
Beispiel #2
0
    def test_peace_scenario(self):
        fence_sitter = User("CoolCat")
        fence_sitter.save()
        clap_command = Command("clap")
        clap_command.allow_user(fence_sitter.name)
        fence_sitter.update_street_cred(10)
        fence_sitter.update_cool_points(10)

        peace_keeper = User("picakhu")
        damn_command = Command("damn")
        damn_command.allow_user(peace_keeper.name)
        Vote(peace_keeper.name).vote("peace")
        peace_keeper.update_cool_points(11)
        peace_keeper.update_street_cred(10)
        peace_keeper.update_cool_points(10)

        peace_keeper2 = User("beginbotsmonster")
        wassup_command = Command("wassup_command")
        wassup_command.allow_user(peace_keeper2.name)
        Vote(peace_keeper2.name).vote("peace")

        revolutionary = User("beginbot")
        listen_command = Command("listen")
        listen_command.allow_user(revolutionary.name)
        Vote(revolutionary.name).vote("revolution")

        subject = Revolution(peace_keeper.name)
        subject.attempt_coup("peace")

        assert peace_keeper.name in listen_command.users()
        assert peace_keeper2.name not in listen_command.users()
        assert revolutionary.name not in listen_command.users()
        assert fence_sitter.name not in clap_command.users()
        assert fence_sitter.street_cred() == 10
        assert fence_sitter.cool_points() == 10
Beispiel #3
0
    def test_fence_sitters(self):
        revolutionary = User("beginbot")
        peace_keeper = User("beginbotsmonster")
        fence_sitter = User("picakhu")
        fence_sitter.save()

        Vote(revolutionary.name).vote("revolution")
        Vote(peace_keeper.name).vote("peace")

        assert Vote.fence_sitters() == ["picakhu"]
Beispiel #4
0
    def route(self):
        # if self.command == "coup" and self.user == "beginbotbot":

        if self.command == "coup":
            threshold = LaLibre.threshold()
            result = Vote.have_tables_turned(threshold)
            print(f"The Result of have_tables_turned: {result}")

            if result in ["peace", "revolution"]:
                return Revolution(self.user).attempt_coup(result)
            else:
                return f"The Will of the People have not chosen: {threshold} votes must be cast for either Peace or Revolution"

        if self.command in ["peace", "revolution", "vote"]:
            if self.command == "vote":
                vote = self.args[0]
                Vote(user=self.user).vote(vote)
            else:
                Vote(user=self.user).vote(self.command)
            return f"Thank you for your vote @{self.user}"
Beispiel #5
0
 def test_attempt_coup_with_enough_cool_points(self):
     revolutionary = "beginbot"
     user = User(revolutionary)
     user.update_street_cred(1)
     user.update_cool_points(11)
     subject = Revolution(revolutionary)
     tide = Vote.have_tables_turned(1)
     subject.attempt_coup(tide)
     assert user.street_cred() == 1
     assert user.cool_points() == 0
     assert self.coup.cost() == 33
Beispiel #6
0
    def test_peace_keeper_losing_it_all(self):
        fence_sitter = User("CoolCat")
        fence_sitter.save()
        clap = Command("clap")
        clap.allow_user(fence_sitter.name)

        damn_command = Command("damn")
        peace_keeper = User("picakhu")
        damn_command.allow_user(peace_keeper.name)
        Vote(peace_keeper.name).vote("peace")
        assert peace_keeper.name in damn_command.users()

        revolutionary = User("beginbot")
        Vote(revolutionary.name).vote("revolution")
        revolutionary.update_cool_points(11)
        subject = Revolution(revolutionary.name)
        subject.attempt_coup("revolution")

        assert peace_keeper.name not in damn_command.users()
        assert revolutionary.name in damn_command.users()
        assert "damn" not in fence_sitter.commands()
        assert fence_sitter.name not in clap.users()
Beispiel #7
0
    def test_inform(self):
        Vote("fake_user").vote("peace")
        result = LaLibre.inform()
        self.coup = Command("coup")
        User("fake_user").save()

        peasants = ChatLogs().recent_stream_peasants()
        threshold = 3

        assert result == [
            "PowerUpL La Libre PowerUpR",
            "Total Votes: 1",
            f"Peace Count: 1 / {threshold}",
            f"Revolution Count: 0 / {threshold}",
            f"panicBasket Coup Cost: {self.coup.cost()} panicBasket",
        ]
Beispiel #8
0
 def test_attempt_coup_without_enough_cool_points(self):
     revolutionary = "beginbot"
     user = User(revolutionary)
     assert user.street_cred() == 0
     assert user.cool_points() == 0
     user.update_street_cred(1)
     user.update_cool_points(1)
     subject = Revolution(revolutionary)
     tide = Vote.have_tables_turned(1)
     result = subject.attempt_coup(tide)
     assert user.street_cred() == 0
     assert user.cool_points() == 0
     assert (
         result ==
         "@beginbot is now Bankrupt, that will teach you a lesson. Coups require 11 Cool Points"
     )
Beispiel #9
0
    def test_the_tipping_point(self):
        thugga = self._create_user("youngthug")
        bbot = self._create_user("beginbot")
        monster = self._create_user("beginbotsmonster")
        assert User.count() == 3

        threshold = int(User.count() / 2)
        assert not Vote.have_tables_turned(threshold)
        Vote(user=thugga.name).vote("revolution")
        assert Vote.have_tables_turned(threshold) == "revolution"
        Vote(user=monster.name).vote("peace")
        assert not Vote.have_tables_turned(threshold)
        Vote(user=bbot.name).vote("peace")
        assert Vote.have_tables_turned(threshold) == "peace"
Beispiel #10
0
 def total_votes(self):
     return Vote.count()
Beispiel #11
0
 def revolution_count(self):
     vote = Vote("beginbot")
     return vote.revolution_count()
Beispiel #12
0
 def peace_count(self):
     vote = Vote("beginbot")
     return vote.peace_count()
Beispiel #13
0
 def test_vote(self):
     assert Vote.count() == 0
     result = RevolutionRouter("beginbotbot", "vote", ["peace"]).route()
     assert Vote.count() == 1
Beispiel #14
0
    def test_create_vote(self):
        user = "******"
        subject = Vote(user=user)

        assert subject.revolution_count() == 0
        assert subject.peace_count() == 0
        assert subject.vote_count() == 0

        subject.vote("revolution")
        assert subject.vote_count() == 1
        assert subject.revolution_count() == 1
        assert subject.peace_count() == 0

        subject.vote("peace")
        assert subject.peace_count() == 1
        assert subject.revolution_count() == 0
        assert subject.vote_count() == 1
        subject = Vote(user="******")
        subject.vote("revolution")
        assert subject.peace_count() == 1
        assert subject.revolution_count() == 1
        assert subject.vote_count() == 2

        subject = Vote(user="******")
        subject.vote("revolution")
        assert subject.revolution_count() == 2
        assert subject.vote_count() == 3