예제 #1
0
파일: advanced.py 프로젝트: runz0rd/phial
def regex_in_command():
    '''Command that uses regex to define structure'''
    base_command = command.message.text.split(" ")[0]
    if slackbot.config['prefix']:
        base_command = base_command[1:]
    if base_command == "center":
        return Response(text="Yeehaw! You're a Yank", channel=command.channel)
    elif base_command == "centre":
        return Response(text="I say! You appear to be a Brit",
                        channel=command.channel)
    else:
        return Response(text="Well this is awkward... this isn't meant to \
                        happen",
                        channel=command.channel)
예제 #2
0
 def test_send_reaction(self):
     self.bot.send_reaction = MagicMock()
     response = Response(reaction='x',
                         channel='channel_id',
                         original_ts='timestamp')
     self.bot._execute_response(response)
     self.bot.send_reaction.assert_called_with(response)
예제 #3
0
    def test_send_message_attachments(self):
        self.bot.send_message = MagicMock()
        response = Response(
            channel="channel_id",
            attachments=[
                MessageAttachment(
                    fallback="fallback",
                    author_name="John Doe",
                    author_link="https://example.com/author",
                    author_icon="https://example.com/author.jpg",
                    color="#36a64f",
                    title="Title",
                    title_link="https://example.com",
                    image_url="https://example.com/image.jpg",
                    text="Go to Example Website",
                    footer="Footer text",
                    footer_icon="https://example.com/footer.jpg",
                    thumb_url="https://example.com/thumb.jpg",
                    fields=[
                        MessageAttachmentField(title="Established",
                                               value="2008",
                                               short=False),
                        MessageAttachmentField(title="Users",
                                               value="27 Million",
                                               short=True)
                    ])
            ])

        self.bot._execute_response(response)
        self.bot.send_message.assert_called_with(response)
예제 #4
0
 def test_send_reply(self):
     self.bot.send_message = MagicMock()
     response = Response(text='Hi test',
                         channel='channel_id',
                         original_ts='timestamp')
     self.bot._execute_response(response)
     self.bot.send_message.assert_called_with(response)
예제 #5
0
파일: advanced.py 프로젝트: runz0rd/phial
def fire_and_forget(channel):
    '''
        Example function used by background_processing().Sends a message
        outside of a command context.
    '''
    sleep(3)
    slackbot.send_message(
        Response(text="Background Process Message", channel=channel))
예제 #6
0
    def test_ephemeral_defaults_to_false(self):
        self.bot.slack_client = MagicMock()
        message = Response(channel="channel_id", text="Test text")
        self.bot.send_message(message)

        self.bot.slack_client.api_call.assert_called_with('chat.postMessage',
                                                          channel='channel_id',
                                                          as_user=True,
                                                          attachments='null',
                                                          text='Test text',
                                                          user=None)
예제 #7
0
파일: starter.py 프로젝트: fossabot/phial
def get_message_with_attachment():
    '''
        A command that posts a message with a Slack attachment
        Read more: https://api.slack.com/docs/message-attachments
    '''
    attachments = [{
        "title": "Here's the title of the attachment",
        "text": "...and here's the text",
        "footer": "Teeny tiny footer text"
    }]
    return Response(channel=command.channel, attachments=attachments)
예제 #8
0
    def test_send_message(self):
        self.bot.slack_client = MagicMock()
        self.bot.slack_client.api_call = MagicMock(return_value="test")
        message = Response(text='Hi test', channel='channel_id')
        self.bot.send_message(message)

        self.bot.slack_client.api_call.assert_called_with('chat.postMessage',
                                                          channel='channel_id',
                                                          text='Hi test',
                                                          as_user=True,
                                                          attachments='null')
예제 #9
0
    def test_errors_with_reaction_and_reply(self):
        response = Response(reaction='x',
                            text='test',
                            channel='channel_id',
                            original_ts='timestamp')

        with self.assertRaises(ValueError) as context:
            self.bot._execute_response(response)

        error_msg = 'Response objects with an original timestamp can ' \
                    + 'only have one of the attributes: Reaction, ' \
                    + 'Text'
        self.assertTrue(error_msg in str(context.exception))
예제 #10
0
    def test_ephemeral(self):
        self.bot.slack_client = MagicMock()
        message = Response(channel="channel_id",
                           ephemeral=True,
                           text="Test text",
                           user="******")
        self.bot.send_message(message)

        self.bot.slack_client.api_call.assert_called_with('chat.postEphemeral',
                                                          channel='channel_id',
                                                          as_user=True,
                                                          attachments='null',
                                                          text='Test text',
                                                          user='******')
예제 #11
0
    def test_basic_functionality(self):
        self.bot.slack_client = MagicMock()
        self.bot.slack_client.api_call = MagicMock()

        response = Response(reaction='x',
                            channel='channel_id',
                            original_ts='timestamp')
        self.bot.send_reaction(response)

        self.bot.slack_client.api_call \
            .assert_called_with("reactions.add",
                                channel=response.channel,
                                timestamp=response.original_ts,
                                name=response.reaction,
                                as_user=True)
