aboutsummaryrefslogtreecommitdiff
path: root/code/cogs/owner/potoken.py
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2024-12-03 06:05:14 +0000
committerGitHub <noreply@github.com>2024-12-03 06:05:14 +0000
commit15e33831639355546b32477a6870eb0a3ac47e24 (patch)
treea5455e0a8391747c7226a751354b7236c8c5d40b /code/cogs/owner/potoken.py
parentfcbfe460701316ded25e29356ed1fda42386e5c0 (diff)
parentce18cd27488d90fbd0aae7319a36a89e9fa85aa7 (diff)
Merge pull request #10 from PacketParker/dev
Update
Diffstat (limited to 'code/cogs/owner/potoken.py')
-rw-r--r--code/cogs/owner/potoken.py46
1 files changed, 46 insertions, 0 deletions
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 <token> <visitor"
+ " data>`\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))