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"
예제 #2
0
    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()
예제 #3
0
    def _do_over(self):
        print("WE ARE GOING FOR IT!")

        for user_name in [user["name"] for user in User.all()]:
            User(user_name).bankrupt()

        DataScrubber.purge_duplicate_users()
        DataScrubber.purge_theme_songs()
        DataScrubber.purge_duplicates()

        # This could be so much faster
        for command_name in Command.db().all():
            command_name = command_name["name"]
            print(command_name)
            command = Command(command_name)
            command_cost = command.cost()

            if command_cost < 2:
                command.set_value("cost", 1)
            else:
                new_cost = int(command_cost / 2)
                TheFed.collect_tax(new_cost)
                command.set_value("cost", new_cost)

        return "Society now must rebuild"
예제 #4
0
    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()
예제 #5
0
    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 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 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_buying_insurance(self, irc_msg):
     user = User("uzi")
     user.update_cool_points(10)
     irc_response = irc_msg("uzi", "!insurance")
     result = CommandRouter(irc_response, logger).build_response()
     assert user.insured()
     assert result == "@uzi thank you for purchasing insurance"
 def test_submitting_js(self, irc_msg):
     user = User("uzi")
     user.save()
     irc_response = irc_msg("uzi",
                            "!js https://gitlab.com/snippets/1990806/raw")
     result = CommandRouter(irc_response, logger).build_response()
     assert result == "Thanks for the custom JS @uzi!"
    def transfer(self) -> str:
        transferrer = User(self.user)

        if transferrer.street_cred() >= self.amount:
            return self._setup_transfer(transferrer)
        else:
            return f"@{self.user} NOT ENOUGH STREET CRED!"
예제 #11
0
 def test_commands(self):
     subject = User("artmattdank")
     assert subject.commands() == []
     command = Command("flacid")
     command.allow_user("artmattdank")
     assert command.users() == ["artmattdank"]
     assert subject.commands() == ["flacid"]
예제 #12
0
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_buying_event(self, irc_msg):
     user = User("bill.evans")
     user.update_cool_points(10)
     irc_response = irc_msg("bill.evans", "!buy gcc")
     result = CommandRouter(irc_response, logger).build_response()
     last_event = UserEvent.last()
     assert last_event["user"] == "bill.evans"
     assert last_event["msg"] == "!buy gcc"
예제 #14
0
    def top8(self):
        user = User(self.user)

        if self.parser.target_user:
            user.add_to_top_eight(self.parser.target_user)
            return f"@{self.parser.target_user} is now in @{self.user}'s Top 8!"
        else:
            raise ValueError(f"We have no target user to add to Top 8 {self.args}")
    def test_voting_for_a_bot(self):
        User("uzibot", 1)
        result = User.register_bot("uzibot", "don.cannon")
        result = BotSurvivorRouter("beginbotbot", "hatebot",
                                   ["uzibot"]).route()

        assert BotVote.count() == 1
        assert result == "Thank you for your vote @beginbotbot"
 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_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
예제 #18
0
 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_breaking_news(self):
     user = User("bill.evans")
     user.save()
     command = Command("damn")
     command.save()
     command.increase_cost(10)
     other_cmd = Command("win")
     other_cmd.save()
     subject = BreakingNewsBot()
예제 #20
0
 def test_buying_same_command(self, user_with_points,
                              mock_affordable_commands):
     user = User(user_with_points)
     assert len(user.commands()) == 0
     command = Command("mchdtmd").save()
     result = Buyer(user.name, command.name).buy()
     assert len(user.commands()) == 1
     result = Buyer(user.name, command.name).buy()
     assert len(user.commands()) == 1
    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_props_random(self, mock_find_random_user):
     uzi = User("uzi")
     uzi.update_street_cred(10)
     uzi.add_to_top_eight("future")
     uzi.add_to_top_eight("young.thug")
     uzi.add_to_top_eight("wheezy")
     result = EconomyRouter(uzi.name, "props", ["random", "2"]).route()
     assert result == "@uzi gave 1 Street Cred to @future @young.thug each"
     result = EconomyRouter(uzi.name, "props", ["random"]).route()
     assert result == "@uzi gave 1 Street Cred to @wheezy"
예제 #23
0
 def test_purge_theme_songs(self):
     uzi = User("uzi")
     illegal_cmd = Command("beginbot")
     illegal_cmd.save()
     illegal_cmd.allow_user("uzi")
     Command("damn").save()
     assert Command.count() == 2
     DataScrubber.purge_theme_songs()
     assert Command.count() == 1
     assert uzi.commands() == []
예제 #24
0
 def test_do_over(self):
     command = Command("damn")
     command.save()
     command.increase_cost(9)
     user = User("future", 100)
     user.save()
     assert user.cool_points() == 100
     result = ModeratorRouter("beginbotbot", "do_over", ["@future"]).route()
     assert command.cost() == 5
     assert result == "Society now must rebuild"
 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_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"
예제 #27
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!"
예제 #28
0
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()
예제 #29
0
    def _try_and_buy(self) -> PurchaseReceipt:
        user = User(self._user)

        if self._target_sfx == "random":
            target_sfx = user._find_affordable_random_command().name
        else:
            target_sfx = self._target_sfx

        print(f"@{user} Attempting to buy {target_sfx}")

        return self._buy_sfx(user, target_sfx)
예제 #30
0
    def test_buying(self):
        subject = Buyer(user="******", target_sfx="handbag")
        user = User("madonna")
        user.set_value("cool_points", 1)
        result = subject.buy()

        assert isinstance(result, Result)
        assert result.user == "madonna"
        assert result.command == "buy"
        assert "handbag" in user.commands()
        assert result.cool_points_diff == -1