Created
September 30, 2016 17:02
-
-
Save Rapptz/8bcdb608e2a45790d9ba618d8303e684 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
USER_TOKEN = 'token' | |
API_BASE = 'https://discordapp.com/api' | |
class Embeds: | |
def __init__(self, data): | |
basic_keys = ('title', 'type', 'description', 'url', 'timestamp', 'color', | |
'footer', 'image', 'thumbnail', 'provider', 'author') | |
for key in basic_keys: | |
setattr(self, key, data.get(key)) | |
self.fields = data.get('fields', []) | |
class User: | |
def __init__(self, data): | |
self.username = data['username'] | |
self.discriminator = data['discriminator'] | |
self.id = int(data['id']) | |
self.avatar = data['avatar'] | |
class Webhook: | |
def __init__(self, data): | |
self.name = data['name'] | |
self.channel_id = int(data['channel_id']) | |
self.guild_id = int(data['guild_id']) | |
self.id = int(data['id']) | |
self.avatar = data['avatar'] | |
self.token = data['token'] | |
self.user = User(data['user']) | |
def execute(self, content, **kwargs): | |
payload = { | |
'content': content, | |
'username': kwargs.get('username') | |
} | |
headers = { | |
'Authorization': USER_TOKEN | |
} | |
url = '%s/webhooks/%s/%s' % (API_BASE, self.id, self.token) | |
r = requests.post(url, json=payload, headers=headers) | |
r.raise_for_status() | |
def create_channel_webhook(channel_id, *, name: str): | |
payload = { | |
'name': name, | |
'avatar': None | |
} | |
headers = { | |
'Authorization': USER_TOKEN | |
} | |
url = '%s/channels/%s/webhooks' % (API_BASE, channel_id) | |
resp = requests.post(url, json=payload, headers=headers) | |
resp.raise_for_status() | |
return Webhook(resp.json()) | |
if __name__ == '__main__': | |
thing = create_channel_webhook(84319995256905728, name='testing') | |
print(thing.__dict__) | |
thing.execute(content='hello') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment