From 94507bd9f531617ed3f9305132cdcf08254d1649 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 28 Jul 2019 19:36:28 +0100 Subject: [PATCH] Add guild prune and prune count. --- disco/api/client.py | 13 ++++++++++++- disco/types/guild.py | 10 ++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/disco/api/client.py b/disco/api/client.py index 210cfaf..70345c8 100644 --- a/disco/api/client.py +++ b/disco/api/client.py @@ -11,7 +11,7 @@ from disco.util.logging import LoggingClass from disco.util.sanitize import S from disco.types.user import User from disco.types.message import Message -from disco.types.guild import Guild, GuildMember, GuildBan, Role, GuildEmoji, AuditLogEntry +from disco.types.guild import Guild, GuildMember, GuildBan, PruneCount, Role, GuildEmoji, AuditLogEntry from disco.types.channel import Channel from disco.types.invite import Invite from disco.types.voice import VoiceRegion @@ -433,6 +433,17 @@ class APIClient(LoggingClass): dict(guild=guild, user=user), headers=_reason_header(reason)) + def guilds_prune_count_get(self, guild, days=None): + r = self.http(Routes.GUILDS_PRUNE_COUNT, dict(guild=guild), params=optional(days=days)) + return PruneCount.create(self.client, r.json()) + + def guilds_prune(self, guild, days=None, compute_prune_count=None): + r = self.http(Routes.GUILDS_PRUNE_BEGIN, dict(guild=guild), params=optional( + days=days, + compute_prune_count=compute_prune_count, + )) + return PruneCount.create(self.client, r.json()) + def guilds_roles_list(self, guild): r = self.http(Routes.GUILDS_ROLES_LIST, dict(guild=guild)) return Role.create_map(self.client, r.json(), guild_id=guild) diff --git a/disco/types/guild.py b/disco/types/guild.py index 026aa8f..7d74396 100644 --- a/disco/types/guild.py +++ b/disco/types/guild.py @@ -79,6 +79,10 @@ class GuildEmoji(Emoji): return self.client.state.guilds.get(self.guild_id) +class PruneCount(SlottedModel): + pruned = Field(int, default=None) + + class Role(SlottedModel): """ A role object. @@ -417,6 +421,12 @@ class Guild(SlottedModel, Permissible): return self.members.get(user) + def get_prune_count(self, days=None): + return self.client.api.guilds_prune_count_get(self.id, days=days) + + def prune(self, days=None, compute_prune_count=None): + return self.client.api.guilds_prune(self.id, days=days, compute_prune_count=compute_prune_count) + def create_role(self, **kwargs): """ Create a new role.