|
@ -2,13 +2,14 @@ import six |
|
|
import json |
|
|
import json |
|
|
import warnings |
|
|
import warnings |
|
|
|
|
|
|
|
|
|
|
|
from six.moves.urllib.parse import quote |
|
|
|
|
|
|
|
|
from disco.api.http import Routes, HTTPClient |
|
|
from disco.api.http import Routes, HTTPClient |
|
|
from disco.util.logging import LoggingClass |
|
|
from disco.util.logging import LoggingClass |
|
|
from disco.util.sanitize import S |
|
|
from disco.util.sanitize import S |
|
|
|
|
|
|
|
|
from disco.types.user import User |
|
|
from disco.types.user import User |
|
|
from disco.types.message import Message |
|
|
from disco.types.message import Message |
|
|
from disco.types.guild import Guild, GuildMember, GuildBan, Role, GuildEmoji |
|
|
from disco.types.guild import Guild, GuildMember, GuildBan, Role, GuildEmoji, AuditLogEntry |
|
|
from disco.types.channel import Channel |
|
|
from disco.types.channel import Channel |
|
|
from disco.types.invite import Invite |
|
|
from disco.types.invite import Invite |
|
|
from disco.types.webhook import Webhook |
|
|
from disco.types.webhook import Webhook |
|
@ -25,7 +26,7 @@ def optional(**kwargs): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _reason_header(value): |
|
|
def _reason_header(value): |
|
|
return optional(**{'X-Audit-Log-Reason': value}) |
|
|
return optional(**{'X-Audit-Log-Reason': quote(value)}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class APIClient(LoggingClass): |
|
|
class APIClient(LoggingClass): |
|
@ -190,20 +191,20 @@ class APIClient(LoggingClass): |
|
|
'type': typ, |
|
|
'type': typ, |
|
|
}, headers=_reason_header(reason)) |
|
|
}, headers=_reason_header(reason)) |
|
|
|
|
|
|
|
|
def channels_permissions_delete(self, channel, permission): |
|
|
def channels_permissions_delete(self, channel, permission, reason=None): |
|
|
self.http(Routes.CHANNELS_PERMISSIONS_DELETE, dict(channel=channel, permission=permission)) |
|
|
self.http(Routes.CHANNELS_PERMISSIONS_DELETE, dict(channel=channel, permission=permission), headers=_reason_header(reason)) |
|
|
|
|
|
|
|
|
def channels_invites_list(self, channel): |
|
|
def channels_invites_list(self, channel): |
|
|
r = self.http(Routes.CHANNELS_INVITES_LIST, dict(channel=channel)) |
|
|
r = self.http(Routes.CHANNELS_INVITES_LIST, dict(channel=channel)) |
|
|
return Invite.create_map(self.client, r.json()) |
|
|
return Invite.create_map(self.client, r.json()) |
|
|
|
|
|
|
|
|
def channels_invites_create(self, channel, max_age=86400, max_uses=0, temporary=False, unique=False): |
|
|
def channels_invites_create(self, channel, max_age=86400, max_uses=0, temporary=False, unique=False, reason=None): |
|
|
r = self.http(Routes.CHANNELS_INVITES_CREATE, dict(channel=channel), json={ |
|
|
r = self.http(Routes.CHANNELS_INVITES_CREATE, dict(channel=channel), json={ |
|
|
'max_age': max_age, |
|
|
'max_age': max_age, |
|
|
'max_uses': max_uses, |
|
|
'max_uses': max_uses, |
|
|
'temporary': temporary, |
|
|
'temporary': temporary, |
|
|
'unique': unique |
|
|
'unique': unique |
|
|
}) |
|
|
}, headers=_reason_header(reason)) |
|
|
return Invite.create(self.client, r.json()) |
|
|
return Invite.create(self.client, r.json()) |
|
|
|
|
|
|
|
|
def channels_pins_list(self, channel): |
|
|
def channels_pins_list(self, channel): |
|
@ -380,6 +381,16 @@ class APIClient(LoggingClass): |
|
|
dict(guild=guild, emoji=emoji), |
|
|
dict(guild=guild, emoji=emoji), |
|
|
headers=_reason_header(reason)) |
|
|
headers=_reason_header(reason)) |
|
|
|
|
|
|
|
|
|
|
|
def guilds_auditlogs_list(self, guild, before, user_id=None, action_type=None, limit=50): |
|
|
|
|
|
r = self.http(Routes.GUILDS, dict(guild=guild), json=optional( |
|
|
|
|
|
before=before, |
|
|
|
|
|
user_id=user_id, |
|
|
|
|
|
action_type=action_type, |
|
|
|
|
|
limit=limit, |
|
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
return AuditLogEntry.create_map(self.client, r.json()['audit_log_entries']) |
|
|
|
|
|
|
|
|
def users_me_get(self): |
|
|
def users_me_get(self): |
|
|
return User.create(self.client, self.http(Routes.USERS_ME_GET).json()) |
|
|
return User.create(self.client, self.http(Routes.USERS_ME_GET).json()) |
|
|
|
|
|
|
|
|