From 2c61ce4fd94ce8169f8a8fbcb40de9bd43b6ac7a Mon Sep 17 00:00:00 2001 From: Parker Date: Mon, 25 Nov 2024 23:46:29 -0600 Subject: [PATCH] update/set poToken for youtube-source --- code/cogs/owner/potoken.py | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 code/cogs/owner/potoken.py diff --git a/code/cogs/owner/potoken.py b/code/cogs/owner/potoken.py new file mode 100644 index 0000000..2eba735 --- /dev/null +++ b/code/cogs/owner/potoken.py @@ -0,0 +1,46 @@ +from discord.ext import commands +import requests + +from utils.config import LAVALINK_HOST, LAVALINK_PORT, LAVALINK_PASSWORD, LOG + + +class POToken(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.command() + @commands.dm_only() + @commands.is_owner() + async def potoken(self, ctx, token: str = None, visitor_data: str = None): + """Update the poToken for lavalink youtube support.""" + if not token or not visitor_data: + return await ctx.send( + "Missing token and/or visitor data. Format as" + f" `{self.bot.command_prefix}potoken `\n\nTo generate a poToken, see" + " [this](https://github.com/iv-org/youtube-trusted-session-generator)" + ) + + url = f"http://{LAVALINK_HOST}:{LAVALINK_PORT}/youtube" + request = requests.post( + url, + json={"poToken": token, "visitorData": visitor_data}, + headers={"Authorization": LAVALINK_PASSWORD}, + ) + + if request.status_code != 204: + LOG.error("Error updating poToken") + return await ctx.send( + "Error setting poToken, YouTube source plugin is likely not" + " enabled. Read the Guava docs and look" + " [here](https://github.com/lavalink-devs/youtube-source)." + ) + + LOG.info("poToken successfully updated") + await ctx.send( + "Successfully posted the token and visitor data to lavalink." + ) + + +async def setup(bot): + await bot.add_cog(POToken(bot))