commit 3e0f09d32c03de0916329c3b131ed1d46672bc02 Author: Rapptz Date: Fri Aug 21 18:18:34 2015 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..e2103c24d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.json +*.pyc +docs/_build diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..e69de29bb diff --git a/README.md b/README.md new file mode 100644 index 000000000..890d24010 --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +# PyDiscord + +PyDiscord is an API wrapper for Discord written in Python. + +This was written to allow easier writing of bots or chat logs. + +## This module is alpha! + +The discord API is constantly changing and the wrapper API is as well. There will be no effort to keep backwards compatibility. + +## Quick Example + +```py +import discord + +client = discord.Client() +client.login('email', 'password') + +@client.event +def on_message(message): + if message.content.startswith('!hello'): + client.send_message(message.channel, 'Hello was received!') + +@client.event +def on_ready(): + print('Logged in as') + print(client.user.name) + print(client.user.id) + print('------') + +client.run() +``` + +## Requirements + +- Python 2.7+ or Python 3.3+. +- `ws4py` library +- `requests` library + +Usually `pip` will handle these for you. + +## Related Projects + +- [discord.js](https://github.com/discord-js/discord.js) +- [node-discord](https://github.com/izy521/node-discord) +- [Discord.NET](https://github.com/RogueException/Discord.Net) +- [DiscordSharp](https://github.com/Luigifan/DiscordSharp) +- [Discord4J](https://github.com/knobody/Discord4J) diff --git a/discord/__init__.py b/discord/__init__.py new file mode 100644 index 000000000..d27da12e6 --- /dev/null +++ b/discord/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +Discord API Wrapper +~~~~~~~~~~~~~~~~~~~ + +A basic wrapper for the Discord API. + +:copyright: (c) 2015 Rapptz +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'discord' +__author__ = 'Rapptz' +__license__ = 'MIT' +__copyright__ = 'Copyright 2015 Rapptz' +__version__ = '0.1.0' +__build__ = 0x001000 + +from client import Client +from user import User +from channel import Channel, PrivateChannel +from server import Server +from message import Message +from errors import * diff --git a/discord/channel.py b/discord/channel.py new file mode 100644 index 000000000..734ad64a5 --- /dev/null +++ b/discord/channel.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +""" +The MIT License (MIT) + +Copyright (c) 2015 Rapptz + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +class Channel(object): + """Represents a Discord server channel. + + Instance attributes: + + .. attribute:: name + + The channel name. + .. attribute:: server + + The :class:`Server` the channel belongs to. + .. attribute:: id + + The channel ID. + .. attribute:: is_private + + ``True`` if the channel is a private channel (i.e. PM). ``False`` in this case. + .. attribute:: position + + The position in the channel list. + .. attribute:: type + + The channel type. Usually ``'voice'`` or ``'text'``. + """ + + def __init__(self, name, server, id, position, type, **kwargs): + self.name = name + self.server = server + self.id = id + self.is_private = False + self.position = position + self.type = type + +class PrivateChannel(object): + """Represents a Discord private channel. + + Instance attributes: + + .. attribute:: user + + The :class:`User` in the private channel. + .. attribute:: id + + The private channel ID. + .. attribute:: is_private + + ``True`` if the channel is a private channel (i.e. PM). ``True`` in this case. + """ + + def __init__(self, user, id, **kwargs): + self.user = user + self.id = id + self.is_private = True + diff --git a/discord/client.py b/discord/client.py new file mode 100644 index 000000000..203eef26f --- /dev/null +++ b/discord/client.py @@ -0,0 +1,280 @@ +# -*- coding: utf-8 -*- + +""" +The MIT License (MIT) + +Copyright (c) 2015 Rapptz + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +import requests +import json, re +import endpoints +from ws4py.client.threadedclient import WebSocketClient +# from threading import Timer +from sys import platform as sys_platform +from errors import InvalidEventName, InvalidDestination +from user import User +from channel import Channel, PrivateChannel +from server import Server +from message import Message + +def _null_event(*args, **kwargs): + pass + +class Client(object): + """Represents a client connection that connects to Discord. + This class is used to interact with the Discord WebSocket and API. + + .. attribute:: user + + A :class:`User` that represents the connected client. None if not logged in. + .. attribute:: servers + + A list of :class:`Server` that the connected client has available. + .. attribute:: private_channels + + A list of :class:`PrivateChannel` that the connected client is participating on. + """ + + def __init__(self, **kwargs): + self._is_logged_in = False + self.user = None + self.servers = [] + self.private_channels = [] + self.token = '' + self.events = { + 'on_ready': _null_event, + 'on_disconnect': _null_event, + 'on_error': _null_event, + 'on_response': _null_event, + 'on_message': _null_event + } + + self.ws = WebSocketClient(endpoints.WEBSOCKET_HUB, protocols=['http-only', 'chat']) + + # this is kind of hacky, but it's to avoid deadlocks. + # i.e. python does not allow me to have the current thread running if it's self + # it throws a 'cannot join current thread' RuntimeError + # So instead of doing a basic inheritance scheme, we're overriding the member functions. + + self.ws.opened = self._opened + self.ws.closed = self._closed + self.ws.received_message = self._received_message + self.ws.connect() + + # the actual headers for the request... + # we only override 'authorization' since the rest could use the defaults. + self.headers = { + 'authorization': self.token, + } + + def _received_message(self, msg): + response = json.loads(str(msg)) + if response.get('op') != 0: + return + + self.events['on_response'](response) + event = response.get('t') + data = response.get('d') + + if event == 'READY': + self.user = User(**data['user']) + guilds = data.get('guilds') + + for guild in guilds: + guild['roles'] = [role.get('name') for role in guild['roles']] + guild['members'] = [User(**member['user']) for member in guild['members']] + + self.servers.append(Server(**guild)) + channels = [Channel(server=self.servers[-1], **channel) for channel in guild['channels']] + self.servers[-1].channels = channels + + for pm in data.get('private_channels'): + self.private_channels.append(PrivateChannel(id=pm['id'], user=User(**pm['recipient']))) + + # set the keep alive interval.. + self.ws.heartbeat_freq = data.get('heartbeat_interval') + + # we're all ready + self.events['on_ready']() + elif event == 'MESSAGE_CREATE': + channel = self.get_channel(data.get('channel_id')) + message = Message(channel=channel, **data) + self.events['on_message'](message) + + def _opened(self): + print('Opened!') + + def _closed(self, code, reason=None): + print('closed with ', code, reason) + + def run(self): + """Runs the client and allows it to receive messages and events.""" + self.ws.run_forever() + + @property + def is_logged_in(self): + """Returns True if the client is successfully logged in. False otherwise.""" + return self._is_logged_in + + def get_channel(self, id): + """Returns a :class:`Channel` or :class:`PrivateChannel` with the following ID. If not found, returns None.""" + if id is None: + return None + + for server in self.servers: + for channel in server.channels: + if channel.id == id: + return channel + + for pm in self.private_channels: + if pm.id == id: + return pm + + def start_private_message(self, user): + """Starts a private message with the user. This allows you to :meth:`send_message` to it. + + Note that this method should rarely be called as :meth:`send_message` does it automatically. + + :param user: A :class:`User` to start the private message with. + """ + if not isinstance(user, User): + raise TypeError('user argument must be a User') + + payload = { + 'recipient_id': user.id + } + + r = response.post('{}/{}/channels'.format(endpoints.USERS, self.user.id), json=payload, headers=self.headers) + if r.status_code == 200: + data = r.json() + self.private_channels.append(PrivateChannel(id=data['id'], user=user)) + + def send_message(self, destination, content, mentions=True): + """Sends a message to the destination given with the content given. + + The destination could be a :class:`Channel` or a :class:`PrivateChannel`. For convenience + it could also be a :class:`User`. If it's a :class:`User` or :class:`PrivateChannel` then it + sends the message via private message, otherwise it sends the message to the channel. + + The content must be a type that can convert to a string through ``str(content)``. + + The mentions must be either an array of :class:`User` to mention or a boolean. If + ``mentions`` is ``True`` then all the users mentioned in the content are mentioned, otherwise + no one is mentioned. Note that to mention someone in the content, you should use :meth:`User.mention`. + + :param destination: The location to send the message. + :param content: The content of the message to send. + :param mentions: A list of :class:`User` to mention in the message or a boolean. Ignored for private messages. + """ + + channel_id = '' + is_private_message = True + if isinstance(destination, Channel) or isinstance(destination, PrivateChannel): + channel_id = destination.id + is_private_message = destination.is_private + elif isinstance(destination, User): + found = next((pm for pm in self.private_channels if pm.user == destination), None) + if found is None: + # Couldn't find the user, so start a PM with them first. + self.start_private_message(destination) + channel_id = self.private_channels[-1].id + else: + channel_id = found.id + else: + raise InvalidDestination('Destination must be Channel, PrivateChannel, or User') + + content = str(content) + + if isinstance(mentions, list): + mentions = [user.id for user in mentions] + elif mentions == True: + mentions = re.findall(r'@<(\d+)>', content) + else: + mentions = [] + + url = '{base}/{id}/messages'.format(base=endpoints.CHANNELS, id=channel_id) + payload = { + 'content': content, + } + + if not is_private_message: + payload['mentions'] = mentions + + response = requests.post(url, json=payload, headers=self.headers) + + + def login(self, email, password): + """Logs in the user with the following credentials. + + After this function is called, :attr:`is_logged_in` returns True if no + errors occur. + + :param str email: The email used to login. + :param str password: The password used to login. + """ + + payload = { + 'email': email, + 'password': password + } + + r = requests.post(endpoints.LOGIN, json=payload) + + if r.status_code == 200: + body = r.json() + self.token = body['token'] + self.headers['authorization'] = self.token + second_payload = { + 'op': 2, + 'd': { + 'token': self.token, + 'properties': { + '$os': sys_platform, + '$browser': 'pydiscord', + '$device': 'pydiscord', + '$referrer': '', + '$referring_domain': '' + } + } + } + + self.ws.send(json.dumps(second_payload)) + self._is_logged_in = True + + def event(self, function): + """A decorator that registers an event to listen to. + + You can find more info about the events on the :ref:`documentation below `. + + Example: :: + + @client.event + def on_ready(): + print('Ready!') + """ + + if function.__name__ not in self.events: + raise InvalidEventName('The function name {} is not a valid event name'.format(function.__name__)) + + self.events[function.__name__] = function + return function + diff --git a/discord/endpoints.py b/discord/endpoints.py new file mode 100644 index 000000000..315e63d17 --- /dev/null +++ b/discord/endpoints.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +""" +The MIT License (MIT) + +Copyright (c) 2015 Rapptz + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +WEBSOCKET_HUB = 'wss://discordapp.com/hub' +BASE = 'https://discordapp.com' +API_BASE = BASE + '/api' +USERS = API_BASE + '/users' +LOGIN = API_BASE + '/auth/login' +LOGOUT = API_BASE + '/auth/logout' +SERVERS = API_BASE + '/guilds' +CHANNELS = API_BASE + '/channels' diff --git a/discord/errors.py b/discord/errors.py new file mode 100644 index 000000000..b0a6679cb --- /dev/null +++ b/discord/errors.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +""" +The MIT License (MIT) + +Copyright (c) 2015 Rapptz + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +class InvalidEventName(Exception): + """Thrown when an event from :meth:`Client.event` has an invalid name.""" + pass + +class InvalidDestination(Exception): + """Thrown when the destination from :meth:`Client.send_message` is invalid.""" + pass diff --git a/discord/message.py b/discord/message.py new file mode 100644 index 000000000..a77738095 --- /dev/null +++ b/discord/message.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- + +""" +The MIT License (MIT) + +Copyright (c) 2015 Rapptz + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +import datetime +from user import User + +class Message(object): + """Represents a message from Discord. + + There should be no need to create one of these manually. + + Instance attributes: + + .. attribute:: edited_timestamp + + A datetime object containing the edited time of the message. Could be None. + .. attribute:: timestamp + + A datetime object containing the time the message was created. + .. attribute:: tts + + Checks the message has text-to-speech support. + .. attribute:: author + + A :class:`User` that sent the message. + .. attribute:: content + + The actual contents of the message. + .. attribute:: embeds + + An array of embedded objects. + .. attribute:: channel + + The :class:`Channel` that the message was sent from. Could be a :class:`PrivateChannel` if it's a private message. + .. attribute:: mention_everyone + + A boolean specifying if the message mentions everyone. + .. attribute:: mentions + + An array of :class:`User`s that were mentioned. + .. attribute:: id + + The message ID. + """ + + def __init__(self, edited_timestamp, timestamp, tts, content, mention_everyone, mentions, embeds, attachments, id, channel, author, **kwargs): + # at the moment, the timestamps seem to be naive so they have no time zone and operate on UTC time. + # we can use this to our advantage to use strptime instead of a complicated parsing routine. + # example timestamp: 2015-08-21T12:03:45.782000+00:00 + time_format = "%Y-%m-%dT%H:%M:%S.%f+00:00" + self.edited_timestamp = None + if edited_timestamp is not None: + self.edited_timestamp = datetime.datetime.strptime(edited_timestamp, time_format) + + self.timestamp = datetime.datetime.strptime(timestamp, time_format) + self.tts = tts + self.content = content + self.mention_everyone = mention_everyone + self.embeds = embeds + self.id = id + self.channel = channel + self.author = User(**author) + self.mentions = [User(**mention) for mention in mentions] + + + diff --git a/discord/server.py b/discord/server.py new file mode 100644 index 000000000..ae4d81649 --- /dev/null +++ b/discord/server.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- + +""" +The MIT License (MIT) + +Copyright (c) 2015 Rapptz + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +from user import User + +class Server(object): + """Represents a Discord server. + + Instance attributes: + + .. attribute:: name + + The server name. + .. attribute:: roles + + An array of role names. + .. attribute:: region + + The region the server belongs on. + .. attribute:: afk_timeout + + The timeout to get sent to the AFK channel. + .. attribute:: afk_channel_id + + The channel ID for the AFK channel. None if it doesn't exist. + .. attribute:: members + + An array of :class:`User` that are currently on the server. + .. attribute:: channels + + An array of :class:`Channel` that are currently on the server. + .. attribute:: icon + + The server's icon. + .. attribute:: id + + The server's ID. + .. attribute:: owner_id + + The ID of the server's owner. + """ + + def __init__(self, name, roles, region, afk_timeout, afk_channel_id, members, icon, id, owner_id, **kwargs): + self.name = name + self.roles = roles + self.region = region + self.afk_timeout = afk_timeout + self.afk_channel_id = afk_channel_id + self.members = members + self.icon = icon + self.id = id + self.owner_id = owner_id diff --git a/discord/user.py b/discord/user.py new file mode 100644 index 000000000..804850e1b --- /dev/null +++ b/discord/user.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +""" +The MIT License (MIT) + +Copyright (c) 2015 Rapptz + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +class User(object): + """Represents a Discord user. + + Instance attributes: + + .. attribute:: name + + The user's username. + .. attribute:: id + + The user's unique ID. + .. attribute:: discriminator + + The user's discriminator. This is given when the username has conflicts. + .. attribute:: avatar + + The avatar hash the user has. Could be None. + """ + + def __init__(self, username, id, discriminator, avatar, **kwargs): + self.name = username + self.id = id + self.discriminator = discriminator + self.avatar = avatar + + def __str__(self): + return self.name + + def __eq__(self, other): + return isinstance(other, User) and other.id == self.id + + def __ne__(self, other): + if isinstance(other, User): + return other.id != self.id + return False + + def avatar_url(self): + """Returns a friendly URL version of the avatar variable the user has. An empty string if + the user has no avatar.""" + if self.avatar is None: + return '' + return 'https://discordapp.com/api/users/{0.id}/avatars/{0.avatar}.jpg'.format(self) + + def mention(self): + """Returns a string that allows you to mention the given user.""" + return '<@{0.id}>'.format(self) + diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 000000000..42691163a --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,183 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @echo " coverage to run coverage check of the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/pydiscord.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/pydiscord.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/pydiscord" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/pydiscord" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +coverage: + $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage + @echo "Testing of coverage in the sources finished, look at the " \ + "results in $(BUILDDIR)/coverage/python.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/api.rst b/docs/api.rst new file mode 100644 index 000000000..ad020d6ea --- /dev/null +++ b/docs/api.rst @@ -0,0 +1,62 @@ +.. currentmodule:: discord + +API Reference +=============== + +The following section outlines the API of pydiscord. + + +Client +------- + +.. autoclass:: Client + :members: + +.. _discord-api-events: + +Event Reference +~~~~~~~~~~~~~~~~ + +This page outlines the different types of events listened to by :meth:`Client.event`. + + +.. function:: on_ready() + + Called when the client is done preparing the data received from Discord. Usually after login is successful + and the :attr:`Client.servers` and co. are filled up. + +.. function:: on_message(message) + + Called when a message is created and sent to a server. + + :param message: A :class:`Message` of the current message. + +.. function:: on_response(response) + + Called whenever a message is received from the websocket. Used mainly for debugging purposes. + The parameter passed is raw data that was parsed via ``json.loads``. + + :param response: The received message response after gone through ``json.loads``. + + +Data Classes +-------------- + +Some classes are just there to be data containers, this lists them. It should be assumed that *all* classes in this category are immutable and should not be modified. + +.. autoclass:: User + :members: + +.. autoclass:: Message + :members: + +.. autoclass:: Server + :members: + +.. autoclass:: Channel + :members: + +.. autoclass:: PrivateChannel + :members: + + diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 000000000..f47a0f62f --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,281 @@ +# -*- coding: utf-8 -*- +# +# pydiscord documentation build configuration file, created by +# sphinx-quickstart on Fri Aug 21 05:43:30 2015. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath('..')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'pydiscord' +copyright = u'2015, Rapptz' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '0.1.0' +# The full version, including alpha/beta/rc tags. +release = '0.1.0' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# html_theme_options = { + +# } + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +#html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +#html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +#html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'pydiscorddoc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', + +# Latex figure (float) alignment +#'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ('index', 'pydiscord.tex', u'pydiscord Documentation', + u'Rapptz', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'pydiscord', u'pydiscord Documentation', + [u'Rapptz'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'pydiscord', u'pydiscord Documentation', + u'Rapptz', 'pydiscord', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 000000000..e74189d80 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,23 @@ +.. pydiscord documentation master file, created by + sphinx-quickstart on Fri Aug 21 05:43:30 2015. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to pydiscord's documentation! +===================================== + +Contents: + +.. toctree:: + :maxdepth: 2 + + api + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 000000000..f04b4b55c --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,263 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + echo. coverage to run coverage check of the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +REM Check if sphinx-build is available and fallback to Python version if any +%SPHINXBUILD% 2> nul +if errorlevel 9009 goto sphinx_python +goto sphinx_ok + +:sphinx_python + +set SPHINXBUILD=python -m sphinx.__init__ +%SPHINXBUILD% 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +:sphinx_ok + + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\pydiscord.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\pydiscord.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "coverage" ( + %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage + if errorlevel 1 exit /b 1 + echo. + echo.Testing of coverage in the sources finished, look at the ^ +results in %BUILDDIR%/coverage/python.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..ba8f903fd --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +ws4py +requests diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..f40748f91 --- /dev/null +++ b/setup.py @@ -0,0 +1,43 @@ +from setuptools import setup +import re + +requirements = '' +from open('requirements.txt') as f: + requirements = f.read().splitlines() + +version = '' +with open('discord/__init__.py') as f: + version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1) + +if not version: + raise RuntimeError('version is not set') + +readme = '' +with open('README.md') as f: + readme = f.read() + +setup(name='pydiscord', + author='Rapptz', + url='https://github.com/Rapptz/pydiscord', + version=version, + packages=['discord'], + license='MIT', + description='A python wrapper for the Discord API', + long_description=readme, + include_package_data=True, + install_requires=requirements, + classifiers=[ + 'Development Status :: 2 - Pre-Alpha', + 'License :: OSI Approved :: MIT License', + 'Intended Audience :: Developers', + 'Natural Language :: English', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Topic :: Internet', + 'Topic :: Software Development :: Libraries', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: Utilities', + ] +)