Exemplo n.º 1
0
    def channels_messages_create(self,
                                 channel,
                                 content,
                                 nonce=None,
                                 tts=False,
                                 attachment=None,
                                 embed=None):
        payload = {
            'content': content,
            'nonce': nonce,
            'tts': tts,
        }

        if embed:
            payload['embed'] = embed.to_dict()

        if attachment:
            r = self.http(Routes.CHANNELS_MESSAGES_CREATE,
                          dict(channel=channel),
                          data={'payload_json': json.dumps(payload)},
                          files={'file': (attachment[0], attachment[1])})
        else:
            r = self.http(Routes.CHANNELS_MESSAGES_CREATE,
                          dict(channel=channel),
                          json=payload)

        return Message.create(self.client, r.json())
Exemplo n.º 2
0
    def channels_messages_create(self, channel, content, nonce=None, tts=False):
        r = self.http(Routes.CHANNELS_MESSAGES_CREATE, dict(channel=channel), json={
            'content': content,
            'nonce': nonce,
            'tts': tts,
        })

        return Message.create(self.client, r.json())
Exemplo n.º 3
0
    def webhooks_token_execute(self, webhook, token, data, wait=False):
        obj = self.http(
            Routes.WEBHOOKS_TOKEN_EXECUTE,
            dict(webhook=webhook, token=token),
            json=optional(**data), params={'wait': int(wait)})

        if wait:
            return Message.create(self.client, obj.json())
Exemplo n.º 4
0
    def channels_messages_list(self, channel, around=None, before=None, after=None, limit=50):
        r = self.http(Routes.CHANNELS_MESSAGES_LIST, dict(channel=channel), params=optional(
            around=around,
            before=before,
            after=after,
            limit=limit
        ))

        return Message.create_map(self.client, r.json())
Exemplo n.º 5
0
    def channels_messages_modify(self, channel, message, content, embed=None):
        payload = {
            'content': content,
        }

        if embed:
            payload['embed'] = embed.to_dict()

        r = self.http(Routes.CHANNELS_MESSAGES_MODIFY,
                      dict(channel=channel, message=message),
                      json=payload)
        return Message.create(self.client, r.json())
Exemplo n.º 6
0
Arquivo: client.py Projeto: zw5/disco
    def channels_messages_create(self,
                                 channel,
                                 content=None,
                                 nonce=None,
                                 tts=False,
                                 attachment=None,
                                 attachments=[],
                                 embed=None,
                                 sanitize=False):

        payload = {
            'nonce': nonce,
            'tts': tts,
        }

        if attachment:
            attachments = [attachment]
            warnings.warn(
                'attachment kwarg has been deprecated, switch to using attachments with a list',
                DeprecationWarning)

        if content:
            if sanitize:
                content = S(content)
            payload['content'] = content

        if embed:
            payload['embed'] = embed.to_dict()

        if attachments:
            if len(attachments) > 1:
                files = {
                    'file{}'.format(idx): tuple(i)
                    for idx, i in enumerate(attachments)
                }
            else:
                files = {
                    'file': tuple(attachments[0]),
                }

            r = self.http(
                Routes.CHANNELS_MESSAGES_CREATE,
                dict(channel=channel),
                data={'payload_json': json.dumps(payload)},
                files=files,
            )
        else:
            r = self.http(Routes.CHANNELS_MESSAGES_CREATE,
                          dict(channel=channel),
                          json=payload)

        return Message.create(self.client, r.json())
Exemplo n.º 7
0
    def channels_messages_modify(self, channel, message, content=None, embed=None, sanitize=False):
        payload = {}

        if content:
            if sanitize:
                content = S(content)
            payload['content'] = content

        if embed:
            payload['embed'] = embed.to_dict()

        r = self.http(Routes.CHANNELS_MESSAGES_MODIFY,
                      dict(channel=channel, message=message),
                      json=payload)
        return Message.create(self.client, r.json())
Exemplo n.º 8
0
 def channels_messages_modify(self, channel, message, content):
     r = self.http(Routes.CHANNELS_MESSAGES_MODIFY,
                   dict(channel=channel, message=message),
                   json={'content': content})
     return Message.create(self.client, r.json())
Exemplo n.º 9
0
 def channels_messages_get(self, channel, message):
     r = self.http(Routes.CHANNELS_MESSAGES_GET, dict(channel=channel, message=message))
     return Message.create(self.client, r.json())
Exemplo n.º 10
0
 def channels_pins_list(self, channel):
     r = self.http(Routes.CHANNELS_PINS_LIST, dict(channel=channel))
     return Message.create_map(self.client, r.json())