Exemple #1
0
def setup_build_dir():
    warning("Setting Up Build Dir")

    # Delete and Recreate Build Direction for BeginWorld Finance HTML
    old_build_path = Path(__file__).parent.parent.parent.joinpath(
        "tmp/old_build/beginworld_finance")
    rmtree(old_build_path, ignore_errors=True)
    copytree(rendered_template_path, old_build_path)

    rmtree(rendered_template_path, ignore_errors=True)
    # This aint working!!!
    rendered_template_path.mkdir(exist_ok=True, parents=True)

    # Move the CSS File
    css_source = Path(__file__).parent.parent.joinpath("static")
    css_dest = Path(__file__).parent.parent.parent.joinpath(
        "build/beginworld_finance/styles")
    copytree(css_source, css_dest)

    # Move JS Files
    js_source = Path(__file__).parent.parent.joinpath("js")

    js_dest = Path(__file__).parent.parent.parent.joinpath(
        "build/beginworld_finance/js")
    copytree(js_source, js_dest)

    success("Finished Setting Up Build Dir")
Exemple #2
0
async def main():
    warning("Fetching All Data")
    all_data = StitchAndSort().call()
    stats = StatsDepartment().stats()
    success("All Data Fetched...Creating Tasks")
    all_commands = [command["name"] for command in all_data["commands"]]

    static_dir = Path(__file__).parent.parent.joinpath("static")
    stylish_users = [f.name[:-len(f.suffix)] for f in static_dir.glob("*.css")]

    print(f"Stylish Users: {stylish_users}")

    homepage_candidates = CSSVote.by_votes()
    try:
        winner = homepage_candidates[0][0]
    except:
        winner = User.wealthiest()

    warning("Setting Up Tasks")
    tasks = (
        [generate_home(all_data, stylish_users, homepage_candidates, winner)] +
        [generate_bots_page(winner)] + [generate_widgets_page(winner)] +
        [generate_stats_page(stats, winner)] + [
            generate_user_page(user_dict, all_commands)
            for user_dict in all_data["users"]
        ] + [
            generate_command_page(command, winner)
            for command in all_data["commands"]
        ])
    success("Finished Setting Up Tasks")

    await asyncio.gather(*[asyncio.create_task(task) for task in tasks])
async def _render_and_save_html(file_name, context, dest_filename=None):
    warning(f"Rendering Template: {dest_filename}")
    template = jinja2.Environment(loader=jinja2.FileSystemLoader(
        template_path), ).get_template(file_name)

    rendered_template = template.render(context)
    success(f"Finished Rendering Template: {dest_filename}")

    warning(f"Writing Template: {file_name}")
    if dest_filename:
        html_file = dest_filename

    else:
        html_file = file_name

    with open(rendered_template_path.joinpath(html_file), "w") as f:
        f.write(rendered_template)
    success(f"Finished Writing Template: {file_name}")
Exemple #4
0
    def vote(self, vote):
        user = self._find_user()

        def user_vote(new_vote):
            def transform(doc):
                doc["vote"] = new_vote

            return transform

        if user:
            print(f"Previous Vote for User {self.user}!")
            self.db().update(user_vote(vote), Query().user == self.user)
        else:
            warning(f"NO Previous Vote for User {self.user}!")
            from tinyrecord import transaction

            with transaction(self.db()) as tr:
                tr.insert(self.doc(vote))
            # self.doc(vote)

        return {"Revolution": self.revolution_count(), "Peace": self.peace_count()}
Exemple #5
0
    def vote(self, vote: str) -> Dict["str", int]:
        user = self._find_user()

        def user_vote(new_vote: str) -> Callable[[Dict], None]:
            def transform(doc: Dict) -> None:
                doc["vote"] = new_vote

            return transform

        if user:
            print(f"Previous Vote for User {self.user}!")
            self.db().update(user_vote(vote), Query().user == self.user)
        else:
            warning(f"NO Previous Vote for User {self.user}!")

            self._vote = vote
            with transaction(self.db()) as tr:
                tr.insert(self.doc())

        return {
            "Revolution": self.revolution_count(),
            "Peace": self.peace_count()
        }
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()