yolo
All checks were successful
Garfbot CI/CD Deployment / Deploy (push) Successful in 59s

This commit is contained in:
2026-03-07 14:15:08 -06:00
parent f77940dff9
commit 940b6b80d9

View File

@@ -1,7 +1,9 @@
import re
import config
import asyncio
import discord
from discord.ext import commands
from urllib.parse import urlparse, parse_qs, urlencode
from garfpy import (
help,
@@ -40,6 +42,36 @@ kroger = Kroger()
weather = WeatherAPI()
URL_PATTERNS = [
r'https?://(?:www\.)?youtube\.com/watch\?[^\s]*',
r'https?://youtu\.be/[^\s]*',
r'https?://(?:open\.)?spotify\.com/[^\s]*',
]
def clean_url(url):
try:
parsed = urlparse(url)
if 'youtube.com' in parsed.hostname:
params = parse_qs(parsed.query)
video_id = params.get('v', [None])[0]
if not video_id:
return None
# timestamp = params.get('t', [None])[0]
# if timestamp:
# return f"https://www.youtube.com/watch?v={video_id}&t={timestamp}"
return f"https://www.youtube.com/watch?v={video_id}"
if 'youtu.be' in parsed.hostname:
return f"https://youtu.be{parsed.path}"
if 'spotify.com' in parsed.hostname:
return f"https://open.spotify.com{parsed.path}"
except Exception:
return None
@garfbot.event
async def on_ready():
try:
@@ -151,6 +183,19 @@ async def on_message(message):
content = message.content.strip()
lower = content.lower()
# Remove tracking stuff from youtube and spotify links
cleaned_urls = []
for pattern in URL_PATTERNS:
for match in re.finditer(pattern, message.content):
cleaned = clean_url(match.group(0))
if cleaned and cleaned != match.group(0):
cleaned_urls.append(cleaned)
if cleaned_urls:
links = '\n'.join(cleaned_urls)
await message.reply(f"🔗 Cleaned link{'s' if len(cleaned_urls) > 1 else ''}:\n{links}")
# Chats & pics
if lower.startswith("hey garfield") or isinstance(
message.channel, discord.DMChannel