Skip to content

Commit 6228f3b

Browse files
committed
Allow for lyrics search
1 parent c298da1 commit 6228f3b

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

bot/src/main/kotlin/me/duncte123/skybot/commands/music/LyricsCommand.kt

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
package me.duncte123.skybot.commands.music
2020

21+
import dev.arbjerg.lavalink.client.LavalinkNode
2122
import dev.arbjerg.lavalink.client.Link
23+
import fredboat.audio.player.LavalinkManager
2224
import me.duncte123.botcommons.messaging.EmbedUtils
2325
import me.duncte123.botcommons.messaging.MessageUtils.sendEmbed
2426
import me.duncte123.botcommons.messaging.MessageUtils.sendMsg
@@ -49,15 +51,16 @@ class LyricsCommand : MusicCommand() {
4951
val args = ctx.args
5052

5153
if (args.isNotEmpty()) {
52-
sendMsg(ctx, "Search is not supported atm, sorry")
53-
/*handleSearch(ctx.argsRaw, ctx.config) {
54+
val randomNode = LavalinkManager.INS.lavalink.nodes.random()
55+
56+
searchForLyrics(randomNode, ctx.argsRaw) {
5457
if (it == null) {
5558
sendMsg(ctx, "There where no lyrics found for `${ctx.argsRaw}`")
56-
return@handleSearch
59+
return@searchForLyrics
5760
}
5861

5962
sendEmbed(ctx, it)
60-
}*/
63+
}
6164
return
6265
}
6366

@@ -122,16 +125,16 @@ class LyricsCommand : MusicCommand() {
122125
event.deferReply().queue()
123126

124127
val search = opt.asString
128+
val randomNode = LavalinkManager.INS.lavalink.nodes.random()
125129

126-
/*handleSearch(search, variables.config) {
130+
searchForLyrics(randomNode, search) {
127131
if (it == null) {
128132
event.hook.sendMessage("There where no lyrics found for `$search`").queue()
129-
return@handleSearch
133+
return@searchForLyrics
130134
}
131135

132136
event.hook.sendMessageEmbeds(it.build()).queue()
133-
}*/
134-
event.hook.sendMessage("Search is not supported atm, sorry").queue()
137+
}
135138
}
136139

137140
private fun loadLyricsFromLavalink(link: Link, cb: (EmbedBuilder?) -> Unit) {
@@ -186,14 +189,27 @@ class LyricsCommand : MusicCommand() {
186189
}
187190
}
188191

189-
// TODO: enable genius on node
190-
/*
191-
private fun searchForLyrics(link: Link, q: String, cb: (EmbedBuilder?) -> Unit) {
192-
link.node.customJsonRequest(Lyrics::class.java) {
193-
it.path("v4/lyrics/search?source=genius&query=$q")
192+
private fun searchForLyrics(node: LavalinkNode, q: String, cb: (EmbedBuilder?) -> Unit) {
193+
node.customJsonRequest(Lyrics::class.java) {
194+
it.path("/v4/lyrics/search?source=genius&query=$q")
194195
}
196+
.subscribe({
197+
it as TextLyrics // We always get text lyrics here since we are using genius.
198+
199+
cb(buildLyricsEmbed(
200+
LyricInfo(
201+
it.track.albumArt.last().url,
202+
it.track.title,
203+
null,
204+
it.source,
205+
it.text
206+
)
207+
))
208+
}) {
209+
LOGGER.error("Failed searching lyrics for genius", it)
210+
cb(null)
211+
}
195212
}
196-
*/
197213

198214
private fun buildLyricsEmbed(data: LyricInfo): EmbedBuilder {
199215
val builder = EmbedUtils.getDefaultEmbed()

0 commit comments

Comments
 (0)