コード例 #1
0
ファイル: command_router.py プロジェクト: cl33per/chat_thief
    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()
コード例 #2
0
 def test_support(self):
     CommunityRouter.SUPPORT_REQUIREMENT = 1
     BreakingNews.count() == 0
     assert Proposal.count() == 0
     result = CommunityRouter(
         "beginbot", "propose", ["!iasip", "The", "Gang", "Steals", "Kappa"]
     ).route()
     result = CommunityRouter("uzi", "support", ["@beginbot"]).route()
     assert result == "@beginbot Thanks You for the support @uzi 1/1"
     assert BreakingNews.count() == 1
コード例 #3
0
 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!")
コード例 #4
0
    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"
コード例 #5
0
 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"])
コード例 #6
0
    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}"
コード例 #7
0
    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!"
コード例 #8
0
    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"
コード例 #9
0
 def test_deleting_proposal_after_report(self):
     CommunityRouter.SUPPORT_REQUIREMENT = 1
     result = CommunityRouter(
         "beginbot", "propose", ["!iasip", "The", "Gang", "Steals", "Kappa"]
     ).route()
     Proposal.count() == 1
     result = CommunityRouter("uzi", "support", ["@beginbot"]).route()
     assert BreakingNews.count() == 1
     assert Proposal.count() == 0
コード例 #10
0
 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
コード例 #11
0
    def check_for_breaking_news(self):
        if BreakingNews.unreported_news():
            last_news_story = BreakingNews.last()
            print(f"last news story: {last_news_story}")
            print(f"in coup: {self.in_coup}")
            print(f"Time since Last Breaking News: {self.last_breaking_time}")

            if self.last_breaking_time:
                how_long_since_break = datetime.now() - self.last_breaking_time
                print(f"How Long: {how_long_since_break}")

                # We Should also take into account the type of event
                # if how_long_since_break.seconds < 300:
                if how_long_since_break.seconds < 5:
                    # if how_long_since_break.seconds < 300:
                    print("Sorry Too Soon, waiting for more news")
                    time.sleep(3)
                else:
                    print("You have my permission to trigger breaking news")
                    self.trigger_breaking_news()
            else:
                print("Triggering Breaking News no previous news stories")
                self.trigger_breaking_news()
コード例 #12
0
    def trigger_breaking_news(self):
        # The key here is that this, changes the news to be unreported
        news_story = BreakingNews.report_last_story()
        category = news_story.get("category", None)

        if category == "iasip":
            os.system("scene iasip")
            time.sleep(7)
            os.system("scene")
        elif category == "curb":
            os.system("scene curb")
        else:
            os.system("scene breakin")
            os.system("nomeme")
            time.sleep(7)
            os.system("nomeme")
            os.system("scene news")

        self.last_breaking_time = datetime.now()
コード例 #13
0
    def route(self):
        if self.user in STREAM_GODS:
            if self.command == "no_news":
                return BreakingNews.purge()

            if self.command == "do_over":
                return self._do_over()

            if self.command == "revive":
                if self.parser.target_sfx:
                    print(
                        f"We are attempting to revive: !{self.parser.target_sfx}"
                    )
                    Command.find_or_create(self.parser.target_sfx)
                    return Command(self.parser.target_sfx).revive()
                elif self.parser.target_user:
                    return User(self.parser.target_user).revive()
                else:
                    print(f"Not Sure who or what to silence: {self.args}")

            if self.command == "silence":
                if self.parser.target_sfx:
                    print(f"We are attempting to silence: {self.target_sfx}")
                    return Command(self.parser.target_sfx).silence()
                elif self.parser.target_user:
                    print(
                        f"We are attempting to silence: {self.parser.target_user}"
                    )
                    return User(self.parser.target_user).kill()
                else:
                    print(f"Not Sure who or what to silence: {self.args}")

        if self.command == "dropeffect" and self.user in STREAM_GODS:
            return BeginFund(
                target_user=self.parser.target_user,
                target_command=self.parser.target_sfx,
                amount=self.parser.amount,
            ).drop()

        if self.command == "dropreward" and self.user in STREAM_GODS:
            return dropreward()
コード例 #14
0
 def test_iasip(self, irc_msg):
     irc_response = irc_msg("beginbot", "!iasip The Gang Steals Kappa")
     CommandRouter(irc_response, logger).build_response()
     news = BreakingNews.last()
     assert news["scope"] == "The Gang Steals Kappa"
コード例 #15
0
 def breaking_news(self, msg, user=None):
     self.last_breaking_time = datetime.now()
     BreakingNews(
         scope=msg,
         user=user,
     ).save()
コード例 #16
0
    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")
コード例 #17
0
 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
コード例 #18
0
ファイル: facts.py プロジェクト: dillonupgradeit/chat_thief
 def breaking_news(self):
     return BreakingNews.last()