UNPKG

@getsolara/solara.voice

Version:

Optional voice functionality for @getsolara/solara.js using @discordjs/voice

45 lines (44 loc) 2.43 kB
module.exports = { name: "$lyrics", description: "Fetches lyrics for a song using Genius. Args: geniusApiKey;songTitle;artist", takesBrackets: true, execute: async (context, args) => { if (!args[0] || !args[1] || !args[2]) { return "[Error: $lyrics requires an API Key, a song title, and an artist. Format: geniusApiKey;songTitle;artist]"; } const geniusApiKey = args[0].trim(); const title = args[1].trim(); const artist = args[2].trim(); if (!geniusApiKey) return "[Error: Genius API Key (first argument) for $lyrics is missing.]"; if (!title) return "[Error: Song title (second argument) for $lyrics is missing.]"; if (!artist) return "[Error: Song artist (third argument) for $lyrics is missing.]"; const options = { apiKey: geniusApiKey, title: title, artist: artist, optimizeQuery: true }; try { const { getLyrics } = require('genius-lyrics-api'); const lyrics = await getLyrics(options); if (!lyrics) { return `[Error: No lyrics found for "${title}${artist ? ` by ${artist}` : ''}" using $lyrics]`; } const maxLength = 4096; if (lyrics.length <= maxLength) { return lyrics; } else { let truncatedLyrics = lyrics.slice(0, maxLength - 4); const lastNewline = truncatedLyrics.lastIndexOf('\n'); if (lastNewline > maxLength * 0.8 && lastNewline > 0) { truncatedLyrics = truncatedLyrics.slice(0, lastNewline); } return truncatedLyrics + "\n..."; } } catch (e) { if (e.code === 'MODULE_NOT_FOUND' && e.message.includes('genius-lyrics-api')) { return "[Error: $lyrics - genius-lyrics-api module not found. Please install it.]"; } console.error(`Solara.voice Error ($lyrics) for Title: "${options.title}", Artist: "${options.artist}":`, e); const errorMessage = e.message?.includes('403') ? "Invalid Genius API Key provided?" : e.message?.includes('404') ? "Song not found on Genius." : e.message ? e.message : "Could not fetch lyrics."; return `[Error fetching lyrics: ${errorMessage}]`; } } };