예제 #12
0
    def test_send_reply(self):
        self.bot.slack_client = MagicMock()
        self.bot.slack_client.api_call = MagicMock(return_value="test")
        message = Response(text='Hi test',
                           channel='channel_id',
                           original_ts='timestamp')
        self.bot.send_message(message)

        self.bot.slack_client.api_call \
            .assert_called_with('chat.postMessage',
                                channel='channel_id',
                                text='Hi test',
                                thread_ts='timestamp',
                                as_user=True,
                                attachments='null',
                                user=None)
예제 #13
0
 def test_send_string(self):
     self.bot.send_message = MagicMock()
     message = phial.wrappers.Message(text="!test",
                                      channel="channel_id",
                                      user="******",
                                      timestamp="timestamp")
     command_instance = phial.wrappers.Command(command_pattern="base",
                                               channel="channel_id",
                                               args={},
                                               user="******",
                                               message=message)
     phial.globals._command_ctx_stack.push(command_instance)
     self.bot._execute_response("string")
     expected_response = Response(text='string', channel='channel_id')
     self.bot.send_message.assert_called_with(expected_response)
     phial.globals._command_ctx_stack.pop()
예제 #14
0
파일: advanced.py 프로젝트: runz0rd/phial
def get_message_with_attachment():
    '''A command that posts a message with a Slack attachment'''
    attachments = [
        MessageAttachment(
            title="Here's a message, it has 2 attachment fields",
            title_link="https://api.slack.com/docs/message-attachments",
            text="This message has some text!",
            fields=[
                MessageAttachmentField(
                    title="Here's the first attachment field",
                    value="And here's it's body",
                    short=True),
                MessageAttachmentField(title="...And here's the second",
                                       value="And here's it's body",
                                       short=True)
            ])
    ]
    return Response(channel=command.channel, attachments=attachments)
예제 #15
0
파일: starter.py 프로젝트: fossabot/phial
def reply():
    '''Simple command that replies to the original message in a thread'''
    return Response(text="this is a thread",
                    channel=command.channel,
                    original_ts=command.message_ts)
예제 #16
0
파일: starter.py 프로젝트: fossabot/phial
def react():
    '''Simple command that reacts to the original message'''
    return Response(reaction="x",
                    channel=command.channel,
                    original_ts=command.message_ts)
예제 #17
0
파일: starter.py 프로젝트: fossabot/phial
def hello(name, from_):
    '''Simple command with two arguments which replies to a message'''
    return Response(text="Hi {0}, from {1}".format(name, from_),
                    channel=command.channel)
예제 #18
0
파일: starter.py 프로젝트: fossabot/phial
def hello(name):
    '''Simple command with argument which replies to a message'''
    return Response(text="Hi {0}".format(name), channel=command.channel)
예제 #19
0
파일: advanced.py 프로젝트: runz0rd/phial
def shceduled_function():
    slackbot.send_message(
        Response(text="Hey! Hey Listen!", channel=SCHEDULED_CHANNEL))
예제 #20
0
    def test_send_message(self):
        self.bot.slack_client = MagicMock()
        message = Response(channel="channel_id",
                           attachments=[{
                               "fallback":
                               "fallback",
                               "author_name":
                               "John Doe",
                               "author_link":
                               "https://example.com/author",
                               "author_icon":
                               "https://example.com/author.jpg",
                               "color":
                               "#36a64f",
                               "title":
                               "Title",
                               "title_link":
                               "https://example.com",
                               "image_url":
                               "https://example.com/image.jpg",
                               "text":
                               "Go to Example Website",
                               "footer":
                               "Footer text",
                               "footer_icon":
                               "https://example.com/footer.jpg",
                               "thumb_url":
                               "https://example.com/thumb.jpg",
                               "fields": [{
                                   "title": "Established",
                                   "value": "2008",
                                   "short": False
                               }, {
                                   "title": "Users",
                                   "value": "27 Million",
                                   "short": True
                               }]
                           }])
        self.bot.send_message(message)

        expected_attachments = """
        [
            {
                "fallback":"fallback",
                "author_name":"John Doe",
                "author_link":"https://example.com/author",
                "author_icon":"https://example.com/author.jpg",
                "color":"#36a64f",
                "title":"Title",
                "title_link":"https://example.com",
                "image_url":"https://example.com/image.jpg",
                "text":"Go to Example Website",
                "footer":"Footer text",
                "footer_icon":"https://example.com/footer.jpg",
                "thumb_url":"https://example.com/thumb.jpg",
                "fields":[
                    {
                        "title":"Established",
                        "value":"2008",
                        "short":false
                    },
                    {
                        "title":"Users",
                        "value":"27 Million",
                        "short":true
                    }
                ]
            }
        ]
"""
        self.bot.slack_client.api_call.assert_called_with(
            'chat.postMessage',
            channel='channel_id',
            as_user=True,
            attachments=json.dumps(json.loads(expected_attachments)),
            text=None,
            user=None)
예제 #21
0
파일: advanced.py 프로젝트: runz0rd/phial
def regex_in_command_with_arg(arg):
    '''Command that uses regex to define structure with an arg'''
    base_command = command.message.text.split(" ")[0]
    return Response(text="My favourite {0} is {1}".format(base_command, arg),
                    channel=command.channel)
예제 #22
0
 def test_send_message(self):
     self.bot.send_message = MagicMock()
     response = Response(text='Hi test', channel='channel_id')
     self.bot._execute_response(response)
     self.bot.send_message.assert_called_with(response)