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 test_unreported_news(self): subject = BreakingNews( scope= "Cool Points are now the most valuable currency in the world!", ) subject.save() old_news = BreakingNews(scope="THE WORLD IS ENDING", reported_on=True) old_news.save() result = BreakingNews.unreported_news() assert "THE WORLD IS ENDING" not in result["scope"] assert ("Cool Points are now the most valuable currency in the world!" in result["scope"])
def _turn_the_tides(self, tide): fence_sitters = Vote.fence_sitters() user = User("beginbot") vote = Vote("beginbot") for fence_sitter in fence_sitters: fs = User(fence_sitter) # Maybe in peace time, you should only lose a fraction of your # commands fs.remove_all_commands() if tide == "revolution": print(fs.bankrupt()) revolutionaries = vote.revolutionaries() peace_keepers = vote.peace_keepers() revolutionary_sounds = list( chain.from_iterable( [User(user).commands() for user in revolutionaries])) peace_keeper_sounds = list( chain.from_iterable( [User(user).commands() for user in peace_keepers])) print(f"Revolutionaries: {revolutionaries}") print(f"Sounds: {revolutionary_sounds}\n") print(f"Peace Keepers: {peace_keepers}") print(f"Sounds: {peace_keeper_sounds}\n") BreakingNews( user=self.revolutionary, scope=f"@{self.revolutionary} triggered a {tide} coup", category=tide, revolutionaries=revolutionaries, peace_keepers=peace_keepers, fence_sitters=fence_sitters, ).save() if tide == "peace": power_users = peace_keepers weaklings = revolutionaries self._transfer_power(peace_keepers, revolutionaries, revolutionary_sounds) return "REVOLUTIONS WILL NOT BE TOLERATED, AND REVOLUTIONARIES WILL BE PUNISHED" if tide == "revolution": power_users = revolutionaries weaklings = peace_keepers # We need to remove all Revolution permissionns before for revolutionary in revolutionaries: print(User(revolutionary).remove_all_commands()) self._transfer_power( revolutionaries, peace_keepers, peace_keeper_sounds + revolutionary_sounds, ) return "THE REVOLUTION IS NOW!"
def test_breaking_news(self): subject = BreakingNews( scope="Cool Points are now the most valuable currency in the world!" ) assert BreakingNews.count() == 0 subject.save() assert BreakingNews.count() == 1
def _support(self): if self.args: user = self.args[0] else: user = Proposal.last()["user"] if user.startswith("@"): user = user[1:] proposal = Proposal.find_by_user(user) if Proposal(user).is_expired(): if proposal: print(f"Deleteing Expired Proposal from: {user}") Proposal.delete(proposal.doc_id) else: print(f"Did not find Proposal for {user}") total_support = len(proposal["supporters"]) + 1 support_msg = "" if proposal: support_msg = Proposal.support(user, proposal.doc_id, self.user) if total_support >= self.SUPPORT_REQUIREMENT: BreakingNews( scope=proposal["proposal"], category=proposal["command"] ).save() if proposal: print(f"Deleteing Proposal from: {user}, since it was approved!") Proposal.delete(proposal.doc_id) return support_msg + f" {total_support}/{self.SUPPORT_REQUIREMENT}"
def test_breaking_news_with_user(self): subject = BreakingNews( scope= "Cool Points are now the most valuable currency in the world!", user="******", ) assert subject._user == "coltrane"
def test_breaking_news_reported_on(self): subject = BreakingNews( scope= "Cool Points are now the most valuable currency in the world!", user="******", category="coup", ) subject.save() result = BreakingNews.report_last_story() assert (result["scope"] == "Cool Points are now the most valuable currency in the world!")
def test_breaking_news_with_category(self): subject = BreakingNews( scope= "Cool Points are now the most valuable currency in the world!", user="******", category="coup", ) subject.save() news = BreakingNews.all()[-1] assert news["user"] == "coltrane" assert news["category"] == "coup"
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")
def test_no_news(self): BreakingNews("Arch Linux is now Illegal").save() assert BreakingNews.count() == 1 ModeratorRouter("beginbotbot", "no_news", []).route() assert BreakingNews.count() == 0
def breaking_news(self, msg, user=None): self.last_breaking_time = datetime.now() BreakingNews( scope=msg, user=user, ).save()