Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.42 KB | None | 0 0
  1. package me.savvy.melodybot.cmds;
  2.  
  3. import com.jagrosh.jdautilities.command.Command;
  4. import com.jagrosh.jdautilities.command.CommandEvent;
  5. import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
  6.  
  7. import me.savvy.melodybot.music.AudioHandler;
  8. import me.savvy.melodybot.music.MusicManager;
  9. import me.savvy.melodybot.music.MusicModule;
  10. import me.savvy.melodybot.music.RadioStations;
  11. import me.savvy.melodybot.music.ResultHandler;
  12. import net.dv8tion.jda.api.EmbedBuilder;
  13. import net.dv8tion.jda.api.JDA;
  14. import net.dv8tion.jda.api.entities.Guild;
  15. import net.dv8tion.jda.api.entities.Member;
  16. import net.dv8tion.jda.api.entities.VoiceChannel;
  17. import net.dv8tion.jda.api.managers.AudioManager;
  18.  
  19. import java.awt.*;
  20.  
  21. public class RadioCommand extends Command {
  22.  
  23.     private final MusicManager manager;
  24.  
  25.     public RadioCommand(MusicManager manager) {
  26.         this.manager = manager;
  27.         this.name = "radio";
  28.         this.help = "Radio command";
  29.         this.guildOnly = true;
  30.     }
  31.  
  32.     @Override
  33.     protected void execute(CommandEvent commandEvent) {
  34.  
  35.         Member member = commandEvent.getMember();
  36.         JDA jda = commandEvent.getJDA();
  37.  
  38.  
  39.         if (member.getVoiceState() == null || !member.getVoiceState().inVoiceChannel()) {
  40.             EmbedBuilder eb = new EmbedBuilder();
  41.             eb.setDescription(member.getAsMention() + " You must be in a voice channel to use this command!");
  42.             eb.setColor(Color.decode("#FF6B68"));
  43.             commandEvent.reply(eb.build());
  44.             return;
  45.         }
  46.  
  47.         if (commandEvent.getArgs().isEmpty()) {
  48.  
  49.             EmbedBuilder eb = new EmbedBuilder();
  50.             try {
  51.                 eb.setTitle(jda.getEmoteById("688147785610035335").getAsMention() + " Please specify a radio station " + jda.getEmoteById("688147785610035335").getAsMention());
  52.             } catch(NullPointerException ignored) {}
  53.             eb.setColor(Color.decode("#CB1450"));
  54.             eb.addField(
  55.                     "\uD83C\uDDEC\uD83C\uDDE7 UK Radio Station's",
  56.                     "CAPITALFM LIVERPOOL"
  57.                             + "\n" +
  58.                             "CAPITALFM LONDON"
  59.                             + "\n" +
  60.                             "CAPITALFM XTRA"
  61.                             + "\n" +
  62.                             "HEART"
  63.                             + "\n" +
  64.                             "3FM",
  65.                     true);
  66.             eb.addField(
  67.                     "\uD83C\uDDE6\uD83C\uDDFA Australia Radio Station's",
  68.                     "2GB"
  69.                             + "\n" +
  70.                             "HIT 92.9 PERTH"
  71.                             + "\n" +
  72.                             "FOX 101.9",
  73.                     true);
  74.             eb.addField(
  75.                     "\uD83C\uDDF3\uD83C\uDDF1 Dutch Radio Station's",
  76.                     "SkyRadio"
  77.                             + "\n" +
  78.                             "RADIO538"
  79.                             + "\n" +
  80.                             "Qmusic",
  81.                     true);
  82.             eb.addField(
  83.                     "If you would like a Radio Station added please join our Discord and @HΞLIX#0420 in \n \uD83D\uDCAC-gossiping Thank you.\n\n Server Invite > http://discord.melody-bot.xyz/",
  84.                     "", false);
  85.             commandEvent.reply(eb.build());
  86.             return;
  87.         }
  88.  
  89.         RadioStations station = RadioStations.getStation(commandEvent.getArgs());
  90.  
  91.         if (station == null) {
  92.             commandEvent.reply("That station does not exist.");
  93.             return;
  94.         }
  95.  
  96.         Guild guild = commandEvent.getGuild();
  97.  
  98.         AudioManager audioManager = guild.getAudioManager();
  99.         AudioHandler audioHandler = (AudioHandler) audioManager.getSendingHandler();
  100.  
  101.         if (guild.getSelfMember().getVoiceState() != null ||
  102.                 !guild.getSelfMember().getVoiceState().inVoiceChannel()) {
  103.             VoiceChannel voiceChannel = member.getVoiceState().getChannel();
  104.             audioManager.openAudioConnection(voiceChannel);
  105.         }
  106.  
  107.         MusicModule module = manager.getData().get(guild.getId());
  108.         AudioPlayerManager playerManager = module.getManager();
  109.         assert audioHandler != null;
  110.         audioHandler.playRadio(station.getStationURL());
  111.         playerManager.loadItemOrdered(guild, station.getStationURL(),
  112.                 new ResultHandler(audioHandler, member.getUser(), commandEvent));
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement