Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8cfb3b951c | ||
|
|
01f39aba68 | ||
|
|
e642551019 | ||
|
|
861aa95d96 | ||
|
|
9b5ae3371d | ||
|
|
9d0bbf0ed1 | ||
|
|
b96d96c849 | ||
|
|
e81e0972a3 | ||
|
|
b3187bb89d | ||
|
|
d681bb6a4d | ||
|
|
96b4533b39 | ||
|
|
498c3b84bc | ||
|
|
4b8b125d05 | ||
|
|
cf7bd68658 | ||
|
|
1e73f6adae | ||
|
|
9d892e7fc2 | ||
|
|
2fd273c298 | ||
|
|
7581dab87d | ||
|
|
28377cf78e | ||
|
|
d1dfab411e | ||
|
|
770ed84983 |
+1
-3
@@ -24,9 +24,7 @@
|
||||
<classpathentry kind="lib" path="lib/commons-collections4-4.3.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-lang3-3.9.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-text-1.6.jar"/>
|
||||
<classpathentry kind="lib" path="lib/google-http-client-1.32.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/google-api-services-youtube-v3-rev212-1.25.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/nanohttpd-2.3.1.jar"/>
|
||||
<classpathentry kind="lib" path="G:/Shared/Coding/Java/workspace/ProKitty/lib/LavaPlayerJar-1.3.50-jar-with-dependencies.jar"/>
|
||||
<classpathentry kind="lib" path="lib/lavaplayer-1.3.19.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -3,4 +3,4 @@ Fun and useful Discord bot designed to be able searching websites, playing games
|
||||
|
||||
This repo is an eclipse project, and can be opened in the IDE directly. Authentication keys will need to be placed in a file called `Ref.java` at `src/offline/`. This folder isn't present in this repository by default.
|
||||
|
||||
If you're looking to contribute, feel free to submit a pull request! Take a look at the styleguide to get some pointers on formatting for this repo!
|
||||
If you're looking to contribute, feel free to submit a pull request! Take a look at the styleguide to get some pointers on formatting for this repo!
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 KiB |
+7
-18
@@ -1,5 +1,4 @@
|
||||
"Type","Key","Value"
|
||||
"Globals","mode (dev or release)","dev"
|
||||
"Localized Commands","beans",""
|
||||
"Localized Commands","benchmark, bench",""
|
||||
"Localized Commands","bet",""
|
||||
@@ -17,12 +16,10 @@
|
||||
"Localized Commands","dbstats",""
|
||||
"Localized Commands","defaultdance",""
|
||||
"Localized Commands","derp",""
|
||||
"Localized Commands","derpi",""
|
||||
"Localized Commands","e6",""
|
||||
"Localized Commands","dew",""
|
||||
"Localized Commands","e621",""
|
||||
"Localized Commands","eightball, 8ball",""
|
||||
"Localized Commands","fetch",""
|
||||
"Localized Commands","getsauce",""
|
||||
"Localized Commands","givebeans",""
|
||||
"Localized Commands","help",""
|
||||
"Localized Commands","indicator",""
|
||||
@@ -50,9 +47,9 @@
|
||||
"Localized Commands","stats",""
|
||||
"Localized Commands","teey",""
|
||||
"Localized Commands","tony, stark, dontfeelgood, dontfeelsogood","tony, stark, dontfeelgood, dontfeelsogood, snap"
|
||||
"Localized Commands","tradebeans, trade",""
|
||||
"Localized Commands","tweet",""
|
||||
"Localized Commands","vote",""
|
||||
"Localized Commands","weh",""
|
||||
"Localized Commands","wolfram",""
|
||||
"Localized Commands","work",""
|
||||
"Localized Commands","yeet",""
|
||||
@@ -65,7 +62,7 @@
|
||||
"Localized Strings","BetBeansInfo","Allows you to bet your beans, set your amount after the command! Warning! House always wins!nSets of 3 will get 2x, 4 will get 10x, and 5 will get 1000x"
|
||||
"Localized Strings","BetBeansLose","Sorry, you didn't win, try again!"
|
||||
"Localized Strings","BetBeansLowBet","Please bet with at least 20 beans!"
|
||||
"Localized Strings","BetBeansMinThreshold",""
|
||||
"Localized Strings","BetBeansMinThreshold","50"
|
||||
"Localized Strings","BetBeansNotEnough","You don't have enough beans!"
|
||||
"Localized Strings","BetBeansNotValid","That's not a valid bet!"
|
||||
"Localized Strings","BetBeansWin","You won %s beans!"
|
||||
@@ -113,10 +110,9 @@
|
||||
"Localized Strings","DBFlushInfo","Takes all objects queued for the database and writes them to the database, then says how many were written."
|
||||
"Localized Strings","DBStatsInfo","Shows current statistics for the database"
|
||||
"Localized Strings","DefaultDanceInfo","y'all know forknife, get ready to dance, or make a friend dance with @!"
|
||||
"Localized Strings","DerpiError",""
|
||||
"Localized Strings","DewInfo","A fun little dev experiment!"
|
||||
"Localized Strings","DoWorkFinished","I finished with my work! :D"
|
||||
"Localized Strings","DoWorkInfo","Occupies a core for a few seconds"
|
||||
"Localized Strings","E6Blacklisted","I can't show that image ;3; (it may be blacklisted)"
|
||||
"Localized Strings","EightBallError","Hmm? You'll need to ask a question!"
|
||||
"Localized Strings","EightBallInfo","Answers a yes or no question! Warning: Kitty can not actually tell the future, she claims no responsibility for any lion mauling, lack of lottery wins, or felony charges."
|
||||
"Localized Strings","EightBallMaybe1","Reply hazy, try again."
|
||||
@@ -147,7 +143,6 @@
|
||||
"Localized Strings","FetchInfo","Throw a custom emote and I'll try to bring it back.... maybe"
|
||||
"Localized Strings","FetchRunAway","*Runs away and doesn't return for a long time*"
|
||||
"Localized Strings","FetchStare","*Stares at %s*"
|
||||
"Localized Strings","GetSauceInfo",""
|
||||
"Localized Strings","GiveBeansInfo","Gives beans to the mentioned users!"
|
||||
"Localized Strings","GiveBeansInvalid","That's not a valid number!"
|
||||
"Localized Strings","GiveBeansNoneMentioned","You didn't mention anyone!"
|
||||
@@ -187,11 +182,7 @@
|
||||
"Localized Strings","MapVersion","Using mapgen v0.1"
|
||||
"Localized Strings","MapWidth",""
|
||||
"Localized Strings","ModInfo","Mod is a super command for admin or mod use only!\n\t`mod ban @user` will ban a user from the server\n\t`mod kick @user` will kick the user from the server"
|
||||
"Localized Strings","MusicAddTrack",""
|
||||
"Localized Strings","MusicInfo",""
|
||||
"Localized Strings","MusicVolChanged","Volume set to %s!"
|
||||
"Localized Strings","MusicVolCurrent","Volume is at %s!"
|
||||
"Localized Strings","MusicVolOOB",""
|
||||
"Localized Strings","PerishInfo","Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned"
|
||||
"Localized Strings","PingInfo","Will respond with Pong!"
|
||||
"Localized Strings","PingResponse","Pong!"
|
||||
@@ -247,13 +238,13 @@
|
||||
"Localized Strings","TeeyInfo","Teey yourself back into existance, or teey a friend with @!"
|
||||
"Localized Strings","TradeBeansInfo","Give your friends some of your beans! Just don't forget to @ them!"
|
||||
"Localized Strings","TradeBeansIntParseError","That's not a real number! D:"
|
||||
"Localized Strings","TradeBeansMultipleUsersTagged",""
|
||||
"Localized Strings","TradeBeansNoTargetError","Don't forget to tag who you want to give the beans to!"
|
||||
"Localized Strings","TradeBeansNotEnoughError","You can't give more beans than you have!"
|
||||
"Localized Strings","TradeBeansStealingBeans","Hey %s! Stealing is wrong! Let's see how you like it! *steals 10 beans*"
|
||||
"Localized Strings","TradeBeansSuccess","%s gave %s %s beans!"
|
||||
"Localized Strings","TweetError","Tweet command failed!"
|
||||
"Localized Strings","TweetInfo","Kitty will tweet to her personal twitter account"
|
||||
"Localized Strings","WehInfo","Weh"
|
||||
"Localized Strings","WolframError","Something went wrong!"
|
||||
"Localized Strings","WolframInfo","Will query wolframalpha with your question and give a full image output of the answer"
|
||||
"Localized Strings","WolframNoArgs","You need to provide some arguments!"
|
||||
@@ -281,12 +272,10 @@
|
||||
"Command Enabler","dbstats","1"
|
||||
"Command Enabler","defaultdance","1"
|
||||
"Command Enabler","derp","1"
|
||||
"Command Enabler","derpi","1"
|
||||
"Command Enabler","e6","1"
|
||||
"Command Enabler","dew","1"
|
||||
"Command Enabler","e621","1"
|
||||
"Command Enabler","eightball, 8ball","1"
|
||||
"Command Enabler","fetch","1"
|
||||
"Command Enabler","getsauce","1"
|
||||
"Command Enabler","givebeans","1"
|
||||
"Command Enabler","guildroleadd","1"
|
||||
"Command Enabler","guildroleallowed","1"
|
||||
@@ -325,9 +314,9 @@
|
||||
"Command Enabler","stats","1"
|
||||
"Command Enabler","teey","1"
|
||||
"Command Enabler","tony, stark, dontfeelgood, dontfeelsogood","1"
|
||||
"Command Enabler","tradebeans, trade","1"
|
||||
"Command Enabler","tweet","1"
|
||||
"Command Enabler","vote","1"
|
||||
"Command Enabler","weh","1"
|
||||
"Command Enabler","wolfram","1"
|
||||
"Command Enabler","work","1"
|
||||
"Command Enabler","yeet","1"
|
||||
|
||||
|
Binary file not shown.
@@ -1,22 +0,0 @@
|
||||
function plugin(message, user)
|
||||
local index;
|
||||
local concat;
|
||||
if(string.find(message, "https://derpicdn.net/img"))then
|
||||
if(string.find(message, "view/"))then
|
||||
index = string.find(message, "/[^/]*$");
|
||||
return "!derpi ID:" .. string.sub(message, index + 1, string.find(message, ".[^.]*$")-1);
|
||||
else
|
||||
if(string.find(message, "download/"))then
|
||||
index = string.find(message, "_");
|
||||
concat = string.sub(message, 0, index-1);
|
||||
return "!derpi ID:" .. string.sub(concat, string.find(message, "/[^/]*$") + 1);
|
||||
else
|
||||
index = string.find(message, "/[^/]*$");
|
||||
concat = string.sub(message, 0, index - 1);
|
||||
index = string.find(concat, "/[^/]*$");
|
||||
|
||||
return "!derpi ID:" .. string.sub(concat, index + 1);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,8 +0,0 @@
|
||||
function plugin(message, user)
|
||||
if(string.find(message, "https://static1.e621.net/data") or string.find(message, "https://static1.e926.net/data"))then
|
||||
if(string.find(message, " "))then
|
||||
message = string.sub(message, 0, string.find(message, " "));
|
||||
end
|
||||
return "!e6 md5:" .. string.sub(message, string.find(message, "/[^/]*$") + 1 ,string.find(message, ".[^.]*$") - 1);
|
||||
end
|
||||
end
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 50 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,11 +2,11 @@ package commands.benchmark;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import core.benchmark.BenchmarkCommand;
|
||||
import core.benchmark.BenchmarkEntry;
|
||||
import core.benchmark.BenchmarkFormattable;
|
||||
import core.benchmark.BenchmarkInput;
|
||||
import core.benchmark.BenchmarkManager;
|
||||
import commands.benchmark.core.BenchmarkCommand;
|
||||
import commands.benchmark.core.BenchmarkEntry;
|
||||
import commands.benchmark.core.BenchmarkFormattable;
|
||||
import commands.benchmark.core.BenchmarkInput;
|
||||
import commands.benchmark.core.BenchmarkManager;
|
||||
|
||||
public class BenchmarkCommandCompare extends BenchmarkCommand
|
||||
{
|
||||
|
||||
@@ -2,7 +2,11 @@ package commands.benchmark;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import core.benchmark.*;
|
||||
import commands.benchmark.core.BenchmarkCommand;
|
||||
import commands.benchmark.core.BenchmarkEntry;
|
||||
import commands.benchmark.core.BenchmarkFormattable;
|
||||
import commands.benchmark.core.BenchmarkInput;
|
||||
import commands.benchmark.core.BenchmarkManager;
|
||||
|
||||
public class BenchmarkCommandFind extends BenchmarkCommand
|
||||
{
|
||||
|
||||
@@ -2,11 +2,11 @@ package commands.benchmark;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import core.benchmark.BenchmarkCommand;
|
||||
import core.benchmark.BenchmarkEntry;
|
||||
import core.benchmark.BenchmarkFormattable;
|
||||
import core.benchmark.BenchmarkInput;
|
||||
import core.benchmark.BenchmarkManager;
|
||||
import commands.benchmark.core.BenchmarkCommand;
|
||||
import commands.benchmark.core.BenchmarkEntry;
|
||||
import commands.benchmark.core.BenchmarkFormattable;
|
||||
import commands.benchmark.core.BenchmarkInput;
|
||||
import commands.benchmark.core.BenchmarkManager;
|
||||
import dataStructures.KittyEmbed;
|
||||
import java.awt.Color;
|
||||
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package commands.general;
|
||||
package commands.benchmark;
|
||||
|
||||
import commands.benchmark.core.BenchmarkFormattable;
|
||||
import commands.benchmark.core.BenchmarkFramework;
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import core.benchmark.BenchmarkFormattable;
|
||||
import core.benchmark.BenchmarkFramework;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package core.benchmark;
|
||||
package commands.benchmark.core;
|
||||
|
||||
public abstract class BenchmarkCommand
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package core.benchmark;
|
||||
package commands.benchmark.core;
|
||||
|
||||
public class BenchmarkEntry
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package core.benchmark;
|
||||
package commands.benchmark.core;
|
||||
|
||||
import dataStructures.KittyEmbed;
|
||||
import dataStructures.Response;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package core.benchmark;
|
||||
package commands.benchmark.core;
|
||||
|
||||
import java.util.HashMap;
|
||||
import commands.benchmark.*;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package core.benchmark;
|
||||
package commands.benchmark.core;
|
||||
|
||||
import utils.StringUtils;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package core.benchmark;
|
||||
package commands.benchmark.core;
|
||||
|
||||
import utils.GlobalLog;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package core.benchmark;
|
||||
package commands.benchmark.core;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package core.benchmark;
|
||||
package commands.benchmark.core;
|
||||
|
||||
public enum BenchmarkType
|
||||
{
|
||||
@@ -0,0 +1,43 @@
|
||||
package commands.dew;
|
||||
|
||||
import commands.dew.core.impl.DewCore;
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import core.SubCommandFramework;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandDew extends Command
|
||||
{
|
||||
public static DewCore core;
|
||||
SubCommandFramework framework = new SubCommandFramework();
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("DewInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
framework.run(guild, channel, user, input).Call(res);
|
||||
}
|
||||
|
||||
public CommandDew(KittyRole level, KittyRating rating)
|
||||
{
|
||||
super(level, rating);
|
||||
|
||||
core = new DewCore(framework);
|
||||
|
||||
framework.addCommand("luatest", new CommandDewLuaTest(KittyRole.Dev, KittyRating.Safe));
|
||||
framework.addCommand("realm", new CommandDewRealm(KittyRole.Dev, KittyRating.Safe));
|
||||
framework.addCommand("w", new CommandDewInput("w", KittyRole.Dev, KittyRating.Safe));
|
||||
framework.addCommand("a", new CommandDewInput("a", KittyRole.Dev, KittyRating.Safe));
|
||||
framework.addCommand("s", new CommandDewInput("s", KittyRole.Dev, KittyRating.Safe));
|
||||
framework.addCommand("d", new CommandDewInput("d", KittyRole.Dev, KittyRating.Safe));
|
||||
framework.addCommand("capture", new CommandDewCapture(KittyRole.Dev, KittyRating.Safe));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package commands.dew;
|
||||
|
||||
import commands.dew.adapter.KittyAdapterDewPlayer;
|
||||
import commands.dew.core.impl.DewCore;
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandDewCapture extends SubCommand
|
||||
{
|
||||
public CommandDewCapture(KittyRole roleLevel, KittyRating contentRating)
|
||||
{
|
||||
super(roleLevel, contentRating);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||
{
|
||||
KittyAdapterDewPlayer player = DewCore.getOrCreate(user);
|
||||
DewCore.playersCaptured.add(player);
|
||||
return null;//new SubCommandFormattable("captured input for " + user.name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package commands.dew;
|
||||
|
||||
import commands.dew.adapter.KittyAdapterDewPlayer;
|
||||
import commands.dew.core.impl.DewCore;
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandDewInput extends SubCommand
|
||||
{
|
||||
String letter = "";
|
||||
public CommandDewInput(String letter, KittyRole roleLevel, KittyRating contentRating)
|
||||
{
|
||||
super(roleLevel, contentRating);
|
||||
this.letter = letter.toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||
{
|
||||
KittyAdapterDewPlayer player = DewCore.getOrCreate(user);
|
||||
|
||||
int x = player.getRealmX();
|
||||
int y = player.getRealmY();
|
||||
|
||||
switch(letter)
|
||||
{
|
||||
case "w": player.setRealmPos(x, y - 1); break;
|
||||
case "a": player.setRealmPos(x - 1, y); break;
|
||||
case "s": player.setRealmPos(x, y + 1); break;
|
||||
case "d": player.setRealmPos(x + 1, y); break;
|
||||
}
|
||||
|
||||
return new SubCommandFormattable(DewCore.drawWorld(player));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package commands.dew;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import commands.dew.core.data.*;
|
||||
import commands.dew.core.impl.DewLuaCore;
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandDewLuaTest extends SubCommand
|
||||
{
|
||||
public CommandDewLuaTest(KittyRole roleLevel, KittyRating contentRating)
|
||||
{
|
||||
super(roleLevel, contentRating);
|
||||
}
|
||||
|
||||
private String asCodeBlock(String string)
|
||||
{
|
||||
return "```lua\n" + string + "```";
|
||||
}
|
||||
|
||||
private String asCodeLine(String string)
|
||||
{
|
||||
return "`" + string + "`";
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||
{
|
||||
String out = "";
|
||||
|
||||
try
|
||||
{
|
||||
out += "**Testing writing...\n**";
|
||||
DewRealm m = new DewRealm();
|
||||
m.id = UUID.randomUUID().toString();
|
||||
String out1 = DewLuaCore.toLua(m);
|
||||
out += asCodeBlock(out1);
|
||||
|
||||
String out2 = DewLuaCore.toLua(new DewMovementInfo());
|
||||
out += asCodeBlock(out2);
|
||||
|
||||
out += "**Testing Reading...**\n";
|
||||
|
||||
DewRealm map = new DewRealm();
|
||||
DewLuaCore.fromLua(map, out1);
|
||||
out += "ID from 1st write: " + asCodeLine(map.id) + "\n";
|
||||
|
||||
DewMovementInfo move = new DewMovementInfo();
|
||||
DewLuaCore.fromLua(move, out2);
|
||||
out += "Qualified type test: " + asCodeLine(move.toString()) + "\n";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
|
||||
|
||||
return new SubCommandFormattable(out);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package commands.dew;
|
||||
|
||||
import commands.dew.adapter.KittyAdapterDewPlayer;
|
||||
import commands.dew.core.impl.DewCore;
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandDewRealm extends SubCommand
|
||||
{
|
||||
public CommandDewRealm(KittyRole roleLevel, KittyRating contentRating)
|
||||
{
|
||||
super(roleLevel, contentRating);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||
{
|
||||
KittyAdapterDewPlayer player = DewCore.getOrCreate(user);
|
||||
|
||||
String out = DewCore.drawWorld(player);
|
||||
|
||||
return new SubCommandFormattable(out);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package commands.dew.adapter;
|
||||
|
||||
import commands.dew.core.api.IDewPlayer;
|
||||
import commands.dew.core.data.DewRealm;
|
||||
import dataStructures.KittyUser;
|
||||
|
||||
public class KittyAdapterDewPlayer implements IDewPlayer
|
||||
{
|
||||
private KittyUser user;
|
||||
private String realmID;
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public KittyAdapterDewPlayer(DewRealm realm, KittyUser user, int x, int y)
|
||||
{
|
||||
this.user = user;
|
||||
this.realmID = realm.id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public String getVisual()
|
||||
{
|
||||
return user.name.length() >= 1 ? user.name.substring(0, 1) : "@";
|
||||
}
|
||||
|
||||
public boolean isUser(KittyUser user)
|
||||
{
|
||||
return user.uniqueID == user.uniqueID;
|
||||
}
|
||||
|
||||
public void setRealmPos(int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
// Interface requirements //
|
||||
////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return user.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueID()
|
||||
{
|
||||
return user.uniqueID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentRealmID()
|
||||
{
|
||||
return realmID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRealmX()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRealmY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package commands.dew.core.api;
|
||||
|
||||
public interface IDewCore {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package commands.dew.core.api;
|
||||
|
||||
public interface IDewEntity
|
||||
{
|
||||
public String getUniqueID();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package commands.dew.core.api;
|
||||
|
||||
public interface IDewLuaCore
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package commands.dew.core.api;
|
||||
|
||||
public interface IDewLuaSerializable<T>
|
||||
{
|
||||
// Type info for derived class encoded in T
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package commands.dew.core.api;
|
||||
|
||||
// Commands are standalone pieces of data that contain only structures.
|
||||
// Each command is simplistic and represents an action in the game world.
|
||||
// Format:
|
||||
/*
|
||||
return
|
||||
{
|
||||
name="SomeCommand",
|
||||
data={
|
||||
-- some object here --
|
||||
}
|
||||
}
|
||||
*/
|
||||
public interface IDewMessage<T>
|
||||
{
|
||||
public String getMessageName();
|
||||
public T getData();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package commands.dew.core.api;
|
||||
|
||||
public interface IDewPlayer extends IDewEntity
|
||||
{
|
||||
public String getName();
|
||||
public String getCurrentRealmID();
|
||||
public int getRealmX();
|
||||
public int getRealmY();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package commands.dew.core.data;
|
||||
|
||||
public enum DewMapTile
|
||||
{
|
||||
// Assign multiples of 2 for flag purposes
|
||||
Default(0), Grass(1), Tree(2);
|
||||
|
||||
private final int value;
|
||||
private DewMapTile(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package commands.dew.core.data;
|
||||
|
||||
import commands.dew.core.api.IDewLuaSerializable;
|
||||
|
||||
// Treat all data objects as structs for the purposes of this.
|
||||
public class DewMovementInfo implements IDewLuaSerializable<DewMovementInfo>
|
||||
{
|
||||
public String entityID;
|
||||
public int x;
|
||||
public int y;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package commands.dew.core.data;
|
||||
|
||||
import commands.dew.core.api.IDewLuaSerializable;
|
||||
|
||||
public final class DewRealm implements IDewLuaSerializable<DewRealm>
|
||||
{
|
||||
public String id = "0";
|
||||
public int[][] map = new int[12][24]; // [Rows][Columns]
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package commands.dew.core.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import commands.dew.adapter.KittyAdapterDewPlayer;
|
||||
import commands.dew.core.data.DewMapTile;
|
||||
import commands.dew.core.data.DewRealm;
|
||||
import core.SubCommandFormattable;
|
||||
import core.SubCommandFramework;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
public class DewCore
|
||||
{
|
||||
// TODO: Make realm and players both per-realm
|
||||
public static String responseHeader = "[Dewdrop Forest]";
|
||||
public static DewRealm realm;
|
||||
public static List<KittyAdapterDewPlayer> players;
|
||||
public static List<KittyAdapterDewPlayer> playersCaptured;
|
||||
private static SubCommandFramework framework;
|
||||
|
||||
public DewCore(SubCommandFramework framework)
|
||||
{
|
||||
DewCore.framework = framework;
|
||||
DewCore.realm = new DewRealm();
|
||||
DewCore.players = new ArrayList<KittyAdapterDewPlayer>();
|
||||
DewCore.playersCaptured = new ArrayList<KittyAdapterDewPlayer>();
|
||||
|
||||
for(int y = 0; y < realm.map.length; ++y)
|
||||
{
|
||||
for(int x = 0; x < realm.map[y].length; ++x)
|
||||
{
|
||||
realm.map[y][x] = DewMapTile.Grass.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Returns false if not captured, true if captured.
|
||||
public static boolean ProcessIfCaptured(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput baseInput, Response res)
|
||||
{
|
||||
// Search for a captured player.
|
||||
KittyAdapterDewPlayer player = null;
|
||||
for(KittyAdapterDewPlayer p : playersCaptured)
|
||||
{
|
||||
if(p.getUniqueID() == user.uniqueID)
|
||||
{
|
||||
player = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If we didn't find that the person is captured, return false since we don't need to do anything.
|
||||
if(player == null)
|
||||
return false;
|
||||
|
||||
// See if we run anything - also, check to see if we need to exit.
|
||||
boolean didRun = false;
|
||||
try
|
||||
{
|
||||
UserInput toEdit = new UserInput(baseInput);
|
||||
String key = toEdit.message.toLowerCase().trim();
|
||||
toEdit.key = key;
|
||||
toEdit.args = key;
|
||||
switch(key)
|
||||
{
|
||||
case "cap":
|
||||
case "capture":
|
||||
case "uncapture":
|
||||
case "stop":
|
||||
case "quit":
|
||||
case "exit":
|
||||
playersCaptured.remove(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
SubCommandFormattable f = framework.run(guild, channel, user, toEdit);
|
||||
|
||||
if(f != null)
|
||||
{
|
||||
Response.GetLastMessage((String last) -> {
|
||||
if(last.contains(responseHeader))
|
||||
Response.EditLastMessage(f.resString);
|
||||
});
|
||||
didRun = true;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
GlobalLog.error(LogFilter.Command, e);
|
||||
}
|
||||
|
||||
if(didRun)
|
||||
{
|
||||
baseInput.deleteOriginInput();
|
||||
}
|
||||
|
||||
return didRun;
|
||||
}
|
||||
|
||||
public static KittyAdapterDewPlayer getOrCreate(KittyUser user)
|
||||
{
|
||||
for(KittyAdapterDewPlayer player : players)
|
||||
{
|
||||
if(player.getUniqueID() == user.uniqueID)
|
||||
{
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
KittyAdapterDewPlayer player = new KittyAdapterDewPlayer(realm, user, 10, 10);
|
||||
players.add(player);
|
||||
return player;
|
||||
}
|
||||
|
||||
public static String drawWorld(KittyAdapterDewPlayer player)
|
||||
{
|
||||
// Build empty world buffer
|
||||
String[][] worldBuffer = new String[realm.map.length][realm.map[0].length];
|
||||
|
||||
// Build world
|
||||
for(int y = 0; y < realm.map.length; ++y)
|
||||
{
|
||||
for(int x = 0; x < realm.map[y].length; ++x)
|
||||
{
|
||||
switch(DewMapTile.values()[realm.map[y][x]])
|
||||
{
|
||||
case Grass:
|
||||
worldBuffer[y][x] = ",";
|
||||
break;
|
||||
|
||||
default:
|
||||
worldBuffer[y][x] = " ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build players
|
||||
for(KittyAdapterDewPlayer p : players)
|
||||
{
|
||||
worldBuffer[p.getRealmY()][p.getRealmX()] = p.getVisual();
|
||||
}
|
||||
|
||||
// Draw world
|
||||
String out = "";
|
||||
out += responseHeader + "\n";
|
||||
out += "**Realm ID - ** `" + realm.id + "`\n";
|
||||
|
||||
for(int y = 0; y < worldBuffer.length; ++y)
|
||||
{
|
||||
out += "`";
|
||||
|
||||
for(int x = 0; x < worldBuffer[y].length; ++x)
|
||||
{
|
||||
out += worldBuffer[y][x];
|
||||
}
|
||||
|
||||
out += "`";
|
||||
out += "\n";
|
||||
}
|
||||
|
||||
out += "**Stats**\n";
|
||||
out += "`Player Name` - `" + player.getName() + "`\n";
|
||||
out += "`Player Icon` - `" + player.getVisual() + "`\n";
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package commands.dew.core.impl;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Varargs;
|
||||
import org.luaj.vm2.lib.jse.JsePlatform;
|
||||
import commands.dew.core.api.IDewLuaCore;
|
||||
import commands.dew.core.api.IDewLuaSerializable;
|
||||
|
||||
public class DewLuaCore implements IDewLuaCore
|
||||
{
|
||||
private static Globals globalLuaCore = null;
|
||||
|
||||
public static String toLua(IDewLuaSerializable<?> item)
|
||||
{
|
||||
return toLua(item, 0);
|
||||
}
|
||||
|
||||
private static String tab(int num)
|
||||
{
|
||||
String line = "";
|
||||
|
||||
for(int i = 0; i < num; ++i)
|
||||
line += "\t";
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
public static String toLua(IDewLuaSerializable<?> item, int tabs)
|
||||
{
|
||||
String out = tab(tabs) + "return {\n";
|
||||
|
||||
// Set up type information
|
||||
out += tab(tabs + 1) + "type=\"" + item.getClass().getTypeName() + "\",\n";
|
||||
|
||||
|
||||
// Set up data information
|
||||
out += tab(tabs + 1) + "data={\n";
|
||||
|
||||
// Write data
|
||||
Field[] fields = item.getClass().getDeclaredFields();
|
||||
for(int i = 0; i < fields.length; ++i)
|
||||
{
|
||||
Field current = fields[i];
|
||||
try
|
||||
{
|
||||
String line = "";
|
||||
String fieldType = current.getType().toString().toLowerCase();
|
||||
|
||||
line += tab(tabs + 2);
|
||||
line += current.getName() + "=";
|
||||
|
||||
switch(fieldType)
|
||||
{
|
||||
case "int":
|
||||
line += "" + current.get(item);
|
||||
break;
|
||||
|
||||
case "class java.lang.string":
|
||||
String content = (String)current.get(item);
|
||||
|
||||
if(content == null || content.length() == 0)
|
||||
line += "\"\"";
|
||||
else
|
||||
line += "\"" + content + "\"";
|
||||
|
||||
break;
|
||||
|
||||
// wrong name
|
||||
case "dewmaptile ":
|
||||
line += "\"" + current.get(item).toString() + "\"";
|
||||
break;
|
||||
|
||||
default:
|
||||
line += "nil";
|
||||
System.err.print("Type could not be foramtted as lua: " + fieldType + "\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// If we're not the last line, add a comma.
|
||||
if(i != fields.length - 1)
|
||||
line += ",";
|
||||
|
||||
out += line + "\n";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
out += tab(tabs + 1) + "}\n";
|
||||
out += tab(tabs)+ "}\n";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public static <T> void fromLua(T obj, String lua)
|
||||
{
|
||||
if(globalLuaCore == null)
|
||||
{
|
||||
globalLuaCore = JsePlatform.standardGlobals();
|
||||
}
|
||||
|
||||
LuaValue luaResult = globalLuaCore.load(lua).call();
|
||||
String type = luaResult.get("type").toString();
|
||||
|
||||
try
|
||||
{
|
||||
LuaValue data = luaResult.get("data");
|
||||
Class<T> concreteClass = (Class<T>) Class.forName(type);
|
||||
|
||||
for(Field field : concreteClass.getDeclaredFields())
|
||||
{
|
||||
String name = field.getName();
|
||||
LuaValue value = data.get(name);
|
||||
|
||||
if(!value.isnil())
|
||||
{
|
||||
String fieldType = field.getType().toString().toLowerCase();
|
||||
switch(fieldType)
|
||||
{
|
||||
case "int":
|
||||
field.set(obj, value.toint());
|
||||
break;
|
||||
|
||||
case "class java.lang.string":
|
||||
field.set(obj, value.toString());
|
||||
break;
|
||||
|
||||
// Not the right name
|
||||
case "dewmaptile":
|
||||
default:
|
||||
System.err.print("Could not set field of type: " + fieldType + "\n");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
System.err.println("Field was not in lua: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package commands.dew.core.messages;
|
||||
|
||||
import commands.dew.core.api.IDewLuaSerializable;
|
||||
|
||||
public class DewMessageMovement implements IDewLuaSerializable<DewMessageMovement>
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,25 +1,8 @@
|
||||
package commands.general;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import core.Command;
|
||||
import core.Constants;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandBeansShow extends Command
|
||||
{
|
||||
@@ -32,15 +15,7 @@ public class CommandBeansShow extends Command
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.mentions == null)
|
||||
{
|
||||
//res.send("" + user.getBeans());
|
||||
try {
|
||||
res.sendFile(combineImages(user.getBeans()), "png");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// res.send(String.format(LocStrings.stub("BeansShowDisplay"), user.getBeans()));
|
||||
}
|
||||
res.send(String.format(LocStrings.stub("BeansShowDisplay"), user.getBeans()));
|
||||
else
|
||||
{
|
||||
String mentionedBeans = "";
|
||||
@@ -51,88 +26,4 @@ public class CommandBeansShow extends Command
|
||||
res.send(String.format(LocStrings.stub("BeansShowMentioned"), mentionedBeans));
|
||||
}
|
||||
}
|
||||
|
||||
private File combineImages(long beans) throws IOException
|
||||
{
|
||||
// Acquire images
|
||||
BufferedImage imageBase = ImageIO.read(new File(Constants.AssetDirectory + "beans/BeansBG.png"));
|
||||
BufferedImage thouBean = ImageIO.read(new File(Constants.AssetDirectory + "beans/thouBean.png"));
|
||||
BufferedImage hunBean = ImageIO.read(new File(Constants.AssetDirectory + "beans/hunBean.png"));
|
||||
BufferedImage tenBean = ImageIO.read(new File(Constants.AssetDirectory + "beans/tenBean.png"));
|
||||
BufferedImage oneBean = ImageIO.read(new File(Constants.AssetDirectory + "beans/oneBean.png"));
|
||||
|
||||
final int baseWidth = imageBase.getWidth();
|
||||
final int baseHeight = imageBase.getHeight();
|
||||
|
||||
long calcBean = beans;
|
||||
|
||||
long thousands = beans / 1000;
|
||||
calcBean = beans % 1000;
|
||||
long hundreds = (calcBean / 100);
|
||||
calcBean = calcBean % 100;
|
||||
long tens = (calcBean / 10);
|
||||
calcBean = calcBean % 10;
|
||||
long ones = calcBean;
|
||||
|
||||
BufferedImage beanImage = new BufferedImage(baseWidth, baseHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics beanGraphics = beanImage.getGraphics();
|
||||
Rectangle rect = new Rectangle(0, 0, baseWidth, baseHeight);
|
||||
beanGraphics.drawImage(imageBase,0,0,null);
|
||||
|
||||
for(int i = 0; i < ones; i++)
|
||||
{
|
||||
int x = (int)(Math.random() * (baseWidth - oneBean.getWidth())) + 1;
|
||||
int y = (int)(Math.random() * (baseHeight - oneBean.getHeight())) + 1;
|
||||
beanGraphics.drawImage(oneBean, x, y, null);
|
||||
}
|
||||
|
||||
for(int i = 0; i < tens; i++)
|
||||
{
|
||||
int x = (int)(Math.random() * (baseWidth - tenBean.getWidth())) + 1;
|
||||
int y = (int)(Math.random() * (baseHeight - tenBean.getHeight())) + 1;
|
||||
beanGraphics.drawImage(tenBean, x, y, null);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hundreds; i++)
|
||||
{
|
||||
int x = (int)(Math.random() * (baseWidth - hunBean.getWidth())) + 1;
|
||||
int y = (int)(Math.random() * (baseHeight - hunBean.getHeight())) + 1;
|
||||
beanGraphics.drawImage(hunBean, x, y, null);
|
||||
}
|
||||
|
||||
for(int i = 0; i < thousands; i++)
|
||||
{
|
||||
int x = (int)(Math.random() * (baseWidth - thouBean.getWidth())) + 1;
|
||||
int y = (int)(Math.random() * (baseHeight - thouBean.getHeight())) + 1;
|
||||
beanGraphics.drawImage(thouBean, x, y, null);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
@SuppressWarnings("unused")
|
||||
Font font = null;
|
||||
font = Font.createFont(Font.TRUETYPE_FONT, new File(Constants.AssetDirectory +"fonts/B612Mono-Regular.ttf"));
|
||||
} catch (Exception e)
|
||||
{
|
||||
}
|
||||
Font beanFont = new Font("font", Font.BOLD, 45);
|
||||
beanGraphics.setFont(beanFont);
|
||||
|
||||
drawCenteredString(beanGraphics, "YOU HAVE", rect, beanFont, .25);
|
||||
drawCenteredString(beanGraphics, "" + beans, rect, beanFont, .5);
|
||||
drawCenteredString(beanGraphics, "BEANS!", rect, beanFont, .75);
|
||||
|
||||
ImageIO.write(beanImage, "PNG", new File("beanImage.png"));
|
||||
return new File("beanImage.png");
|
||||
}
|
||||
|
||||
private void drawCenteredString(Graphics beanGraphics, String text, Rectangle rect, Font font, double segment)
|
||||
{
|
||||
FontMetrics metrics = beanGraphics.getFontMetrics(font);
|
||||
|
||||
int x = rect.x + (rect.width - metrics.stringWidth(text)) / 2;
|
||||
int y = (int)(rect.y + ((rect.height - metrics.getHeight()) * segment) + metrics.getAscent());
|
||||
|
||||
beanGraphics.drawString(text, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class CommandBetBeans extends Command
|
||||
{
|
||||
String call = "";
|
||||
|
||||
int min = 20;
|
||||
int min = 50;
|
||||
int bet = 0;
|
||||
int win = 0;
|
||||
|
||||
@@ -36,8 +36,7 @@ public class CommandBetBeans extends Command
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
GlobalLog.log(LogFilter.Command, "Betting took place, but a value was not specified in the config file "
|
||||
+ "so 50 was used as the minimum bet threshold. Consider specifying BetBeansMinThreshold.");
|
||||
GlobalLog.log(LogFilter.Command, "Betting took place, but a value was not specified in the config file so 50 was used as the minimum bet threshold. Consider specifying BetBeansMinThreshold.");
|
||||
}
|
||||
|
||||
try
|
||||
|
||||
@@ -68,23 +68,22 @@ public class CommandBoop extends Command
|
||||
{
|
||||
if(input.mentions == null)
|
||||
{
|
||||
// No one is booped, just the bot!
|
||||
boopTracker.applyBoop();
|
||||
res.send(String.format(LocStrings.stub("BoopStandard"), user.name, boopTracker.howMany()));
|
||||
}
|
||||
else
|
||||
{
|
||||
// When someone boops one other person
|
||||
if(input.mentions.length == 1)
|
||||
{
|
||||
boopTracker.applyBoop();
|
||||
res.send(String.format(LocStrings.stub("BoopPerson"), user.name, input.mentions[0].name));
|
||||
return;
|
||||
}
|
||||
|
||||
// A number of people have been booped
|
||||
String booped = "";
|
||||
for(int i = 0; i < input.mentions.length; i++)
|
||||
{
|
||||
boopTracker.applyBoop();
|
||||
if(i < input.mentions.length-1)
|
||||
booped += input.mentions[i].name + ", ";
|
||||
else
|
||||
|
||||
@@ -27,20 +27,12 @@ public class CommandChoose extends Command
|
||||
|
||||
String [] choices = input.args.split(",");
|
||||
|
||||
if(choices.length <= 1)
|
||||
if(choices.length == 1)
|
||||
{
|
||||
res.send(LocStrings.stub("ChooseOne"));
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 0; i < choices.length; i ++)
|
||||
{
|
||||
if (choices[i].equals(""))
|
||||
{
|
||||
choices[i] = "KittyBot is the best!";
|
||||
}
|
||||
}
|
||||
|
||||
res.send(String.format(LocStrings.stub("ChooseChoice"), (choices[(int) (Math.random()*choices.length)]).toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,28 @@ public class CommandColor extends Command
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.args == null || input.args.length() == 0)
|
||||
{
|
||||
res.send(LocStrings.stub("ColorNotSearchable"));
|
||||
return;
|
||||
}
|
||||
|
||||
String toFind = null;
|
||||
String[] split = input.args.split(" ");
|
||||
|
||||
if(split.length >= 1)
|
||||
toFind = split[0];
|
||||
|
||||
// First, try and parse out the color to make sure we can even get it.
|
||||
ColorData colorData = theColorAPI.lookupHex(input.args);
|
||||
ColorData colorData = null;
|
||||
if(toFind == null)
|
||||
{
|
||||
colorData = theColorAPI.lookupHex(input.args.trim());
|
||||
}
|
||||
else
|
||||
{
|
||||
colorData = theColorAPI.lookupHex(toFind.trim());
|
||||
}
|
||||
|
||||
// Verify the color was even found
|
||||
if(colorData == null)
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyEmbed;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import network.NetworkDerpi;
|
||||
|
||||
public class CommandDerpi extends Command
|
||||
{
|
||||
NetworkDerpi searcher = new NetworkDerpi();
|
||||
KittyEmbed response;
|
||||
|
||||
// Required constructor
|
||||
public CommandDerpi(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return "Will search derpibooru for the tags entered, if KittyBot's content filter allows it"; }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(guild.contentRating == KittyRating.Filtered)
|
||||
{
|
||||
try
|
||||
{
|
||||
response = searcher.getDerpi(input.args.replace(',', ' ') + " safe").output();
|
||||
res.send(response);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send(LocStrings.stub("DerpiError"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(input.args == null || input.args.length() == 0)
|
||||
res.send("DerpiNoSearchError");
|
||||
else
|
||||
{
|
||||
response = searcher.getDerpi(input.args).output();
|
||||
try
|
||||
{
|
||||
res.send(response);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send(LocStrings.stub("DerpiError"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(input.args.startsWith("ID:"))
|
||||
{
|
||||
response = searcher.getDerpiByID(input.args.substring(input.args.indexOf(':'))).output();
|
||||
try
|
||||
{
|
||||
res.send(response);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send(LocStrings.stub("DerpiError"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
import network.NetworkE6;
|
||||
|
||||
public class CommandE6 extends Command
|
||||
{
|
||||
NetworkE6 searcher = new NetworkE6();
|
||||
KittyEmbed response;
|
||||
GenericImage image;
|
||||
|
||||
public CommandE6(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText()
|
||||
{
|
||||
String toRet = "Will search e6";
|
||||
toRet += "21 for the tags entered, if KittyBot's content filter allows it";
|
||||
return toRet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(guild.contentRating == KittyRating.Filtered)
|
||||
{
|
||||
image = searcher.getE6(input.args + " rating:safe", "");
|
||||
try
|
||||
{
|
||||
response = image.output();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send(LocStrings.stub("E6Blacklisted"));
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if(response.bodyImageURL == null)
|
||||
{
|
||||
Exception e = new Exception();
|
||||
throw e;
|
||||
}
|
||||
res.send(response);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send(LocStrings.stub("E6Blacklisted"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(input.args == null || input.args.length() == 0)
|
||||
res.send("E6NoSearchError");
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
response = searcher.getE6(input.args, "").output();
|
||||
res.send(response);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send(LocStrings.stub("E6Blacklisted"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import network.NetworkSauceNAO;
|
||||
|
||||
public class CommandGetSauce extends Command
|
||||
{
|
||||
NetworkSauceNAO sauce = new NetworkSauceNAO();
|
||||
|
||||
public CommandGetSauce(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("GetSauceInfo"); };
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
try
|
||||
{
|
||||
res.send(sauce.getSauce(input.args).output());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send("Image not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import java.util.Stack;
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
public class CommandRoll extends Command
|
||||
{
|
||||
@@ -22,9 +24,7 @@ public class CommandRoll extends Command
|
||||
{
|
||||
KittyEmbed embed = new KittyEmbed();
|
||||
embed.title = user.name +"'s roll!";
|
||||
System.out.println("HERE");
|
||||
embed.descriptionText = rollDice(input.args);
|
||||
System.out.println("THERE");
|
||||
Random numGen = new Random(user.name.hashCode());
|
||||
float hue = numGen.nextFloat();
|
||||
float sat = .7f;
|
||||
@@ -34,6 +34,7 @@ public class CommandRoll extends Command
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
GlobalLog.error(LogFilter.Command, e);
|
||||
res.send(LocStrings.stub("RollError"));
|
||||
}
|
||||
}
|
||||
@@ -43,11 +44,10 @@ public class CommandRoll extends Command
|
||||
Stack<Integer> values = new Stack<Integer>();
|
||||
Stack<Character> operators = new Stack<Character>();
|
||||
String steps = "";
|
||||
|
||||
for(int i = 0; i < thing.length(); i ++)
|
||||
{
|
||||
char current = thing.charAt(i);
|
||||
System.out.println("ROLLING");
|
||||
|
||||
switch(current)
|
||||
{
|
||||
case '+':
|
||||
@@ -125,11 +125,8 @@ public class CommandRoll extends Command
|
||||
{
|
||||
steps += "\n" + calculate(values, operators);
|
||||
}
|
||||
if(steps != "")
|
||||
{
|
||||
return "Roll```" + thing + "```" + "Steps```" + steps + "```" + "Final value ```" + values.pop() +"```";
|
||||
}
|
||||
return "That's not a roll that's just " + values.pop() +"!";
|
||||
|
||||
return "Roll```" + thing + "```" + "Steps```" + steps + "```" + "Final value ```" + values.pop() +"```";
|
||||
}
|
||||
|
||||
|
||||
@@ -176,18 +173,18 @@ public class CommandRoll extends Command
|
||||
|
||||
private int[] roll(int first, int second)
|
||||
{
|
||||
int roll = 0;
|
||||
int dice = first;
|
||||
int sides = second;
|
||||
int [] rolls = new int [dice];
|
||||
int numberOfDice = first;
|
||||
int diceSideCount = second;
|
||||
int [] rolls = new int[numberOfDice];
|
||||
|
||||
if(dice < 1)
|
||||
GlobalLog.log("number: " + numberOfDice + " diceSides: " + diceSideCount);
|
||||
|
||||
if(numberOfDice < 1)
|
||||
return new int[0];
|
||||
for(int i = 0; dice > i; i ++)
|
||||
{
|
||||
roll = (int)(Math.random() * sides) + 1;
|
||||
rolls[i] = roll;
|
||||
}
|
||||
|
||||
for(int i = 0; i < numberOfDice; i++)
|
||||
rolls[i] = (int)(Math.random() * diceSideCount + 1);
|
||||
|
||||
return rolls;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,29 +25,15 @@ public class CommandTradeBeans extends Command
|
||||
res.send(LocStrings.stub("TradeBeansNoTargetError"));
|
||||
return;
|
||||
}
|
||||
if(input.mentions.length > 1)
|
||||
{
|
||||
res.send(LocStrings.stub("TradeBeansMultipleUsersTagged"));
|
||||
return;
|
||||
}
|
||||
|
||||
int beans = 0;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
beans = Integer.parseInt(input.args.split(" ")[0]);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
try
|
||||
{
|
||||
beans = Integer.parseInt(input.args.split(" ")[1]);
|
||||
}
|
||||
catch(Exception eInner)
|
||||
{
|
||||
res.send(LocStrings.stub("TradeBeansIntParseError"));
|
||||
return;
|
||||
}
|
||||
res.send(LocStrings.stub("TradeBeansIntParseError"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(user.getBeans() < beans)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandWeh extends Command {
|
||||
|
||||
public String getHelpText() { return LocStrings.stub("WehInfo"); }
|
||||
|
||||
public CommandWeh(KittyRole roleLevel, KittyRating contentRating) {
|
||||
super(roleLevel, contentRating);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
// The format for reutrning an emoji is: <:name:ID#>
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
res.send("<:weh:548301646929723393>");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package commands.music;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import core.SubCommandFormattable;
|
||||
import core.SubCommandFramework;
|
||||
import dataStructures.*;
|
||||
|
||||
@@ -10,24 +9,18 @@ public class CommandMusicMain extends Command
|
||||
{
|
||||
SubCommandFramework framework = new SubCommandFramework();
|
||||
public CommandMusicMain(KittyRole level, KittyRating rating)
|
||||
{
|
||||
{
|
||||
super(level, rating);
|
||||
framework.addCommand("join", new SubCommandJoin(KittyRole.General, KittyRating.Safe));
|
||||
framework.addCommand("leave", new SubCommandLeave(KittyRole.General, KittyRating.Safe));
|
||||
framework.addCommand("add", new SubCommandAddTrack(KittyRole.General, KittyRating.Safe));
|
||||
framework.addCommand("skip", new SubCommandSkip(KittyRole.General, KittyRating.Safe));
|
||||
framework.addCommand("stop", new SubCommandStop(KittyRole.General, KittyRating.Safe));
|
||||
framework.addCommand("playlist", new SubCommandPlaylist(KittyRole.General, KittyRating.Safe));
|
||||
framework.addCommand("volume", new SubCommandVolume(KittyRole.General, KittyRating.Safe));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() {return LocStrings.stub("MusicInfo"); }
|
||||
public String getHelpText() { return LocStrings.stub("MusicInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
SubCommandFormattable scf = framework.run(guild, channel, user, input);
|
||||
scf.Call(res);
|
||||
framework.run(guild, channel, user, input).Call(res);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package commands.music;
|
||||
|
||||
import core.LocStrings;
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
@@ -9,25 +8,14 @@ import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.UserInput;
|
||||
import network.NetworkYoutube;
|
||||
|
||||
public class SubCommandAddTrack extends SubCommand
|
||||
{
|
||||
|
||||
public SubCommandAddTrack(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
NetworkYoutube YT = new NetworkYoutube();
|
||||
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||
{
|
||||
//Get track from Youtube
|
||||
String video = input.args;
|
||||
if(!(video.startsWith("https://www.youtube") || video.startsWith("https://www.youtu.be")))
|
||||
{
|
||||
video = YT.getYT(video);
|
||||
}
|
||||
guild.audio.playVideo(video);
|
||||
return new SubCommandFormattable(String.format(LocStrings.stub("MusicAddTrack"), video));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package commands.music;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class SubCommandPlaylist extends SubCommand
|
||||
{
|
||||
|
||||
public SubCommandPlaylist(KittyRole roleLevel, KittyRating contentRating) {super(roleLevel, contentRating); }
|
||||
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||
{
|
||||
ArrayList <AudioTrack> playlist = guild.audio.getPlaylist();
|
||||
String stringPlaylist = "";
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package commands.music;
|
||||
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class SubCommandSkip extends SubCommand
|
||||
{
|
||||
public SubCommandSkip(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
{
|
||||
|
||||
}
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||
{
|
||||
return new SubCommandFormattable(guild.audio.skipVideo(guild.audio.player));
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package commands.music;
|
||||
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class SubCommandStop extends SubCommand
|
||||
{
|
||||
|
||||
public SubCommandStop(KittyRole roleLevel, KittyRating contentRating) {super(roleLevel, contentRating);}
|
||||
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||
{
|
||||
return new SubCommandFormattable(guild.audio.stopPlayer(guild.audio.player));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package commands.music;
|
||||
|
||||
import core.LocStrings;
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class SubCommandVolume extends SubCommand
|
||||
{
|
||||
public SubCommandVolume(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
{
|
||||
|
||||
}
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||
{
|
||||
int newVol = guild.audio.getVolume(guild.audio.player);
|
||||
if(input.args != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
newVol = Integer.parseInt(input.args);
|
||||
if(newVol > 100 || newVol <1)
|
||||
{
|
||||
return new SubCommandFormattable(String.format(LocStrings.stub("MusicVolOOB")));
|
||||
}
|
||||
guild.audio.changeVolume(guild.audio.player, newVol);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return new SubCommandFormattable(String.format(LocStrings.stub("MusicVolCurrent"), newVol));
|
||||
}
|
||||
|
||||
}
|
||||
return new SubCommandFormattable(String.format(LocStrings.stub("MusicVolChanged"), newVol));
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import commands.benchmark.CommandBenchmark;
|
||||
import commands.characters.CommandCharacterMain;
|
||||
import commands.dew.CommandDew;
|
||||
import commands.general.*;
|
||||
import commands.guildrole.CommandGuildRoleMain;
|
||||
import commands.mod.CommandModMain;
|
||||
@@ -62,6 +64,7 @@ public class CommandManager
|
||||
this.register(LocCommands.stub("tweet"), new CommandTweet(KittyRole.Dev, KittyRating.Safe));
|
||||
this.register(LocCommands.stub("dbflush"), new CommandDBFlush(KittyRole.Dev, KittyRating.Safe));
|
||||
this.register(LocCommands.stub("dbstats"), new CommandDBStats(KittyRole.Dev, KittyRating.Safe));
|
||||
this.register(LocCommands.stub("dew"), new CommandDew(KittyRole.Dev, KittyRating.Safe));
|
||||
|
||||
// Admin
|
||||
this.register(LocCommands.stub("rating"), new CommandRating(KittyRole.Admin, KittyRating.Safe));
|
||||
@@ -107,11 +110,7 @@ public class CommandManager
|
||||
this.register(LocCommands.stub("poll"), new CommandPollMain(KittyRole.General, KittyRating.Safe));
|
||||
this.register(LocCommands.stub("music"), new CommandMusicMain(KittyRole.General, KittyRating.Safe));
|
||||
this.register(LocCommands.stub("defaultdance"), new CommandDefaultDance(KittyRole.General, KittyRating.Safe));
|
||||
this.register(LocCommands.stub("getsauce"), new CommandGetSauce(KittyRole.General, KittyRating.Safe));
|
||||
this.register(LocCommands.stub("tradebeans, trade"), new CommandTradeBeans(KittyRole.General, KittyRating.Safe));
|
||||
|
||||
this.register(LocCommands.stub("e6"), new CommandE6(KittyRole.General, KittyRating.Filtered));
|
||||
this.register(LocCommands.stub("derpi"), new CommandDerpi(KittyRole.General, KittyRating.Filtered));
|
||||
this.register(LocCommands.stub("weh"), new CommandWeh(KittyRole.General, KittyRating.Safe));
|
||||
}
|
||||
|
||||
// Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands)
|
||||
|
||||
@@ -52,4 +52,4 @@ public class CommandThread extends Thread
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ public class Config
|
||||
sections = new Vector<IConfigSection>();
|
||||
|
||||
// Add all sections
|
||||
sections.add(new ConfigGlobals());
|
||||
sections.add(new LocCommands());
|
||||
sections.add(new LocStrings());
|
||||
sections.add(new CommandEnabler());
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
package core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dataStructures.KittyStartupMode;
|
||||
import utils.GlobalLog;
|
||||
|
||||
// Want to add a single item to the config file? This is where that lives.
|
||||
public class ConfigGlobals implements IConfigSection
|
||||
{
|
||||
// Defined const variables
|
||||
public static final String header = "Globals";
|
||||
public static ConfigGlobals instance;
|
||||
|
||||
|
||||
// A pile of variables being manually tracked/serialized to the config file
|
||||
private static final String startupStyleKey = "mode (dev or release)";
|
||||
private KittyStartupMode startupStyleValue = KittyStartupMode.Dev;
|
||||
|
||||
// Constructor
|
||||
public ConfigGlobals()
|
||||
{
|
||||
if(instance == null)
|
||||
instance = this;
|
||||
else
|
||||
GlobalLog.error("Attempted to initialize a second config globals! Probably don't do this!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSectionTitle()
|
||||
{
|
||||
return header;
|
||||
}
|
||||
|
||||
public static KittyStartupMode getStartupMode()
|
||||
{
|
||||
return instance.startupStyleValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consume(List<ConfigItem> pairs)
|
||||
{
|
||||
for(int i = 0; i < pairs.size(); ++i)
|
||||
{
|
||||
String key = pairs.get(i).key;
|
||||
String value = pairs.get(i).value;
|
||||
|
||||
// Parse startup style
|
||||
if(key.equalsIgnoreCase(startupStyleKey))
|
||||
{
|
||||
startupStyleValue = KittyStartupMode.Dev;
|
||||
|
||||
if(value.equalsIgnoreCase(KittyStartupMode.Release.name()))
|
||||
startupStyleValue = KittyStartupMode.Release;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConfigItem> produce()
|
||||
{
|
||||
List<ConfigItem> items = new ArrayList<ConfigItem>();
|
||||
items.add(new ConfigItem(getSectionTitle(), startupStyleKey, startupStyleValue.name().toLowerCase()));
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,9 @@ import utils.StringUtils;
|
||||
// perform any parsing past naming columns, and just holds the raw data.
|
||||
public class ConfigItem
|
||||
{
|
||||
public String type; // The section this specific key/value pair belongs to. This almost certainly will appear in multiple places.
|
||||
public String key; // A unique key for a given lookup value for the specified section. Keys, within sections, are unique.
|
||||
public String value; // The value assocaited with the key.
|
||||
public String type;
|
||||
public String key;
|
||||
public String value;
|
||||
public static final int items = 3;
|
||||
public static final String[] header = {"Type","Key","Value"};
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import dataStructures.Pair;
|
||||
public class LocCommands extends BaseLocFile implements IConfigSection
|
||||
{
|
||||
// Defined const variables
|
||||
public static final String header = "Localized Commands";
|
||||
public static final String HeaderName = "Localized Commands";
|
||||
public static final String function = "LocCommands.stub";
|
||||
|
||||
// Instance
|
||||
@@ -20,7 +20,7 @@ public class LocCommands extends BaseLocFile implements IConfigSection
|
||||
// Constructor
|
||||
public LocCommands()
|
||||
{
|
||||
super(header, function);
|
||||
super(HeaderName, function);
|
||||
|
||||
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
||||
|
||||
|
||||
+452
-484
@@ -1,485 +1,453 @@
|
||||
package core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
||||
|
||||
//import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
//import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
|
||||
import core.lua.PluginManager;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyCore;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyStartupMode;
|
||||
import dataStructures.KittyUser;
|
||||
import main.Main;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.JDABuilder;
|
||||
import net.dv8tion.jda.core.entities.Emote;
|
||||
import net.dv8tion.jda.core.entities.Game;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import offline.Ref;
|
||||
import utils.AdminControl;
|
||||
//import utils.AudioUtils;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
import utils.audio.AudioUtils;
|
||||
|
||||
// NOTE(wisp): Isolated factory to assist with storage and caching if needed.
|
||||
// This also minimizes the number of places JDA interacts with our codebase.
|
||||
// As it stands, if the object name begins with Kitty, it's constructed here.
|
||||
// TODO: Make all methods ID based instead of event based
|
||||
public class ObjectBuilderFactory
|
||||
{
|
||||
// Key: guild string id, Value: guild information
|
||||
private static HashMap<String, KittyGuild> guildCache;
|
||||
|
||||
// Key: channel string id, Value: channel information
|
||||
private static HashMap<String, KittyChannel> channelCache;
|
||||
|
||||
// Key: guild string id + user string id, Value: user information
|
||||
private static HashMap<String, KittyUser> userCache;
|
||||
|
||||
// For tracking and managing object sync
|
||||
private static DatabaseManager database;
|
||||
|
||||
// Stats tracking and whatnot... for setting stats too internally potentially
|
||||
private static Stats stats;
|
||||
|
||||
// RPManger for tracking RP system
|
||||
private static RPManager rpManager;
|
||||
|
||||
// Plugin manager
|
||||
private static PluginManager pluginManager;
|
||||
|
||||
// Command manager
|
||||
private static CommandManager commandManager;
|
||||
|
||||
//Audio track manager
|
||||
private static AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
|
||||
|
||||
// Localization classes - these are singletons, but should be initialized before almost all other
|
||||
// things so their inclusion in the factory is to ensure they're started at the correct time.
|
||||
@SuppressWarnings("unused") private static LocStrings locStrings;
|
||||
@SuppressWarnings("unused") private static LocCommands locCommands;
|
||||
|
||||
// Config
|
||||
@SuppressWarnings("unused") private static Config config;
|
||||
|
||||
// Lazy initialization multithreaded mutex stuff to prevent explosions.
|
||||
// TODO: Investigate using 'synchronized' instead potentially
|
||||
private static boolean hasInitialized;
|
||||
private static Semaphore initMutex = new Semaphore(1);
|
||||
private static JDA kitty;
|
||||
|
||||
// This is it, this is how the lazy init starts!
|
||||
private static void lazyInit()
|
||||
{
|
||||
if(hasInitialized)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
initMutex.acquire();
|
||||
try
|
||||
{
|
||||
// structure initialization
|
||||
// Construct necessary data structures.
|
||||
guildCache = new HashMap<String, KittyGuild>();
|
||||
userCache = new HashMap<String, KittyUser>();
|
||||
channelCache = new HashMap<String, KittyChannel>();
|
||||
database = null;
|
||||
stats = null;
|
||||
|
||||
AudioSourceManagers.registerRemoteSources(playerManager);
|
||||
AudioSourceManagers.registerLocalSource(playerManager);
|
||||
|
||||
// Start by reading from things that are external. Because
|
||||
// we require these things to be resolved before the rest of the application,
|
||||
// we place them here.
|
||||
config = new Config();
|
||||
}
|
||||
finally
|
||||
{
|
||||
initMutex.release();
|
||||
hasInitialized = true;
|
||||
}
|
||||
}
|
||||
catch(InterruptedException ie)
|
||||
{
|
||||
GlobalLog.error(LogFilter.Core, "Issue during object builder lazy initialization."
|
||||
+ " The factory was not initialized, and kitty will not be able to continue functionally.");
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
// Extraction Methods //
|
||||
////////////////////////
|
||||
|
||||
// Explicitly locks: guildCache
|
||||
public static KittyGuild extractGuild(GuildMessageReceivedEvent event)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
// Look up the guild. This process can only happen in a single-threaded way
|
||||
// because of the nature of the cache. We wait until the last second to
|
||||
// look up the guild.
|
||||
String uid = event.getGuild().getId();
|
||||
|
||||
List<Emote> emotes = event.getGuild().getEmotes();
|
||||
ArrayList<String> emotesString = new ArrayList<String>();
|
||||
HashMap<Long, KittyChannel> channels = new HashMap<Long, KittyChannel>();
|
||||
String emote;
|
||||
String emoteFix;
|
||||
channels.put(Long.getLong(uid), extractChannel(event));
|
||||
for(int i = 0; i < emotes.size(); i++)
|
||||
{
|
||||
emote = emotes.get(i).toString();
|
||||
emoteFix = "<:" + emote.substring(2, emote.indexOf("("));
|
||||
emoteFix += ":" + emote.substring(emote.indexOf("(")+1, emote.length()-1) + ">";
|
||||
emotesString.add(emoteFix);
|
||||
}
|
||||
|
||||
// once we're lazily initialized, we can synchronize w/ the
|
||||
// guildCache object now instead of having to use a mutex.
|
||||
KittyGuild guild = null;
|
||||
synchronized (guildCache)
|
||||
{
|
||||
KittyGuild cachedGuild = guildCache.get(uid);
|
||||
if(cachedGuild != null)
|
||||
{
|
||||
guild = cachedGuild;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Construct a new guild with defaults
|
||||
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString,
|
||||
new AudioUtils(event.getGuild(), playerManager), channels);
|
||||
DatabaseManager.instance.globalRegister(guild);
|
||||
guildCache.put(uid, guild);
|
||||
}
|
||||
}
|
||||
|
||||
return guild;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Explicitly locks: guildCache
|
||||
public static KittyRole extractRole(GuildMessageReceivedEvent event)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
// Looks up the user role. If none is found we check to see if they own
|
||||
// the guild if not, they're assumed to be
|
||||
// allowed to use the bot at a general level.
|
||||
KittyRole role = KittyRole.General;
|
||||
|
||||
if(event.getAuthor().getId() == event.getGuild().getOwner().getUser().getId())
|
||||
{
|
||||
role = KittyRole.Admin;
|
||||
}
|
||||
|
||||
String uid = event.getGuild().getId() + event.getAuthor().getId();
|
||||
synchronized(userCache)
|
||||
{
|
||||
KittyUser cachedUser = userCache.get(uid);
|
||||
if(cachedUser != null)
|
||||
role = cachedUser.getRole();
|
||||
}
|
||||
|
||||
return role;
|
||||
}
|
||||
|
||||
// Explicitly locks: guildCache
|
||||
// Extracts the content rating information it can from the provided event.
|
||||
public static KittyRating extractContentRating(GuildMessageReceivedEvent event)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
// Look up content rating of the guild, returns a safe content rating.
|
||||
KittyRating contentRating = KittyRating.Safe;
|
||||
String uid = event.getGuild().getId();
|
||||
synchronized(guildCache)
|
||||
{
|
||||
KittyGuild cachedGuild = guildCache.get(uid);
|
||||
if(cachedGuild != null)
|
||||
contentRating = cachedGuild.contentRating;
|
||||
}
|
||||
|
||||
return contentRating;
|
||||
}
|
||||
|
||||
// Implicitly locks guild cache by calling ExtractGuild
|
||||
public static KittyChannel extractChannel(GuildMessageReceivedEvent event)
|
||||
{
|
||||
lazyInit();
|
||||
String channelID = event.getChannel().getId();
|
||||
KittyChannel channel = null;
|
||||
|
||||
synchronized(channelCache)
|
||||
{
|
||||
KittyChannel cachedChannel = channelCache.get(channelID);
|
||||
boolean mature;
|
||||
|
||||
if(cachedChannel != null)
|
||||
{
|
||||
channel = cachedChannel;
|
||||
}
|
||||
else
|
||||
{
|
||||
mature = event.getChannel().isNSFW();
|
||||
channel = new KittyChannel(channelID, mature);
|
||||
channelCache.put(channelID, channel);
|
||||
}
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
// Implicitly locks guild cache by calling ExtractRole and ExtractGuild
|
||||
public static KittyUser extractUser(GuildMessageReceivedEvent event)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
String uid = event.getGuild().getId() + event.getAuthor().getId();
|
||||
KittyUser user = null;
|
||||
synchronized(userCache)
|
||||
{
|
||||
KittyUser cachedUser = userCache.get(uid);
|
||||
if(cachedUser != null)
|
||||
{
|
||||
updateUser(cachedUser, event.getMember());
|
||||
user = cachedUser;
|
||||
}
|
||||
else
|
||||
{
|
||||
KittyRole role = extractRole(event);
|
||||
KittyGuild guild = extractGuild(event);
|
||||
|
||||
String name;
|
||||
if(event.getMember().getNickname() == null)
|
||||
name = event.getAuthor().getName();
|
||||
else
|
||||
name = event.getMember().getNickname();
|
||||
|
||||
String discordID = event.getMember().getUser().getId();
|
||||
String avatarID = event.getAuthor().getAvatarUrl();
|
||||
user = new KittyUser(name, guild, role, uid, avatarID, discordID);
|
||||
DatabaseManager.instance.globalRegister(user);
|
||||
userCache.put(uid, user);
|
||||
}
|
||||
}
|
||||
|
||||
if(event.getMessage().getMentionedMembers().isEmpty())
|
||||
return user;
|
||||
|
||||
Member mentioned;
|
||||
for(int i = 0; i < event.getMessage().getMentionedMembers().size(); i++)
|
||||
{
|
||||
mentioned = event.getMessage().getMentionedMembers().get(i);
|
||||
if(mentioned.getNickname() != null)
|
||||
extractUserByJDAUser(event.getGuild().getId(), mentioned.getNickname(),
|
||||
mentioned.getUser().getId(), mentioned.getUser().getAvatarUrl(), mentioned.getUser().getId());
|
||||
else
|
||||
extractUserByJDAUser(event.getGuild().getId(), mentioned.getUser().getName(),
|
||||
mentioned.getUser().getId(), mentioned.getUser().getAvatarUrl(), mentioned.getUser().getId());
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
// TODO: Clean up
|
||||
public static KittyUser extractUserByJDAUser(String guildID, String name, String userID, String avatarID, String discordID)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
String uid = guildID + userID;
|
||||
KittyUser user = null;
|
||||
synchronized(userCache)
|
||||
{
|
||||
KittyUser cachedUser = userCache.get(uid);
|
||||
if(cachedUser != null)
|
||||
{
|
||||
if(name != null)
|
||||
cachedUser.name = name;
|
||||
|
||||
cachedUser.avatarID = avatarID;
|
||||
user = cachedUser;
|
||||
}
|
||||
else
|
||||
{
|
||||
KittyRole role = KittyRole.General;
|
||||
KittyGuild guild = guildCache.get(guildID);
|
||||
user = new KittyUser(name, guild, role, uid, avatarID, discordID);
|
||||
DatabaseManager.instance.globalRegister(user);
|
||||
userCache.put(uid, user);
|
||||
}
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
// There is some redundant lookup occurring. If the user isn't cached yet, then we construct them and cache them.
|
||||
// The assumption is made that the user does, in fact, exist.
|
||||
public static KittyUser getKittyUser(String guildID, String userID)
|
||||
{
|
||||
String uid = guildID + userID;
|
||||
KittyUser user = null;
|
||||
synchronized(userCache)
|
||||
{
|
||||
user = userCache.get(uid);
|
||||
}
|
||||
|
||||
if(user == null)
|
||||
{
|
||||
Guild jdaGuild = kitty.getGuildById(guildID);
|
||||
if(jdaGuild == null) return null;
|
||||
|
||||
Member jdaMember = jdaGuild.getMemberById(userID);
|
||||
if(jdaMember == null) return null;
|
||||
|
||||
User jdaUser = jdaMember.getUser();
|
||||
if(jdaUser == null) return null;
|
||||
|
||||
user = extractUserByJDAUser(guildID, jdaMember.getNickname(), jdaUser.getId(), jdaUser.getAvatarUrl(), jdaUser.getId());
|
||||
updateUser(user, jdaMember);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
// Updates a user's name appropriately based on nickname if available
|
||||
public static void updateUser(KittyUser user, Member member)
|
||||
{
|
||||
if(member.getNickname() == null)
|
||||
{
|
||||
user.name = member.getUser().getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
user.name = member.getNickname();
|
||||
}
|
||||
|
||||
user.avatarID = member.getUser().getAvatarUrl();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////
|
||||
// Construction Methods //
|
||||
//////////////////////////
|
||||
// Builds the core of the bot
|
||||
public static KittyCore constructKittyCore() throws LoginException, InterruptedException
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
// Determine token based on config. Default to test token.
|
||||
String tokenToUse = Ref.TestToken;
|
||||
if(ConfigGlobals.getStartupMode() == KittyStartupMode.Release)
|
||||
tokenToUse = Ref.Token;
|
||||
if(ConfigGlobals.getStartupMode() == KittyStartupMode.PoguRelease)
|
||||
tokenToUse = Ref.PoguToken;
|
||||
|
||||
|
||||
// Construct bot based on token
|
||||
kitty = new JDABuilder(AccountType.BOT)
|
||||
.setToken(tokenToUse).buildBlocking();
|
||||
kitty.getPresence().setGame(Game.playing("with a laser pointer"));
|
||||
kitty.addEventListener(new Main());
|
||||
|
||||
return new KittyCore(kitty);
|
||||
}
|
||||
|
||||
// Default construction of the command manager. In order to remotely resolve command enabling
|
||||
// and disabling, what we do is construct the commands with a localized pair that is checked against
|
||||
// the CommandEnabler object passed in. In theory, we could have multiple CommandManagers, tho we can
|
||||
// only have one CommandEnabler.
|
||||
public static CommandManager constructCommandManager(CommandEnabler commandEnabler)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
if(commandManager == null)
|
||||
commandManager = new CommandManager(commandEnabler);
|
||||
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
// Default database manager construction. It can be constructed
|
||||
// in different ways, and so we construct it outside of the constructor for
|
||||
// the factory since it doesn't have to be present / can be elsewhere.
|
||||
// Effectively we cache the database here.
|
||||
public static DatabaseManager constructDatabaseManager()
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
if(database == null)
|
||||
database = new DatabaseManager();
|
||||
|
||||
return database;
|
||||
}
|
||||
|
||||
public static Stats constructStats(CommandManager manager)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
if(stats == null)
|
||||
stats = new Stats(manager);
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
public static RPManager constructRPManager()
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
if(rpManager == null)
|
||||
rpManager = new RPManager();
|
||||
|
||||
return rpManager;
|
||||
}
|
||||
|
||||
public static PluginManager constructPluginManager()
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
if(pluginManager == null)
|
||||
pluginManager = new PluginManager(Constants.AssetDirectory + "plugins/");
|
||||
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////
|
||||
// Utility Methods //
|
||||
/////////////////////
|
||||
|
||||
// Returns number of cached guilds (does not equal total users in the database, only what's in memory)
|
||||
public static Integer getGuildCount()
|
||||
{ synchronized(guildCache)
|
||||
{
|
||||
return guildCache.size();
|
||||
}
|
||||
}
|
||||
|
||||
// Returns number of cached users (does not equal total users in the database, only what's in memory)
|
||||
public static Integer getUserCount()
|
||||
{ synchronized(userCache)
|
||||
{
|
||||
return userCache.size();
|
||||
}
|
||||
}
|
||||
package core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
//import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
//import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
|
||||
import core.lua.PluginManager;
|
||||
import dataStructures.*;
|
||||
import main.Main;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.JDABuilder;
|
||||
import net.dv8tion.jda.core.entities.*;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import offline.Ref;
|
||||
import utils.AdminControl;
|
||||
//import utils.AudioUtils;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
// NOTE(wisp): Isolated factory to assist with storage and caching if needed.
|
||||
// This also minimizes the number of places JDA interacts with our codebase.
|
||||
// As it stands, if the object name begins with Kitty, it's constructed here.
|
||||
// TODO: Make all methods ID based instead of event based
|
||||
public class ObjectBuilderFactory
|
||||
{
|
||||
// Key: guild string id, Value: guild information
|
||||
private static HashMap<String, KittyGuild> guildCache;
|
||||
|
||||
// Key: channel string id, Value: channel information
|
||||
private static HashMap<String, KittyChannel> channelCache;
|
||||
|
||||
// Key: guild string id + user string id, Value: user information
|
||||
private static HashMap<String, KittyUser> userCache;
|
||||
|
||||
// For tracking and managing object sync
|
||||
private static DatabaseManager database;
|
||||
|
||||
// Stats tracking and whatnot... for setting stats too internally potentially
|
||||
private static Stats stats;
|
||||
|
||||
// RPManger for tracking RP system
|
||||
private static RPManager rpManager;
|
||||
|
||||
// Plugin manager
|
||||
private static PluginManager pluginManager;
|
||||
|
||||
// Command manager
|
||||
private static CommandManager commandManager;
|
||||
|
||||
//Audio track manager
|
||||
// private static AudioPlayerManager audioPlayer = new DefaultAudioPlayerManager();
|
||||
|
||||
// Localization classes - these are singletons, but should be initialized before almost all other
|
||||
// things so their inclusion in the factory is to ensure they're started at the correct time.
|
||||
@SuppressWarnings("unused") private static LocStrings locStrings;
|
||||
@SuppressWarnings("unused") private static LocCommands locCommands;
|
||||
|
||||
// Config
|
||||
@SuppressWarnings("unused") private static Config config;
|
||||
|
||||
// Lazy initialization multithreaded mutex stuff to prevent explosions.
|
||||
// TODO: Investigate using 'synchronized' instead potentially
|
||||
private static boolean hasInitialized;
|
||||
private static Semaphore initMutex = new Semaphore(1);
|
||||
private static JDA kitty;
|
||||
|
||||
// This is it, this is how the lazy init starts!
|
||||
private static void lazyInit()
|
||||
{
|
||||
if(hasInitialized)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
initMutex.acquire();
|
||||
try
|
||||
{
|
||||
// structure initialization
|
||||
// Construct necessary data structures.
|
||||
guildCache = new HashMap<String, KittyGuild>();
|
||||
userCache = new HashMap<String, KittyUser>();
|
||||
channelCache = new HashMap<String, KittyChannel>();
|
||||
database = null;
|
||||
stats = null;
|
||||
|
||||
// Start by reading from things that are external. Because
|
||||
// we require these things to be resolved before the rest of the application,
|
||||
// we place them here.
|
||||
config = new Config();
|
||||
}
|
||||
finally
|
||||
{
|
||||
initMutex.release();
|
||||
hasInitialized = true;
|
||||
}
|
||||
}
|
||||
catch(InterruptedException ie)
|
||||
{
|
||||
GlobalLog.error(LogFilter.Core, "Issue during object builder lazy initialization."
|
||||
+ " The factory was not initialized, and kitty will not be able to continue functionally.");
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
// Extraction Methods //
|
||||
////////////////////////
|
||||
|
||||
// Explicitly locks: guildCache
|
||||
public static KittyGuild extractGuild(GuildMessageReceivedEvent event)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
// Look up the guild. This process can only happen in a single-threaded way
|
||||
// because of the nature of the cache. We wait until the last second to
|
||||
// look up the guild.
|
||||
String uid = event.getGuild().getId();
|
||||
|
||||
List<Emote> emotes = event.getGuild().getEmotes();
|
||||
ArrayList<String> emotesString = new ArrayList<String>();
|
||||
String emote;
|
||||
String emoteFix;
|
||||
for(int i = 0; i < emotes.size(); i++)
|
||||
{
|
||||
emote = emotes.get(i).toString();
|
||||
emoteFix = "<:" + emote.substring(2, emote.indexOf("("));
|
||||
emoteFix += ":" + emote.substring(emote.indexOf("(")+1, emote.length()-1) + ">";
|
||||
emotesString.add(emoteFix);
|
||||
}
|
||||
|
||||
// once we're lazily initialized, we can synchronize w/ the
|
||||
// guildCache object now instead of having to use a mutex.
|
||||
KittyGuild guild = null;
|
||||
synchronized (guildCache)
|
||||
{
|
||||
KittyGuild cachedGuild = guildCache.get(uid);
|
||||
if(cachedGuild != null)
|
||||
{
|
||||
guild = cachedGuild;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Construct a new guild with defaults
|
||||
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString);
|
||||
DatabaseManager.instance.globalRegister(guild);
|
||||
guildCache.put(uid, guild);
|
||||
}
|
||||
}
|
||||
|
||||
return guild;
|
||||
}
|
||||
|
||||
// Explicitly locks: guildCache
|
||||
public static KittyRole extractRole(GuildMessageReceivedEvent event)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
// Looks up the user role. If none is found we check to see if they own
|
||||
// the guild if not, they're assumed to be
|
||||
// allowed to use the bot at a general level.
|
||||
KittyRole role = KittyRole.General;
|
||||
|
||||
if(event.getAuthor().getId() == event.getGuild().getOwner().getUser().getId())
|
||||
{
|
||||
role = KittyRole.Admin;
|
||||
}
|
||||
|
||||
String uid = event.getGuild().getId() + event.getAuthor().getId();
|
||||
synchronized(userCache)
|
||||
{
|
||||
KittyUser cachedUser = userCache.get(uid);
|
||||
if(cachedUser != null)
|
||||
role = cachedUser.getRole();
|
||||
}
|
||||
|
||||
return role;
|
||||
}
|
||||
|
||||
// Explicitly locks: guildCache
|
||||
// Extracts the content rating information it can from the provided event.
|
||||
public static KittyRating extractContentRating(GuildMessageReceivedEvent event)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
// Look up content rating of the guild, returns a safe content rating.
|
||||
KittyRating contentRating = KittyRating.Safe;
|
||||
String uid = event.getGuild().getId();
|
||||
synchronized(guildCache)
|
||||
{
|
||||
KittyGuild cachedGuild = guildCache.get(uid);
|
||||
if(cachedGuild != null)
|
||||
contentRating = cachedGuild.contentRating;
|
||||
}
|
||||
|
||||
return contentRating;
|
||||
}
|
||||
|
||||
// Implicitly locks guild cache by calling ExtractGuild
|
||||
public static KittyChannel extractChannel(GuildMessageReceivedEvent event)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
String channelID = event.getChannel().getId();
|
||||
String guildID = event.getGuild().getId();
|
||||
KittyChannel channel = null;
|
||||
|
||||
synchronized(channelCache)
|
||||
{
|
||||
KittyChannel cachedChannel = channelCache.get(channelID);
|
||||
|
||||
if(cachedChannel != null)
|
||||
{
|
||||
channel = cachedChannel;
|
||||
}
|
||||
else
|
||||
{
|
||||
KittyGuild cachedGuild = guildCache.get(guildID);
|
||||
channel = new KittyChannel(channelID, cachedGuild);
|
||||
channelCache.put(channelID, channel);
|
||||
}
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
// Implicitly locks guild cache by calling ExtractRole and ExtractGuild
|
||||
public static KittyUser extractUser(GuildMessageReceivedEvent event)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
String uid = event.getGuild().getId() + event.getAuthor().getId();
|
||||
KittyUser user = null;
|
||||
synchronized(userCache)
|
||||
{
|
||||
KittyUser cachedUser = userCache.get(uid);
|
||||
if(cachedUser != null)
|
||||
{
|
||||
updateUser(cachedUser, event.getMember());
|
||||
user = cachedUser;
|
||||
}
|
||||
else
|
||||
{
|
||||
KittyRole role = extractRole(event);
|
||||
KittyGuild guild = extractGuild(event);
|
||||
|
||||
String name;
|
||||
if(event.getMember().getNickname() == null)
|
||||
name = event.getAuthor().getName();
|
||||
else
|
||||
name = event.getMember().getNickname();
|
||||
|
||||
String discordID = event.getMember().getUser().getId();
|
||||
String avatarID = event.getAuthor().getAvatarUrl();
|
||||
user = new KittyUser(name, guild, role, uid, avatarID, discordID);
|
||||
DatabaseManager.instance.globalRegister(user);
|
||||
userCache.put(uid, user);
|
||||
}
|
||||
}
|
||||
|
||||
if(event.getMessage().getMentionedMembers().isEmpty())
|
||||
return user;
|
||||
|
||||
Member mentioned;
|
||||
for(int i = 0; i < event.getMessage().getMentionedMembers().size(); i++)
|
||||
{
|
||||
mentioned = event.getMessage().getMentionedMembers().get(i);
|
||||
if(mentioned.getNickname() != null)
|
||||
extractUserByJDAUser(event.getGuild().getId(), mentioned.getNickname(),
|
||||
mentioned.getUser().getId(), mentioned.getUser().getAvatarUrl(), mentioned.getUser().getId());
|
||||
else
|
||||
extractUserByJDAUser(event.getGuild().getId(), mentioned.getUser().getName(),
|
||||
mentioned.getUser().getId(), mentioned.getUser().getAvatarUrl(), mentioned.getUser().getId());
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
// TODO: Clean up
|
||||
public static KittyUser extractUserByJDAUser(String guildID, String name, String userID, String avatarID, String discordID)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
String uid = guildID + userID;
|
||||
KittyUser user = null;
|
||||
synchronized(userCache)
|
||||
{
|
||||
KittyUser cachedUser = userCache.get(uid);
|
||||
if(cachedUser != null)
|
||||
{
|
||||
if(name != null)
|
||||
cachedUser.name = name;
|
||||
|
||||
cachedUser.avatarID = avatarID;
|
||||
user = cachedUser;
|
||||
}
|
||||
else
|
||||
{
|
||||
KittyRole role = KittyRole.General;
|
||||
KittyGuild guild = guildCache.get(guildID);
|
||||
user = new KittyUser(name, guild, role, uid, avatarID, discordID);
|
||||
DatabaseManager.instance.globalRegister(user);
|
||||
userCache.put(uid, user);
|
||||
}
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
// There is some redundant lookup occurring. If the user isn't cached yet, then we construct them and cache them.
|
||||
// The assumption is made that the user does, in fact, exist.
|
||||
public static KittyUser getKittyUser(String guildID, String userID)
|
||||
{
|
||||
String uid = guildID + userID;
|
||||
KittyUser user = null;
|
||||
synchronized(userCache)
|
||||
{
|
||||
user = userCache.get(uid);
|
||||
}
|
||||
|
||||
if(user == null)
|
||||
{
|
||||
Guild jdaGuild = kitty.getGuildById(guildID);
|
||||
if(jdaGuild == null) return null;
|
||||
|
||||
Member jdaMember = jdaGuild.getMemberById(userID);
|
||||
if(jdaMember == null) return null;
|
||||
|
||||
User jdaUser = jdaMember.getUser();
|
||||
if(jdaUser == null) return null;
|
||||
|
||||
user = extractUserByJDAUser(guildID, jdaMember.getNickname(), jdaUser.getId(), jdaUser.getAvatarUrl(), jdaUser.getId());
|
||||
updateUser(user, jdaMember);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
// Updates a user's name appropriately based on nickname if available
|
||||
public static void updateUser(KittyUser user, Member member)
|
||||
{
|
||||
if(member.getNickname() == null)
|
||||
{
|
||||
user.name = member.getUser().getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
user.name = member.getNickname();
|
||||
}
|
||||
|
||||
user.avatarID = member.getUser().getAvatarUrl();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////
|
||||
// Construction Methods //
|
||||
//////////////////////////
|
||||
// Builds the core of the bot
|
||||
public static KittyCore constructKittyCore() throws LoginException, InterruptedException
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
kitty = new JDABuilder(AccountType.BOT).setToken(Ref.TestToken).buildBlocking();
|
||||
kitty.getPresence().setGame(Game.playing("with digital yarn"));
|
||||
kitty.addEventListener(new Main());
|
||||
|
||||
return new KittyCore(kitty);
|
||||
}
|
||||
|
||||
// Default construction of the command manager. In order to remotely resolve command enabling
|
||||
// and disabling, what we do is construct the commands with a localized pair that is checked against
|
||||
// the CommandEnabler object passed in. In theory, we could have multiple CommandManagers, tho we can
|
||||
// only have one CommandEnabler.
|
||||
public static CommandManager constructCommandManager(CommandEnabler commandEnabler)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
if(commandManager == null)
|
||||
commandManager = new CommandManager(commandEnabler);
|
||||
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
// Default database manager construction. It can be constructed
|
||||
// in different ways, and so we construct it outside of the constructor for
|
||||
// the factory since it doesn't have to be present / can be elsewhere.
|
||||
// Effectively we cache the database here.
|
||||
public static DatabaseManager constructDatabaseManager()
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
if(database == null)
|
||||
database = new DatabaseManager();
|
||||
|
||||
return database;
|
||||
}
|
||||
|
||||
public static Stats constructStats(CommandManager manager)
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
if(stats == null)
|
||||
stats = new Stats(manager);
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
public static RPManager constructRPManager()
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
if(rpManager == null)
|
||||
rpManager = new RPManager();
|
||||
|
||||
return rpManager;
|
||||
}
|
||||
|
||||
public static PluginManager constructPluginManager()
|
||||
{
|
||||
lazyInit();
|
||||
|
||||
if(pluginManager == null)
|
||||
pluginManager = new PluginManager(Constants.AssetDirectory + "plugins/");
|
||||
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////
|
||||
// Utility Methods //
|
||||
/////////////////////
|
||||
|
||||
// Returns number of cached guilds (does not equal total users in the database, only what's in memory)
|
||||
public static Integer getGuildCount()
|
||||
{ synchronized(guildCache)
|
||||
{
|
||||
return guildCache.size();
|
||||
}
|
||||
}
|
||||
|
||||
// Returns number of cached users (does not equal total users in the database, only what's in memory)
|
||||
public static Integer getUserCount()
|
||||
{ synchronized(userCache)
|
||||
{
|
||||
return userCache.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.UserInput;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
public class SubCommandFramework
|
||||
{
|
||||
@@ -41,10 +42,14 @@ public class SubCommandFramework
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
GlobalLog.error(LogFilter.Command, e);
|
||||
|
||||
String help = Stats.instance.getHelpText(input.key);
|
||||
|
||||
if(help != null)
|
||||
return new SubCommandFormattable(help);
|
||||
return new SubCommandFormattable("Something has gone very wrong.");
|
||||
|
||||
return new SubCommandFormattable("Whoops! Internal subcommand error!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +1,40 @@
|
||||
package dataStructures;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
// This is a structure representing an image response for handing around.
|
||||
// This is a structure representing an image reponse for handing around.
|
||||
public class GenericImage
|
||||
{
|
||||
private KittyEmbed response= new KittyEmbed();
|
||||
private String artist;
|
||||
private String postURL;
|
||||
private String imageURL;
|
||||
|
||||
public GenericImage(String artist, String postURL, String imageURL)
|
||||
{
|
||||
response.authorText = null;
|
||||
response.color = new Color(0,0,0);
|
||||
this.artist = artist;
|
||||
this.postURL = postURL;
|
||||
this.imageURL = imageURL;
|
||||
}
|
||||
|
||||
public void editArtist(String artist)
|
||||
{
|
||||
response.authorText = artist;
|
||||
}
|
||||
|
||||
public void editAuthorImage(String URL)
|
||||
{
|
||||
response.authorImage = URL;
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
public void editPostURL(String postURL)
|
||||
{
|
||||
response.authorLink = postURL;
|
||||
this.postURL = postURL;
|
||||
}
|
||||
|
||||
public void editImageURL(String imageURL)
|
||||
{
|
||||
response.imageURL = imageURL;
|
||||
this.imageURL = imageURL;
|
||||
}
|
||||
|
||||
public void editDescriptionText(String score)
|
||||
public String toString()
|
||||
{
|
||||
response.descriptionText = score;
|
||||
}
|
||||
|
||||
public void editFooterText(String tags)
|
||||
{
|
||||
response.footerText = tags;
|
||||
}
|
||||
|
||||
public KittyEmbed output()
|
||||
{
|
||||
return response;
|
||||
}
|
||||
|
||||
public boolean isValid()
|
||||
{
|
||||
if(response.title != null)
|
||||
return true;
|
||||
return false;
|
||||
if(imageURL.isEmpty())
|
||||
{
|
||||
return "I couldn't find anything! Please try again!";
|
||||
}
|
||||
return "Artist: " + artist + "\n<" + postURL.trim() + ">\n" + imageURL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,31 @@
|
||||
package dataStructures;
|
||||
|
||||
|
||||
public class KittyChannel
|
||||
{
|
||||
public String uniqueID;
|
||||
public boolean mature;
|
||||
|
||||
public KittyChannel(String uniqueID, boolean mature)
|
||||
{
|
||||
//super(uniqueID);
|
||||
this.uniqueID = uniqueID;
|
||||
this.mature = false;
|
||||
}
|
||||
}
|
||||
package dataStructures;
|
||||
|
||||
//import core.DatabaseTrackedObject;
|
||||
|
||||
public class KittyChannel //extends DatabaseTrackedObject
|
||||
{
|
||||
public String uniqueID;
|
||||
public KittyGuild guild;
|
||||
|
||||
//public KittyRating rating;
|
||||
//public bool isVoice;
|
||||
|
||||
public KittyChannel(String uniqueID, KittyGuild guild)
|
||||
{
|
||||
//super(uniqueID);
|
||||
this.uniqueID = uniqueID;
|
||||
this.guild = guild;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String serialize()
|
||||
// {
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void deSerialzie(String string)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
+173
-182
@@ -1,182 +1,173 @@
|
||||
package dataStructures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import core.DatabaseManager;
|
||||
import core.DatabaseTrackedObject;
|
||||
import utils.AdminControl;
|
||||
import utils.audio.AudioUtils;
|
||||
|
||||
// Context for a given guild for kittybot. Primarily designed to hold guild-specific settings.
|
||||
public class KittyGuild extends DatabaseTrackedObject
|
||||
{
|
||||
// Variables
|
||||
public final String uniqueID;
|
||||
public KittyRating contentRating;
|
||||
public KittyUser guildOwner;
|
||||
public boolean polling;
|
||||
public String poll;
|
||||
public boolean raffling;
|
||||
public int raffleCost;
|
||||
public ArrayList<String> hasVoted = new ArrayList<String>();
|
||||
public ArrayList<String> emoji = new ArrayList<String>();
|
||||
public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>();
|
||||
public HashMap <Long, KittyChannel> channels;
|
||||
public AdminControl control;
|
||||
public AudioUtils audio;
|
||||
public ArrayList <KittyUser> raffleUsersUnchosen = new ArrayList<KittyUser>();
|
||||
public ArrayList <KittyUser> raffleUsersChosen = new ArrayList<KittyUser>();
|
||||
|
||||
// Database synced info
|
||||
private final String roleListName = "guildRoles";
|
||||
public final KittyTrackedVector roleList;
|
||||
|
||||
private final String beansName = "guildBeans";
|
||||
public final KittyTrackedLong beans;
|
||||
|
||||
private String commandIndicator;
|
||||
|
||||
private void registerTrackedObjects()
|
||||
{
|
||||
DatabaseManager.instance.globalRegister(roleList);
|
||||
DatabaseManager.instance.globalRegister(beans);
|
||||
}
|
||||
|
||||
// Default content for a guild
|
||||
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji,
|
||||
AudioUtils audio, HashMap<Long, KittyChannel> channels)
|
||||
{
|
||||
|
||||
super(uniqueID);
|
||||
this.uniqueID = uniqueID;
|
||||
roleList = new KittyTrackedVector(roleListName, uniqueID);
|
||||
beans = new KittyTrackedLong(beansName, uniqueID);
|
||||
registerTrackedObjects();
|
||||
|
||||
control = adminControl;
|
||||
this.contentRating = KittyRating.Safe;
|
||||
this.polling = false;
|
||||
this.emoji = emoji;
|
||||
this.audio = audio;
|
||||
this.channels = channels;
|
||||
setCommandIndicator("!");
|
||||
}
|
||||
|
||||
// Explicit constructor
|
||||
public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner,
|
||||
String uniqueID, AudioUtils audio, HashMap<Long, KittyChannel> channels)
|
||||
{
|
||||
super(uniqueID);
|
||||
this.uniqueID = uniqueID;
|
||||
roleList = new KittyTrackedVector(roleListName, uniqueID);
|
||||
beans = new KittyTrackedLong(beansName, uniqueID);
|
||||
registerTrackedObjects();
|
||||
|
||||
setCommandIndicator(commandIndicator);
|
||||
this.contentRating = contentRating;
|
||||
this.polling = false;
|
||||
this.guildOwner = guildOwner;
|
||||
this.audio = audio;
|
||||
this.channels = channels;
|
||||
}
|
||||
|
||||
public String startPoll(String poll)
|
||||
{
|
||||
polling = true;
|
||||
this.poll = poll;
|
||||
return "Poll `" + poll + "` started! Don't forget to add choices with `!poll choice`~";
|
||||
}
|
||||
|
||||
public String addChoiceToPoll(String choice)
|
||||
{
|
||||
choices.add(new KittyPoll(choice));
|
||||
return "Added `" + choice + "` to poll!";
|
||||
}
|
||||
|
||||
public String endPoll()
|
||||
{
|
||||
choices.clear();
|
||||
hasVoted.clear();
|
||||
this.polling = false;
|
||||
poll = null;
|
||||
return "Poll ended!";
|
||||
}
|
||||
|
||||
//Raffle methods
|
||||
public boolean startRaffle(int beanCost)
|
||||
{
|
||||
if(raffling)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
raffleCost = beanCost;
|
||||
raffling = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean endRaffle()
|
||||
{
|
||||
if(raffling)
|
||||
{
|
||||
raffleCost = 0;
|
||||
raffling = false;
|
||||
raffleUsersChosen.removeAll(raffleUsersChosen);
|
||||
raffleUsersUnchosen.removeAll(raffleUsersUnchosen);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean joinRaffle(KittyUser user)
|
||||
{
|
||||
if(!raffleUsersChosen.contains(user) && !raffleUsersUnchosen.contains(user) && user.getBeans() > raffleCost && raffling)
|
||||
{
|
||||
user.changeBeans(-raffleCost);
|
||||
raffleUsersUnchosen.add(user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public KittyUser chooseRaffleWinner()
|
||||
{
|
||||
if(!raffleUsersUnchosen.isEmpty())
|
||||
{
|
||||
KittyUser chosen = raffleUsersUnchosen.get((int) (Math.random() * raffleUsersUnchosen.size()));
|
||||
raffleUsersUnchosen.remove(chosen);
|
||||
raffleUsersChosen.add(chosen);
|
||||
return chosen;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize()
|
||||
{
|
||||
return commandIndicator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialzie(String string)
|
||||
{
|
||||
if(string == null || string.length() == 0)
|
||||
setCommandIndicator("!");
|
||||
else
|
||||
setCommandIndicator(string);
|
||||
}
|
||||
|
||||
public String getCommandIndicator()
|
||||
{
|
||||
return commandIndicator;
|
||||
}
|
||||
|
||||
public void setCommandIndicator(String newIndicator)
|
||||
{
|
||||
if(newIndicator != commandIndicator)
|
||||
{
|
||||
commandIndicator = newIndicator;
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
package dataStructures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import core.DatabaseManager;
|
||||
import core.DatabaseTrackedObject;
|
||||
import utils.AdminControl;
|
||||
import utils.AudioUtils;
|
||||
|
||||
// Context for a given guild for kittybot. Primarily designed to hold guild-specific settings.
|
||||
public class KittyGuild extends DatabaseTrackedObject
|
||||
{
|
||||
// Variables
|
||||
public final String uniqueID;
|
||||
public KittyRating contentRating;
|
||||
public KittyUser guildOwner;
|
||||
public boolean polling;
|
||||
public String poll;
|
||||
public boolean raffling;
|
||||
public int raffleCost;
|
||||
public ArrayList<String> hasVoted = new ArrayList<String>();
|
||||
public ArrayList<String> emoji = new ArrayList<String>();
|
||||
public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>();
|
||||
public AdminControl control;
|
||||
public AudioUtils audio;
|
||||
public ArrayList <KittyUser> raffleUsersUnchosen = new ArrayList<KittyUser>();
|
||||
public ArrayList <KittyUser> raffleUsersChosen = new ArrayList<KittyUser>();
|
||||
|
||||
// Database synced info
|
||||
private final String roleListName = "guildRoles";
|
||||
public final KittyTrackedVector roleList;
|
||||
|
||||
private final String beansName = "guildBeans";
|
||||
public final KittyTrackedLong beans;
|
||||
|
||||
private String commandIndicator;
|
||||
|
||||
private void registerTrackedObjects()
|
||||
{
|
||||
DatabaseManager.instance.globalRegister(roleList);
|
||||
DatabaseManager.instance.globalRegister(beans);
|
||||
}
|
||||
|
||||
// Default content for a guild
|
||||
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji)
|
||||
{
|
||||
super(uniqueID);
|
||||
this.uniqueID = uniqueID;
|
||||
roleList = new KittyTrackedVector(roleListName, uniqueID);
|
||||
beans = new KittyTrackedLong(beansName, uniqueID);
|
||||
registerTrackedObjects();
|
||||
|
||||
control = adminControl;
|
||||
this.contentRating = KittyRating.Safe;
|
||||
this.polling = false;
|
||||
this.emoji = emoji;
|
||||
setCommandIndicator("!");
|
||||
}
|
||||
|
||||
// Explicit constructor
|
||||
public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner, String uniqueID)
|
||||
{
|
||||
super(uniqueID);
|
||||
this.uniqueID = uniqueID;
|
||||
roleList = new KittyTrackedVector(roleListName, uniqueID);
|
||||
beans = new KittyTrackedLong(beansName, uniqueID);
|
||||
registerTrackedObjects();
|
||||
|
||||
setCommandIndicator(commandIndicator);
|
||||
this.contentRating = contentRating;
|
||||
this.polling = false;
|
||||
this.guildOwner = guildOwner;
|
||||
}
|
||||
|
||||
public String startPoll(String poll)
|
||||
{
|
||||
polling = true;
|
||||
this.poll = poll;
|
||||
return "Poll `" + poll + "` started! Don't forget to add choices with `!poll choice`~";
|
||||
}
|
||||
|
||||
public String addChoiceToPoll(String choice)
|
||||
{
|
||||
choices.add(new KittyPoll(choice));
|
||||
return "Added `" + choice + "` to poll!";
|
||||
}
|
||||
|
||||
public String endPoll()
|
||||
{
|
||||
choices.clear();
|
||||
hasVoted.clear();
|
||||
this.polling = false;
|
||||
poll = null;
|
||||
return "Poll ended!";
|
||||
}
|
||||
|
||||
//Raffle methods
|
||||
public boolean startRaffle(int beanCost)
|
||||
{
|
||||
if(raffling)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
raffleCost = beanCost;
|
||||
raffling = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean endRaffle()
|
||||
{
|
||||
if(raffling)
|
||||
{
|
||||
raffleCost = 0;
|
||||
raffling = false;
|
||||
raffleUsersChosen.removeAll(raffleUsersChosen);
|
||||
raffleUsersUnchosen.removeAll(raffleUsersUnchosen);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean joinRaffle(KittyUser user)
|
||||
{
|
||||
if(!raffleUsersChosen.contains(user) && !raffleUsersUnchosen.contains(user) && user.getBeans() > raffleCost && raffling)
|
||||
{
|
||||
user.changeBeans(raffleCost);
|
||||
raffleUsersUnchosen.add(user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public KittyUser chooseRaffleWinner()
|
||||
{
|
||||
if(!raffleUsersUnchosen.isEmpty())
|
||||
{
|
||||
KittyUser chosen = raffleUsersUnchosen.get((int) (Math.random() * raffleUsersUnchosen.size()));
|
||||
raffleUsersUnchosen.remove(chosen);
|
||||
raffleUsersChosen.add(chosen);
|
||||
return chosen;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize()
|
||||
{
|
||||
return commandIndicator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deSerialzie(String string)
|
||||
{
|
||||
if(string == null || string.length() == 0)
|
||||
setCommandIndicator("!");
|
||||
else
|
||||
setCommandIndicator(string);
|
||||
}
|
||||
|
||||
public String getCommandIndicator()
|
||||
{
|
||||
return commandIndicator;
|
||||
}
|
||||
|
||||
public void setCommandIndicator(String newIndicator)
|
||||
{
|
||||
if(newIndicator != commandIndicator)
|
||||
{
|
||||
commandIndicator = newIndicator;
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package dataStructures;
|
||||
|
||||
public enum KittyStartupMode
|
||||
{
|
||||
Dev(1), Release(2), PoguRelease(3);
|
||||
|
||||
private final int value;
|
||||
private KittyStartupMode(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package dataStructures;
|
||||
|
||||
public class KittyTrackedResponse
|
||||
{
|
||||
// TODO: Fill this out!
|
||||
}
|
||||
+214
-153
@@ -1,153 +1,214 @@
|
||||
package dataStructures;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.MessageBuilder;
|
||||
import net.dv8tion.jda.core.entities.TextChannel;
|
||||
import net.dv8tion.jda.core.events.message.guild.*;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
// This isn't constructed with the factory at this time, mostly because we need it
|
||||
// to handle all the response queue behavior and everything internally. So long as
|
||||
// commands aren't exposed to the GuildMessageReceivedEvent then we should be fine.
|
||||
public class Response
|
||||
{
|
||||
// Variables
|
||||
private GuildMessageReceivedEvent event;
|
||||
private final int discordMessageMax = 2000;
|
||||
private final int kittyMessageMax = 1950;
|
||||
private JDA kitty;
|
||||
|
||||
// Constructor
|
||||
public Response(GuildMessageReceivedEvent event, KittyCore kitty)
|
||||
{
|
||||
this.event = event;
|
||||
this.kitty = kitty.jda;
|
||||
}
|
||||
|
||||
// Builds a nicely formatted embedded message based on information provided
|
||||
public void send(KittyEmbed embedInfo)
|
||||
{
|
||||
EmbedBuilder embed = new EmbedBuilder();
|
||||
|
||||
if(embedInfo.title != null && !embedInfo.title.isEmpty())
|
||||
{
|
||||
embed.setTitle(embedInfo.title);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have to set the title to at least something that's not empty.
|
||||
// By defualt, this creates nothing really visible.
|
||||
embed.setTitle(" ");
|
||||
}
|
||||
|
||||
if(embedInfo.color != null)
|
||||
embed.setColor(embedInfo.color);
|
||||
|
||||
if(embedInfo.descriptionText != null)
|
||||
embed.setDescription(embedInfo.descriptionText);
|
||||
|
||||
if(embedInfo.footerText != null)
|
||||
embed.setFooter(embedInfo.footerText, null);
|
||||
|
||||
if(embedInfo.authorImage != null || embedInfo.authorLink != null || embedInfo.authorText != null)
|
||||
embed.setAuthor(embedInfo.authorText, embedInfo.authorLink, embedInfo.authorImage);
|
||||
|
||||
if(embedInfo.imageURL != null)
|
||||
embed.setImage(embedInfo.imageURL);
|
||||
|
||||
if(embedInfo.thumbnailURL != null && embedInfo.thumbnailURL.contains("attachment://"))
|
||||
{
|
||||
// This is the case where you have a thumbnail image, but you want it to be a local file.
|
||||
// TODO: Make this more generic. Consider message builder for the entire thing.
|
||||
String thumbPath = embedInfo.thumbnailURL;
|
||||
String thumbName = thumbPath.replace("attachment://", "");
|
||||
|
||||
// Build the message and send if the file is valid
|
||||
MessageBuilder message = new MessageBuilder();
|
||||
embed.setThumbnail(thumbPath);
|
||||
message.setEmbed(embed.build());
|
||||
|
||||
File thumbImage = new File(thumbName);
|
||||
if(thumbImage.exists())
|
||||
{
|
||||
event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(embedInfo.thumbnailURL != null)
|
||||
embed.setThumbnail(embedInfo.thumbnailURL);
|
||||
|
||||
event.getChannel().sendMessage(embed.build()).queue();
|
||||
}
|
||||
}
|
||||
|
||||
// Queues a standard text-based message response to the channel that issued the command.
|
||||
public void send(String toRespondWith)
|
||||
{
|
||||
GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
|
||||
if(toRespondWith.length() > discordMessageMax)
|
||||
{
|
||||
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
||||
}
|
||||
else
|
||||
{
|
||||
event.getChannel().sendMessage(toRespondWith).queue();
|
||||
}
|
||||
}
|
||||
|
||||
// Queues a standard text-based message response to the specified channel.
|
||||
public void sendToChannel(String toRespondWith, String channelID)
|
||||
{
|
||||
TextChannel channel;
|
||||
channel = kitty.getTextChannelById(Long.parseLong(channelID));
|
||||
if(toRespondWith.length() > discordMessageMax)
|
||||
{
|
||||
channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
||||
}
|
||||
else
|
||||
{
|
||||
channel.sendMessage(toRespondWith).queue();
|
||||
}
|
||||
}
|
||||
|
||||
// Immediately dispatches the message to the channel that issued the command.
|
||||
public void sendImmediate(String toRespondWith)
|
||||
{
|
||||
GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
|
||||
if(toRespondWith.length() > discordMessageMax)
|
||||
{
|
||||
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!");
|
||||
}
|
||||
else
|
||||
{
|
||||
event.getChannel().sendMessage(toRespondWith).complete();
|
||||
}
|
||||
}
|
||||
|
||||
// Queues a file response to the channel that issued the command.
|
||||
public void sendFile(File toRespondWith, String extension)
|
||||
{
|
||||
GlobalLog.log(LogFilter.Response, "Sending file response");
|
||||
event.getChannel().sendFile(toRespondWith, "return." + extension).queue();
|
||||
}
|
||||
|
||||
// Queues an input stream response to the channel that issued the command.
|
||||
public void sendFile(InputStream in, String extension)
|
||||
{
|
||||
GlobalLog.log(LogFilter.Response, "Sending input stream response");
|
||||
event.getChannel().sendFile(in, "return." + extension).queue();
|
||||
}
|
||||
|
||||
//Sends Kittybot as an object
|
||||
//WARNING: THIS WILL EDIT THE ENTIRE BOT, DO NOT USE LIGHTLY
|
||||
public JDA getKitty()
|
||||
{
|
||||
return kitty;
|
||||
}
|
||||
}
|
||||
package dataStructures;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.MessageBuilder;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.entities.TextChannel;
|
||||
import net.dv8tion.jda.core.events.message.guild.*;
|
||||
import net.dv8tion.jda.core.requests.restaction.MessageAction;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
// This isn't constructed with the factory at this time, mostly because we need it
|
||||
// to handle all the response queue behavior and everything internally. So long as
|
||||
// commands aren't exposed to the GuildMessageReceivedEvent then we should be fine.
|
||||
public class Response
|
||||
{
|
||||
// Last message
|
||||
private static Message lastSentMessage = new MessageBuilder().append(" ").build();
|
||||
|
||||
// Variables
|
||||
private GuildMessageReceivedEvent event;
|
||||
private final int discordMessageMax = 2000;
|
||||
private final int kittyMessageMax = 1950;
|
||||
private JDA kitty;
|
||||
|
||||
// Constructor
|
||||
public Response(GuildMessageReceivedEvent event, KittyCore kitty)
|
||||
{
|
||||
this.event = event;
|
||||
this.kitty = kitty.jda;
|
||||
}
|
||||
|
||||
// Builds a nicely formatted embedded message based on information provided
|
||||
public void send(KittyEmbed embedInfo)
|
||||
{
|
||||
EmbedBuilder embed = new EmbedBuilder();
|
||||
|
||||
if(embedInfo.title != null && !embedInfo.title.isEmpty())
|
||||
{
|
||||
embed.setTitle(embedInfo.title);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have to set the title to at least something that's not empty.
|
||||
// By defualt, this creates nothing really visible.
|
||||
embed.setTitle(" ");
|
||||
}
|
||||
|
||||
if(embedInfo.color != null)
|
||||
embed.setColor(embedInfo.color);
|
||||
|
||||
if(embedInfo.descriptionText != null)
|
||||
embed.setDescription(embedInfo.descriptionText);
|
||||
|
||||
if(embedInfo.footerText != null)
|
||||
embed.setFooter(embedInfo.footerText, null);
|
||||
|
||||
if(embedInfo.authorImage != null || embedInfo.authorLink != null || embedInfo.authorText != null)
|
||||
embed.setAuthor(embedInfo.authorText, embedInfo.authorLink, embedInfo.authorImage);
|
||||
|
||||
if(embedInfo.imageURL != null)
|
||||
embed.setImage(embedInfo.imageURL);
|
||||
|
||||
if(embedInfo.thumbnailURL != null && embedInfo.thumbnailURL.contains("attachment://"))
|
||||
{
|
||||
// This is the case where you have a thumbnail image, but you want it to be a local file.
|
||||
// TODO: Make this more generic. Consider message builder for the entire thing.
|
||||
String thumbPath = embedInfo.thumbnailURL;
|
||||
String thumbName = thumbPath.replace("attachment://", "");
|
||||
|
||||
// Build the message and send if the file is valid
|
||||
MessageBuilder message = new MessageBuilder();
|
||||
embed.setThumbnail(thumbPath);
|
||||
message.setEmbed(embed.build());
|
||||
|
||||
File thumbImage = new File(thumbName);
|
||||
if(thumbImage.exists())
|
||||
{
|
||||
respond(event.getChannel().sendFile(thumbImage, thumbName, message.build()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(embedInfo.thumbnailURL != null)
|
||||
embed.setThumbnail(embedInfo.thumbnailURL);
|
||||
|
||||
respond(event.getChannel().sendMessage(embed.build()));
|
||||
}
|
||||
}
|
||||
|
||||
// Queues a standard text-based message response to the channel that issued the command.
|
||||
public void send(String toRespondWith)
|
||||
{
|
||||
GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
|
||||
if(toRespondWith.length() > discordMessageMax)
|
||||
{
|
||||
respond(event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
respond(event.getChannel().sendMessage(toRespondWith));
|
||||
}
|
||||
}
|
||||
|
||||
// Queues a standard text-based message response to the specified channel.
|
||||
public void sendToChannel(String toRespondWith, String channelID)
|
||||
{
|
||||
TextChannel channel;
|
||||
channel = kitty.getTextChannelById(Long.parseLong(channelID));
|
||||
if(toRespondWith.length() > discordMessageMax)
|
||||
{
|
||||
respond(channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
respond(channel.sendMessage(toRespondWith));
|
||||
}
|
||||
}
|
||||
|
||||
// Immediately dispatches the message to the channel that issued the command.
|
||||
public void sendImmediate(String toRespondWith)
|
||||
{
|
||||
GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
|
||||
if(toRespondWith.length() > discordMessageMax)
|
||||
{
|
||||
respondImmediate(event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
respondImmediate(event.getChannel().sendMessage(toRespondWith));
|
||||
}
|
||||
}
|
||||
|
||||
// Queues a file response to the channel that issued the command.
|
||||
public void sendFile(File toRespondWith, String extension)
|
||||
{
|
||||
GlobalLog.log(LogFilter.Response, "Sending file response");
|
||||
respond(event.getChannel().sendFile(toRespondWith, "return." + extension));
|
||||
}
|
||||
|
||||
// Queues an input stream response to the channel that issued the command.
|
||||
public void sendFile(InputStream in, String extension)
|
||||
{
|
||||
GlobalLog.log(LogFilter.Response, "Sending input stream response");
|
||||
respond(event.getChannel().sendFile(in, "return." + extension));
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
// Message Management //
|
||||
////////////////////////
|
||||
|
||||
// Blast that message out and don't do anything else on this thread until sent.
|
||||
// BLOCKING
|
||||
protected void respondImmediate(MessageAction toSend)
|
||||
{
|
||||
synchronized(lastSentMessage)
|
||||
{
|
||||
lastSentMessage = toSend.complete();
|
||||
}
|
||||
}
|
||||
|
||||
// thread-safe assignment. Assignment may technically be out of order, so keep that in mind.
|
||||
// ASYNC
|
||||
protected void respond(MessageAction toSend)
|
||||
{
|
||||
toSend.submit().whenComplete((msg, err) -> {
|
||||
synchronized(lastSentMessage)
|
||||
{
|
||||
lastSentMessage = msg;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// BLOCKING
|
||||
public static String GetLastMessage()
|
||||
{
|
||||
synchronized(lastSentMessage)
|
||||
{
|
||||
if(lastSentMessage == null)
|
||||
return null;
|
||||
|
||||
return lastSentMessage.getContentRaw();
|
||||
}
|
||||
}
|
||||
|
||||
// ASYNC
|
||||
public static void GetLastMessage(Consumer<String> consumer)
|
||||
{
|
||||
synchronized(lastSentMessage)
|
||||
{
|
||||
if(lastSentMessage == null)
|
||||
return;
|
||||
|
||||
consumer.accept(lastSentMessage.getContentRaw());
|
||||
}
|
||||
}
|
||||
|
||||
// BLOCKING
|
||||
public static void EditLastMessage(String newContent)
|
||||
{
|
||||
synchronized(lastSentMessage)
|
||||
{
|
||||
if(lastSentMessage != null)
|
||||
{
|
||||
lastSentMessage.editMessage(newContent).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import core.ObjectBuilderFactory;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
|
||||
public class UserInput
|
||||
@@ -14,6 +15,7 @@ public class UserInput
|
||||
public KittyUser [] mentions;
|
||||
private boolean isValid;
|
||||
public String message;
|
||||
private Message internalJDAMessage;
|
||||
|
||||
// NOTE(wisp): Designed to parse a string as it's constructed.
|
||||
// If a user enters the command "!ping some stuff here :D"
|
||||
@@ -25,6 +27,7 @@ public class UserInput
|
||||
// The CommandIndicator and spaces between the key and args are dropped.
|
||||
public UserInput(GuildMessageReceivedEvent event, KittyGuild guildContext)
|
||||
{
|
||||
this.internalJDAMessage = event.getMessage();
|
||||
String toParse = event.getMessage().getContentRaw();
|
||||
message = toParse;
|
||||
|
||||
@@ -61,6 +64,18 @@ public class UserInput
|
||||
}
|
||||
}
|
||||
|
||||
// Copy Constructor
|
||||
public UserInput(UserInput other)
|
||||
{
|
||||
this.key = other.key;
|
||||
this.args = other.args;
|
||||
this.mentions = other.mentions;
|
||||
this.isValid = other.isValid;
|
||||
this.message = other.message;
|
||||
this.internalJDAMessage = other.internalJDAMessage;
|
||||
}
|
||||
|
||||
|
||||
// Used for injecting direct commands from plugins
|
||||
public UserInput(String input, KittyGuild contextGuild)
|
||||
{
|
||||
@@ -75,6 +90,12 @@ public class UserInput
|
||||
return isValid;
|
||||
}
|
||||
|
||||
// This deletes the input that was originally sent
|
||||
public void deleteOriginInput()
|
||||
{
|
||||
internalJDAMessage.delete().queue();
|
||||
}
|
||||
|
||||
// Finds first whitespace in the string
|
||||
private int findFirstWhitespace(String str)
|
||||
{
|
||||
|
||||
+124
-135
@@ -1,136 +1,125 @@
|
||||
package main;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
||||
|
||||
import core.CharacterManager;
|
||||
import core.CommandEnabler;
|
||||
import core.CommandManager;
|
||||
import core.DatabaseManager;
|
||||
import core.ObjectBuilderFactory;
|
||||
import core.RPManager;
|
||||
import core.Stats;
|
||||
import core.lua.PluginManager;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyCore;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.JDABuilder;
|
||||
import net.dv8tion.jda.core.audio.AudioSendHandler;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.TextChannel;
|
||||
import net.dv8tion.jda.core.entities.VoiceChannel;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.core.managers.AudioManager;
|
||||
import offline.Ref;
|
||||
import utils.GlobalLog;
|
||||
|
||||
// http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation.
|
||||
// This is the application entry point, and bot startup location!
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Main extends ListenerAdapter
|
||||
{
|
||||
// Variables and bot specific objects
|
||||
private static KittyCore kittyCore;
|
||||
private static DatabaseManager databaseManager;
|
||||
private static CommandManager commandManager;
|
||||
private static Stats stats;
|
||||
private static RPManager rpManager;
|
||||
private static PluginManager pluginManager;
|
||||
private static CharacterManager charManager;
|
||||
|
||||
|
||||
// Initialization and setup
|
||||
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
||||
{
|
||||
// Factory startup. The ordering is intentional.
|
||||
GlobalLog.initialize();
|
||||
databaseManager = ObjectBuilderFactory.constructDatabaseManager();
|
||||
commandManager = ObjectBuilderFactory.constructCommandManager(CommandEnabler.instance); // TODO: Untangle this singleton
|
||||
stats = ObjectBuilderFactory.constructStats(commandManager);
|
||||
charManager = new CharacterManager();
|
||||
rpManager = ObjectBuilderFactory.constructRPManager();
|
||||
pluginManager = ObjectBuilderFactory.constructPluginManager();
|
||||
|
||||
// Bot startup
|
||||
kittyCore = ObjectBuilderFactory.constructKittyCore();
|
||||
}
|
||||
|
||||
// When a message is sent in a server that kitty is in, this is what's called.
|
||||
@Override
|
||||
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
|
||||
{
|
||||
// Tweak the event as necessary
|
||||
if(!Superintendent.preProcessSetup(event, stats))
|
||||
return;
|
||||
|
||||
// Factory objects
|
||||
KittyUser user = ObjectBuilderFactory.extractUser(event);
|
||||
KittyGuild guild = ObjectBuilderFactory.extractGuild(event);
|
||||
KittyChannel channel = ObjectBuilderFactory.extractChannel(event);
|
||||
|
||||
// Specialized uncached objects
|
||||
Response response = new Response(event, kittyCore);
|
||||
UserInput input = new UserInput(event, guild);
|
||||
|
||||
// Tweak object construction as necessary
|
||||
if(!Superintendent.postProcessSetup(event, user, guild, channel, response, input))
|
||||
return;
|
||||
|
||||
// Track beans!
|
||||
user.changeBeans(1);
|
||||
|
||||
// RP logging system
|
||||
RPManager.instance.addLine(channel, user, input);
|
||||
|
||||
// Run any pre-emptive upkeep we need to
|
||||
if(!Superintendent.perCommandUpkeepPre(pluginManager))
|
||||
return;
|
||||
|
||||
// Attempt to spin up a command. If the command doesn't exist.
|
||||
// Run plugins right before invoking the commands but after all other setup.
|
||||
if(commandManager.invokeOnNewThread(guild, channel, user, input, response) == false)
|
||||
{
|
||||
List<String> pluginOutput = pluginManager.runAll(input.message, user);
|
||||
|
||||
if(pluginOutput != null && pluginOutput.size() > 0)
|
||||
{
|
||||
for(int i = 0; i < pluginOutput.size(); ++i)
|
||||
{
|
||||
if(pluginOutput.get(i).startsWith("!"))
|
||||
{
|
||||
commandManager.invokeOnNewThread(guild, channel, user,
|
||||
new UserInput(pluginOutput.get(i).substring(1), guild), response);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.send(pluginOutput.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run any upkeep in post we need to
|
||||
if(!Superintendent.perCommandUpkeepPost(kittyCore, databaseManager))
|
||||
return;
|
||||
}
|
||||
package main;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import commands.dew.core.impl.DewCore;
|
||||
import core.CharacterManager;
|
||||
import core.CommandEnabler;
|
||||
import core.CommandManager;
|
||||
import core.DatabaseManager;
|
||||
import core.ObjectBuilderFactory;
|
||||
import core.RPManager;
|
||||
import core.Stats;
|
||||
import core.lua.PluginManager;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyCore;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.JDABuilder;
|
||||
import net.dv8tion.jda.core.entities.Game;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
||||
import offline.Ref;
|
||||
import utils.GlobalLog;
|
||||
|
||||
// http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation.
|
||||
// This is the application entry point, and bot startup location!
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Main extends ListenerAdapter
|
||||
{
|
||||
// Variables and bot specific objects
|
||||
private static KittyCore kittyCore;
|
||||
private static DatabaseManager databaseManager;
|
||||
private static CommandManager commandManager;
|
||||
private static Stats stats;
|
||||
private static RPManager rpManager;
|
||||
private static PluginManager pluginManager;
|
||||
private static CharacterManager charManager;
|
||||
|
||||
// Initialization and setup
|
||||
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
||||
{
|
||||
// Factory startup. The ordering is intentional.
|
||||
GlobalLog.initialize();
|
||||
databaseManager = ObjectBuilderFactory.constructDatabaseManager();
|
||||
commandManager = ObjectBuilderFactory.constructCommandManager(CommandEnabler.instance); // TODO: Untangle this singleton
|
||||
stats = ObjectBuilderFactory.constructStats(commandManager);
|
||||
charManager = new CharacterManager();
|
||||
rpManager = ObjectBuilderFactory.constructRPManager();
|
||||
pluginManager = ObjectBuilderFactory.constructPluginManager();
|
||||
|
||||
// Bot startup
|
||||
kittyCore = ObjectBuilderFactory.constructKittyCore();
|
||||
}
|
||||
|
||||
// When a message is sent in a server that kitty is in, this is what's called.
|
||||
@Override
|
||||
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
|
||||
{
|
||||
// Tweak the event as necessary
|
||||
if(!Superintendent.preProcessSetup(event, stats))
|
||||
return;
|
||||
|
||||
// Factory objects
|
||||
KittyUser user = ObjectBuilderFactory.extractUser(event);
|
||||
KittyGuild guild = ObjectBuilderFactory.extractGuild(event);
|
||||
KittyChannel channel = ObjectBuilderFactory.extractChannel(event);
|
||||
|
||||
// Specialized uncached objects
|
||||
Response response = new Response(event, kittyCore);
|
||||
UserInput input = new UserInput(event, guild);
|
||||
|
||||
// Tweak object construction as necessary
|
||||
if(!Superintendent.postProcessSetup(event, user, guild, channel, response, input))
|
||||
return;
|
||||
|
||||
// Track beans!
|
||||
user.changeBeans(1);
|
||||
|
||||
// RP logging system
|
||||
RPManager.instance.addLine(channel, user, input);
|
||||
|
||||
// Run any pre-emptive upkeep we need to
|
||||
if(!Superintendent.perCommandUpkeepPre(pluginManager))
|
||||
return;
|
||||
|
||||
// TODO: Condense outer if somehow...
|
||||
if(!DewCore.ProcessIfCaptured(guild, channel, user, input, response))
|
||||
{
|
||||
|
||||
// Attempt to spin up a command. If the command doesn't exist.
|
||||
// Run plugins right before invoking the commands but after all other setup.
|
||||
if(commandManager.invokeOnNewThread(guild, channel, user, input, response) == false)
|
||||
{
|
||||
List<String> pluginOutput = pluginManager.runAll(input.message, user);
|
||||
|
||||
if(pluginOutput != null && pluginOutput.size() > 0)
|
||||
{
|
||||
for(int i = 0; i < pluginOutput.size(); ++i)
|
||||
{
|
||||
if(pluginOutput.get(i).startsWith("!"))
|
||||
{
|
||||
commandManager.invokeOnNewThread(guild, channel, user, new UserInput(pluginOutput.get(i).substring(1), guild), response);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.send(pluginOutput.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Run any upkeep in post we need to
|
||||
if(!Superintendent.perCommandUpkeepPost(kittyCore, databaseManager))
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package main;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import commands.dew.core.impl.DewCore;
|
||||
import core.Config;
|
||||
import core.DatabaseManager;
|
||||
import core.RPManager;
|
||||
|
||||
@@ -6,41 +6,14 @@ public class NetworkColiru
|
||||
{
|
||||
public String compileCPlusPlus(String query)
|
||||
{
|
||||
// Escape characters that need escaping - mostly whitespace.
|
||||
// Escape characters that need escaping.
|
||||
// Primarily types of whitespace.
|
||||
query = query.replace("\\n", "\\\\n");
|
||||
query = query.replace("\\t", "\\\\t");
|
||||
query = query.replace("\n", "\\n");
|
||||
query = query.replace("\"", "\\\"");
|
||||
query = query.replace("\t", "\\t");
|
||||
query = query.replace("`", "");
|
||||
|
||||
// // replace backticks on only the edges of the string.
|
||||
// StringBuilder s = new StringBuilder(query);
|
||||
//
|
||||
// for(int i = 0; i < s.length(); ++i)
|
||||
// {
|
||||
// if(s.charAt(i) != '`')
|
||||
// break;
|
||||
//
|
||||
// s.setCharAt(i, ' ');
|
||||
// }
|
||||
//
|
||||
// for(int i = s.length() - 1; i >= 0; --i)
|
||||
// {
|
||||
// if(s.charAt(i) != '`')
|
||||
// break;
|
||||
//
|
||||
// s.setCharAt(i, ' ');
|
||||
// }
|
||||
//
|
||||
// query = s.toString().trim();
|
||||
|
||||
// Determine if the query is effectively empty or not. If it is, don't attempt to compile it.
|
||||
if(query.trim().length() == 0)
|
||||
{
|
||||
return "I can't compile nothing!";
|
||||
}
|
||||
|
||||
// Send the compilation request!
|
||||
String result = HTTPUtils.sendPOSTRequest("http://coliru.stacked-crooked.com/compile"
|
||||
, "{ \"cmd\": \"g++ main.cpp && ./a.out\", \"src\": \"" + query + "\" }");
|
||||
@@ -48,7 +21,7 @@ public class NetworkColiru
|
||||
// If we got a valid response...
|
||||
if(!result.isEmpty())
|
||||
{
|
||||
result = "Here's what happened when I went to compile that! \n```" + result + "```";
|
||||
result = "Here's what happened when I went to compiled that! \n```" + result + "```";
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -7,14 +7,13 @@ import utils.*;
|
||||
|
||||
public class NetworkDerpi
|
||||
{
|
||||
private final String mainURL = "https://derpibooru.org/api/v1/json/search/images?q=";
|
||||
private final String mainURL = "https://derpibooru.org/search.json?q=";
|
||||
private static final Gson jsonParser_ = new Gson();
|
||||
|
||||
private class DerpiResponseObject
|
||||
{
|
||||
public String image;
|
||||
public String tags;
|
||||
public String score;
|
||||
}
|
||||
|
||||
private class InitialRequest
|
||||
@@ -24,41 +23,22 @@ public class NetworkDerpi
|
||||
|
||||
public GenericImage getDerpi(String query)
|
||||
{
|
||||
String res;
|
||||
GenericImage image = new GenericImage(" ", " ", " ");
|
||||
query = query.trim();
|
||||
query = query.replace(" ", ",");
|
||||
System.out.println(mainURL + query + "&sf=random&key=" + Ref.derpiKey);
|
||||
if(query.startsWith("ID:"))
|
||||
{
|
||||
res = HTTPUtils.sendGETRequest("https://derpibooru.org/api/v1/json/images/" + query.substring(3));
|
||||
}
|
||||
else
|
||||
{
|
||||
res = HTTPUtils.sendGETRequest(mainURL + query + "&sf=random&key=" + Ref.derpiKey);
|
||||
}
|
||||
System.out.println(res);
|
||||
String res = HTTPUtils.sendGETRequest(mainURL + query + "&random_image=1&key=" + Ref.derpiKey);
|
||||
if(res != null)
|
||||
{
|
||||
InitialRequest obj;
|
||||
// Use class evaluation on an array of the response object to be able to hold multiple.
|
||||
try
|
||||
{
|
||||
obj = jsonParser_.fromJson(res, InitialRequest.class);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
InitialRequest obj = jsonParser_.fromJson(res, InitialRequest.class);
|
||||
if(res != null)
|
||||
{
|
||||
|
||||
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);
|
||||
|
||||
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:"))
|
||||
{
|
||||
String [] sepTags = imageObj.tags.split(",");
|
||||
@@ -74,20 +54,8 @@ public class NetworkDerpi
|
||||
artists += sepTags[i].substring(sepTags[i].indexOf(":")+1);
|
||||
}
|
||||
}
|
||||
image.editAuthorImage("https://derpicdn.net/favicon.ico");
|
||||
|
||||
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
|
||||
{
|
||||
@@ -98,46 +66,4 @@ public class NetworkDerpi
|
||||
|
||||
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,218 +0,0 @@
|
||||
package network;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import dataStructures.GenericImage;
|
||||
import offline.Ref;
|
||||
import utils.HTTPUtils;
|
||||
|
||||
/**
|
||||
* This is the e621 request class, designed for form and parse requests that
|
||||
* use the e621 API, and is entirely static.
|
||||
*
|
||||
* 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
|
||||
* HTTPUtils to something other than a browser emulating string, or the default
|
||||
* java one.
|
||||
*
|
||||
* @author Wisp
|
||||
* Edited by Rin
|
||||
*/
|
||||
public class NetworkE6
|
||||
{
|
||||
///////////////////////////////////////
|
||||
// Internal JSON class and variables //
|
||||
//////////////////////////////////.////
|
||||
private static final Gson jsonParser_ = new Gson();
|
||||
private static final String API_ROOT = "https://e621.net/posts.json?";
|
||||
private static int maxSearchResults_ = 10;
|
||||
private static String[] blacklist = Ref.e621Blacklist;
|
||||
|
||||
private class E6ResponseObject
|
||||
{
|
||||
// public variables matching the case and the type we want for JSON.
|
||||
// There are many more fields, but if we don't provide some it just
|
||||
// doesn't bother parsing them.
|
||||
public E6ResponseObjectPost [] posts;
|
||||
|
||||
}
|
||||
|
||||
private class E6ResponseObjectPost
|
||||
{
|
||||
public String id;
|
||||
public String [] sources;
|
||||
public String[] pools;
|
||||
public String rating;
|
||||
public E6ResponseObjectFile file;
|
||||
public E6ResponseObjectScore score;
|
||||
public E6ResponseObjectTags tags;
|
||||
public E6ResponseObjectRelationships relationships;
|
||||
}
|
||||
|
||||
private class E6ResponseObjectFile
|
||||
{
|
||||
public String url;
|
||||
}
|
||||
|
||||
private class E6ResponseObjectScore
|
||||
{
|
||||
public String total;
|
||||
}
|
||||
|
||||
private class E6ResponseObjectTags
|
||||
{
|
||||
public String[] general;
|
||||
public String[] artist;
|
||||
}
|
||||
|
||||
private class E6ResponseObjectRelationships
|
||||
{
|
||||
public String has_children;
|
||||
public String[] children;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////
|
||||
// Static methods //
|
||||
////////////////////
|
||||
// Requests a specific image, then returns a few.
|
||||
public GenericImage getE6(String input, String sauceNaoDependant)
|
||||
{
|
||||
GenericImage image = new GenericImage("","","");
|
||||
boolean blacklisted;
|
||||
// Clean up request and replace problematic characters for the query string.
|
||||
input = input.trim();
|
||||
input = input.replace("+", "%2B");
|
||||
input = input.replace(" ", "%20");
|
||||
|
||||
// Configure and send request. Note: Random ordering added as first
|
||||
// tag by default. User-provided tags, therefore, will override it.
|
||||
// If order:score is provided, that will be honored over order:random.
|
||||
String res = HTTPUtils.sendGETRequest(API_ROOT + "tags=order:random%20" + input + "&limit=" + maxSearchResults_);
|
||||
if(res != null)
|
||||
{
|
||||
|
||||
// Use class evaluation on an array of the response imageObject to be able to hold multiple.
|
||||
E6ResponseObject imageObj = jsonParser_.fromJson(res, E6ResponseObject.class);
|
||||
// For now, we really just wanna display images and their source.
|
||||
// Append them all separately to a response string w/ some flavor text.
|
||||
if(imageObj.posts.length < 1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < imageObj.posts.length; ++i)
|
||||
{
|
||||
String [] TagsList = imageObj.posts[i].tags.general;
|
||||
blacklisted = false;
|
||||
for(int j = 0; j < blacklist.length; j++)
|
||||
{
|
||||
for(int k = 0; k < TagsList.length; k ++)
|
||||
{
|
||||
if(TagsList[k].equals(blacklist[j]))
|
||||
{
|
||||
System.out.println("BLACKLISTED " + blacklist[j]);
|
||||
blacklisted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(blacklisted)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// We will always have a file URL. That's a given.
|
||||
image.editImageURL(imageObj.posts[i].file.url);
|
||||
image.editPostURL("https://e621.net/posts/" + imageObj.posts[i].id);
|
||||
if(imageObj.posts[i].tags.artist.length > 0)
|
||||
{
|
||||
String artists = imageObj.posts[i].tags.artist[0];
|
||||
for(int j = 1; j < imageObj.posts[i].tags.artist.length; j++)
|
||||
artists += ", " + imageObj.posts[i].tags.artist[j];
|
||||
image.editArtist(artists);
|
||||
}
|
||||
else
|
||||
image.editArtist("Artist Not Found!");
|
||||
|
||||
image.editAuthorImage("https://e621.net/favicon.ico");
|
||||
|
||||
String sources = "";
|
||||
|
||||
if(imageObj.posts[i].sources != null)
|
||||
{
|
||||
for(int k = 0; k < imageObj.posts[i].sources.length; k ++)
|
||||
{
|
||||
if(!imageObj.posts[i].sources[k].endsWith(imageObj.posts[i].file.url.substring(imageObj.posts[i].file.url.lastIndexOf('.'))))
|
||||
{
|
||||
String source = imageObj.posts[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('.')) + "]";
|
||||
if(source.equals("[pbs]"))
|
||||
{
|
||||
source = "[twitter-cdn]";
|
||||
}
|
||||
}
|
||||
sources += " [" + source + "](" + imageObj.posts[i].sources[k] + ") ";
|
||||
}
|
||||
}
|
||||
if(sources.equals(""))
|
||||
{
|
||||
sources = " Source not listed";
|
||||
}
|
||||
if(sauceNaoDependant.equals(""))
|
||||
{
|
||||
image.editDescriptionText("Score: " + imageObj.posts[i].score.total + "\n**Source:**" + sources);
|
||||
}
|
||||
else
|
||||
{
|
||||
image.editDescriptionText(sauceNaoDependant + "\nScore: " + imageObj.posts[i].score.total + "\n**Source:**" + sources);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
image.editDescriptionText("Score: " + imageObj.posts[i].score.total);
|
||||
}
|
||||
|
||||
|
||||
String descTags = "";
|
||||
if(imageObj.posts[i].tags.general.length > 15)
|
||||
{
|
||||
for(int o = 0; o < 15; o++)
|
||||
{
|
||||
descTags += imageObj.posts[i].tags.general[o] + ", ";
|
||||
}
|
||||
image.editFooterText("[Tags] " + descTags + " etc.");
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int o = 0; o < imageObj.posts[i].tags.general.length - 1; o++)
|
||||
{
|
||||
descTags += imageObj.posts[i].tags.general[o] + ", ";
|
||||
}
|
||||
descTags += imageObj.posts[i].tags.general[imageObj.posts[i].tags.general.length-1] + "";
|
||||
|
||||
image.editFooterText("[Tags] " + descTags);
|
||||
}
|
||||
|
||||
if(image.output().authorText != null)
|
||||
{
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package network;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import dataStructures.GenericImage;
|
||||
import offline.Ref;
|
||||
import utils.*;
|
||||
|
||||
/**
|
||||
* This is the e621 request class, designed for form and parse requests that
|
||||
* use the e621 API, and is entirely static.
|
||||
*
|
||||
* 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
|
||||
* HTTPUtils to something other than a browser emulating string, or the default
|
||||
* java one.
|
||||
*
|
||||
* @author Wisp
|
||||
* Edited by Rin
|
||||
*/
|
||||
public class NetworkE621
|
||||
{
|
||||
///////////////////////////////////////
|
||||
// Internal JSON class and variables //
|
||||
//////////////////////////////////.////
|
||||
private static final Gson jsonParser_ = new Gson();
|
||||
private static final String API_ROOT = "https://e621.net/post/index.json?";
|
||||
private static int maxSearchResults_ = 10;
|
||||
private static String[] blacklist = Ref.e621Blacklist;
|
||||
private class E621ResponseObject
|
||||
{
|
||||
// public varaibles matching the case and the type we want for JSON.
|
||||
// There are many more fields, but if we don't provide some it just
|
||||
// doesn't bother parsing them.
|
||||
public String file_url;
|
||||
public String id;
|
||||
public String tags;
|
||||
public String [] artist;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////
|
||||
// Static methods //
|
||||
////////////////////
|
||||
// Requests a specific image, then returns a few.
|
||||
public GenericImage getE621(String input)
|
||||
{
|
||||
|
||||
GenericImage image = new GenericImage("","","");
|
||||
boolean blacklisted;
|
||||
// Clean up request and replace problematic characters for the query string.
|
||||
input = input.trim();
|
||||
input = input.replace("+", "%2B");
|
||||
input = input.replace(" ", "%20");
|
||||
|
||||
// Configure and send request. Note: Random ordering added as first
|
||||
// tag by default. User-provided tags, therefore, will override it.
|
||||
// If order:score is provided, that will be honored over order:random.
|
||||
String res = HTTPUtils.sendPOSTRequest(API_ROOT
|
||||
, "tags=order:random%20" + input + "&limit=" + maxSearchResults_);
|
||||
|
||||
|
||||
if(res != null)
|
||||
{
|
||||
// Use class evaluation on an array of the response imageObject to be able to hold multiple.
|
||||
E621ResponseObject[] imageObj = jsonParser_.fromJson(res, E621ResponseObject[].class);
|
||||
|
||||
// For now, we really just wanna display images and their source.
|
||||
// Append them all separately to a response string w/ some flavor text.
|
||||
if(imageObj.length < 1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < imageObj.length; ++i)
|
||||
{
|
||||
blacklisted = false;
|
||||
for(int j = 0; j < blacklist.length; j++)
|
||||
{
|
||||
if(imageObj[i].tags.contains(blacklist[j]))
|
||||
{
|
||||
blacklisted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(blacklisted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// We will always have a file URL. That's a given.
|
||||
image.editImageURL(imageObj[i].file_url);
|
||||
image.editPostURL("https://e621.net/post/show/" + imageObj[i].id);
|
||||
if(imageObj[i].artist.length > 0)
|
||||
image.editArtist(imageObj[i].artist[0]);
|
||||
else
|
||||
image.editArtist("Artist Not Found!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package network;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import dataStructures.GenericImage;
|
||||
import offline.Ref;
|
||||
import utils.HTTPUtils;
|
||||
|
||||
public class NetworkSauceNAO
|
||||
{
|
||||
private static final Gson jsonParser_ = new Gson();
|
||||
private static final String API_ROOT = "https://saucenao.com/search.php?dbmask=268435456&output_type=2&numres=10&api_key=" + Ref.SauceNAOKey +"&url=";
|
||||
NetworkE6 e6Sauce = new NetworkE6();
|
||||
private class SauceNAOResponseObject
|
||||
{
|
||||
List<SauceNAOResult> results;
|
||||
}
|
||||
|
||||
private class SauceNAOResult
|
||||
{
|
||||
SauceNAOData data;
|
||||
SauceNAOHeader header;
|
||||
}
|
||||
|
||||
private class SauceNAOHeader
|
||||
{
|
||||
double similarity;
|
||||
}
|
||||
|
||||
private class SauceNAOData
|
||||
{
|
||||
String [] ext_urls;
|
||||
}
|
||||
|
||||
public GenericImage getSauce(String input)
|
||||
{
|
||||
double similarity;
|
||||
input = input.trim();
|
||||
input = input.replace("+", "%2B");
|
||||
input = input.replace(" ", "%20");
|
||||
|
||||
String res = HTTPUtils.sendGETRequest(API_ROOT + input);
|
||||
SauceNAOResponseObject sauce = jsonParser_.fromJson(res, SauceNAOResponseObject.class);
|
||||
String sauceUrl = sauce.results.get(0).data.ext_urls[0];
|
||||
similarity = sauce.results.get(0).header.similarity;
|
||||
if(sauceUrl.startsWith("https://e621.net/post/show/"))
|
||||
{
|
||||
return e6Sauce.getE6("id:" + sauceUrl.substring(27), "Confidence: " + similarity + "%");
|
||||
}
|
||||
GenericImage unknown = new GenericImage("", "","");
|
||||
return unknown;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -73,36 +73,9 @@ public class NetworkTheColorAPI
|
||||
|
||||
public ColorData lookupHex(String hex)
|
||||
{
|
||||
if(hex == null)
|
||||
return null;
|
||||
|
||||
hex = hex.replace("#", "").trim();
|
||||
int len = hex.length();
|
||||
|
||||
if(len == 0)
|
||||
return null;
|
||||
|
||||
// Verify we're either a full or half length color. Intermediate colors not supported.
|
||||
// Alpha is also not supported.
|
||||
if(len != 6 && len != 3)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
String hexUpper = hex.toUpperCase();
|
||||
|
||||
// Verify the number is hex.
|
||||
for(int i = 0; i < hexUpper.length(); ++i)
|
||||
{
|
||||
char current = hexUpper.charAt(i);
|
||||
Boolean isValidNum = current >= '0' && current <= '9';
|
||||
Boolean isValidChar = current >= 'A' && current <= 'F';
|
||||
|
||||
// If it's not a valid character or a valid number, return null/
|
||||
if(!isValidNum && !isValidChar)
|
||||
return null;
|
||||
}
|
||||
|
||||
hex = hex.replace("#", "");
|
||||
String response = HTTPUtils.sendGETRequest("https://www.thecolorapi.com/id?hex=" + hex);
|
||||
|
||||
ColorData data = jsonParser.fromJson(response, ColorData.class);
|
||||
|
||||
@@ -1,56 +1,14 @@
|
||||
package network;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.api.services.youtube.YouTube;
|
||||
|
||||
import offline.Ref;
|
||||
import utils.HTTPUtils;
|
||||
|
||||
public class NetworkYoutube
|
||||
{
|
||||
///////////////////////////////////////
|
||||
// Internal JSON class and variables //
|
||||
//////////////////////////////////.////
|
||||
private static YouTube youtube;
|
||||
|
||||
//https://www.youtube.com/watch?v=
|
||||
|
||||
private static final Gson jsonParser_ = new Gson();
|
||||
private static final String API_ROOT = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&q=";
|
||||
|
||||
|
||||
// Use this as the base
|
||||
public class YTOuter
|
||||
public NetworkYoutube()
|
||||
{
|
||||
List<YTInner> items;
|
||||
}
|
||||
|
||||
public class YTInner
|
||||
{
|
||||
YTID id;
|
||||
YTSnippet snippet;
|
||||
}
|
||||
|
||||
public class YTID
|
||||
{
|
||||
String videoId;
|
||||
}
|
||||
|
||||
public class YTSnippet
|
||||
{
|
||||
String title;
|
||||
String description;
|
||||
}
|
||||
|
||||
public String getYT(String input)
|
||||
{
|
||||
input = input.trim();
|
||||
input = input.replace("+", "%2B");
|
||||
input = input.replace(" ", "%20");
|
||||
|
||||
String res = HTTPUtils.sendGETRequest(API_ROOT + input +
|
||||
"&order=viewCount&type=video&topicId=%2Fm%2F04rlf&videoDefinition=high&key=" + Ref.youtube);
|
||||
YTOuter videoObj = jsonParser_.fromJson(res, YTOuter.class);
|
||||
return "https://www.youtube.com/watch?v=" + videoObj.items.get(0).id.videoId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package utils;
|
||||
/***
|
||||
* https://developers.google.com/youtube/v3/code_samples/code_snippets?apix_params=%7B%22part%22%3A%22snippet%22%2C%22maxResults%22%3A25%2C%22q%22%3A%22surfing%22%7D
|
||||
* https://github.com/sedmelluq/LavaPlayer#jda-integration
|
||||
* https://ci.dv8tion.net/job/JDA/javadoc/net/dv8tion/jda/core/entities/VoiceChannel.html
|
||||
* https://developers.google.com/youtube/registering_an_application#Create_API_Keys
|
||||
*/
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.VoiceChannel;
|
||||
import net.dv8tion.jda.core.managers.AudioManager;
|
||||
|
||||
public class AudioUtils
|
||||
{
|
||||
private Guild guild;
|
||||
AudioManager audio;
|
||||
AudioPlayer player;
|
||||
|
||||
|
||||
public AudioUtils(Guild guild)
|
||||
{
|
||||
this.guild = guild;
|
||||
audio = guild.getAudioManager();
|
||||
}
|
||||
|
||||
public boolean joinChannel(String channelName)
|
||||
{
|
||||
VoiceChannel channel = null;
|
||||
channel = guild.getVoiceChannelsByName(channelName, true).get(0);
|
||||
if(channel != null)
|
||||
{
|
||||
audio.openAudioConnection(channel);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean leaveChannel()
|
||||
{
|
||||
if(audio.isConnected())
|
||||
{
|
||||
audio.closeAudioConnection();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package utils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.DateFormat;
|
||||
@@ -28,18 +29,27 @@ public class GlobalLog
|
||||
GlobalLog.log(LogFilter.Util, "Finished initializing logging system");
|
||||
}
|
||||
|
||||
private static void write(String status, LogFilter filter, String body)
|
||||
private static void write(String status, LogFilter filter, String body, PrintStream stream)
|
||||
{
|
||||
String logLine = "[" + status + "] " + "[" + filter.name() + "] " + body;
|
||||
outputLog.write(logLine + "\n");
|
||||
outputLog.flush();
|
||||
System.out.println(logLine);
|
||||
stream.println(logLine);
|
||||
}
|
||||
|
||||
public static void log(LogFilter filter, String msg) { write(log, filter, msg); }
|
||||
public static void warn(LogFilter filter, String msg) { write(warn, filter, msg); }
|
||||
public static void error(LogFilter filter, String msg) { write(error, filter, msg); System.err.println(msg); System.err.flush(); }
|
||||
public static void fatal(LogFilter filter, String msg) throws Exception { write(fatal, filter, msg); throw new Exception(msg); }
|
||||
public static void log(LogFilter filter, String msg) { write(log, filter, msg, System.out); }
|
||||
public static void warn(LogFilter filter, String msg) { write(warn, filter, msg, System.out); }
|
||||
public static void error(LogFilter filter, String msg) { write(error, filter, msg, System.err); System.err.println(msg); System.err.flush(); }
|
||||
public static void error(LogFilter filter, Exception e)
|
||||
{
|
||||
write(error, filter, e.toString(), System.err);
|
||||
e.printStackTrace(outputLog);
|
||||
e.printStackTrace(System.err);
|
||||
outputLog.flush();
|
||||
System.err.flush();
|
||||
}
|
||||
|
||||
public static void fatal(LogFilter filter, String msg) throws Exception { write(fatal, filter, msg, System.out); throw new Exception(msg); }
|
||||
|
||||
public static void log(String msg) { log(LogFilter.Debug, msg); }
|
||||
public static void warn(String msg) { warn(LogFilter.Debug, msg); }
|
||||
|
||||
@@ -1,188 +0,0 @@
|
||||
package utils.audio;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
||||
|
||||
import net.dv8tion.jda.core.audio.AudioSendHandler;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.VoiceChannel;
|
||||
import net.dv8tion.jda.core.managers.AudioManager;
|
||||
|
||||
public class AudioUtils
|
||||
{
|
||||
private Guild guild;
|
||||
public AudioManager am;
|
||||
public final AudioPlayer player;
|
||||
public final AudioPlayerManager playerManager;
|
||||
private ArrayList <AudioTrack> playlist = new ArrayList<AudioTrack>();
|
||||
|
||||
|
||||
public AudioUtils(Guild guild, AudioPlayerManager playerManager)
|
||||
{
|
||||
player = playerManager.createPlayer();
|
||||
this.playerManager = playerManager;
|
||||
this.guild = guild;
|
||||
am = guild.getAudioManager();
|
||||
|
||||
}
|
||||
|
||||
public boolean joinChannel(String channelName)
|
||||
{
|
||||
VoiceChannel channel = null;
|
||||
channel = guild.getVoiceChannelsByName(channelName, true).get(0);
|
||||
if(channel != null)
|
||||
{
|
||||
am.openAudioConnection(channel);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean leaveChannel()
|
||||
{
|
||||
if(am.isConnected())
|
||||
{
|
||||
am.closeAudioConnection();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public class AudioPlayerSendHandler implements AudioSendHandler
|
||||
{
|
||||
private final AudioPlayer audioPlayer;
|
||||
private AudioFrame lastFrame;
|
||||
|
||||
public AudioPlayerSendHandler(AudioPlayer audioPlayer)
|
||||
{
|
||||
this.audioPlayer = audioPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvide()
|
||||
{
|
||||
lastFrame = audioPlayer.provide();
|
||||
return lastFrame != null;
|
||||
}
|
||||
|
||||
@Override public byte[] provide20MsAudio()
|
||||
{
|
||||
return lastFrame.getData();
|
||||
}
|
||||
|
||||
@Override public boolean isOpus()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class SmallAudio implements AudioLoadResultHandler
|
||||
{
|
||||
private SmallAudio(AudioPlayer player)
|
||||
{
|
||||
}
|
||||
|
||||
@Override public void loadFailed(FriendlyException arg0) { }
|
||||
@Override public void noMatches() { }
|
||||
@Override public void playlistLoaded(AudioPlaylist arg0) { }
|
||||
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack track)
|
||||
{
|
||||
synchronized(playlist)
|
||||
{
|
||||
playlist.add(track);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String playVideo(String videoURL)
|
||||
{
|
||||
guild.getAudioManager().setSendingHandler(new AudioPlayerSendHandler(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;
|
||||
}
|
||||
|
||||
public int getVolume(AudioPlayer player)
|
||||
{
|
||||
return player.getVolume();
|
||||
}
|
||||
|
||||
public void changeVolume(AudioPlayer player, int newVol)
|
||||
{
|
||||
player.setVolume(newVol);
|
||||
}
|
||||
|
||||
public String skipVideo(AudioPlayer player)
|
||||
{
|
||||
player.stopTrack();
|
||||
return "Skipped";
|
||||
}
|
||||
|
||||
public String stopPlayer(AudioPlayer player)
|
||||
{
|
||||
playlist.clear();
|
||||
player.stopTrack();
|
||||
return "Stopped";
|
||||
}
|
||||
|
||||
public ArrayList<AudioTrack> getPlaylist()
|
||||
{
|
||||
return 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()
|
||||
{
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {}
|
||||
AudioTrack nowPlaying = null;
|
||||
do
|
||||
{
|
||||
if(!playlist.isEmpty() || nowPlaying != null)
|
||||
{
|
||||
if(player.getPlayingTrack() == null)
|
||||
{
|
||||
if(playlist.isEmpty())
|
||||
nowPlaying = null;
|
||||
else
|
||||
{
|
||||
nowPlaying = playlist.get(0);
|
||||
playlist.remove(0);
|
||||
}
|
||||
player.startTrack(nowPlaying, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
while(!playlist.isEmpty() || player.getPlayingTrack() != null);
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package utils.audio;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* This class schedules tracks for the audio player. It contains the queue of tracks.
|
||||
*/
|
||||
public class TrackScheduler extends AudioEventAdapter {
|
||||
private final AudioPlayer player;
|
||||
private final BlockingQueue<AudioTrack> queue;
|
||||
|
||||
/**
|
||||
* @param player The audio player this scheduler uses
|
||||
*/
|
||||
public TrackScheduler(AudioPlayer player) {
|
||||
this.player = player;
|
||||
this.queue = new LinkedBlockingQueue<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the next track to queue or play right away if nothing is in the queue.
|
||||
*
|
||||
* @param track The track to play or add to queue.
|
||||
*/
|
||||
public void queue(AudioTrack track)
|
||||
{
|
||||
// Calling startTrack with the noInterrupt set to true will start the track only if nothing is currently playing. If
|
||||
// something is playing, it returns false and does nothing. In that case the player was already playing so this
|
||||
// track goes to the queue instead.
|
||||
if (!player.startTrack(track, true)) {
|
||||
queue.offer(track);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the next track, stopping the current one if it is playing.
|
||||
*/
|
||||
public void nextTrack() {
|
||||
// Start the next track, regardless of if something is already playing or not. In case queue was empty, we are
|
||||
// giving null to startTrack, which is a valid argument and will simply stop the player.
|
||||
player.startTrack(queue.poll(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
|
||||
// Only start the next track if the end reason is suitable for it (FINISHED or LOAD_FAILED)
|
||||
if (endReason.mayStartNext) {
|
||||
nextTrack();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user