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_thieves(self): UserEvent(user="******", command="steal", msg="!steal handbag @future", result=[]).save() UserEvent(user="******", command="steal", msg="!steal damn @carti ", result=[]).save() UserEvent(user="******", command="steal", msg="!steal rickroll @futre", result=[]).save() assert BWIA.thieves() == [("uzi", 2), ("carti", 1)]
def test_find_thief(self): UserEvent(user="******", command="steal", msg="!steal handbag @future", result=[]).save() UserEvent(user="******", command="steal", msg="!steal damn @carti ", result=[]).save() UserEvent(user="******", command="steal", msg="!steal rickroll @futre", result=[]).save() assert BWIA.find_thief("uzi") == 2 assert BWIA.find_thief("duzi") == 0
def test_buying_event(self, irc_msg): user = User("bill.evans") user.update_cool_points(10) irc_response = irc_msg("bill.evans", "!buy gcc") result = CommandRouter(irc_response, logger).build_response() last_event = UserEvent.last() assert last_event["user"] == "bill.evans" assert last_event["msg"] == "!buy gcc"
def thieves(cls): steal_events = UserEvent.db().search(Query().command == "steal") thieves = itertools.groupby(steal_events, operator.itemgetter("user")) steal_counts = [] for thief, user_events in thieves: steal_count = 0 for event in user_events: steal_count += 1 steal_counts.append((thief, steal_count)) return steal_counts
def test_user_events(self, irc_msg): user = User("bill.evans") miles = User("miles.davis") miles.save() irc_response = irc_msg("bill.evans", "!top8 miles.davis") result = CommandRouter(irc_response, logger).build_response() last_event = UserEvent.last() assert last_event["user"] == "bill.evans" assert last_event["msg"] == "!top8 miles.davis" assert last_event[ "result"] == "@miles.davis is now in @bill.evans's Top 8!" assert last_event["command"] == "top8"
def test_count(self): assert UserEvent.count() == 0 subject = UserEvent( user="******", command="me", msg="!me", result="Cool Result" ) subject.save() assert UserEvent.count() == 1 user_event = UserEvent.last() assert user_event["user"] == "beginbot" assert user_event["command"] == "me" assert "created_at" in user_event
def test_find_robinscore(self): UserEvent(user="******", command="give", msg="!give handbag @future", result=[]).save() UserEvent(user="******", command="give", msg="!give damn @carti ", result=[]).save() UserEvent(user="******", command="share", msg="!share rickroll @carti ", result=[]).save() UserEvent(user="******", command="steal", msg="!steal rickroll @carti ", result=[]).save() UserEvent(user="******", command="give", msg="!give rickroll @futre", result=[]).save() assert BWIA.robinhood_score("uzi") == 3 assert BWIA.robinhood_score("duzi") == 0 assert BWIA.robinhood_score("carti") == 1
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 find_thief(cls, thief): return len(UserEvent.db().search((Query().command == "steal") & (Query().user == thief)))
def robinhood_score(cls, user): return len(UserEvent.db().search(( (Query().command == "give") | (Query().command == "share")) & (Query().user == user)))