From 27465fc5f0c1cff05114679ddb4f1496accc64be Mon Sep 17 00:00:00 2001 From: kmmiio99o Date: Tue, 30 Sep 2025 19:03:33 +0200 Subject: [PATCH] Add Spotify Share Commands --- plugins/Commands/index.ts | 20 +++- plugins/Commands/settings.tsx | 35 ++++++- plugins/Commands/src/commands/spotify.ts | 115 +++++++++++++++++++++++ 3 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 plugins/Commands/src/commands/spotify.ts diff --git a/plugins/Commands/index.ts b/plugins/Commands/index.ts index c550a1a..15192de 100644 --- a/plugins/Commands/index.ts +++ b/plugins/Commands/index.ts @@ -9,7 +9,13 @@ import { pluginListCommand, themeListCommand } from "./src/commands/lists"; import { petPetCommand } from "./src/commands/petpet"; import { konoSelfCommand, konoSendCommand } from "./src/commands/konochan"; import { firstMessageCommand } from "./src/commands/firstmessage"; -import { sysinfoCommand } from "./src/commands/sysinfo"; +import { sysinfoCommand } from "./src/commands/sysinfo"; +import { + spotifyTrackCommand, + spotifyAlbumCommand, + spotifyArtistsCommand, + spotifyCoverCommand +} from "./src/commands/spotify"; import settings from "./settings"; // Initialize storage with default values @@ -38,7 +44,11 @@ if (!storage.enabledCommands) { konoself: true, konosend: true, firstmessage: true, - sysinfo: true, // Add sysinfo to enabled commands + sysinfo: true, + spotifyTrack: true, + spotifyAlbum: true, + spotifyArtists: true, + spotifyCover: true, }; } @@ -53,7 +63,11 @@ const commandMap = { konoself: konoSelfCommand, konosend: konoSendCommand, firstmessage: firstMessageCommand, - sysinfo: sysinfoCommand, // Add sysinfo to command map + sysinfo: sysinfoCommand, + spotifyTrack: spotifyTrackCommand, + spotifyAlbum: spotifyAlbumCommand, + spotifyArtists: spotifyArtistsCommand, + spotifyCover: spotifyCoverCommand, }; // Store registered commands for cleanup diff --git a/plugins/Commands/settings.tsx b/plugins/Commands/settings.tsx index 3c9c432..526dcb3 100644 --- a/plugins/Commands/settings.tsx +++ b/plugins/Commands/settings.tsx @@ -41,6 +41,10 @@ if (!storage.enabledCommands) { konosend: true, firstmessage: true, sysinfo: true, + spotifyTrack: true, + spotifyAlbum: true, + spotifyArtists: true, + spotifyCover: true, }; } @@ -156,7 +160,7 @@ export default function Settings() { {/* Image Commands */} - + + {/* Spotify Commands */} + + handleCommandToggle("spotifyTrack", v)} + /> + handleCommandToggle("spotifyAlbum", v)} + /> + handleCommandToggle("spotifyArtists", v)} + /> + handleCommandToggle("spotifyCover", v)} + /> + + {/* Credits */} @@ -212,6 +244,7 @@ export default function Settings() { /> + {/* About */} diff --git a/plugins/Commands/src/commands/spotify.ts b/plugins/Commands/src/commands/spotify.ts new file mode 100644 index 0000000..3f0030f --- /dev/null +++ b/plugins/Commands/src/commands/spotify.ts @@ -0,0 +1,115 @@ +import { findByProps, findByStoreName } from "@vendetta/metro"; +import { storage } from "@vendetta/plugin"; + +const MessageActions = findByProps('sendMessage', 'receiveMessage'); +const SpotifyStore = findByStoreName('SpotifyStore'); + +// Individual command functions +async function spotifyTrackExecute(args: any[], ctx: any) { + if (!storage.enabledCommands?.spotifyTrack) return { type: 4 }; + return handleSpotifyCommand(ctx, (track: any) => + `https://open.spotify.com/track/${track.id}` + ); +} + +async function spotifyAlbumExecute(args: any[], ctx: any) { + if (!storage.enabledCommands?.spotifyAlbum) return { type: 4 }; + return handleSpotifyCommand(ctx, (track: any) => + `https://open.spotify.com/album/${track.album.id}` + ); +} + +async function spotifyArtistsExecute(args: any[], ctx: any) { + if (!storage.enabledCommands?.spotifyArtists) return { type: 4 }; + return handleSpotifyCommand(ctx, (track: any) => + track.artists.map((artist: any) => + `[${artist.name}](${artist.external_urls.spotify})` + ).join('\n') + ); +} + +async function spotifyCoverExecute(args: any[], ctx: any) { + if (!storage.enabledCommands?.spotifyCover) return { type: 4 }; + return handleSpotifyCommand(ctx, (track: any) => + track.album.image.url + ); +} + +// Common handler for all Spotify commands +async function handleSpotifyCommand(ctx: any, contentGenerator: (track: any) => string) { + try { + const channelId = ctx.channel.id; + const track = SpotifyStore?.getTrack?.(); + + if (!track) { + const fixNonce = Date.now().toString(); + MessageActions.sendMessage( + channelId, + { content: 'You are not listening to any track.' }, + void 0, + { nonce: fixNonce } + ); + return { type: 4 }; + } + + const content = contentGenerator(track); + const fixNonce = Date.now().toString(); + + MessageActions.sendMessage( + channelId, + { content }, + void 0, + { nonce: fixNonce } + ); + + return { type: 4 }; + } catch (error) { + console.error('[Spotify Command] Error:', error); + return { type: 4 }; + } +} + +// Export individual command objects +export const spotifyTrackCommand = { + name: 'spotify track', + displayName: 'spotify track', + description: 'Sends your current Spotify track', + displayDescription: 'Sends your current Spotify track', + applicationId: '-1', + inputType: 1, + type: 1, + execute: spotifyTrackExecute +}; + +export const spotifyAlbumCommand = { + name: 'spotify album', + displayName: 'spotify album', + description: "Sends your current track's album", + displayDescription: "Sends your current track's album", + applicationId: '-1', + inputType: 1, + type: 1, + execute: spotifyAlbumExecute +}; + +export const spotifyArtistsCommand = { + name: 'spotify artists', + displayName: 'spotify artists', + description: "Sends your current track's artists", + displayDescription: "Sends your current track's artists", + applicationId: '-1', + inputType: 1, + type: 1, + execute: spotifyArtistsExecute +}; + +export const spotifyCoverCommand = { + name: 'spotify cover', + displayName: 'spotify cover', + description: "Sends your current track's cover", + displayDescription: "Sends your current track's cover", + applicationId: '-1', + inputType: 1, + type: 1, + execute: spotifyCoverExecute +};