Browse Source

Use kwargs if the number of arguments needed is too many.

pull/3/head
Rapptz 10 years ago
parent
commit
b00ad4ad79
  1. 14
      discord/channel.py
  2. 9
      discord/client.py
  3. 26
      discord/message.py
  4. 20
      discord/server.py

14
discord/channel.py

@ -52,14 +52,14 @@ class Channel(object):
values in the :attr:`Server.roles` attribute.
"""
def __init__(self, name, server, id, position, type, permission_overwrites=None, **kwargs):
self.name = name
self.server = server
self.id = id
def __init__(self, **kwargs):
self.name = kwargs.get('name')
self.server = kwargs.get('server')
self.id = kwargs.get('id')
self.is_private = False
self.position = position
self.type = type
self.changed_roles = permission_overwrites if permission_overwrites is not None else []
self.position = kwargs.get('position')
self.type = kwargs.get('type')
self.changed_roles = kwargs.get('permission_overwrites', [])
class PrivateChannel(object):
"""Represents a Discord private channel.

9
discord/client.py

@ -683,3 +683,12 @@ class Client(object):
url = '{0}/{1.id}'.format(endpoints.CHANNELS, channel)
requests.delete(url, headers=self.headers)
def leave_server(self, server):
"""Leaves a :class:`Server`.
:param server: The :class:`Server` to leave.
"""
url = '{0}/{1.id}'.format(endpoints.SERVERS, server)
requests.delete(url, headers=self.headers)

26
discord/message.py

@ -70,25 +70,25 @@ class Message(object):
An array of attachments given to a message.
"""
def __init__(self, edited_timestamp, timestamp, tts, content, mention_everyone, mentions, embeds, attachments, id, channel, author, **kwargs):
def __init__(self, **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
# sometimes the .%f modifier is missing
self.edited_timestamp = None
if edited_timestamp is not None:
self.edited_timestamp = kwargs.get('edited_timestamp')
if self.edited_timestamp is not None:
self.edited_timestamp = self._parse_time(edited_timestamp)
self.timestamp = self._parse_time(timestamp)
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]
self.attachments = attachments
self.timestamp = self._parse_time(kwargs.get('timestamp'))
self.tts = kwargs.get('tts')
self.content = kwargs.get('content')
self.mention_everyone = kwargs.get('mention_everyone')
self.embeds = kwargs.get('embeds')
self.id = kwargs.get('id')
self.channel = kwargs.get('channel')
self.author = User(**kwargs.get('author', {}))
self.mentions = [User(**mention) for mention in kwargs.get('mentions', {})]
self.attachments = kwargs.get('attachments')
def _parse_time(self, time_string):
return datetime.datetime(*map(int, re.split(r'[^\d]', time_string.replace('+00:00', ''))))

20
discord/server.py

@ -128,13 +128,13 @@ class Server(object):
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
def __init__(self, **kwargs):
self.name = kwargs.get('name')
self.roles = kwargs.get('roles')
self.region = kwargs.get('region')
self.afk_timeout = kwargs.get('afk_timeout')
self.afk_channel_id = kwargs.get('afk_channel_id')
self.members = kwargs.get('members')
self.icon = kwargs.get('icon')
self.id = kwargs.get('id')
self.owner_id = kwargs.get('owner_id')

Loading…
Cancel
Save