From 896ac7d40092eca88d69af4bf6c92d230ed4177a Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Fri, 14 Apr 2023 10:53:00 +0200 Subject: [PATCH] remove audio detection because nobody uses it anyways --- commands/message/search/audio.js | 86 ++++++++------------------------ labscore/api/endpoints.js | 1 - labscore/api/index.js | 6 --- 3 files changed, 22 insertions(+), 71 deletions(-) diff --git a/commands/message/search/audio.js b/commands/message/search/audio.js index 4497139..6684837 100644 --- a/commands/message/search/audio.js +++ b/commands/message/search/audio.js @@ -13,85 +13,43 @@ module.exports = { name: 'audio', aliases: ['aud'], metadata: { - description: '**Audio Detection**\nUsing the audio command without replying to a message will try to identify the song in the most recent video in chat.\n\n**Music Platform Links**\n__Replying__ to a message while using this command will return a list of music platforms the provided music (link) is available on.', - description_short: 'Audio detection', + description: '__Replying__ to a message while using this command will return a list of music streamin platforms the provided song (link) is available on.', + description_short: 'Cross-platform music search', examples: ['aud'], category: 'search', usage: 'audio' }, run: async (context) => { context.triggerTyping(); - try{ - - if(context.message.messageReference){ - let msg; - try{ - msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId) - } catch(e){ - return editOrReply(context, {embeds:[createEmbed("error", context, "Unable to fetch message.")]}) - } - let urls = msg.content.match(urlr) - if(urls){ - try{ - let songlink = await superagent.get(`https://api.song.link/v1-alpha.1/links?url=${encodeURIComponent(urls[0])}`) - let song = songlink.body.entitiesByUniqueId[songlink.body.entityUniqueId] - - let btns = renderMusicButtons(songlink.body.linksByPlatform) - return editOrReply(context, {embeds:[ - createEmbed("default", context, { - author: { - name: `${song.title} by ${song.artistName}`.substr(0,1000), - iconUrl: song.thumbnailUrl, - url: urls[0] - }, - footer: {} - }) - ], components: btns}) - }catch(e){} //ignore it and run the audio detection flow - } + if (!context.message.messageReference) return editOrReply(context, { embeds: [createEmbed("warning", context, "You need to reply to a message containing a song link.")] }) + try { + let msg; + try { + msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId) + } catch (e) { + return editOrReply(context, { embeds: [createEmbed("error", context, "Unable to fetch message.")] }) } + let urls = msg.content.match(urlr) + if (urls) { + let songlink = await superagent.get(`https://api.song.link/v1-alpha.1/links?url=${encodeURIComponent(urls[0])}`) + let song = songlink.body.entitiesByUniqueId[songlink.body.entityUniqueId] - - let audios = await getRecentVideo(context, 50) - if(!audios.length) return editOrReply(context, {embeds:[createEmbed("warning", context, `Could not find supported video.`)]}) - let audioSearch = await searchAudio(context, audios[0].url) - search = audioSearch.response - if(audioSearch.response.body.status == 0){ - // API lowkey sucks, fetch more metadata via songlink - let url = audioSearch.response.body.media[Object.keys(audioSearch.response.body.media)[0]] - if(audioSearch.response.body.media.deezer) url = audioSearch.response.body.media.deezer - if(audioSearch.response.body.media.napster) url = audioSearch.response.body.media.napster - if(audioSearch.response.body.media.apple_music) url = audioSearch.response.body.media.apple_music - if(audioSearch.response.body.media.spotify) url = audioSearch.response.body.media.spotify - try{ - let songlink = await superagent.get(`https://api.song.link/v1-alpha.1/links?url=${encodeURIComponent(url)}`) - //get song meta - let song = songlink.body.entitiesByUniqueId[songlink.body.entityUniqueId] - - let btns = renderMusicButtons(songlink.body.linksByPlatform) - return editOrReply(context, {embeds:[ + let btns = renderMusicButtons(songlink.body.linksByPlatform) + return editOrReply(context, { + embeds: [ createEmbed("default", context, { author: { - name: `${song.title} by ${song.artistName}`.substr(0,1000), + name: `${song.title} by ${song.artistName}`.substr(0, 1000), iconUrl: song.thumbnailUrl, - url: url + url: urls[0] }, footer: {} }) - ], components: btns}) - }catch(e){ - return editOrReply(context, {embeds: [ - createEmbed("error", context, "Links for this song are unavailable..") - ]}) - } + ], components: btns + }) } - - }catch(e){ - if(e.response?.body?.status){ - return editOrReply(context, {embeds:[createEmbed("error", context, e.response.body.message)]}) - } - console.log(e) - return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform audio search.`)]}) + } catch (e) { + return editOrReply(context, { embeds: [createEmbed("error", context, `Unable to perform song search.`)] }) } }, }; \ No newline at end of file diff --git a/labscore/api/endpoints.js b/labscore/api/endpoints.js index e8b5c1a..f003b03 100644 --- a/labscore/api/endpoints.js +++ b/labscore/api/endpoints.js @@ -25,7 +25,6 @@ const Api = Object.freeze({ PHOTOFUNIA_RETRO_WAVE: '/photofunia/retro-wave', PHOTOFUNIA_YACHT: '/photofunia/yacht', - SEARCH_AUDIO: '/search/audio', SEARCH_BING: '/search/bing', SEARCH_BING_IMAGES: '/search/bing-images', SEARCH_DICTIONARY: '/search/dictionary', diff --git a/labscore/api/index.js b/labscore/api/index.js index e2d8103..ed9ce03 100644 --- a/labscore/api/index.js +++ b/labscore/api/index.js @@ -92,12 +92,6 @@ module.exports.googleVisionWebDetection = async function(context, url){ }) } -module.exports.searchAudio = async function(context, url){ - return await request(Api.SEARCH_AUDIO, "GET", {}, { - url: url - }) -} - module.exports.lyrics = async function(context, query){ return await request(Api.SEARCH_LYRICS, "GET", {}, { q: query