From 8b18fa307b5e4a9acc6c057b7489c4d11de359b4 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 25 Nov 2018 01:42:33 -0500 Subject: [PATCH] Add support for default notification level in audit logs and Guild.edit --- discord/audit_logs.py | 40 ++++++++++++++++++++++------------------ discord/enums.py | 2 +- discord/guild.py | 9 +++++++++ discord/http.py | 2 +- docs/api.rst | 8 +++++++- 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index 09b1e5260..2c8769e6a 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -33,6 +33,9 @@ from .invite import Invite def _transform_verification_level(entry, data): return enums.try_enum(enums.VerificationLevel, data) +def _transform_default_notifications(entry, data): + return enums.try_enum(enums.NotificationLevel, data) + def _transform_explicit_content_filter(entry, data): return enums.try_enum(enums.ContentFilter, data) @@ -94,24 +97,25 @@ class AuditLogDiff: class AuditLogChanges: TRANSFORMERS = { - 'verification_level': (None, _transform_verification_level), - 'explicit_content_filter': (None, _transform_explicit_content_filter), - 'allow': (None, _transform_permissions), - 'deny': (None, _transform_permissions), - 'permissions': (None, _transform_permissions), - 'id': (None, _transform_snowflake), - 'color': ('colour', _transform_color), - 'owner_id': ('owner', _transform_owner_id), - 'inviter_id': ('inviter', _transform_inviter_id), - 'channel_id': ('channel', _transform_channel), - 'afk_channel_id': ('afk_channel', _transform_channel), - 'system_channel_id': ('system_channel', _transform_channel), - 'widget_channel_id': ('widget_channel', _transform_channel), - 'permission_overwrites': ('overwrites', _transform_overwrites), - 'splash_hash': ('splash', None), - 'icon_hash': ('icon', None), - 'avatar_hash': ('avatar', None), - 'rate_limit_per_user': ('slowmode_delay', None), + 'verification_level': (None, _transform_verification_level), + 'explicit_content_filter': (None, _transform_explicit_content_filter), + 'allow': (None, _transform_permissions), + 'deny': (None, _transform_permissions), + 'permissions': (None, _transform_permissions), + 'id': (None, _transform_snowflake), + 'color': ('colour', _transform_color), + 'owner_id': ('owner', _transform_owner_id), + 'inviter_id': ('inviter', _transform_inviter_id), + 'channel_id': ('channel', _transform_channel), + 'afk_channel_id': ('afk_channel', _transform_channel), + 'system_channel_id': ('system_channel', _transform_channel), + 'widget_channel_id': ('widget_channel', _transform_channel), + 'permission_overwrites': ('overwrites', _transform_overwrites), + 'splash_hash': ('splash', None), + 'icon_hash': ('icon', None), + 'avatar_hash': ('avatar', None), + 'rate_limit_per_user': ('slowmode_delay', None), + 'default_message_notifications': ('default_notifications', _transform_default_notifications), } def __init__(self, entry, data): diff --git a/discord/enums.py b/discord/enums.py index 55d1c73c7..a1ebab8bc 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -123,7 +123,7 @@ class RelationshipType(Enum): incoming_request = 3 outgoing_request = 4 -class NotificationLevel(Enum): +class NotificationLevel(IntEnum): all_messages = 0 only_mentions = 1 diff --git a/discord/guild.py b/discord/guild.py index 5d99aa068..0e4c30995 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -748,6 +748,8 @@ class Guild(Hashable): be owner of the guild to do this. verification_level: :class:`VerificationLevel` The new verification level for the guild. + default_notifications: :class:`NotificationLevel` + The new default notification level for the guild. vanity_code: str The new vanity code for the guild. system_channel: Optional[:class:`TextChannel`] @@ -798,6 +800,13 @@ class Guild(Hashable): fields['icon'] = icon fields['splash'] = splash + try: + default_message_notifications = int(fields.pop('default_notifications')) + except (TypeError, KeyError): + pass + else: + fields['default_message_notifications'] = default_message_notifications + try: afk_channel = fields.pop('afk_channel') except KeyError: diff --git a/discord/http.py b/discord/http.py index a0784e494..e4c0e55cb 100644 --- a/discord/http.py +++ b/discord/http.py @@ -565,7 +565,7 @@ class HTTPClient: def edit_guild(self, guild_id, *, reason=None, **fields): valid_keys = ('name', 'region', 'icon', 'afk_timeout', 'owner_id', 'afk_channel_id', 'splash', 'verification_level', - 'system_channel_id') + 'system_channel_id', 'default_message_notifications') payload = { k: v for k, v in fields.items() if k in valid_keys diff --git a/docs/api.rst b/docs/api.rst index ef6cabaf4..345fd913c 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -855,7 +855,7 @@ All enumerations are subclasses of `enum`_. .. class:: NotificationLevel Specifies whether a :class:`Guild` has notifications on for all messages or mentions only by default. - + ..attribute:: all_messages Members receive notifications for every message regardless of them being mentioned. @@ -1595,6 +1595,12 @@ this goal, it must make use of a couple of data classes that aid in this goal. See also :attr:`Guild.verification_level`. + .. attribute:: default_notifications + + :class:`NotificationLevel` – The guild's default notification level. + + See also :attr:`Guild.default_notifications`. + .. attribute:: explicit_content_filter :class:`ContentFilter` – The guild's content filter.