This repository has been archived by the owner on Jan 22, 2021. It is now read-only.
forked from scarletcafe/jishaku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
voice.py
79 lines (53 loc) · 1.81 KB
/
voice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
"""
jishaku.voice
~~~~~~~~~~~~~
Voice-related functions and classes.
:copyright: (c) 2019 Devon (Gorialis) R
:license: MIT, see LICENSE for more details.
"""
import discord.opus
import discord.voice_client
from discord.ext import commands
try:
import youtube_dl
except ImportError:
youtube_dl = None
async def vc_check(ctx: commands.Context): # pylint: disable=unused-argument
"""
Check for whether VC is available in this bot.
"""
if not discord.voice_client.has_nacl:
raise commands.CheckFailure("voice cannot be used because PyNaCl is not loaded")
if not discord.opus.is_loaded():
raise commands.CheckFailure("voice cannot be used because libopus is not loaded")
return True
async def connected_check(ctx: commands.Context):
"""
Check whether we are connected to VC in this guild.
"""
voice = ctx.guild.voice_client
if not voice or not voice.is_connected():
raise commands.CheckFailure("Not connected to VC in this guild")
return True
async def playing_check(ctx: commands.Context):
"""
Checks whether we are playing audio in VC in this guild.
This doubles up as a connection check.
"""
if await connected_check(ctx) and not ctx.guild.voice_client.is_playing():
raise commands.CheckFailure("The voice client in this guild is not playing anything.")
return True
BASIC_OPTS = {
'format': 'webm[abr>0]/bestaudio/best',
'prefer_ffmpeg': True,
'quiet': True
}
class BasicYouTubeDLSource(discord.FFmpegPCMAudio):
"""
Basic audio source for youtube_dl-compatible URLs.
"""
def __init__(self, url, download: bool = False):
ytdl = youtube_dl.YoutubeDL(BASIC_OPTS)
info = ytdl.extract_info(url, download=download)
super().__init__(info['url'])