def test_hate_and_like_command(self):
     assert SFXVote("clap").supporter_count() == 0
     assert SFXVote("clap").detractor_count() == 0
     result = EconomyRouter("thugga", "like", ["clap"]).route()
     assert SFXVote("clap").supporter_count() == 1
     result = EconomyRouter("future", "hate", ["clap"]).route()
     assert SFXVote("clap").detractor_count() == 1
Esempio n. 2
0
def command_stats(command_name):
    command = Command(command_name)
    sfx_vote = SFXVote(command_name)
    return render_template(
        "command.html",
        command=command,
        like_to_hate_ratio=sfx_vote.like_to_hate_ratio(),
    )
Esempio n. 3
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()
Esempio n. 4
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()
    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 hate(self) -> str:
     if self.parser.target_sfx and not self.parser.target_user:
         result = SFXVote(self.parser.target_sfx).detract(self.user)
         love_count = len(result["supporters"])
         hate_count = len(result["detractors"])
         return f"!{self.parser.target_sfx} supporters: {love_count} | detractors {hate_count}"
     else:
         return f"We are not sure who or what you trying to hate. Maybe try and focusing your hate better next time @{self.user}"
    def love(self) -> Optional[str]:
        if self.parser.target_sfx and not self.parser.target_user:
            result = SFXVote(self.parser.target_sfx).support(self.user)
            love_count = len(result["supporters"])
            hate_count = len(result["detractors"])
            return f"!{self.parser.target_sfx} supporters: {love_count} | detractors {hate_count}"

        if self.parser.target_user and not self.parser.target_sfx:
            if self.user == self.parser.target_user:
                return f"You can love yourself in real life, but not in Beginworld @{self.user}"
            else:
                User(self.user).set_ride_or_die(self.parser.target_user)
                return f"@{self.user} Made @{self.parser.target_user} their Ride or Die"
        else:
            return None
Esempio n. 8
0
 def test_sfx_vote(self):
     SFXVote.count() == 0
Esempio n. 9
0
 def test_create_sfx_vote(self):
     subject = SFXVote(command="clap")
     subject.support("thugga")
     SFXVote.count() == 1
     assert subject.supporter_count() == 1
     assert subject.detractor_count() == 0
     assert subject.is_enabled()
     subject.detract("bill")
     subject.detract("dennis")
     assert subject.detractor_count() == 2
     SFXVote.count() == 3
     assert not subject.is_enabled()