Optional YouTube support #5

Merged
PacketParker merged 2 commits from dev into main 2024-08-24 14:59:08 -05:00
4 changed files with 20 additions and 10 deletions

View File

@ -68,6 +68,7 @@ BOT_COLOR | `HEX CODE`: Color that will be used for the color of message embeds
BOT_INVITE_LINK | `URL`: Discord Invite link for your bot (shown on the `help` command) | **OPTIONAL** - *Adds an "Invite Me" button to the /help message* BOT_INVITE_LINK | `URL`: Discord Invite link for your bot (shown on the `help` command) | **OPTIONAL** - *Adds an "Invite Me" button to the /help message*
FEEDBACK_CHANNEL_ID | `CHANNEL ID`: Discord channel for feedback messages to be sent to | **OPTIONAL** - *Used for feedback messages* FEEDBACK_CHANNEL_ID | `CHANNEL ID`: Discord channel for feedback messages to be sent to | **OPTIONAL** - *Used for feedback messages*
BUG_CHANNEL_ID | `CHANNEL ID`: Discord channel for bug messages to be sent to | **OPTIONAL** - *Used for bug reporting* BUG_CHANNEL_ID | `CHANNEL ID`: Discord channel for bug messages to be sent to | **OPTIONAL** - *Used for bug reporting*
YOUTUBE_SUPPORT | `BOOLEAN`: Whether or not YouTube links are supported | **OPTIONAL**
SPOTIFY_CLIENT_ID | `CLIENT ID`: ID from Spotify Developer account | **OPTIONAL** - *Used for Spotify support* SPOTIFY_CLIENT_ID | `CLIENT ID`: ID from Spotify Developer account | **OPTIONAL** - *Used for Spotify support*
SPOTIFY_CLIENT_SECRET | `CLIENT SECRET`: Secret string from Spotify Developer account | **OPTIONAL** - *Used for Sporify support* SPOTIFY_CLIENT_SECRET | `CLIENT SECRET`: Secret string from Spotify Developer account | **OPTIONAL** - *Used for Sporify support*
GENIUS_CLIENT_ID | `CLIENT ID`: ID from Genius API Dashboard | **OPTIONAL** - *Used for the /lyrics command* GENIUS_CLIENT_ID | `CLIENT ID`: ID from Genius API Dashboard | **OPTIONAL** - *Used for the /lyrics command*

View File

@ -28,6 +28,7 @@ class MyBot(commands.Bot):
bot.openai = openai.OpenAI(api_key=config.OPENAI_API_KEY) bot.openai = openai.OpenAI(api_key=config.OPENAI_API_KEY)
config.LOG.info("Loading cogs...") 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"): for ext in os.listdir("./code/cogs"):
if ext.endswith(".py"): if ext.endswith(".py"):
# Load the OPTIONAL feedback cog # Load the OPTIONAL feedback cog

View File

@ -7,7 +7,7 @@ import re
import requests import requests
from cogs.music import Music, LavalinkVoiceClient 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 from utils.custom_sources import SpotifySource, AppleSource
@ -25,15 +25,15 @@ class Play(commands.Cog):
"Play a song from your favorite music provider" "Play a song from your favorite music provider"
player = self.bot.lavalink.player_manager.get(interaction.guild.id) 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: if "youtube.com" in query or "youtu.be" in query:
embed = discord.Embed( if not YOUTUBE_SUPPORT:
title="YouTube Not Supported", embed = discord.Embed(
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.", title="YouTube Not Supported",
color=BOT_COLOR, 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) )
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 ### APPLE MUSIC links, perform API requests and load all tracks from the playlist/album/track

View File

@ -31,6 +31,7 @@ BOT_COLOR = None
BOT_INVITE_LINK = None BOT_INVITE_LINK = None
FEEDBACK_CHANNEL_ID = None FEEDBACK_CHANNEL_ID = None
BUG_CHANNEL_ID = None BUG_CHANNEL_ID = None
YOUTUBE_SUPPORT = None
SPOTIFY_CLIENT_ID = None SPOTIFY_CLIENT_ID = None
SPOTIFY_CLIENT_SECRET = None SPOTIFY_CLIENT_SECRET = None
GENIUS_CLIENT_ID = None GENIUS_CLIENT_ID = None
@ -51,6 +52,7 @@ schema = {
"bot_invite_link": {"type": "string"}, "bot_invite_link": {"type": "string"},
"feedback_channel_id": {"type": "integer"}, "feedback_channel_id": {"type": "integer"},
"bug_channel_id": {"type": "integer"}, "bug_channel_id": {"type": "integer"},
"youtube_support": {"type": "boolean"},
}, },
"required": ["token"], "required": ["token"],
}, },
@ -114,6 +116,7 @@ bot_info:
bot_invite_link: "" bot_invite_link: ""
feedback_channel_id: "" feedback_channel_id: ""
bug_channel_id: "" bug_channel_id: ""
youtube_support: false
spotify: spotify:
spotify_client_id: "" spotify_client_id: ""
@ -142,7 +145,7 @@ lavalink:
# Thouroughly validate all of the options in the config.yaml file # Thouroughly validate all of the options in the config.yaml file
def validate_config(file_contents): 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) config = yaml.safe_load(file_contents)
try: try:
@ -198,6 +201,11 @@ def validate_config(file_contents):
else: else:
BUG_CHANNEL_ID = config["bot_info"]["bug_channel_id"] 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 # If the SPOTIFY section is present, make sure the client ID and secret are valid
# #