-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
568 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/ca/tristan/easycommands/commands/music/LyricsCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package ca.tristan.easycommands.commands.music; | ||
|
||
import ca.tristan.easycommands.commands.EasyCommands; | ||
import ca.tristan.easycommands.commands.EventData; | ||
import ca.tristan.easycommands.commands.slash.SlashExecutor; | ||
import ca.tristan.easycommands.embeds.MusicEB; | ||
import ca.tristan.easycommands.lavaplayer.GuildMusicManager; | ||
import ca.tristan.easycommands.lavaplayer.PlayerManager; | ||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; | ||
import core.GLA; | ||
import genius.SongSearch; | ||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.entities.channel.Channel; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class LyricsCmd extends SlashExecutor { | ||
|
||
@Override | ||
public String getName() { | ||
return "lyrics"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Retrieves the lyrics of the current playing music."; | ||
} | ||
|
||
@Override | ||
public List<Channel> getAuthorizedChannels(JDA jda) { | ||
List<Channel> channels = new ArrayList<>(); | ||
if(EasyCommands.getMusicChannel() != null) { | ||
channels.add(EasyCommands.getMusicChannel()); | ||
} | ||
return channels; | ||
} | ||
|
||
@Override | ||
public void execute(EventData data) { | ||
final GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(data.getGuild()); | ||
final AudioPlayer audioPlayer = musicManager.audioPlayer; | ||
|
||
MusicEB musicEB = new MusicEB(); | ||
|
||
if(audioPlayer.getPlayingTrack() == null){ | ||
musicEB.getBuilder().setDescription("There is no music currently playing."); | ||
data.reply(musicEB.getBuilder().build(), true).queue(); | ||
return; | ||
} | ||
|
||
String title = audioPlayer.getPlayingTrack().getInfo().title; | ||
|
||
GLA gla = new GLA(); | ||
try { | ||
|
||
SongSearch search = gla.search(title.toLowerCase().replaceAll("official", "").replaceAll("music", "").replaceAll("video", "").replaceAll("Audio", "")); | ||
|
||
String url = search.getHits().isEmpty() ? "" : search.getHits().getFirst().getUrl(); | ||
if(url.isBlank()){ | ||
musicEB.getBuilder().setDescription("Sorry, I haven't found any lyrics for that song."); | ||
data.reply(musicEB.getBuilder().build(), true).queue(); | ||
return; | ||
} | ||
musicEB.getBuilder().setDescription("Here's what I've found: " + url); | ||
data.reply(musicEB.getBuilder().build(), true).queue(); | ||
} catch (IOException e) { | ||
musicEB.getBuilder().setDescription("Sorry, I haven't found any lyrics for that song."); | ||
data.reply(musicEB.getBuilder().build(), true).queue(); | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.