Ejemplo n.º 1
0
    def give(self) -> str:
        parser = CommandParser(
            user=self.user,
            command=self.command,
            args=self.args,
            allow_random_sfx=True,
            allow_random_user=True,
        ).parse()

        if parser.target_command == "random":
            sfx_choices = random.choice(User(self.user).commands(),
                                        1) - [self.user]
            parser.target_sfx = sfx_choices[0]
            print(f"Choosing Random Command: {parser.target_command}")

        if parser.target_user == "random":
            command = Command(parser.target_sfx)
            parser.target_user = find_random_user(
                blacklisted_users=[command.users()] + [self.user])

        if parser.target_user is None:
            raise ValueError("We didn't find a user to give to")

        print(
            f"Attempting to give: !{parser.target_sfx} @{parser.target_user}")

        # This interface needs to call Command SFX
        return CommandGiver(
            user=self.user,
            command=parser.target_sfx,
            friend=parser.target_user,
        ).give()
Ejemplo n.º 2
0
 def collect_taxes(self):
     for command in Command.db().all():
         if command["cost"] > 1:
             print(f"Taxing {command['name']}")
             new_cost = int(command["cost"] / 2)
             Command(command["name"]).set_value("cost", new_cost)
             self.collect_tax(new_cost)
    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
Ejemplo n.º 4
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"]
Ejemplo n.º 5
0
def drop_effect(user, soundeffect):
    if user not in INVALID_USERS:
        print(f"\n\n\tDROPPING FOR: {user}\n")
        command = Command(soundeffect)
        TheFed.pay(command.cost())
        command.allow_user(user)
        return (user, soundeffect)
 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_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()
 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_expensive_command(self):
     Command("damn").save()
     Command("damn").set_value("cost", 10)
     CubeBet("uzi", 45, ["damn"]).save()
     CubeBet("ella", 38, ["8bitrickroll", "hello"]).save()
     CubeBet("miles", 36, ["handbag"]).save()
     result = NewCubeCasino(37).gamble()
     assert result == [
         ("miles", "ella", "hello"),
     ]
Ejemplo n.º 10
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()
 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",
     ]
    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"
Ejemplo n.º 13
0
    def test_dropeffect(self):
        result = BeginFund().dropeffect()
        assert result == "The Fed is Broke"

        Command("damn", 2).save()
        Command("handbag", 10).save()
        TheFed.collect_taxes()
        assert TheFed.reserve() == 6

        result = BeginFund().dropeffect()
        assert "now has access" in result
Ejemplo n.º 14
0
 def test_saving_a_problem_sample(self):
     assert Command.count() == 0
     subject = SampleSaver(
         user="******",
         youtube_id="https://www.youtube.com/watch?v=Ve-ATf6OTBQ",
         command="qwertimer",
         start_time="0:07",
         end_time="0:11",
     )
     subject.save()
     assert Command.count() == 1
Ejemplo n.º 15
0
    def _welcome(self, user):
        sound_effect_files = SoundeffectsLibrary.find_soundeffect_files(user)

        if sound_effect_files:
            effect = sound_effect_files[0]
            command = Command(user)
            command.update_health(1)
            PlaySoundeffectRequest(user=user, command=user).save()
        else:
            # Use non private method
            User(user)._find_or_create_user()
            send_twitch_msg(BeginFund(user).dropeffect())
