Advertisement
austinh115

[JAVA] Sing command

Oct 2nd, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. case "sing":
  2.             if (!BotUtils.checkMinrank(cmd, uid)) {
  3.                 return;
  4.             }
  5.             final String search = Utils.get("http://search.azlyrics.com/search.php?q=" + msg.replace(' ', '+'));
  6.             final String song1 = Utils.getBetween(search, "<td class=\"text-left visitedlyr\">", " by ");
  7.             if (!song1.substring(0, 2).equals("1.")) {
  8.                 XatUtils.respond("The song \"" + msg + "\" was not found.", type, uid);
  9.                 return;
  10.             }
  11.             final String song2 = Utils.getBetween(song1, "<a href=\"", "\" target=\"_blank");
  12.             final String lyrics[] = Utils.getBetween(Utils.get(song2),
  13.                     "<!-- Usage of azlyrics.com content by any third-party lyrics provider is prohibited by our licensing agreement. Sorry about that. -->",
  14.                     "</div>").split("<br>");
  15.             Thread song = new Thread(() -> {
  16.                 String lastLyric = "";
  17.                 for (String lyric : lyrics) {
  18.                     lyric = lyric.trim();
  19.                     try {
  20.                         System.out.println(PacketHandler.PACKET);
  21.                         if (PacketHandler.PACKET.containsKey("t")
  22.                                 && (PacketHandler.PACKET.get("t").toLowerCase().indexOf("stop thread") != -1)) {
  23.                             XatUtils.respond("I have stopped singing", type, uid0);
  24.                             Thread.currentThread().interrupt();
  25.                             return;
  26.                         }
  27.                     } catch (Exception e) {
  28.                         e.printStackTrace();
  29.                     }
  30.                     if (Thread.interrupted())
  31.                         return;
  32.                     if (lyric.equals(lastLyric)) {
  33.                         lastLyric = lyric;
  34.                         lyric += " ";
  35.                     }
  36.                     if (lyric.equals("")) {
  37.                         continue;
  38.                     }
  39.                     try {
  40.                         XatUtils.sendMessage(lyric);
  41.                         lastLyric = lyric;
  42.                         Thread.sleep(1000);
  43.                     } catch (final Exception e1) {
  44.                         return;
  45.                     }
  46.                 }
  47.                 try {
  48.                     XatUtils.respond("That was: \"" + Utils.getBetween(Utils.get(song2), "song: \"", "\",") + "\" by \""
  49.                             + Utils.getBetween(Utils.get(song2), "artist: \"", "\",") + "\"", type, uid0);
  50.                 } catch (Exception e) {
  51.                     e.printStackTrace();
  52.                 }
  53.             });
  54.             song.start();
  55.             break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement