def test_your_bot_stealing_from_you(self, mock_present_users): creator = User("uzi").save() bot = User("uzibot").save() Command("clap").allow_user("uzi") User.register_bot("uzibot", "uzi") result = EconomyRouter("uzibot", "steal", ["uzi", "clap"]).route() assert result == "You cannot steal from your creator @uzibot @uzi"
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 props(self) -> str: parser = CommandParser( user=self.user, command=self.command, args=self.args, allow_random_user=True, ).parse() target_user_creator = User(parser.target_user).creator() user_creator = User(self.user).creator() target_user = parser.target_user top_eight = [] if parser.target_user == "random" or parser.target_user is None: top_eight = [ friend for friend in User(self.user).top_eight() if User(friend).creator() != self.user ] if top_eight == []: return f"@{self.user} You must specify a Top8 to give random props (Bots Don't count). !top8 @user" if target_user_creator == self.user: return f"You cannot props your own bot @{self.user} @{parser.target_user}" elif user_creator and user_creator == parser.target_user: return f"You cannot props your creator @{self.user} @{parser.target_user}" # target_user = random.sample( top_eight, 1)[0] return StreetCredTransfer( user=self.user, cool_person=target_user, top_eight=top_eight, amount=parser.amount, ).transfer()
def test_ya_bot_cannot_props_you(self): creator = User("uzi").save() bot = User("uzibot").save() User("uzi").update_street_cred(10) User.register_bot("uzibot", "uzi") result = EconomyRouter("uzibot", "props", ["uzi"]).route() assert result == "You cannot props your creator @uzibot @uzi"
def share(self): if not self.command in SoundeffectsLibrary.fetch_soundeffect_names(): raise ValueError(f"!{self.command} invalid command") command = Command(name=self.command) command_cost = command.cost() user_cool_points = User(self.user).cool_points() if self.user in STREAM_GODS: perm_result = command.allow_user(self.friend) return f"{self.user} shared {perm_result}" elif user_cool_points >= command_cost: perm_result = command.allow_user(self.friend) if perm_result: print("\nWe have a Perm Result") User(self.user).update_cool_points(-command_cost) command.increase_cost(command_cost * 2) return f"{self.user} shared {perm_result}" else: print("\nWe NOOOOO have a Perm Result") return f"{self.user} cannot add permissions" else: return f"@{self.user} Not enough cool_points ({user_cool_points}/{command_cost}) to share !{self.command} with @{self.friend}"
def route(self) -> Optional[Union[List[str], str]]: if self.command in ["insurance", "insure"]: return User(self.user).buy_insurance() if self.command == "archpack" and self.user in STREAM_GODS: return [ drop_effect(self.parser.target_user, "arch"), drop_effect(self.parser.target_user, "archluke"), drop_effect(self.parser.target_user, "gcc") ] if self.command == "commands": cmd_list = " | ".join(User(self.user).commands()) return f"@{self.user} Commands: {cmd_list}" if self.command == "css": # if self.user in STREAM_LORDS: return self.set_css() if self.command in ["me", "perm"]: return self.me() if self.command in ["permissions", "permission", "perms", "perm"]: return self.perms() if self.command == "donate": return self.donate() if self.command in ["love", "like"]: return self.love() if self.command in ["dislike", "hate", "detract"]: return self.hate() if self.command in [ "props", "bigups", "endorse", ]: return self.props() if self.command in ["steal"]: return self.steal() if self.command == "buy": return self.buy() # So What are the aliases here if self.command in COMMANDS["give"]["aliases"]: return self.give() if self.command in [ "share", "clone", "add_perm", "add_perms", "share_perm", "share_perms", ]: return self.share()
def route(self): if self.command == "la_libre": return " | ".join(LaLibre.inform()) if self.command == "streamlords": return " ".join(STREAM_LORDS) if self.command == "streamgods": return " ".join(STREAM_GODS) if self.command == "so": return self._shoutout() if self.user in STREAM_GODS: parser = CommandParser( user=self.user, command=self.command, args=self.args ).parse() if self.command == "bankrupt": return User(parser.target_user).bankrupt() if self.command == "paperup": if parser.target_user: return User(parser.target_user).paperup() else: return "You need to specify who to Paperup"
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
def _attempt_robbery(self, thief, command): thief.update_mana(-2) steal_count = BWIA.find_thief(thief) give_count = BWIA.robinhood_score(thief) print(f"This Thief Has Stolen {steal_count} times before") was_caught_stealing, the_odds = CaughtStealing(self._thief, self._target_sfx, self._victim, steal_count, give_count).call() the_odds = f"{the_odds}%" victim = User(self._victim) if victim.insured(): victim.set_value("insured", False) self.metadata[ "stealing_result"] = f"@{self._thief} was blocked by @{self._victim}'s insurance! Num Attempts: {steal_count}" elif was_caught_stealing: thief.update_value("notoriety", 1) self.metadata[ "stealing_result"] = f"@{self._thief} WAS CAUGHT STEALING! Chance of Success: {the_odds}. Num Attempts: {steal_count}" User(self._thief).set_value("mana", 0) else: self._steal(command, thief, the_odds)
def test_try_steal_unowned_sound(self, mock_present_users, mock_find_random_user): User("uzi").update_cool_points(10) user = User("young.thug") user.update_cool_points(10) result = EconomyRouter(user.name, "steal", ["clap", "uzi"]).route() assert result == "!clap is not owned by @uzi" assert user.cool_points() == 10
def fetch_permissions(cls, user, target_command, target_user): # Personal Permissions if not target_command and not target_user: user = User(user) stats = user.stats() sfx_count = len(user.commands()) return f"{stats} | SFX Count: {sfx_count}" # User Permissions if target_user and not target_command: title = f"@{target_user}'s" sfx_count = len(User(target_user).commands()) stats = User(target_user).stats() return f"{title} {stats} | SFX Count: {sfx_count}" # Command Permissions if target_command and not target_user: command = Command(target_command) user_permissions = " ".join( [f"@{perm}" for perm in command.users()]) from chat_thief.models.sfx_vote import SFXVote link = f"{BASE_URL}/commands/{target_command}.html" like_ratio = SFXVote(target_command).like_to_hate_ratio() stats = f"!{target_command} | Cost: {command.cost()} | Health: {command.health()} | Like Ratio {round(like_ratio)}% | {link}" return stats
def test_top_8_features(self, irc_msg): user = User("bill.evans") miles = User("miles.davis") miles.save() irc_response = irc_msg("bill.evans", "!top8 miles.davis") result = CommandRouter(irc_response, logger).build_response() assert result == "@miles.davis is now in @bill.evans's Top 8!" assert user.top_eight() == ["miles.davis"]
def test_removing_street_cred(self): assert User.total_street_cred() == 0 User("artmattdank").update_street_cred(-10) assert User.total_street_cred() == -10 User("artmattdank").update_street_cred(-3) assert User.total_street_cred() == -13 User("brianeno").update_street_cred(-420) assert User.total_street_cred() == -433
def test_total_cool_points(self): assert User.total_cool_points() == 0 User("artmattdank").update_cool_points(-10) assert User.total_cool_points() == -10 User("artmattdank").update_cool_points(-3) assert User.total_cool_points() == -13 User("brianeno").update_cool_points(-420) assert User.total_cool_points() == -433
def test_total_street_cred(self): assert User.total_street_cred() == 0 User("artmattdank").update_street_cred(10) assert User.total_street_cred() == 10 User("artmattdank").update_street_cred(3) assert User.total_street_cred() == 13 User("brianeno").update_street_cred(420) assert User.total_street_cred() == 433
def test_sharing_with_another_user(self, mock_find_random_user): user = "******" User("uzi").save() User(user).update_cool_points(10) command = Command("damn") command.allow_user(user) result = EconomyRouter(user, "share", ["damn", "uzi"]).route() assert result == "young.thug shared @uzi now has access to !damn"
def test_buying_a_random_command_with_syntax(self, user_with_points, mock_affordable_commands): Command("ohh").save() user = "******" initial_cool_points = User(user).cool_points() result = Buyer(user, "random").buy() assert "clap" not in User(user_with_points).commands() assert User(user).cool_points() < initial_cool_points
def test_people_get_caught_stealing(self): random.seed(1) # 17 from randint(0, 100) thief = "uzi" target_sfx = "clap" assert User("uzi").mana() == 3 busted, percentage = CaughtStealing(thief, target_sfx, "future").call() assert not busted assert User("uzi").mana() == 3
def test_buying_random(self, mock_find_random_user): user = "******" User(user).update_cool_points(10) result = EconomyRouter(user, "buy", ["clap"]).route() # This returns a Result Object right now # We have not decided all the proper boundaries # assert "@young.thug bought 1 SFXs: !clap" in result assert User(user).cool_points() < 10
def test_richest_cool_points(self): User.richest_cool_points() == None watto = User("watto", 3) artmattdank = User("artmattdank", 9) tpain = User("tpain", 1) tpain.update_cool_points(1) User.richest_cool_points()["name"] == "artmattdank" assert User.wealthiest() == "artmattdank"
def test_bot_survivor(self, irc_msg): user = User("uzi") user.save() User("uzibot").save() User.register_bot("uzibot", "don.cannon") irc_response = irc_msg("uzi", "!hatebot uzibot") result = CommandRouter(irc_response, logger).build_response() BotVote.count() == 1 assert result == "Thank you for your vote @uzi"
def test_all_props(self): young_thug = User("young.thug") young_thug.update_street_cred(10) uzi = User("uzi") result = EconomyRouter(young_thug.name, "props", [uzi.name, "all"]).route() assert young_thug.cool_points() == 0 assert young_thug.street_cred() == 0 assert uzi.cool_points() == 10
def test_richest(self): subject = User("artmattdank") subject.update_cool_points(10) thugga = User("thugga") thugga.update_cool_points(3) otheruser = User("otheruser") otheruser.update_cool_points(5) result = User.richest() expected = [("thugga", 3), ("otheruser", 5), ("artmattdank", 10)] assert result == expected
def test_invalid_command(self): user = User("fake_user") friend = User("bizmarkie") result = CommandSharer( user=user.name, command="fake_command", friend=friend.name, ).share() assert result == "@fake_user cannot share !fake_command as it's invalid"
def test_donate(self, mock_present_users, mock_find_random_user): user = User("uzi") User("young.thug").save() Command("clap").allow_user(user.name) assert "uzi" in Command("clap").users() assert "young.thug" not in Command("clap").users() result = EconomyRouter("uzi", "donate", ["young.thug"]).route() assert "young.thug" in Command("clap").users() assert "uzi" not in Command("clap").users() assert "was gifted" in result
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"]
def test_no_mana_to_steal(self): madonna = User("madonna") madonna.set_value("mana", 0) bowie = User("bowie") handbag = Command("handbag").save().allow_user("bowie") subject = Stealer(thief="madonna", target_sfx="handbag", victim="bowie") result = subject.steal() assert ( result.metadata["stealing_result"] == "@madonna has no Mana to steal from @bowie" )
def __init__(self, thief, target_sfx, victim, steal_count=0, give_count=0): self.thief = thief self.target_sfx = target_sfx self.victim = victim self.steal_count = steal_count self.give_count = give_count self.target_sfx_cost = Command(target_sfx).cost() self.thief_wealth = User(self.thief).wealth() self.victim_wealth = User(self.victim).wealth()
def test_transferring_a_command_already_owned(self, irc_msg): transferrer = User("thugga") transferee = User("wheezy") damn_command = Command("damn") damn_command.allow_user(transferee.name) message = "!transfer !damn @wheezy" irc_response = irc_msg(transferrer.name, message) result = CommandRouter(irc_response, logger).build_response() assert result == "@wheezy already has accesss to !damn @thugga"
def test_transferring_to_another_user(self, mock_find_random_user): user = "******" User("uzi").save() User(user).update_cool_points(10) command = Command("damn") command.allow_user(user) result = EconomyRouter(user, "give", ["damn", "uzi"]).route() assert result == [ "@uzi now has access to !damn", "@young.thug lost access to !damn", ]