Ejemplo n.º 16
0
    def test_giving_a_command_to_yourself(self):
        user = User("Miles")
        command = Command("damn")
        command.allow_user(user.name)

        assert user.name in command.users()

        with pytest.raises(ValueError) as e:
            subject = CommandGiver(user=user.name,
                                   command=command.name,
                                   friend=user.name)
            subject.give()
    def test_sharing_with_another_user(self, monkeypatch):
        def fake_random_user(self):
            return users.pop()

        monkeypatch.setattr(CurrentStream, "random_user", fake_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"
Ejemplo n.º 18
0
 def test_saving_a_sample(self):
     assert Command.count() == 0
     subject = SampleSaver(
         user="******",
         youtube_id="UZvwFztC1Gc",
         command="my_girlfriend",
         start_time="0:08",
         end_time="0:13",
     )
     subject.save()
     assert Command.count() == 1
     subject.save()
     assert Command.count() == 1
Ejemplo n.º 19
0
    def _find_affordable_random_command(self):
        if self.cool_points() < 1:
            raise ValueError("You can't afford anything!")

        looking_for_effect = True

        while looking_for_effect:
            effect = random_soundeffect()
            command = Command(effect)
            if self.cool_points() >= command.cost(
            ) and not command.allowed_to_play(self.name):
                looking_for_effect = False
        return command
Ejemplo n.º 20
0
 def test_breaking_news_initialization(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()
     assert subject.in_coup == False
     assert subject.last_breaking_time == None
     assert subject.initial_most_expensive["name"] == "damn"
     assert subject.initial_richest_user["name"] == "bill.evans"
Ejemplo n.º 21
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() == []
Ejemplo n.º 22
0
 def test_donate(self):
     user = User("uzi")
     Command("clap").allow_user(user.name)
     Command("damn").allow_user(user.name)
     assert "uzi" in Command("clap").users()
     assert "uzi" in Command("damn").users()
     assert "young.thug" not in Command("clap").users()
     assert "young.thug" not in Command("damn").users()
     result = Donator(user.name).donate("young.thug")
     assert "young.thug" in Command("clap").users()
     assert "young.thug" in Command("damn").users()
     assert "uzi" not in Command("clap").users()
     assert "uzi" not in Command("damn").users()
     assert result == "@young.thug was gifted !clap !damn"
Ejemplo n.º 23
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"
Ejemplo n.º 24
0
    def _welcome(self, user):
        sound_effect_files = SoundeffectsLibrary.find_soundeffect_files(user)

        if sound_effect_files:
            effect = sound_effect_files[0]
            command = Command(user)
            command.update_health(1)
            PlaySoundeffectRequest(user=user, command=user).save()
        else:
            # Use non private method
            User(user)._find_or_create_user()
            send_twitch_msg(BeginFund(user).dropeffect())
            send_twitch_msg(
                f"Welcome @{user}! You need a Theme song (max 5 secs): !soundeffect YOUTUBE-URL @{user} 00:03 00:07"
            )
    def test_submit_custom_css(self):
        user = "******"
        User(user).update_cool_points(10)
        command = Command("damn")
        command.allow_user(user)
        result = EconomyRouter(
            user,
            "css",
            ["https://gist.githubusercontent.com/davidbegin/raw/beginfun.css"],
        ).route()
        assert "Thanks for the custom CSS @beginbotbot!" in result

        css_filepath = Path(__file__).parent.parent.parent.joinpath(
            "build/beginworld_finance/styles/beginbotbot.css")
        assert css_filepath.exists()
Ejemplo n.º 26
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
Ejemplo n.º 27
0
 def __init__(self):
     self._all_votes = SFXVote.db().all()
     self._all_users = User.db().all()
     self._all_cmds = Command.db().all()
     # self._user_code = UserCode.db().all()
     self._all_sfxs = SoundeffectsLibrary.fetch_soundeffect_samples()
     self.command_users = self._setup_command_users()
Ejemplo n.º 28
0
    def _match_winners_and_losers(self):
        all_bets = CubeBet.all_bets()
        winners, loser_commands, winning_bet = self._find_winners_and_losers(all_bets)

        winner_names = " ".join([f"@{winner[0]}" for winner in winners])
        send_twitch_msg(f"Winners: {' | '.join(winner_names)}")

        transfer_of_wealth = []

        # We have to sort winners by their bet amount
        for winner in winners:
            user, bet, wager = winner
            bet_amount = sum([Command(command).cost() for command in wager])
            commands_to_win = [
                loser for loser in loser_commands if loser[2] <= bet_amount
            ]

            while bet_amount > 0 and len(commands_to_win) > 0:
                random.shuffle(commands_to_win)
                command_tuple = commands_to_win.pop()

                # We remove the Command, so others Winners can't win it
                loser_commands.remove(command_tuple)
                loser, command, cost = command_tuple
                bet_amount -= cost
                transfer_obj = (user, loser, command)
                print(f"Transfer Obj: {transfer_obj}")
                transfer_of_wealth.append(transfer_obj)

        return transfer_of_wealth
 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"
Ejemplo n.º 30
0
def home():
    users = User.by_cool_points()
    commands = Command.by_cost()
    return render_template(
        "beginworld_finance.html",
        users=users,
        commands=commands,
    )