Example #1
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
Example #2
0
def sync_main():
    PlaySoundeffectRequest(user="******", command="openingbell").save()

    while True:
        try:
            peasants = ChatLogs().recent_stream_peasants()
            # We need to make this better
            result = drop_random_soundeffect_to_user(
                random.sample(peasants, 1)[0])
            send_twitch_msg(result)

            for peasant in peasants:
                if peasant not in BLACKLIST:
                    user = User(peasant)
                    user_karma = user.karma()
                    print(f"@{peasant} Karma: {user.karma()}")
                    user.update_street_cred(1)
                    # user.update_street_cred(1 + user_karma)
                    user.revive(3 + user_karma)

            send_twitch_msg("CoolCat CoolCat CoolCat")
            # formatted_peasants = [f"@{peasant}" for peasant in peasants]
            # send_twitch_msg(
            #     f"Squid1 Enjoy your street cred: {' '.join(formatted_peasants)} Squid4"
            # )

            # Every 5 minutes, all the chatters have a chance at some street cred
            # os.system("time make deploy")
            time.sleep(300)
        except Exception as e:
            time.sleep(30)
            if e is KeyboardInterrupt:
                raise e
            else:
                traceback.print_exc()
Example #3
0
    def gamble(self) -> TransferOfWealth:
        transfer_of_wealth = self._match_winners_and_losers()
        for winner, loser, command in transfer_of_wealth:
            msg = f"@{winner} won !{command} from @{loser}"
            print(msg)
            send_twitch_msg(msg)
            result = CommandGiver(user=loser, command=command,
                                  friend=winner).give()

        return transfer_of_wealth
Example #4
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()
Example #5
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())
    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"
            )
Example #7
0
    def save(self):
        previous_requests = RequestSaver.previous_requests()

        request_to_save = self.user + " " + self.msg
        print(f"\n\nPrevious Request: {previous_requests}")
        print(f"Saving Request: {request_to_save}")

        # TODO: Make these messages configurable, aka turn them off
        if request_to_save in previous_requests:
            send_twitch_msg(
                f"Thank you @{self.user} we already have that request")
            pass
        else:
            if self.user not in BLACKLISTED_REQUESTERS:
                send_twitch_msg(begins_promise(self.user))
                with open(SOUNDEFFECT_REQUESTS_PATH, "a") as f:
                    f.write(request_to_save + "\n")
Example #8
0
def handle_user_requests():
    previous_requests = [
        request
        for request in SOUNDEFFECT_REQUESTS_PATH.read_text().split("\n")
        if request != ""
    ]

    print(f"Previous Requests: {previous_requests}")

    if previous_requests:
        for sound_request in previous_requests:
            if sound_request:
                send_twitch_msg("Request: @" + sound_request)
    else:
        send_twitch_msg("No Requests! Great Job STREAM_LORDS")

    try:
        _remove_completed_requests()
    except Exception as e:
        print(f"Error Removing Message: {e}")
 def _notify(self, sample_updated):
     if sample_updated:
         send_twitch_msg(f"Updated Sound Available: !{self.name}")
     else:
         send_twitch_msg(f"New Sound Available: !{self.name}")