def test_requesting_sfx(self):
     result = FeedbackRouter(
         "beginbotbot",
         "soundeffect",
         [YOUTUBE_URL, "@cool_user", "00:01", "00:04"],
     ).route()
     assert SoundeffectRequest.count() == 1
     sfx = SoundeffectRequest.last()
     assert sfx["command"] == "cool_user"
 def test_denying_sfx(self, mock_present_users):
     result = FeedbackRouter(
         "not_streamlord",
         "soundeffect",
         [YOUTUBE_URL, "storm_seeker", "00:01", "00:04"],
     ).route()
     assert SoundeffectRequest.count() == 1
     result = FeedbackRouter("beginbotbot", "deny",
                             ["not_streamlord"]).route()
     assert SoundeffectRequest.count() == 0
 def test_requesting_sfx_with_no_timestamps(self):
     result = FeedbackRouter(
         "cool_user",
         "soundeffect",
         [YOUTUBE_URL],
     ).route()
     assert SoundeffectRequest.count() == 1
     sfx = SoundeffectRequest.last()
     assert sfx["command"] == "cool_user"
     assert sfx["requester"] == "cool_user"
def sync_main():
    while True:
        try:
            SoundeffectRequest.pop_all_off()
            time.sleep(1)
        except Exception as e:
            if e is KeyboardInterrupt:
                raise e
            else:
                traceback.print_exc()
    def test_approving(self):
        assert SoundeffectRequest.unapproved_count() == 0
        subject = SoundeffectRequest(
            user="******",
            youtube_id="VW2yff3su0U",
            command="storm_seeker",
            start_time="00:01",
            end_time="00:06",
        )

        subject.save()
        assert not subject.approved
 def test_requesting_sfx(self):
     result = FeedbackRouter(
         "beginbotbot",
         "soundeffect",
         [YOUTUBE_URL, "storm_seeker", "00:01", "00:04"],
     ).route()
     assert SoundeffectRequest.count() == 1
 def test_deny_doc_id(self):
     subject = SoundeffectRequest(
         user="******",
         command="damn",
         youtube_id="VW2yff3su0U",
         start_time="00:01",
         end_time="00:05",
     )
     subject.save()
     request = SoundeffectRequest.get(command="damn")
     SoundeffectRequest.deny_doc_id("denier", request.doc_id)
     assert "damn" not in [
         request["command"] for request in SoundeffectRequest.all()
     ]
    def parse(self):
        # Santize the command
        if self.command.startswith("@") or self.command.startswith("!"):
            self.command = self.command[1:]

        if self.youtube_id is None:
            raise ValueError("Could not Find Valid URL")

        return SoundeffectRequest(
            user=self.user,
            youtube_id=self.youtube_id,
            command=self.command,
            start_time=self.start_time,
            end_time=self.end_time,
        )
    def test_creating_soundeffect_requests(self, request_parser, expected):
        assert SoundeffectRequest.count() == 0

        subject = SoundeffectRequest(
            user=request_parser.user,
            command=request_parser.command,
            youtube_id=request_parser.youtube_id,
            start_time=request_parser.start_time,
            end_time=request_parser.end_time,
        )

        subject.save()
        assert SoundeffectRequest.count() == 1
        assert subject.is_auto_approved() == expected["auto_approved"]
    def test_updating_a_sound(self):
        assert SoundeffectRequest.count() == 0

        subject = SoundeffectRequest(
            user="******",
            youtube_id="VW2yff3su0U",
            command="storm_seeker",
            start_time="00:01",
            end_time="00:06",
        ).save()

        assert SoundeffectRequest.count() == 1

        new_soundeffect = SoundeffectRequest(
            user="******",
            youtube_id="VW2yff3su0U",
            command="storm_seeker",
            start_time="00:02",
            end_time="00:08",
        )
        new_soundeffect.save()
        assert SoundeffectRequest.count() == 1
 def test_deny_doc_id_when_request_is_not_real(self):
     user = "******"
     doc_id = 1
     # We expect this to throw an error
     SoundeffectRequest.deny_doc_id(user, doc_id)
 def test_approve_doc_id(self):
     user = "******"
     doc_id = 1
     SoundeffectRequest.approve_doc_id(user, doc_id)
 def test_approve_command(self):
     command = "fake_command"
     user = "******"
     results = SoundeffectRequest.approve_command(user, command)
 def test_approve_all(self):
     user = "******"
     results = SoundeffectRequest.approve_all(approver=user)
    def test_stats(self, monkeypatch):
        # See Our Object is annoying!!!
        # We need a better way of saving these requests!
        unapproved = [
            FakeTinyDbResult({
                "requester": "c4tfive",
                "approver": None,
                "approved": False,
                "youtube_id": "qs7f3ssuEjA",
                "command": "tootsie",
                "start_time": "00:02",
                "end_time": "00:6",
                "doc_id": 3,
            }),
            FakeTinyDbResult({
                "requester": "kevinsjoberg",
                "approver": None,
                "approved": False,
                "youtube_id": "b1E9ucBTHsg",
                "command": "@kevinsjoberg",
                "start_time": "00:48",
                "end_time": "00:53",
                "doc_id": 2,
            }),
            FakeTinyDbResult({
                "requester": "whatsinmyopsec",
                "approver": None,
                "approved": False,
                "youtube_id": "sYPrBZFGkMM",
                "command": "bullyme",
                "start_time": "0:04",
                "end_time": "0:09",
                "doc_id": 1,
            }),
        ]

        monkeypatch.setattr(SoundeffectRequest, "unapproved",
                            lambda: unapproved)
        result = SoundeffectRequest.stats()

        expected = {
            "kevinsjoberg": {
                2: {
                    "name": "@kevinsjoberg",
                    "youtube": "https://youtu.be/b1E9ucBTHsg?t=48",
                    "time": "00:48 - 00:53",
                }
            },
            "c4tfive": {
                3: {
                    "name": "tootsie",
                    "youtube": "https://youtu.be/qs7f3ssuEjA?t=2",
                    "time": "00:02 - 00:6",
                }
            },
            "whatsinmyopsec": {
                1: {
                    "name": "bullyme",
                    "youtube": "https://youtu.be/sYPrBZFGkMM?t=4",
                    "time": "0:04 - 0:09",
                }
            },
        }

        assert result == expected
