Add Spotify Share Commands
This commit is contained in:
parent
2d9e1e2ba1
commit
27465fc5f0
3 changed files with 166 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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() {
|
|||
</TableRowGroup>
|
||||
|
||||
{/* Image Commands */}
|
||||
<TableRowGroup title="Image Commands">
|
||||
<TableRowGroup title="Petpet Commands">
|
||||
<TableSwitchRow
|
||||
label="/petpet"
|
||||
subLabel="Create pet-pet GIF of a user"
|
||||
|
|
@ -201,6 +205,34 @@ export default function Settings() {
|
|||
/>
|
||||
</TableRowGroup>
|
||||
|
||||
{/* Spotify Commands */}
|
||||
<TableRowGroup title="Spotify Commands">
|
||||
<TableSwitchRow
|
||||
label="/spotify track"
|
||||
subLabel="Share your current Spotify track"
|
||||
value={storage.enabledCommands?.spotifyTrack ?? true}
|
||||
onValueChange={(v) => handleCommandToggle("spotifyTrack", v)}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/spotify album"
|
||||
subLabel="Share your current track's album"
|
||||
value={storage.enabledCommands?.spotifyAlbum ?? true}
|
||||
onValueChange={(v) => handleCommandToggle("spotifyAlbum", v)}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/spotify artists"
|
||||
subLabel="Share your current track's artists"
|
||||
value={storage.enabledCommands?.spotifyArtists ?? true}
|
||||
onValueChange={(v) => handleCommandToggle("spotifyArtists", v)}
|
||||
/>
|
||||
<TableSwitchRow
|
||||
label="/spotify cover"
|
||||
subLabel="Share your current track's cover"
|
||||
value={storage.enabledCommands?.spotifyCover ?? true}
|
||||
onValueChange={(v) => handleCommandToggle("spotifyCover", v)}
|
||||
/>
|
||||
</TableRowGroup>
|
||||
|
||||
{/* Credits */}
|
||||
<TableRowGroup title="Credits">
|
||||
<TableRow label="Facts Commands" subLabel="by jdev082" />
|
||||
|
|
@ -212,6 +244,7 @@ export default function Settings() {
|
|||
/>
|
||||
<TableRow label="FirstMessage Command" subLabel="by sapphire" />
|
||||
<TableRow label="Sysinfo Command" subLabel="by mugman" />
|
||||
<TableRow label="Spotify Commands" subLabel="by Kitomanari" />
|
||||
</TableRowGroup>
|
||||
|
||||
{/* About */}
|
||||
|
|
|
|||
115
plugins/Commands/src/commands/spotify.ts
Normal file
115
plugins/Commands/src/commands/spotify.ts
Normal file
|
|
@ -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
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue