From 940b6b80d9c71558b742b6d0e00324268513f93c Mon Sep 17 00:00:00 2001 From: Aaron Crate Date: Sat, 7 Mar 2026 14:15:08 -0600 Subject: [PATCH] yolo --- garfmain.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/garfmain.py b/garfmain.py index 150ee7f..f7e68fe 100644 --- a/garfmain.py +++ b/garfmain.py @@ -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