From 145e23cc914f366c7aba2cf072a589599b151547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 29 Nov 2021 19:50:05 +0200 Subject: [PATCH] Add direct search to Stations class --- src/client/classes/Radio.js | 2 +- src/client/classes/Stations.js | 14 +++++++++++++- src/client/commands/play.js | 11 ++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/client/classes/Radio.js b/src/client/classes/Radio.js index 89bd4c0..7990782 100644 --- a/src/client/classes/Radio.js +++ b/src/client/classes/Radio.js @@ -41,7 +41,7 @@ module.exports = class Radio extends Map { if(voiceChannel.members.filter(member => !member.user.bot).size === 0) return; - const sstation = await client.stations.search(state.station.name); + const sstation = await client.stations.search(state.station.name, "direct"); let station = sstation; if(!station) return; diff --git a/src/client/classes/Stations.js b/src/client/classes/Stations.js index caaf534..62bfdf1 100644 --- a/src/client/classes/Stations.js +++ b/src/client/classes/Stations.js @@ -60,9 +60,20 @@ module.exports = class Stations extends Array { } } - search(key) { + search(key, type) { if (this === null) return false; if (!key) return false; + if (!type) return false; + + if(type == "direct"){ + let foundStation; + this.forEach(station => { + if(station.name != key) return false; + foundStation = station; + }); + + return foundStation; + } else { let foundStations = []; if (key == "radio") return false; @@ -122,5 +133,6 @@ module.exports = class Stations extends Array { } } return highestProbabilityStation; + } } }; diff --git a/src/client/commands/play.js b/src/client/commands/play.js index 47cd34f..0cc7df8 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -84,7 +84,16 @@ module.exports = { content: client.messageEmojis["error"] + client.messages.tooShortSearch, ephemeral: true }); - const sstation = await client.stations.search(query, client); + + let type = ""; + + if(interaction.values?.[0]){ + type = "direct"; + } else { + type = "text"; + } + + const sstation = await client.stations.search(query, type); if (!sstation) return interaction.reply({ content: client.messageEmojis["error"] + client.messages.noSearchResults, ephemeral: true