add providers
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is passing

This commit is contained in:
Roy Olav Purser 2024-05-25 19:09:44 +02:00
parent 6bb90fd02e
commit 9e164ff0f5
Signed by: roypur
GPG Key ID: 063DAA01D56E28CB

36
bot.py
View File

@ -2,8 +2,10 @@
import os import os
from urllib.parse import urlparse, parse_qs from urllib.parse import urlparse, parse_qs
import aiohttp
import discord import discord
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
DISCORD_CHANNEL = int(os.getenv("DISCORD_CHANNEL")) DISCORD_CHANNEL = int(os.getenv("DISCORD_CHANNEL"))
DISCORD_GUILD = int(os.getenv("DISCORD_GUILD")) DISCORD_GUILD = int(os.getenv("DISCORD_GUILD"))
@ -45,6 +47,40 @@ class CustomClient(discord.Client):
content=f"https://stream.purser.it/{video_id}?provider=youtube&direct=true" content=f"https://stream.purser.it/{video_id}?provider=youtube&direct=true"
) )
elif "seafile" in url.hostname:
stripped = url.path.strip("/")
async with aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=5)
) as session:
resp = await session.head(
"https://stream.purser.it/{stripped}/?provider=seafile&raw=true"
)
raw = (
ctype := resp.headers.get("content-type")
) and "image" in ctype
await message.reply(
content=f"https://stream.purser.it/{stripped}/?provider=seafile&raw={raw}"
)
elif "twitch" in url.hostname:
stripped = url.path.strip("/")
await message.reply(
content=f"https://stream.purser.it/{stripped}?provider=twitch"
)
elif "twitter" in url.hostname:
stripped = url.path.strip("/")
await message.reply(
content=f"https://stream.purser.it/{stripped}?provider=twitter"
)
elif "x.com" in url.hostname:
stripped = url.path.strip("/")
await message.reply(
content=f"https://stream.purser.it/{stripped}?provider=twitter"
)
intents = discord.Intents.default() intents = discord.Intents.default()
intents.message_content = True intents.message_content = True