Exemplo n.º 16
0
    def route(self):
        if self.command == "soundeffect":
            try:
                sfx_request = SoundeffectRequestParser(self.user, self.args).parse()
            except Exception as e:
                return f'@{self.user} Correct Syntax: {HELP_COMMANDS["soundeffect"]}'

            SoundeffectRequest(
                user=self.user,
                youtube_id=sfx_request.youtube_id,
                command=sfx_request.command,
                start_time=sfx_request.start_time,
                end_time=sfx_request.end_time,
            ).save()

            return f"Thank you for your request @{self.user}, beginbotbot will you inform you when !{sfx_request.command} is available"

        # "!approve all"
        # "!approve 1"
        # "!approve @artmattdank"
        # "!approve !new_command"
        if self.command == "approve":
            if self.user in STREAM_LORDS:

                parser = RequestApproverParser(user=self.user, args=self.args).parse()

                if parser.target_user:
                    return SoundeffectRequest.approve_user(
                        self.user, parser.target_user
                    )
                elif parser.target_command:
                    return SoundeffectRequest.approve_command(
                        self.user, parser.target_command
                    )
                elif parser.doc_id:
                    return SoundeffectRequest.approve_doc_id(self.user, parser.doc_id)
                else:
                    return "Not Sure What to Approve"

        if self.command in ["deny"]:
            if self.user in STREAM_LORDS:
                parser = RequestApproverParser(user=self.user, args=self.args).parse()
                if parser.doc_id:
                    SoundeffectRequest.deny_doc_id(self.user, parser.doc_id)
                    return f"@{self.user} DENIED Request: {parser.doc_id}"

        if self.command in ["issue", "bug", "feature"]:
            if self.args:
                msg = " ".join(self.args)
                issue = Issue(user=self.user, msg=msg).save()
                return f"Thank You @{self.user} for your feedback, we will review and get back to you shortly"
            else:
                return f"@{self.user} Must include a description of the !issue"

        if self.command == "delete_issue" and self.user in STREAM_GODS:
            parser = RequestApproverParser(user=self.user, args=self.args).parse()

            if parser.doc_id:
                Issue.delete(parser.doc_id)
                return f"Issue: {parser.doc_id} Deleted "

        if self.command == "issues" and self.user in STREAM_GODS:
            return [
                f"@{issue['user']} ID: {issue.doc_id} - {issue['msg']}"
                for issue in Issue.all()
            ]

        if self.command == "requests":
            stats = SoundeffectRequest.formatted_stats()
            if not stats:
                stats = "Excellent Job Stream Lords No Requests!"
            return stats
 def test_approve_user(self):
     user = "******"
     target_user = "******"
     results = SoundeffectRequest.approve_user(user, target_user)