From d961269cf942f7bbafef72c173678f493972134b Mon Sep 17 00:00:00 2001 From: scanash00 Date: Sun, 10 Aug 2025 03:52:03 -0800 Subject: [PATCH] fix: Fix social command being registered on users when it isn't installed on the guild being rand and bluesky handles supporting custom domains now --- src/commands/utilities/social.ts | 4 +++ .../social/fetchers/UnifiedFetcher.ts | 35 +++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/commands/utilities/social.ts b/src/commands/utilities/social.ts index 26c1ce3..b62eeb4 100644 --- a/src/commands/utilities/social.ts +++ b/src/commands/utilities/social.ts @@ -4,6 +4,8 @@ import { EmbedBuilder, ChatInputCommandInteraction, MessageFlags, + InteractionContextType, + ApplicationIntegrationType, } from 'discord.js'; import { SlashCommandProps } from '@/types/command'; import BotClient from '@/services/Client'; @@ -40,6 +42,8 @@ const command: SocialCommand = { .setDescription('Get notifications of posts from Fediverse and Bluesky accounts') .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild) .setDMPermission(false) + .setContexts([InteractionContextType.Guild]) + .setIntegrationTypes([ApplicationIntegrationType.GuildInstall]) .addSubcommand((subcommand) => subcommand .setName('add') diff --git a/src/services/social/fetchers/UnifiedFetcher.ts b/src/services/social/fetchers/UnifiedFetcher.ts index 06d9aa2..6a32d89 100644 --- a/src/services/social/fetchers/UnifiedFetcher.ts +++ b/src/services/social/fetchers/UnifiedFetcher.ts @@ -84,16 +84,33 @@ export class BlueskyFetcher implements SocialMediaFetcher { return /^did:[a-z0-9]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$/.test(account); } - const parts = account.split('@').filter(Boolean); - if (parts.length < 2) return false; + const normalizedAccount = account.startsWith('@') ? account.slice(1) : account; + + if (normalizedAccount.includes('@')) { + const parts = normalizedAccount.split('@').filter(Boolean); + if (parts.length < 2) return false; + + const handle = parts[0]; + const domain = parts[1]; + + const isValidHandle = /^[a-zA-Z0-9-]+$/.test(handle); + const isValidDomain = /^[a-zA-Z0-9.-]+$/.test(domain); + + return isValidHandle && isValidDomain; + } + const parts = normalizedAccount.split('.'); const handle = parts[0]; - const domain = parts.slice(1).join('@'); - const isValidHandle = /^[a-zA-Z0-9-]+$/.test(handle); - const isValidDomain = /^[a-zA-Z0-9.-]+$/.test(domain); + if (!/^[a-zA-Z0-9-]+$/.test(handle)) { + return false; + } + + if (parts.length > 1) { + return parts.every((part) => /^[a-zA-Z0-9-]+$/.test(part)); + } - return isValidHandle && isValidDomain; + return true; } private normalizeHandle(handle: string): string { @@ -102,9 +119,13 @@ export class BlueskyFetcher implements SocialMediaFetcher { } handle = handle.startsWith('@') ? handle.slice(1) : handle; - if (!handle.includes('.')) { + + if (handle.includes('@')) { + return handle.toLowerCase(); + } else if (!handle.includes('.')) { return `${handle}.bsky.social`.toLowerCase(); } + return handle.toLowerCase(); } -- 2.51.2