From e1f8bdc440eaff0f2e04ffa017052117621fe939 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 28 Jun 2016 00:57:52 -0400 Subject: [PATCH] Make PyNaCl optional --- discord/client.py | 4 ++++ discord/voice_client.py | 12 +++++++++++- requirements.txt | 1 - 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/discord/client.py b/discord/client.py index 5ab263cd9..3a2ef8fbe 100644 --- a/discord/client.py +++ b/discord/client.py @@ -154,6 +154,10 @@ class Client: self._is_logged_in = asyncio.Event(loop=self.loop) self._is_ready = asyncio.Event(loop=self.loop) + if VoiceClient.warn_nacl: + VoiceClient.warn_nacl = False + log.warning("PyNaCl is not installed, voice will NOT be supported") + # internals @asyncio.coroutine diff --git a/discord/voice_client.py b/discord/voice_client.py index c5b24a77f..a92bf5b8e 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -51,10 +51,15 @@ import shlex import functools import datetime import audioop -import nacl.secret log = logging.getLogger(__name__) +try: + import nacl.secret + has_nacl = True +except ImportError: + has_nacl = False + from . import utils, opus from .gateway import * from .errors import ClientException, InvalidArgument, ConnectionClosed @@ -182,6 +187,9 @@ class VoiceClient: The event loop that the voice client is running on. """ def __init__(self, user, main_ws, session_id, channel, data, loop): + if not has_nacl: + raise RuntimeError("PyNaCl library needed in order to use voice") + self.user = user self.main_ws = main_ws self.channel = channel @@ -196,6 +204,8 @@ class VoiceClient: self.encoder = opus.Encoder(48000, 2) log.info('created opus encoder with {0.__dict__}'.format(self.encoder)) + warn_nacl = not has_nacl + @property def server(self): return self.channel.server diff --git a/requirements.txt b/requirements.txt index 9221d17ab..f4c9a5d85 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ aiohttp>=0.21.0,<0.22.0 websockets==3.1 -PyNaCl==1.0.1