discord_bot/util/lastfm/roast.js
2025-04-30 20:19:01 +02:00

37 lines
No EOL
1.3 KiB
JavaScript

require("dotenv").config();
module.exports = async function(topArtists, topAlbums) {
let prompt = "Roast the top 10 artists albums the user has listened to most for the last year. Go as hard as possible and be mean. Keep it concise in one paragraph.\n"
prompt += "Top artists and their playcounts:\n"
topArtists.forEach(topArtist => {
prompt += `${topArtist.name} (${topArtist.playcount})\n`
});
prompt += "Top albums and their playcounts:\n"
topAlbums.forEach(topAlbum => {
prompt += `${topAlbum.artist} - ${topAlbum.name} (${topAlbum.playcount})\n`
})
let answer = "";
await fetch(`https://openrouter.ai/api/v1/chat/completions`, {
method: `POST`,
headers: {
"Authorization": `Bearer ${process.env.OPENROUTER_API_KEY}`,
"Content-Type": `application/json`
},
body: JSON.stringify({
"model": `deepseek/deepseek-chat-v3-0324:free`,
"messages": [
{
"role": `system`,
"content": prompt
}
],
"max_tokens": 350
})
}).then(response => response.json()).then(data => {
answer = data.choices[0].message.content;
}).catch(error => {
console.error(error);
});
return {embed: null, text: answer};
}