Compare commits
5 Commits
env-vars
...
boy-you-sa
| Author | SHA1 | Date | |
|---|---|---|---|
| 4880229e26 | |||
| bfef23eb72 | |||
| 940b6b80d9 | |||
| f77940dff9 | |||
| 68696e25f0 |
@@ -1,6 +1,6 @@
|
|||||||
MIT No Attribution
|
MIT No Attribution
|
||||||
|
|
||||||
Copyright 2025 Aaron Crate
|
Copyright 2026 Aaron Crate
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||||
software and associated documentation files (the "Software"), to deal in the Software
|
software and associated documentation files (the "Software"), to deal in the Software
|
||||||
|
|||||||
50
garfmain.py
50
garfmain.py
@@ -1,7 +1,9 @@
|
|||||||
|
import re
|
||||||
import config
|
import config
|
||||||
import asyncio
|
import asyncio
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from urllib.parse import urlparse, parse_qs
|
||||||
|
|
||||||
from garfpy import (
|
from garfpy import (
|
||||||
help,
|
help,
|
||||||
@@ -16,7 +18,7 @@ from garfpy import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
gapikey = config.GIF_TOKEN
|
# gapikey = config.GIF_TOKEN
|
||||||
garfkey = config.GARFBOT_TOKEN
|
garfkey = config.GARFBOT_TOKEN
|
||||||
txtmodel = config.TXT_MODEL
|
txtmodel = config.TXT_MODEL
|
||||||
imgmodel = config.IMG_MODEL
|
imgmodel = config.IMG_MODEL
|
||||||
@@ -40,6 +42,36 @@ kroger = Kroger()
|
|||||||
weather = WeatherAPI()
|
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
|
@garfbot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
try:
|
try:
|
||||||
@@ -118,6 +150,9 @@ async def garfbot_weather(ctx, *, location):
|
|||||||
|
|
||||||
@garfbot.command(name="chat")
|
@garfbot.command(name="chat")
|
||||||
async def garfchat(ctx, *, prompt):
|
async def garfchat(ctx, *, prompt):
|
||||||
|
if "is this true" in prompt.lower():
|
||||||
|
messages = [msg async for msg in ctx.channel.history(limit=2)]
|
||||||
|
prompt = messages[1].content
|
||||||
answer = await garfield.generate_chat(prompt)
|
answer = await garfield.generate_chat(prompt)
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Chat Request - User: {ctx.author.name}, Server: {ctx.guild.name}, Prompt: {prompt}"
|
f"Chat Request - User: {ctx.author.name}, Server: {ctx.guild.name}, Prompt: {prompt}"
|
||||||
@@ -148,6 +183,19 @@ async def on_message(message):
|
|||||||
content = message.content.strip()
|
content = message.content.strip()
|
||||||
lower = content.lower()
|
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
|
# Chats & pics
|
||||||
if lower.startswith("hey garfield") or isinstance(
|
if lower.startswith("hey garfield") or isinstance(
|
||||||
message.channel, discord.DMChannel
|
message.channel, discord.DMChannel
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import json
|
import json
|
||||||
import discord
|
import discord
|
||||||
from garfpy import logger
|
from garfpy import logger
|
||||||
@@ -121,3 +122,17 @@ async def aod_message(garfbot, message):
|
|||||||
for field, values in zip(table_fields, table_columns):
|
for field, values in zip(table_fields, table_columns):
|
||||||
stats_embed.add_field(name=field, value="\n".join(values), inline=True)
|
stats_embed.add_field(name=field, value="\n".join(values), inline=True)
|
||||||
await message.channel.send(embed=stats_embed)
|
await message.channel.send(embed=stats_embed)
|
||||||
|
|
||||||
|
# Boy You Said It
|
||||||
|
words = re.findall(r"[a-zA-Z']+", message.content.lower())
|
||||||
|
stops = {"a", "an", "the", "and", "or", "but", "is", "it", "in", "on", "at", "to", "of"}
|
||||||
|
words = [w for w in words if w not in stops]
|
||||||
|
|
||||||
|
if words:
|
||||||
|
firsts = [w[0] for w in words]
|
||||||
|
commons = max(set(firsts), key=firsts.count)
|
||||||
|
count = firsts.count(commons)
|
||||||
|
|
||||||
|
if count >= 3 or (len(words) >= 2 and count / len(words) >= 0.75):
|
||||||
|
await message.channel.send("Boy, you said it!")
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class WeatherAPI:
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return await response.json()
|
return await response.json()
|
||||||
except aiohttp.ClientError as e:
|
except aiohttp.ClientError as e:
|
||||||
logger.error(f"Error fetching weather data for '{location}'")
|
logger.error(f"Error fetching weather data for '{location}' - {e}")
|
||||||
await ctx.send(f"`Error fetching weather data for '{location}'`")
|
await ctx.send(f"`Error fetching weather data for '{location}'`")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user