-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for creating and joining voice channels
added voice channels to config fixed linting errors added tests for voice channel creation mocking voice channels in progress Can join fake voice channels Leaving and joining channels for members and bot working Fixed some linting errors Fixed voice and channel creation tests, added pynacl requirement Reverted some changes to config, removed unused join channel function Fixed edit_message callback signature Edit member callback fixed to work with changing nicknames and roles. Added docstring Added docstrings Added support for deleting voice channels in FakeHttp Fixed typo in test_permissions.py
- Loading branch information
Showing
8 changed files
with
194 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ invoke | |
sphinx-automodapi | ||
build | ||
flake8~=6.0.0 | ||
pynacl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Callable | ||
|
||
from discord import Client, VoiceClient | ||
from discord.abc import Connectable, T | ||
from discord.channel import VoiceChannel | ||
|
||
|
||
class FakeVoiceClient(VoiceClient): | ||
""" | ||
Mock implementation of a Discord VoiceClient. VoiceClient.connect tries to contact the Discord API and is called | ||
whenever connect() is called on a VoiceChannel, so we need to override that method and pass in the fake version | ||
to prevent the program from actually making calls to the Discord API. | ||
""" | ||
async def connect(self, *, reconnect: bool, timeout: float, self_deaf: bool = False, | ||
self_mute: bool = False) -> None: | ||
self._connected.set() | ||
|
||
|
||
class FakeVoiceChannel(VoiceChannel): | ||
""" | ||
Mock implementation of a Discord VoiceChannel. Exists just to pass a FakeVoiceClient into the superclass connect() | ||
method. | ||
""" | ||
|
||
async def connect( | ||
self, | ||
*, | ||
timeout: float = 60.0, | ||
reconnect: bool = True, | ||
cls: Callable[[Client, Connectable], T] = FakeVoiceClient, | ||
self_deaf: bool = False, | ||
self_mute: bool = False, | ||
) -> T: | ||
return await super().connect(timeout=timeout, reconnect=reconnect, cls=cls, self_deaf=self_deaf, | ||
self_mute=self_mute) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
import discord | ||
import discord.ext.test as dpytest | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_voice_channel(bot): | ||
guild = bot.guilds[0] | ||
http = bot.http | ||
|
||
# create_channel checks the value of variables in the parent call context, so we need to set these for it to work | ||
self = guild # noqa: F841 | ||
name = "voice_channel_1" | ||
channel = await http.create_channel(guild, channel_type=discord.ChannelType.voice.value) | ||
assert channel['type'] == discord.ChannelType.voice | ||
assert channel['name'] == name | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_make_voice_channel(bot): | ||
guild = bot.guilds[0] | ||
bitrate = 100 | ||
user_limit = 5 | ||
channel = dpytest.backend.make_voice_channel("voice", guild, bitrate=bitrate, user_limit=user_limit) | ||
assert channel.name == "voice" | ||
assert channel.guild == guild | ||
assert channel.bitrate == bitrate | ||
assert channel.user_limit == user_limit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_bot_join_voice(bot): | ||
assert not bot.voice_clients | ||
await bot.guilds[0].voice_channels[0].connect() | ||
assert bot.voice_clients | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_bot_leave_voice(bot): | ||
voice_client = await bot.guilds[0].voice_channels[0].connect() | ||
await voice_client.disconnect() | ||
assert not bot.voice_clients | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_move_member(bot): | ||
guild = bot.guilds[0] | ||
voice_channel = guild.voice_channels[0] | ||
member = guild.members[0] | ||
|
||
assert member.voice is None | ||
await member.move_to(voice_channel) | ||
assert member.voice.channel == voice_channel | ||
|
||
await member.move_to(None) | ||
assert member.voice is None |