Browse Source

bugfix - fix `create_hash` not reading from the created object

also add GuildBan
feature/docs
Andrei 8 years ago
parent
commit
ceb57e19d4
  1. 4
      disco/api/client.py
  2. 10
      disco/types/base.py
  3. 5
      disco/types/guild.py

4
disco/api/client.py

@ -6,7 +6,7 @@ from disco.util.logging import LoggingClass
from disco.types.user import User
from disco.types.message import Message
from disco.types.guild import Guild, GuildMember, Role, GuildEmoji
from disco.types.guild import Guild, GuildMember, GuildBan, Role, GuildEmoji
from disco.types.channel import Channel
from disco.types.invite import Invite
from disco.types.webhook import Webhook
@ -231,7 +231,7 @@ class APIClient(LoggingClass):
def guilds_bans_list(self, guild):
r = self.http(Routes.GUILDS_BANS_LIST, dict(guild=guild))
return User.create_hash(self.client, 'id', r.json())
return GuildBan.create_hash(self.client, 'user.id', r.json())
def guilds_bans_create(self, guild, user, delete_message_days):
self.http(Routes.GUILDS_BANS_CREATE, dict(guild=guild, user=user), params={

10
disco/types/base.py

@ -15,6 +15,12 @@ DATETIME_FORMATS = [
]
def get_item_by_path(obj, path):
for part in path.split('.'):
obj = getattr(obj, part)
return obj
class Unset(object):
def __nonzero__(self):
return False
@ -352,7 +358,9 @@ class Model(six.with_metaclass(ModelMeta, AsyncChainable)):
@classmethod
def create_hash(cls, client, key, data, **kwargs):
return HashMap({
getattr(item, key): cls.create(client, item, **kwargs) for item in data
get_item_by_path(item, key): item
for item in [
cls.create(client, item, **kwargs) for item in data]
})
@classmethod

5
disco/types/guild.py

@ -110,6 +110,11 @@ class Role(SlottedModel):
return self.client.state.guilds.get(self.guild_id)
class GuildBan(SlottedModel):
user = Field(User)
reason = Field(str)
class GuildMember(SlottedModel):
"""
A GuildMember object.

Loading…
Cancel
Save