def test_mana(self): subject = User("artmattdank") assert subject.mana() == 3 subject.kill() assert subject.mana() == 0 subject.revive() assert subject.mana() == 3 subject.update_mana(-1) assert subject.mana() == 2 subject.revive() assert subject.mana() == 3
def authorizer(sound, username): user = User(username) mana = user.mana() streamlord = username in STREAM_LORDS # streamlord = username in STREAM_GODS owned = Command(sound).allowed_to_play(username) if streamlord: allowed = True else: allowed = owned and mana > 0 if allowed: user.update_mana(-1) result = { "allowed": allowed, "owned": owned, "streamlord": streamlord, "extra": False, "mana": mana } print(f"\n\n\t{result=}") return result
def test_caught_stealing(self): random.seed(5) madonna = User("madonna") bowie = User("bowie") handbag = Command("handbag").save().allow_user("bowie") subject = Stealer(thief="madonna", target_sfx="handbag", victim="bowie") assert madonna.mana() == 3 assert "handbag" not in madonna.commands() assert "handbag" in bowie.commands() result = subject.steal() assert "handbag" not in madonna.commands() assert "handbag" in bowie.commands() assert isinstance(result, Result) assert madonna.mana() == 0 assert ( "@madonna WAS CAUGHT STEALING! Chance of Success:" in result.metadata["stealing_result"] )
def sync_main(): while True: try: # This deletes them from the DB all_effects = PlaySoundeffectRequest().pop_all_off() for sfx in all_effects: command = Command(sfx["command"]) user = User(sfx["user"]) command_health = 5 # command_health = command.health() user_mana = user.mana() sfx_vote = SFXVote(command.name) user_allowed_to_play = command.allowed_to_play(user.name) public_approved = sfx_vote.is_enabled() if user.name in STREAM_GODS: soundfile = SoundeffectsLibrary.find_sample(sfx["command"]) if soundfile: AudioPlayer.play_sample(soundfile.resolve(), sfx["notification"], user.name) elif not public_approved: msg = f"Command: '!{command.name}' silenced: {round(sfx_vote.like_to_hate_ratio(), 2)}% Love/Hate Ratio" send_twitch_msg(msg) warning(msg) elif user_allowed_to_play and command_health > 0 and user_mana > 0: soundfile = SoundeffectsLibrary.find_sample(sfx["command"]) print(f"WE ARE TRYING TO PLAY: {soundfile}") if soundfile: AudioPlayer.play_sample(soundfile.resolve(), sfx["notification"], user.name) # user.update_mana(-1) else: warning( f"Couldn't find soundfile for {sfx['command']}") else: if user.name not in ["beginbot", "beginbotbot"]: # is the soundeffect isn't a real command # don't say anything msg = f"Not Playing '!{command.name}' for @{user.name} | Allowed: {user_allowed_to_play} | Mana: {user_mana}" send_twitch_msg(msg) warning(msg) # time.sleep(15) time.sleep(1) except Exception as e: if e is KeyboardInterrupt: raise e else: traceback.print_exc()
def test_stealing(self): madonna = User("madonna") bowie = User("bowie") handbag = Command("handbag").save().allow_user("bowie") subject = Stealer(thief="madonna", target_sfx="handbag", victim="bowie") assert "handbag" not in madonna.commands() assert "handbag" in bowie.commands() result = subject.steal() assert isinstance(result, Result) assert "handbag" in madonna.commands() assert "handbag" not in bowie.commands() assert madonna.mana() == 1 result.metadata["stealing_result"] == "@madonna stole from @bowie"
def steal(self): command = Command(self._target_sfx) thief = User(self._thief) the_odds = 0.7 if thief.mana() < 3: self.metadata[ "stealing_result"] = f"@{self._thief} has no Mana to steal from @{self._victim}" elif self._target_sfx not in User(self._victim).commands(): self.metadata[ "stealing_result"] = f"!{self._target_sfx} is not owned by @{self._victim}" else: self._attempt_robbery(thief, command) return Result(user=self._thief, command="steal", metadata=self.metadata)
def test_revive(self): user = User("future") ModeratorRouter("beginbotbot", "silence", ["@future"]).route() assert user.mana() == 0 result = ModeratorRouter("beginbotbot", "revive", ["@future"]).route() assert user.mana() == 3