This commit is contained in:
2025-08-29 22:33:27 +01:00
parent 70667e7567
commit 972106f3d2

10
bot.py
View File

@@ -22,16 +22,16 @@ async def on_message(message):
if message.author == bot.user: if message.author == bot.user:
return return
# Check if the message contains "nixos" (case-insensitive, as a whole word, not in a URL) # Replace "nixos" with "fagOS" (preserving case of the first letter), but exclude URLs starting with http(s)://
if re.search(r'\bnixos\b', message.content, re.IGNORECASE):
# Replace "nixos" with "fagOS" (preserving case of the first letter), but exclude URLs
new_content = re.sub( new_content = re.sub(
r'(?<!https?://\S*)\b(nixos)\b(?!\S*\/)', r'(https?://\S+)|(\bnixos\b)',
lambda m: 'FagOS' if m.group(1)[0].isupper() else 'fagOS', lambda m: m.group(1) if m.group(1) else ('FagOS' if m.group(2)[0].isupper() else 'fagOS'),
message.content, message.content,
flags=re.IGNORECASE flags=re.IGNORECASE
) )
# Only proceed if the content was actually modified
if new_content != message.content:
# Get or create a webhook for impersonation # Get or create a webhook for impersonation
webhooks = await message.channel.webhooks() webhooks = await message.channel.webhooks()
webhook = next((w for w in webhooks if w.name == 'FagOSWebhook'), None) webhook = next((w for w in webhooks if w.name == 'FagOSWebhook'), None)