|
18 | 18 |
|
19 | 19 | package me.duncte123.skybot.commands.music |
20 | 20 |
|
| 21 | +import dev.arbjerg.lavalink.client.LavalinkNode |
21 | 22 | import dev.arbjerg.lavalink.client.Link |
| 23 | +import fredboat.audio.player.LavalinkManager |
22 | 24 | import me.duncte123.botcommons.messaging.EmbedUtils |
23 | 25 | import me.duncte123.botcommons.messaging.MessageUtils.sendEmbed |
24 | 26 | import me.duncte123.botcommons.messaging.MessageUtils.sendMsg |
@@ -49,15 +51,16 @@ class LyricsCommand : MusicCommand() { |
49 | 51 | val args = ctx.args |
50 | 52 |
|
51 | 53 | 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) { |
54 | 57 | if (it == null) { |
55 | 58 | sendMsg(ctx, "There where no lyrics found for `${ctx.argsRaw}`") |
56 | | - return@handleSearch |
| 59 | + return@searchForLyrics |
57 | 60 | } |
58 | 61 |
|
59 | 62 | sendEmbed(ctx, it) |
60 | | - }*/ |
| 63 | + } |
61 | 64 | return |
62 | 65 | } |
63 | 66 |
|
@@ -122,16 +125,16 @@ class LyricsCommand : MusicCommand() { |
122 | 125 | event.deferReply().queue() |
123 | 126 |
|
124 | 127 | val search = opt.asString |
| 128 | + val randomNode = LavalinkManager.INS.lavalink.nodes.random() |
125 | 129 |
|
126 | | - /*handleSearch(search, variables.config) { |
| 130 | + searchForLyrics(randomNode, search) { |
127 | 131 | if (it == null) { |
128 | 132 | event.hook.sendMessage("There where no lyrics found for `$search`").queue() |
129 | | - return@handleSearch |
| 133 | + return@searchForLyrics |
130 | 134 | } |
131 | 135 |
|
132 | 136 | event.hook.sendMessageEmbeds(it.build()).queue() |
133 | | - }*/ |
134 | | - event.hook.sendMessage("Search is not supported atm, sorry").queue() |
| 137 | + } |
135 | 138 | } |
136 | 139 |
|
137 | 140 | private fun loadLyricsFromLavalink(link: Link, cb: (EmbedBuilder?) -> Unit) { |
@@ -186,14 +189,27 @@ class LyricsCommand : MusicCommand() { |
186 | 189 | } |
187 | 190 | } |
188 | 191 |
|
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") |
194 | 195 | } |
| 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 | + } |
195 | 212 | } |
196 | | - */ |
197 | 213 |
|
198 | 214 | private fun buildLyricsEmbed(data: LyricInfo): EmbedBuilder { |
199 | 215 | val builder = EmbedUtils.getDefaultEmbed() |
|
0 commit comments