������my cover art
This commit is contained in:
parent
0a95b72051
commit
6359da85ea
4 changed files with 95 additions and 4 deletions
|
|
@ -9,7 +9,8 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.17.2",
|
"discord.js": "^14.17.2",
|
||||||
"ts-node": "^10.9.2"
|
"ts-node": "^10.9.2",
|
||||||
|
"zod": "^3.24.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^5.5.3"
|
"typescript": "^5.5.3"
|
||||||
|
|
|
||||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
|
|
@ -14,6 +14,9 @@ importers:
|
||||||
ts-node:
|
ts-node:
|
||||||
specifier: ^10.9.2
|
specifier: ^10.9.2
|
||||||
version: 10.9.2(@types/node@22.10.5)(typescript@5.7.2)
|
version: 10.9.2(@types/node@22.10.5)(typescript@5.7.2)
|
||||||
|
zod:
|
||||||
|
specifier: ^3.24.2
|
||||||
|
version: 3.24.2
|
||||||
devDependencies:
|
devDependencies:
|
||||||
typescript:
|
typescript:
|
||||||
specifier: ^5.5.3
|
specifier: ^5.5.3
|
||||||
|
|
@ -189,6 +192,9 @@ packages:
|
||||||
resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==}
|
resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
|
||||||
|
zod@3.24.2:
|
||||||
|
resolution: {integrity: sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==}
|
||||||
|
|
||||||
snapshots:
|
snapshots:
|
||||||
|
|
||||||
'@cspotcode/source-map-support@0.8.1':
|
'@cspotcode/source-map-support@0.8.1':
|
||||||
|
|
@ -353,3 +359,5 @@ snapshots:
|
||||||
ws@8.18.0: {}
|
ws@8.18.0: {}
|
||||||
|
|
||||||
yn@3.1.1: {}
|
yn@3.1.1: {}
|
||||||
|
|
||||||
|
zod@3.24.2: {}
|
||||||
|
|
|
||||||
57
src/helper.ts
Normal file
57
src/helper.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export interface Song {
|
||||||
|
title: string;
|
||||||
|
artist: string;
|
||||||
|
apiProvider: string;
|
||||||
|
thumbnailUrl: string;
|
||||||
|
link: string;
|
||||||
|
}
|
||||||
|
const songLinkShape = z.object({
|
||||||
|
userCountry: z.string(),
|
||||||
|
entitiesByUniqueId: z.record(
|
||||||
|
z.string(),
|
||||||
|
z.object({
|
||||||
|
id: z.string(),
|
||||||
|
type: z.string(),
|
||||||
|
title: z.string(),
|
||||||
|
thumbnailUrl: z.string(),
|
||||||
|
apiProvider: z.string(),
|
||||||
|
artistName: z.string(),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
linksByPlatform: z.record(
|
||||||
|
z.string(),
|
||||||
|
z.object({
|
||||||
|
country: z.string(),
|
||||||
|
url: z.string().url(),
|
||||||
|
entityUniqueId: z.string(),
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
//i hate this
|
||||||
|
export const preferredProviders = [
|
||||||
|
"spotify",
|
||||||
|
"deezer",
|
||||||
|
"youtubeMusic"
|
||||||
|
];
|
||||||
|
|
||||||
|
export function getSongOnPreferredProvider(json: any, link: string): Song | null {
|
||||||
|
const song = songLinkShape.parse(json);
|
||||||
|
for (const platform of preferredProviders) {
|
||||||
|
if (!song.linksByPlatform[platform]) {
|
||||||
|
console.log(`couldnt find song on ${platform}`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const entityId = song.linksByPlatform[platform].entityUniqueId;
|
||||||
|
const songInfo = song.entitiesByUniqueId[entityId]
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: songInfo.title,
|
||||||
|
artist: songInfo.artistName,
|
||||||
|
apiProvider: songInfo.apiProvider,
|
||||||
|
thumbnailUrl: songInfo.thumbnailUrl,
|
||||||
|
link
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
27
src/index.ts
27
src/index.ts
|
|
@ -1,8 +1,13 @@
|
||||||
import config from "../config.json" with {type: "json"};
|
import config from "../config.json" with {type: "json"};
|
||||||
import {
|
import {
|
||||||
|
ActionRow,
|
||||||
|
ActionRowBuilder,
|
||||||
Application,
|
Application,
|
||||||
ApplicationIntegrationType,
|
ApplicationIntegrationType,
|
||||||
|
ButtonBuilder,
|
||||||
|
ButtonStyle,
|
||||||
Client,
|
Client,
|
||||||
|
EmbedBuilder,
|
||||||
Events,
|
Events,
|
||||||
GatewayIntentBits,
|
GatewayIntentBits,
|
||||||
InteractionContextType,
|
InteractionContextType,
|
||||||
|
|
@ -10,6 +15,7 @@ import {
|
||||||
Routes,
|
Routes,
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
|
import { getSongOnPreferredProvider } from "./helper.ts";
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: Object.keys(GatewayIntentBits).map((a) => {
|
intents: Object.keys(GatewayIntentBits).map((a) => {
|
||||||
|
|
@ -71,7 +77,26 @@ client.on(Events.InteractionCreate, async (interaction) => {
|
||||||
if (meow.payload.count === 0) {
|
if (meow.payload.count === 0) {
|
||||||
interaction.followUp("user isnt listening to music");
|
interaction.followUp("user isnt listening to music");
|
||||||
} else {
|
} else {
|
||||||
interaction.followUp("[" + meow.payload.listens[0].track_metadata.artist_name + " - " + meow.payload.listens[0].track_metadata.track_name + "](" + keepV(meow.payload.listens[0].track_metadata.additional_info.origin_url) + ")");
|
const track_metadata = meow.payload.listens[0].track_metadata
|
||||||
|
const link = keepV(track_metadata.additional_info.origin_url)
|
||||||
|
|
||||||
|
const preferredApi = getSongOnPreferredProvider(await fetch(`https://api.song.link/v1-alpha.1/links?url=${link}`).then(a => a.json()), link)
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setAuthor({
|
||||||
|
name: preferredApi.artist,
|
||||||
|
})
|
||||||
|
.setTitle(preferredApi.title)
|
||||||
|
.setThumbnail(preferredApi.thumbnailUrl)
|
||||||
|
.setFooter({
|
||||||
|
text: "amy jr",
|
||||||
|
});
|
||||||
|
const nya = new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setURL(preferredApi.link).setLabel("link").setStyle(ButtonStyle.Link))
|
||||||
|
interaction.followUp({
|
||||||
|
components: [
|
||||||
|
nya
|
||||||
|
],
|
||||||
|
embeds: [embed]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue