mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-23 19:34:23 +00:00
Add support for server verification levels.
This adds a new enum named VerificationLevel to denote said verification level. This enum will also be used in the Client.edit_server calls instead of the undocumented int parameter.
This commit is contained in:
parent
713037836c
commit
203c64a9a4
@ -34,7 +34,7 @@ from .invite import Invite
|
|||||||
from .object import Object
|
from .object import Object
|
||||||
from . import utils, opus, compat
|
from . import utils, opus, compat
|
||||||
from .voice_client import VoiceClient
|
from .voice_client import VoiceClient
|
||||||
from .enums import ChannelType, ServerRegion, Status, MessageType
|
from .enums import ChannelType, ServerRegion, Status, MessageType, VerificationLevel
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
@ -38,7 +38,7 @@ from .errors import *
|
|||||||
from .state import ConnectionState
|
from .state import ConnectionState
|
||||||
from .permissions import Permissions, PermissionOverwrite
|
from .permissions import Permissions, PermissionOverwrite
|
||||||
from . import utils, compat
|
from . import utils, compat
|
||||||
from .enums import ChannelType, ServerRegion
|
from .enums import ChannelType, ServerRegion, VerificationLevel
|
||||||
from .voice_client import VoiceClient
|
from .voice_client import VoiceClient
|
||||||
from .iterators import LogsFromIterator
|
from .iterators import LogsFromIterator
|
||||||
from .gateway import *
|
from .gateway import *
|
||||||
@ -1930,6 +1930,8 @@ class Client:
|
|||||||
owner : :class:`Member`
|
owner : :class:`Member`
|
||||||
The new owner of the server to transfer ownership to. Note that you must
|
The new owner of the server to transfer ownership to. Note that you must
|
||||||
be owner of the server to do this.
|
be owner of the server to do this.
|
||||||
|
verification_level: :class:`VerificationLevel`
|
||||||
|
The new verification level for the server.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
-------
|
-------
|
||||||
@ -1968,6 +1970,11 @@ class Client:
|
|||||||
if 'region' in fields:
|
if 'region' in fields:
|
||||||
fields['region'] = str(fields['region'])
|
fields['region'] = str(fields['region'])
|
||||||
|
|
||||||
|
level = fields.get('verification_level', server.verification_level)
|
||||||
|
if not isinstance(level, VerificationLevel):
|
||||||
|
raise InvalidArgument('verification_level field must of type VerificationLevel')
|
||||||
|
|
||||||
|
fields['verification_level'] = level.value
|
||||||
yield from self.http.edit_server(server.id, **fields)
|
yield from self.http.edit_server(server.id, **fields)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -64,6 +64,16 @@ class ServerRegion(Enum):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
|
class VerificationLevel(Enum):
|
||||||
|
none = 0
|
||||||
|
low = 1
|
||||||
|
medium = 2
|
||||||
|
high = 3
|
||||||
|
table_flip = 3
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
class Status(Enum):
|
class Status(Enum):
|
||||||
online = 'online'
|
online = 'online'
|
||||||
offline = 'offline'
|
offline = 'offline'
|
||||||
|
@ -30,7 +30,7 @@ from .member import Member
|
|||||||
from .emoji import Emoji
|
from .emoji import Emoji
|
||||||
from .game import Game
|
from .game import Game
|
||||||
from .channel import Channel
|
from .channel import Channel
|
||||||
from .enums import ServerRegion, Status
|
from .enums import ServerRegion, Status, try_enum, VerificationLevel
|
||||||
from .mixins import Hashable
|
from .mixins import Hashable
|
||||||
|
|
||||||
class Server(Hashable):
|
class Server(Hashable):
|
||||||
@ -92,12 +92,15 @@ class Server(Hashable):
|
|||||||
Indicates the server's two factor authorisation level. If this value is 0 then
|
Indicates the server's two factor authorisation level. If this value is 0 then
|
||||||
the server does not require 2FA for their administrative members. If the value is
|
the server does not require 2FA for their administrative members. If the value is
|
||||||
1 then they do.
|
1 then they do.
|
||||||
|
verification_level: :class:`VerificationLevel`
|
||||||
|
The server's verification level.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ['afk_timeout', 'afk_channel', '_members', '_channels', 'icon',
|
__slots__ = ['afk_timeout', 'afk_channel', '_members', '_channels', 'icon',
|
||||||
'name', 'id', 'owner', 'unavailable', 'name', 'region',
|
'name', 'id', 'owner', 'unavailable', 'name', 'region',
|
||||||
'_default_role', '_default_channel', 'roles', '_member_count',
|
'_default_role', '_default_channel', 'roles', '_member_count',
|
||||||
'large', 'owner_id', 'mfa_level', 'emojis']
|
'large', 'owner_id', 'mfa_level', 'emojis',
|
||||||
|
'verification_level' ]
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self._channels = {}
|
self._channels = {}
|
||||||
@ -176,12 +179,8 @@ class Server(Hashable):
|
|||||||
self._member_count = member_count
|
self._member_count = member_count
|
||||||
|
|
||||||
self.name = guild.get('name')
|
self.name = guild.get('name')
|
||||||
self.region = guild.get('region')
|
self.region = try_enum(ServerRegion, guild.get('region'))
|
||||||
try:
|
self.verification_level = try_enum(VerificationLevel, guild.get('verification_level'))
|
||||||
self.region = ServerRegion(self.region)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.afk_timeout = guild.get('afk_timeout')
|
self.afk_timeout = guild.get('afk_timeout')
|
||||||
self.icon = guild.get('icon')
|
self.icon = guild.get('icon')
|
||||||
self.unavailable = guild.get('unavailable', False)
|
self.unavailable = guild.get('unavailable', False)
|
||||||
|
24
docs/api.rst
24
docs/api.rst
@ -512,6 +512,30 @@ All enumerations are subclasses of `enum`_.
|
|||||||
|
|
||||||
The Amsterdam region for VIP servers.
|
The Amsterdam region for VIP servers.
|
||||||
|
|
||||||
|
.. class:: VerificationLevel
|
||||||
|
|
||||||
|
Specifies a :class:`Server`\'s verification level, which is the criteria in
|
||||||
|
which a member must meet before being able to send messages to the server.
|
||||||
|
|
||||||
|
.. attribute:: none
|
||||||
|
|
||||||
|
No criteria set.
|
||||||
|
.. attribute:: low
|
||||||
|
|
||||||
|
Member must have a verified email on their Discord account.
|
||||||
|
.. attribute:: medium
|
||||||
|
|
||||||
|
Member must have a verified email and be registered on Discord for more
|
||||||
|
than five minutes.
|
||||||
|
.. attribute:: high
|
||||||
|
|
||||||
|
Member must have a verified email, be registered on Discord for more
|
||||||
|
than five minutes, and be a member of the server itself for more than
|
||||||
|
ten minutes.
|
||||||
|
.. attribute:: table_flip
|
||||||
|
|
||||||
|
An alias for :attr:`high`.
|
||||||
|
|
||||||
.. class:: Status
|
.. class:: Status
|
||||||
|
|
||||||
Specifies a :class:`Member` 's status.
|
Specifies a :class:`Member` 's status.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user