= Merging
This commit is contained in:
@@ -27,6 +27,7 @@ public class CommandMusicMain extends Command
|
|||||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||||
{
|
{
|
||||||
SubCommandFormattable scf = framework.run(guild, channel, user, input);
|
SubCommandFormattable scf = framework.run(guild, channel, user, input);
|
||||||
|
System.out.println("SCF: " + scf.resString);
|
||||||
scf.Call(res);
|
scf.Call(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package commands.music;
|
||||||
|
|
||||||
|
public class MusicThread extends Thread
|
||||||
|
{
|
||||||
|
public MusicThread()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Called when spawned
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
package commands.music;
|
package commands.music;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
|
||||||
|
|
||||||
import core.SubCommand;
|
import core.SubCommand;
|
||||||
import core.SubCommandFormattable;
|
import core.SubCommandFormattable;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
@@ -21,17 +17,8 @@ public class SubCommandPlaylist extends SubCommand
|
|||||||
@Override
|
@Override
|
||||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||||
{
|
{
|
||||||
ArrayList <AudioTrack> playlist = guild.audio.getPlaylist();
|
// ArrayList<AudioTrack> playlist = guild.audio.getPlaylist();
|
||||||
String stringPlaylist = "";
|
String stringPlaylist = guild.audio.getPlaylist(guild.audio.player);
|
||||||
|
|
||||||
for(AudioTrack track : playlist)
|
|
||||||
{
|
|
||||||
stringPlaylist += (playlist.indexOf(track) + 1) + ": " + track.getInfo().title + "\n";
|
|
||||||
}
|
|
||||||
if(stringPlaylist.equals(""))
|
|
||||||
{
|
|
||||||
return new SubCommandFormattable("Nothing Queued!");
|
|
||||||
}
|
|
||||||
return new SubCommandFormattable(stringPlaylist);
|
return new SubCommandFormattable(stringPlaylist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class SubCommandStop extends SubCommand
|
|||||||
@Override
|
@Override
|
||||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||||
{
|
{
|
||||||
|
|
||||||
return new SubCommandFormattable(guild.audio.stopPlayer(guild.audio.player));
|
return new SubCommandFormattable(guild.audio.stopPlayer(guild.audio.player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import dataStructures.KittyCore;
|
|||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
import dataStructures.KittyRating;
|
import dataStructures.KittyRating;
|
||||||
import dataStructures.KittyRole;
|
import dataStructures.KittyRole;
|
||||||
import dataStructures.KittyStartupMode;
|
|
||||||
import dataStructures.KittyUser;
|
import dataStructures.KittyUser;
|
||||||
import main.Main;
|
import main.Main;
|
||||||
import net.dv8tion.jda.core.AccountType;
|
import net.dv8tion.jda.core.AccountType;
|
||||||
@@ -142,8 +141,10 @@ public class ObjectBuilderFactory
|
|||||||
|
|
||||||
List<Emote> emotes = event.getGuild().getEmotes();
|
List<Emote> emotes = event.getGuild().getEmotes();
|
||||||
ArrayList<String> emotesString = new ArrayList<String>();
|
ArrayList<String> emotesString = new ArrayList<String>();
|
||||||
|
HashMap<Long, KittyChannel> channels = new HashMap<Long, KittyChannel>();
|
||||||
String emote;
|
String emote;
|
||||||
String emoteFix;
|
String emoteFix;
|
||||||
|
channels.put(Long.getLong(uid), extractChannel(event));
|
||||||
for(int i = 0; i < emotes.size(); i++)
|
for(int i = 0; i < emotes.size(); i++)
|
||||||
{
|
{
|
||||||
emote = emotes.get(i).toString();
|
emote = emotes.get(i).toString();
|
||||||
@@ -165,7 +166,7 @@ public class ObjectBuilderFactory
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Construct a new guild with defaults
|
// Construct a new guild with defaults
|
||||||
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString, new AudioUtils(event.getGuild(), playerManager));
|
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString, new AudioUtils(event.getGuild(), playerManager), channels);
|
||||||
DatabaseManager.instance.globalRegister(guild);
|
DatabaseManager.instance.globalRegister(guild);
|
||||||
guildCache.put(uid, guild);
|
guildCache.put(uid, guild);
|
||||||
}
|
}
|
||||||
@@ -223,14 +224,13 @@ public class ObjectBuilderFactory
|
|||||||
public static KittyChannel extractChannel(GuildMessageReceivedEvent event)
|
public static KittyChannel extractChannel(GuildMessageReceivedEvent event)
|
||||||
{
|
{
|
||||||
lazyInit();
|
lazyInit();
|
||||||
|
|
||||||
String channelID = event.getChannel().getId();
|
String channelID = event.getChannel().getId();
|
||||||
String guildID = event.getGuild().getId();
|
|
||||||
KittyChannel channel = null;
|
KittyChannel channel = null;
|
||||||
|
|
||||||
synchronized(channelCache)
|
synchronized(channelCache)
|
||||||
{
|
{
|
||||||
KittyChannel cachedChannel = channelCache.get(channelID);
|
KittyChannel cachedChannel = channelCache.get(channelID);
|
||||||
|
boolean mature;
|
||||||
|
|
||||||
if(cachedChannel != null)
|
if(cachedChannel != null)
|
||||||
{
|
{
|
||||||
@@ -238,8 +238,8 @@ public class ObjectBuilderFactory
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
KittyGuild cachedGuild = guildCache.get(guildID);
|
mature = event.getChannel().isNSFW();
|
||||||
channel = new KittyChannel(channelID, cachedGuild);
|
channel = new KittyChannel(channelID, mature);
|
||||||
channelCache.put(channelID, channel);
|
channelCache.put(channelID, channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -383,15 +383,9 @@ public class ObjectBuilderFactory
|
|||||||
{
|
{
|
||||||
lazyInit();
|
lazyInit();
|
||||||
|
|
||||||
// Determine token based on config. Default to test token.
|
|
||||||
String tokenToUse = Ref.TestToken;
|
|
||||||
if(ConfigGlobals.getStartupMode() == KittyStartupMode.Release)
|
|
||||||
tokenToUse = Ref.Token;
|
|
||||||
|
|
||||||
// Construct bot based on token
|
|
||||||
kitty = new JDABuilder(AccountType.BOT)
|
kitty = new JDABuilder(AccountType.BOT)
|
||||||
.setToken(tokenToUse).buildBlocking();
|
.setToken(Ref.TestToken).buildBlocking();
|
||||||
kitty.getPresence().setGame(Game.playing("with a laser pointer"));
|
kitty.getPresence().setGame(Game.playing("with digital yarn"));
|
||||||
kitty.addEventListener(new Main());
|
kitty.addEventListener(new Main());
|
||||||
|
|
||||||
return new KittyCore(kitty);
|
return new KittyCore(kitty);
|
||||||
|
|||||||
@@ -1,31 +1,15 @@
|
|||||||
package dataStructures;
|
package dataStructures;
|
||||||
|
|
||||||
//import core.DatabaseTrackedObject;
|
|
||||||
|
|
||||||
public class KittyChannel //extends DatabaseTrackedObject
|
public class KittyChannel
|
||||||
{
|
{
|
||||||
public String uniqueID;
|
public String uniqueID;
|
||||||
public KittyGuild guild;
|
public boolean mature;
|
||||||
|
|
||||||
//public KittyRating rating;
|
public KittyChannel(String uniqueID, boolean mature)
|
||||||
//public bool isVoice;
|
|
||||||
|
|
||||||
public KittyChannel(String uniqueID, KittyGuild guild)
|
|
||||||
{
|
{
|
||||||
//super(uniqueID);
|
//super(uniqueID);
|
||||||
this.uniqueID = uniqueID;
|
this.uniqueID = uniqueID;
|
||||||
this.guild = guild;
|
this.mature = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public String serialize()
|
|
||||||
// {
|
|
||||||
// return "";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void deSerialzie(String string)
|
|
||||||
// {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package dataStructures;
|
package dataStructures;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import core.DatabaseManager;
|
import core.DatabaseManager;
|
||||||
import core.DatabaseTrackedObject;
|
import core.DatabaseTrackedObject;
|
||||||
@@ -21,6 +22,7 @@ public class KittyGuild extends DatabaseTrackedObject
|
|||||||
public ArrayList<String> hasVoted = new ArrayList<String>();
|
public ArrayList<String> hasVoted = new ArrayList<String>();
|
||||||
public ArrayList<String> emoji = new ArrayList<String>();
|
public ArrayList<String> emoji = new ArrayList<String>();
|
||||||
public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>();
|
public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>();
|
||||||
|
public HashMap <Long, KittyChannel> channels;
|
||||||
public AdminControl control;
|
public AdminControl control;
|
||||||
public AudioUtils audio;
|
public AudioUtils audio;
|
||||||
public ArrayList <KittyUser> raffleUsersUnchosen = new ArrayList<KittyUser>();
|
public ArrayList <KittyUser> raffleUsersUnchosen = new ArrayList<KittyUser>();
|
||||||
@@ -42,7 +44,7 @@ public class KittyGuild extends DatabaseTrackedObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Default content for a guild
|
// Default content for a guild
|
||||||
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji, AudioUtils audio)
|
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji, AudioUtils audio, HashMap<Long, KittyChannel> channels)
|
||||||
{
|
{
|
||||||
|
|
||||||
super(uniqueID);
|
super(uniqueID);
|
||||||
@@ -56,11 +58,12 @@ public class KittyGuild extends DatabaseTrackedObject
|
|||||||
this.polling = false;
|
this.polling = false;
|
||||||
this.emoji = emoji;
|
this.emoji = emoji;
|
||||||
this.audio = audio;
|
this.audio = audio;
|
||||||
|
this.channels = channels;
|
||||||
setCommandIndicator("!");
|
setCommandIndicator("!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicit constructor
|
// Explicit constructor
|
||||||
public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner, String uniqueID, AudioUtils audio)
|
public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner, String uniqueID, AudioUtils audio, HashMap<Long, KittyChannel> channels)
|
||||||
{
|
{
|
||||||
super(uniqueID);
|
super(uniqueID);
|
||||||
this.uniqueID = uniqueID;
|
this.uniqueID = uniqueID;
|
||||||
@@ -73,6 +76,7 @@ public class KittyGuild extends DatabaseTrackedObject
|
|||||||
this.polling = false;
|
this.polling = false;
|
||||||
this.guildOwner = guildOwner;
|
this.guildOwner = guildOwner;
|
||||||
this.audio = audio;
|
this.audio = audio;
|
||||||
|
this.channels = channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String startPoll(String poll)
|
public String startPoll(String poll)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public class NetworkDerpi
|
|||||||
{
|
{
|
||||||
public String image;
|
public String image;
|
||||||
public String tags;
|
public String tags;
|
||||||
|
public String score;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class InitialRequest
|
private class InitialRequest
|
||||||
@@ -29,16 +30,26 @@ public class NetworkDerpi
|
|||||||
String res = HTTPUtils.sendGETRequest(mainURL + query + "&random_image=1&key=" + Ref.derpiKey);
|
String res = HTTPUtils.sendGETRequest(mainURL + query + "&random_image=1&key=" + Ref.derpiKey);
|
||||||
if(res != null)
|
if(res != null)
|
||||||
{
|
{
|
||||||
|
InitialRequest obj;
|
||||||
// Use class evaluation on an array of the response object to be able to hold multiple.
|
// Use class evaluation on an array of the response object to be able to hold multiple.
|
||||||
InitialRequest obj = jsonParser_.fromJson(res, InitialRequest.class);
|
try
|
||||||
|
{
|
||||||
|
obj = jsonParser_.fromJson(res, InitialRequest.class);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if(res != null)
|
if(res != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
String res2 = HTTPUtils.sendGETRequest("https://derpibooru.org/" + obj.id + ".json");
|
String res2 = HTTPUtils.sendGETRequest("https://derpibooru.org/" + obj.id + ".json");
|
||||||
image.editPostURL("<https://derpibooru.org/" + obj.id +">");
|
image.editPostURL("https://derpibooru.org/" + obj.id);
|
||||||
DerpiResponseObject imageObj = jsonParser_.fromJson(res2, DerpiResponseObject.class);
|
DerpiResponseObject imageObj = jsonParser_.fromJson(res2, DerpiResponseObject.class);
|
||||||
|
|
||||||
image.editImageURL("https:" + imageObj.image.substring(0, imageObj.image.indexOf('_')) + imageObj.image.substring(imageObj.image.lastIndexOf('.')));
|
image.editImageURL("https:" + imageObj.image.substring(0, imageObj.image.indexOf('_')) +
|
||||||
|
imageObj.image.substring(imageObj.image.lastIndexOf('.')));
|
||||||
if(imageObj.tags.contains("artist:"))
|
if(imageObj.tags.contains("artist:"))
|
||||||
{
|
{
|
||||||
String [] sepTags = imageObj.tags.split(",");
|
String [] sepTags = imageObj.tags.split(",");
|
||||||
@@ -54,8 +65,20 @@ public class NetworkDerpi
|
|||||||
artists += sepTags[i].substring(sepTags[i].indexOf(":")+1);
|
artists += sepTags[i].substring(sepTags[i].indexOf(":")+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
image.editAuthorImage("https://derpicdn.net/favicon.ico");
|
||||||
|
|
||||||
image.editArtist(artists);
|
image.editArtist(artists);
|
||||||
|
String tags = "";
|
||||||
|
for(int i = 0; i < sepTags.length && i < 15; i++)
|
||||||
|
{
|
||||||
|
if(!sepTags[i].contains("artist:"))
|
||||||
|
{
|
||||||
|
tags += sepTags[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
image.editFooterText("[Tags]" + tags);
|
||||||
|
image.editDescriptionText("Score: " + imageObj.score);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -66,4 +89,46 @@ public class NetworkDerpi
|
|||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GenericImage getDerpiByID(String id)
|
||||||
|
{
|
||||||
|
GenericImage image = new GenericImage(" ", " ", " ");
|
||||||
|
String artists = "";
|
||||||
|
image.editAuthorImage("https://derpicdn.net/favicon.ico");
|
||||||
|
String res;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
res = HTTPUtils.sendGETRequest("https://derpibooru.org/" + id + ".json");
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DerpiResponseObject imageObj = jsonParser_.fromJson(res, DerpiResponseObject.class);
|
||||||
|
if(imageObj.tags.contains("artist:"))
|
||||||
|
{
|
||||||
|
String [] sepTags = imageObj.tags.split(",");
|
||||||
|
for(int i = 0; i < sepTags.length; i++)
|
||||||
|
{
|
||||||
|
if(sepTags[i].contains("artist:"))
|
||||||
|
{
|
||||||
|
if(!artists.equals(""))
|
||||||
|
{
|
||||||
|
artists += " and ";
|
||||||
|
}
|
||||||
|
artists += sepTags[i].substring(sepTags[i].indexOf(":")+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(artists != "")
|
||||||
|
image.editArtist(artists);
|
||||||
|
else
|
||||||
|
image.editArtist("Artist Unknown!");
|
||||||
|
|
||||||
|
image.editFooterText("[Tags]" + imageObj.tags);
|
||||||
|
image.editDescriptionText("Score: " + imageObj.score);
|
||||||
|
image.editImageURL("https:" + imageObj.image.substring(0, imageObj.image.indexOf('_')) +
|
||||||
|
imageObj.image.substring(imageObj.image.lastIndexOf('.')));
|
||||||
|
return image;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
package network;
|
package network;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import dataStructures.GenericImage;
|
import dataStructures.GenericImage;
|
||||||
import offline.Ref;
|
import offline.Ref;
|
||||||
import utils.*;
|
import utils.HTTPUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the e6 request class, designed for form and parse requests that
|
* This is the e621 request class, designed for form and parse requests that
|
||||||
* use the e6 API, and is entirely static.
|
* use the e621 API, and is entirely static.
|
||||||
*
|
*
|
||||||
* If you ever find this class randomly not working,
|
* If you ever find this class randomly not working,
|
||||||
* it may be a good idea to make sure the user agent string is set in
|
* it may be a good idea to make sure the user agent string is set in
|
||||||
@@ -26,6 +27,7 @@ public class NetworkE6
|
|||||||
private static final String API_ROOT = "https://e621.net/post/index.json?";
|
private static final String API_ROOT = "https://e621.net/post/index.json?";
|
||||||
private static int maxSearchResults_ = 10;
|
private static int maxSearchResults_ = 10;
|
||||||
private static String[] blacklist = Ref.e621Blacklist;
|
private static String[] blacklist = Ref.e621Blacklist;
|
||||||
|
|
||||||
private class E6ResponseObject
|
private class E6ResponseObject
|
||||||
{
|
{
|
||||||
// public varaibles matching the case and the type we want for JSON.
|
// public varaibles matching the case and the type we want for JSON.
|
||||||
@@ -35,6 +37,8 @@ public class NetworkE6
|
|||||||
public String id;
|
public String id;
|
||||||
public String tags;
|
public String tags;
|
||||||
public String [] artist;
|
public String [] artist;
|
||||||
|
public String [] sources;
|
||||||
|
public String score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +49,6 @@ public class NetworkE6
|
|||||||
// Requests a specific image, then returns a few.
|
// Requests a specific image, then returns a few.
|
||||||
public GenericImage getE6(String input)
|
public GenericImage getE6(String input)
|
||||||
{
|
{
|
||||||
|
|
||||||
GenericImage image = new GenericImage("","","");
|
GenericImage image = new GenericImage("","","");
|
||||||
boolean blacklisted;
|
boolean blacklisted;
|
||||||
// Clean up request and replace problematic characters for the query string.
|
// Clean up request and replace problematic characters for the query string.
|
||||||
@@ -60,6 +63,7 @@ public class NetworkE6
|
|||||||
, "tags=order:random%20" + input + "&limit=" + maxSearchResults_);
|
, "tags=order:random%20" + input + "&limit=" + maxSearchResults_);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(res != null)
|
if(res != null)
|
||||||
{
|
{
|
||||||
// Use class evaluation on an array of the response imageObject to be able to hold multiple.
|
// Use class evaluation on an array of the response imageObject to be able to hold multiple.
|
||||||
@@ -80,13 +84,14 @@ public class NetworkE6
|
|||||||
{
|
{
|
||||||
if(imageObj[i].tags.contains(blacklist[j]))
|
if(imageObj[i].tags.contains(blacklist[j]))
|
||||||
{
|
{
|
||||||
|
System.out.println("BLACKLISTED " + blacklist[j]);
|
||||||
blacklisted = true;
|
blacklisted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(blacklisted)
|
if(blacklisted)
|
||||||
{
|
{
|
||||||
continue;
|
return null;
|
||||||
}
|
}
|
||||||
// We will always have a file URL. That's a given.
|
// We will always have a file URL. That's a given.
|
||||||
image.editImageURL(imageObj[i].file_url);
|
image.editImageURL(imageObj[i].file_url);
|
||||||
@@ -95,6 +100,59 @@ public class NetworkE6
|
|||||||
image.editArtist(imageObj[i].artist[0]);
|
image.editArtist(imageObj[i].artist[0]);
|
||||||
else
|
else
|
||||||
image.editArtist("Artist Not Found!");
|
image.editArtist("Artist Not Found!");
|
||||||
|
|
||||||
|
image.editAuthorImage("https://e621.net/favicon.ico");
|
||||||
|
|
||||||
|
String sources = "";
|
||||||
|
|
||||||
|
if(imageObj[i].sources != null)
|
||||||
|
{
|
||||||
|
for(int k = 0; k < imageObj[i].sources.length; k ++)
|
||||||
|
{
|
||||||
|
if(!imageObj[i].sources[k].endsWith(imageObj[i].file_url.substring(imageObj[i].file_url.lastIndexOf('.'))))
|
||||||
|
{
|
||||||
|
String source = imageObj[i].sources[k];
|
||||||
|
if(source.contains("//www."))
|
||||||
|
{
|
||||||
|
source = source.substring(source.indexOf(".") + 1);
|
||||||
|
source = source.substring(0, source.indexOf('.'));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
source = source.substring(source.indexOf("/") + 2);
|
||||||
|
source = source.substring(0, source.indexOf('.'));
|
||||||
|
}
|
||||||
|
sources += " [" + source + "](" + imageObj[i].sources[k] + ") ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
image.editDescriptionText("Score: " + imageObj[i].score + "\n**Source:**" + sources);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
image.editDescriptionText("Score: " + imageObj[i].score);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(imageObj[i].tags.split(" ").length > 15)
|
||||||
|
{
|
||||||
|
String [] splitTags = imageObj[i].tags.split(" ");
|
||||||
|
String descTags = "";
|
||||||
|
for(int o = 0; o < 15; o++)
|
||||||
|
{
|
||||||
|
descTags += splitTags[o] + ", ";
|
||||||
|
}
|
||||||
|
image.editFooterText("[Tags] " + descTags + " etc.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
image.editFooterText("[Tags] " + imageObj[i].tags.replace(" ", ", "));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(image.output().authorText != null)
|
||||||
|
{
|
||||||
|
return image;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package utils.audio;
|
package utils.audio;
|
||||||
import java.util.ArrayList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||||
@@ -20,7 +21,7 @@ public class AudioUtils
|
|||||||
public AudioManager am;
|
public AudioManager am;
|
||||||
public final AudioPlayer player;
|
public final AudioPlayer player;
|
||||||
public final AudioPlayerManager playerManager;
|
public final AudioPlayerManager playerManager;
|
||||||
private ArrayList <AudioTrack> playlist = new ArrayList<AudioTrack>();
|
private Queue <AudioTrack> playlist = new LinkedList<>();
|
||||||
|
|
||||||
|
|
||||||
public AudioUtils(Guild guild, AudioPlayerManager playerManager)
|
public AudioUtils(Guild guild, AudioPlayerManager playerManager)
|
||||||
@@ -85,8 +86,11 @@ public class AudioUtils
|
|||||||
|
|
||||||
public class SmallAudio implements AudioLoadResultHandler
|
public class SmallAudio implements AudioLoadResultHandler
|
||||||
{
|
{
|
||||||
|
private AudioPlayer player;
|
||||||
|
|
||||||
private SmallAudio(AudioPlayer player)
|
private SmallAudio(AudioPlayer player)
|
||||||
{
|
{
|
||||||
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void loadFailed(FriendlyException arg0) { }
|
@Override public void loadFailed(FriendlyException arg0) { }
|
||||||
@@ -100,6 +104,14 @@ public class AudioUtils
|
|||||||
{
|
{
|
||||||
playlist.add(track);
|
playlist.add(track);
|
||||||
}
|
}
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if(player.getPlayingTrack() == null)
|
||||||
|
{
|
||||||
|
player.startTrack(playlist.poll(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(!playlist.isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,21 +120,13 @@ public class AudioUtils
|
|||||||
{
|
{
|
||||||
guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(player));
|
guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(player));
|
||||||
playerManager.loadItemOrdered(player, videoURL, new SmallAudio(player));
|
playerManager.loadItemOrdered(player, videoURL, new SmallAudio(player));
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
if(player.getPlayingTrack() == null)
|
|
||||||
{
|
|
||||||
MusicController control = new MusicController(player, playlist);
|
|
||||||
control.start();
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String skipVideo(AudioPlayer player)
|
public String skipVideo(AudioPlayer player)
|
||||||
{
|
{
|
||||||
player.stopTrack();
|
return null;
|
||||||
return "Skipped";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String stopPlayer(AudioPlayer player)
|
public String stopPlayer(AudioPlayer player)
|
||||||
@@ -132,44 +136,13 @@ public class AudioUtils
|
|||||||
return "Stopped";
|
return "Stopped";
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<AudioTrack> getPlaylist()
|
public String getPlaylist(AudioPlayer player)
|
||||||
{
|
{
|
||||||
return playlist;
|
String response ="";
|
||||||
}
|
for(AudioTrack track:playlist)
|
||||||
}
|
|
||||||
|
|
||||||
class MusicController extends Thread
|
|
||||||
{
|
|
||||||
AudioPlayer player;
|
|
||||||
private ArrayList <AudioTrack> playlist;
|
|
||||||
|
|
||||||
public MusicController(AudioPlayer player, ArrayList <AudioTrack> playlist)
|
|
||||||
{
|
|
||||||
this.player = player;
|
|
||||||
this.playlist = playlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
AudioTrack nowPlaying = null;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if(!playlist.isEmpty() || nowPlaying != null)
|
|
||||||
{
|
{
|
||||||
if(player.getPlayingTrack() == null)
|
response += track.getInfo().title;
|
||||||
{
|
|
||||||
if(playlist.isEmpty())
|
|
||||||
nowPlaying = null;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nowPlaying = playlist.get(0);
|
|
||||||
playlist.remove(0);
|
|
||||||
}
|
|
||||||
player.startTrack(nowPlaying, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while(!playlist.isEmpty() || player.getPlayingTrack() != null);
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user