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!"
def test_remove_all_commands(self): subject = User("artmattdank") assert subject.commands() == [] command = Command("flacid") command.allow_user("artmattdank") assert command.permitted_users() == ["artmattdank"] assert subject.commands() == ["flacid"] subject.remove_all_commands() assert subject.commands() == [] assert command.permitted_users() == []
def _transfer_power(self, power_users, weaklings, bounty): the_cycle_of_power_users = cycle(power_users) for user in weaklings: print(f"Removing All Commands for {user}") poor_sap = User(user) poor_sap.remove_all_commands() poor_sap.bankrupt() for sfx in bounty: user = next(the_cycle_of_power_users) print(f"Giving {user} SFX: {sfx}") Command(sfx).allow_user(user) return f"Power Transferred: {power_users} | {weaklings} | {bounty}"