aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2024-08-24 14:56:51 -0500
committerParker <contact@pkrm.dev>2024-08-24 14:56:51 -0500
commitc62d2306974475aa82da8902dc3c973705588043 (patch)
tree1a7712aa9fa90212f34b51ab785e3d7af7421e9f
parent2cdaa11af4ce1a99d7bb51ef311a5262dd656bf1 (diff)
Make YouTube support optional
-rw-r--r--code/bot.py1
-rw-r--r--code/cogs/play.py18
-rw-r--r--code/utils/config.py10
3 files changed, 19 insertions, 10 deletions
diff --git a/code/bot.py b/code/bot.py
index 3569e68..d0154e3 100644
--- a/code/bot.py
+++ b/code/bot.py
@@ -28,6 +28,7 @@ class MyBot(commands.Bot):
bot.openai = openai.OpenAI(api_key=config.OPENAI_API_KEY)
config.LOG.info("Loading cogs...")
+ config.LOG.info("YouTube support is enabled" if config.YOUTUBE_SUPPORT else "YouTube support is disabled")
for ext in os.listdir("./code/cogs"):
if ext.endswith(".py"):
# Load the OPTIONAL feedback cog
diff --git a/code/cogs/play.py b/code/cogs/play.py
index fdd0233..3c60633 100644
--- a/code/cogs/play.py
+++ b/code/cogs/play.py
@@ -7,7 +7,7 @@ import re
import requests
from cogs.music import Music, LavalinkVoiceClient
-from utils.config import BOT_COLOR
+from utils.config import BOT_COLOR, YOUTUBE_SUPPORT
from utils.custom_sources import SpotifySource, AppleSource
@@ -25,15 +25,15 @@ class Play(commands.Cog):
"Play a song from your favorite music provider"
player = self.bot.lavalink.player_manager.get(interaction.guild.id)
- # Notify users that YouTube links are not allowed
-
+ # Notify users that YouTube links are not allowed if YouTube support is disabled
if "youtube.com" in query or "youtu.be" in query:
- embed = discord.Embed(
- title="YouTube Not Supported",
- description="Unfortunately, YouTube does not allow bots to stream from their platform. Try sending a link for a different platform, or simply type the name of the song and I will automatically find it on a supported platform.",
- color=BOT_COLOR,
- )
- return await interaction.response.send_message(embed=embed, ephemeral=True)
+ if not YOUTUBE_SUPPORT:
+ embed = discord.Embed(
+ title="YouTube Not Supported",
+ description="Unfortunately, YouTube does not allow bots to stream from their platform. Try sending a link for a different platform, or simply type the name of the song and I will automatically find it on a supported platform.",
+ color=BOT_COLOR,
+ )
+ return await interaction.response.send_message(embed=embed, ephemeral=True)
###
### APPLE MUSIC links, perform API requests and load all tracks from the playlist/album/track
diff --git a/code/utils/config.py b/code/utils/config.py
index 951676e..1d3c349 100644
--- a/code/utils/config.py
+++ b/code/utils/config.py
@@ -31,6 +31,7 @@ BOT_COLOR = None
BOT_INVITE_LINK = None
FEEDBACK_CHANNEL_ID = None
BUG_CHANNEL_ID = None
+YOUTUBE_SUPPORT = None
SPOTIFY_CLIENT_ID = None
SPOTIFY_CLIENT_SECRET = None
GENIUS_CLIENT_ID = None
@@ -51,6 +52,7 @@ schema = {
"bot_invite_link": {"type": "string"},
"feedback_channel_id": {"type": "integer"},
"bug_channel_id": {"type": "integer"},
+ "youtube_support": {"type": "boolean"},
},
"required": ["token"],
},
@@ -114,6 +116,7 @@ bot_info:
bot_invite_link: ""
feedback_channel_id: ""
bug_channel_id: ""
+ youtube_support: false
spotify:
spotify_client_id: ""
@@ -142,7 +145,7 @@ lavalink:
# Thouroughly validate all of the options in the config.yaml file
def validate_config(file_contents):
- global TOKEN, BOT_COLOR, BOT_INVITE_LINK, FEEDBACK_CHANNEL_ID, BUG_CHANNEL_ID, SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET, GENIUS_CLIENT_ID, GENIUS_CLIENT_SECRET, OPENAI_API_KEY, LAVALINK_HOST, LAVALINK_PORT, LAVALINK_PASSWORD
+ global TOKEN, BOT_COLOR, BOT_INVITE_LINK, FEEDBACK_CHANNEL_ID, BUG_CHANNEL_ID, YOUTUBE_SUPPORT, SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET, GENIUS_CLIENT_ID, GENIUS_CLIENT_SECRET, OPENAI_API_KEY, LAVALINK_HOST, LAVALINK_PORT, LAVALINK_PASSWORD
config = yaml.safe_load(file_contents)
try:
@@ -198,6 +201,11 @@ def validate_config(file_contents):
else:
BUG_CHANNEL_ID = config["bot_info"]["bug_channel_id"]
+ if "youtube_support" in config["bot_info"]:
+ YOUTUBE_SUPPORT = bool(config["bot_info"]["youtube_support"])
+ else:
+ YOUTUBE_SUPPORT = False
+
#
# If the SPOTIFY section is present, make sure the client ID and secret are valid
#