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")
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])
def build_response(self) -> Optional[str]: if self.user == "nightbot": return if self.user not in BLACKLISTED_LOG_USERS: self._logger.info(f"{self.user}: {self.msg}") WelcomeCommittee().welcome_new_users(self.user) success(f"\n{self.user}: {self.msg}") if self.user in STREAM_GODS: print(f"Oh Look we got a Stream God over here: {self.user}") if self.command == "curb_your_begin": return BreakingNews(" ".join(self.irc_msg.args), category="curb").save() if self.command in ["iasip", "alwayssunny"]: BreakingNews(" ".join(self.irc_msg.args), category="iasip").save() return parser = CommandParser( user=self.user, command=self.command, args=self.args ).parse() for Router in ROUTERS: try: if result := Router(self.user, self.command, self.args, parser).route(): # TODO: Sort out this Result Concept Better if isinstance(result, Result): # TODO: Update This UserEvent( user=self.irc_msg.user, command=self.irc_msg.command, msg=self.irc_msg.msg, result=[], # result=result, ).save() else: UserEvent( user=self.irc_msg.user, command=self.irc_msg.command, msg=self.irc_msg.msg, result=result, ).save() return result except Exception as e: traceback.print_exc() # raise e if self.command in OBS_COMMANDS and self.user in STREAM_LORDS: print(f"executing OBS Command: {self.command}") return os.system(f"so {self.command}") if self.command in SoundeffectsLibrary.fetch_soundeffect_names(): if self.command: PlaySoundeffectRequest(user=self.user, command=self.command).save()
def _find_or_create_user(self) -> Dict: user_result = self.db().get(Query().name == self.name) if user_result: return user_result else: success(f"Creating New User: {self.doc()}") with transaction(self.db()) as tr: tr.insert(self.doc()) return self.doc()
def _find_or_create_cube_bet(self): result = self.db().get(Query().user == self.user) if result: return result success(f"Creating New Cube Bet: {self.doc()}") from tinyrecord import transaction with transaction(self.db()) as tr: tr.insert(self.doc()) return self.doc()
def save(self): bet = self.db().get(Query().user == self.user) if bet: self.set_value("duration", self._duration) else: success(f"Creating New Cube Bet: {self.doc()}") from tinyrecord import transaction with transaction(self.db()) as tr: tr.insert(self.doc()) return self.doc()
def _find_or_create_user(self): # We should be using get user_result = self.db().search(Query().name == self.name) if user_result: user_result = user_result[0] return user_result else: success(f"Creating New User: {self.doc()}") from tinyrecord import transaction with transaction(self.db()) as tr: tr.insert(self.doc()) return self.doc()
def create_or_update(self): result = self.db().get(Query().user == self.user) if result: success(f"Updating Cube Bet: {self.doc()}") result = self.db().update(self.doc(), doc_ids=[result.doc_id]) return result else: success(f"Creating New Cube Bet: {self.doc()}") from tinyrecord import transaction with transaction(self.db()) as tr: tr.insert(self.doc()) return self.doc()
def play_sample(sound_file, notification=True): sound_name = sound_file.name[: -len(sound_file.suffix)] Command(sound_name).decay() success(f"Playing: {sound_name}") if notification: Notification(f"Playing: !{sound_name}", duration=1).save() try: subprocess.call( ["mplayer", "-af", f"volnorm=2:{MPLAYER_VOL_NORM}", sound_file], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, ) except: traceback.print_exc()
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}")
def build_response(self) -> Optional[str]: if self.user == "nightbot": return if self.user not in BLACKLISTED_LOG_USERS: self._logger.info(f"{self.user}: {self.msg}") WelcomeCommittee().welcome_new_users(self.user) success(f"\n{self.user}: {self.msg}") if self.user in STREAM_GODS: print(f"Oh Look we got a Stream God over here: {self.user}") if self.command == "curb_your_begin": return BreakingNews(" ".join(self.irc_msg.args), category="curb").save() if self.command in ["iasip", "alwayssunny"]: BreakingNews(" ".join(self.irc_msg.args), category="iasip").save() return parser = CommandParser( user=self.user, command=self.command, args=self.args ).parse() for Router in ROUTERS: try: if result := Router(self.user, self.command, self.args, parser).route(): # TODO: Sort out this Result Concept Better if isinstance(result, Result): # TODO: Update This UserEvent( user=self.irc_msg.user, command=self.irc_msg.command, msg=self.irc_msg.msg, result=[], # result=result, ).save() else: UserEvent( user=self.irc_msg.user, command=self.irc_msg.command, msg=self.irc_msg.msg, result=result, ).save() return result except Exception as e: traceback.print_exc() # raise e if self.command == "whylua": os.system(f"scene codin_and_teej") pack_config = { "teej_pack" : [], "dean_pack" : [], "erik_pack" : [], "vim_pack" : [], "pokemon_pack" : [], "sandstorm_pack" : [], "linux_pack" : [], "eightbit_pack" : [ "8bitmack", "8bitymca", "8bitmackintro", "8bitsk8erboi", "8bitmacarena", "8bitrickandmorty", "8bitimperial", "8bitfriday", "8bitghostbusters1", "8bitghostbuster2", "8bitfatbottomedgirls", "8bittoto", "8bitbitesthedust", "8bitchampions", "8bitbohemian", "8bitbagpipes", "8bitwreckingball", "8bitzelda", "8bitonemoretime", "8bitabout", "8bitblue", "8bithammer", "8bitafrica", "8bitrugrats", "8bitroll", "8bitparadise", "8bitrangers", "8bitcalifornialove" ], "silicon_valley_pack" : [], "gaming_pack" : [], "begin_pack" : [ "itsmedavid", "penisinspected", "bestsound", "beginsing", "beginvimeyes", "crack" ], "yacht_pack" : [], "luke_pack" : [ "gcc", "alpine", "xoomers", "inspiredme", "i3", "i3v2", "python" ], "wesley_willis_pack" : [], "art_matt_pack" : ["thisiscoke", "easyartmatt", "zenofartmatt", "moremore", "thisslaps"], "shannon_pack" : [], "meme_pack" : [], "i3_pack" : [], "prime_pack" : [ "primetrollsbegin", "primebegin", "primeslam", "primeagen", "primeagenpity", "begin_v_prime", "nevervim", ] } if self.command in pack_config["prime_pack"]: os.system(f"scene primetime") if self.command == "droppack" and self.user in STREAM_GODS and self.args[0] in pack_config.keys(): sounds = pack_config[ self.args[0] ] for sound in sounds: drop_effect(parser.target_user, sound) return f"Dropping the {self.args[0]} Pack for {parser.target_user}" if self.command in OBS_COMMANDS and self.user in STREAM_LORDS: print(f"executing OBS Command: {self.command}") return os.system(f"so {self.command}") if self.command == "trollbegin" and User(self.user).mana() > 0: User(self.user).kill() pause = 1 if parser.amount > 10: return "Trolling is the Art of Sublety" for _ in range(0, parser.amount): spin_begin(pause / parser.amount) return if self.command == "hottub" and self.user in STREAM_LORDS: return os.system("scene hottub") if self.command in SoundeffectsLibrary.fetch_soundeffect_names(): if self.command: return PlaySoundeffectRequest( user=self.user, command=self.command ).save() from pathlib import Path user_msgs_path = Path(__file__).parent.parent.joinpath("logs/user_msgs.log") if self.user not in BLACKLISTED_LOG_USERS: with open(user_msgs_path, "a") as log_file: log_file.write(f"{self.user}: {self.msg}\n")