diff --git a/disco/api/client.py b/disco/api/client.py index aa3aff4..68c551d 100644 --- a/disco/api/client.py +++ b/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={ diff --git a/disco/types/base.py b/disco/types/base.py index f72d8bb..0cf0646 100644 --- a/disco/types/base.py +++ b/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 diff --git a/disco/types/guild.py b/disco/types/guild.py index 468acbc..a9075bb 100644 --- a/disco/types/guild.py +++ b/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.