13 Commits
45 changed files with 1145 additions and 1031 deletions
+2 -2
View File
@@ -12,7 +12,6 @@
<classpathentry kind="lib" path="lib/httpclient-4.5.5.jar"/> <classpathentry kind="lib" path="lib/httpclient-4.5.5.jar"/>
<classpathentry kind="lib" path="lib/httpcore-4.4.9.jar"/> <classpathentry kind="lib" path="lib/httpcore-4.4.9.jar"/>
<classpathentry kind="lib" path="lib/WolframAlpha-1.1.jar"/> <classpathentry kind="lib" path="lib/WolframAlpha-1.1.jar"/>
<classpathentry kind="lib" path="lib/JDA-3.7.1_385-withDependencies.jar"/>
<classpathentry kind="lib" path="lib/sqlite-jdbc-3.23.1.jar"/> <classpathentry kind="lib" path="lib/sqlite-jdbc-3.23.1.jar"/>
<classpathentry kind="lib" path="lib/slf4j-jdk14-1.7.25.jar"/> <classpathentry kind="lib" path="lib/slf4j-jdk14-1.7.25.jar"/>
<classpathentry kind="lib" path="lib/twitter4j-core-4.0.7-javadoc.jar"/> <classpathentry kind="lib" path="lib/twitter4j-core-4.0.7-javadoc.jar"/>
@@ -27,6 +26,7 @@
<classpathentry kind="lib" path="lib/google-http-client-1.32.0.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/google-api-services-youtube-v3-rev212-1.25.0.jar"/>
<classpathentry kind="lib" path="lib/nanohttpd-2.3.1.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/LavaPlayerJar-1.3.50-jar-with-dependencies.jar"/>
<classpathentry kind="lib" path="lib/JDA-4.2.0_168-withDependencies.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
+2
View File
@@ -68,3 +68,5 @@ rP\.txt
*.log *.log
cloc\.exe cloc\.exe
beanImage.png
+5 -1
View File
@@ -1,5 +1,6 @@
"Type","Key","Value" "Type","Key","Value"
"Globals","mode (dev or release)","dev" "Globals","mode (dev or release)","dev"
"Globals","activity","with a laser pointer"
"Localized Commands","beans","" "Localized Commands","beans",""
"Localized Commands","benchmark, bench","" "Localized Commands","benchmark, bench",""
"Localized Commands","bet","" "Localized Commands","bet",""
@@ -57,6 +58,8 @@
"Localized Commands","work","" "Localized Commands","work",""
"Localized Commands","yeet","" "Localized Commands","yeet",""
"Localized Strings","AddGuildRoleFailure","Failed to add %s to %s" "Localized Strings","AddGuildRoleFailure","Failed to add %s to %s"
"Localized Strings","BeansImageBottomText","BEANS"
"Localized Strings","BeansImageTopText","YOU HAVE"
"Localized Strings","BeansShowDisplay","You have %s beans!" "Localized Strings","BeansShowDisplay","You have %s beans!"
"Localized Strings","BeansShowInfo","Displays how many beans you have" "Localized Strings","BeansShowInfo","Displays how many beans you have"
"Localized Strings","BeansShowMentioned","I took a look and %sbeans!" "Localized Strings","BeansShowMentioned","I took a look and %sbeans!"
@@ -70,7 +73,8 @@
"Localized Strings","BetBeansNotValid","That's not a valid bet!" "Localized Strings","BetBeansNotValid","That's not a valid bet!"
"Localized Strings","BetBeansWin","You won %s beans!" "Localized Strings","BetBeansWin","You won %s beans!"
"Localized Strings","BetHistoryInfo","Gives how many beans I've ~~stolen~~ won from your bets!" "Localized Strings","BetHistoryInfo","Gives how many beans I've ~~stolen~~ won from your bets!"
"Localized Strings","BetHistoryOutput","I have %s treats from betting!" "Localized Strings","BetHistoryOptionalPNGPath",""
"Localized Strings","BetHistoryOutput","I have %s beans from betting!"
"Localized Strings","BlurryInfo","Blurs your icon or the icon of a friend you mentioned" "Localized Strings","BlurryInfo","Blurs your icon or the icon of a friend you mentioned"
"Localized Strings","BoopInfo","Kitty will react with a counter" "Localized Strings","BoopInfo","Kitty will react with a counter"
"Localized Strings","BoopMultiple","%s booped several others - %s!" "Localized Strings","BoopMultiple","%s booped several others - %s!"
1 Type Key Value
2 Globals mode (dev or release) dev
3 Globals activity with a laser pointer
4 Localized Commands beans
5 Localized Commands benchmark, bench
6 Localized Commands bet
58 Localized Commands work
59 Localized Commands yeet
60 Localized Strings AddGuildRoleFailure Failed to add %s to %s
61 Localized Strings BeansImageBottomText BEANS
62 Localized Strings BeansImageTopText YOU HAVE
63 Localized Strings BeansShowDisplay You have %s beans!
64 Localized Strings BeansShowInfo Displays how many beans you have
65 Localized Strings BeansShowMentioned I took a look and %sbeans!
73 Localized Strings BetBeansNotValid That's not a valid bet!
74 Localized Strings BetBeansWin You won %s beans!
75 Localized Strings BetHistoryInfo Gives how many beans I've ~~stolen~~ won from your bets!
76 Localized Strings BetHistoryOutput BetHistoryOptionalPNGPath I have %s treats from betting!
77 Localized Strings BetHistoryOutput I have %s beans from betting!
78 Localized Strings BlurryInfo Blurs your icon or the icon of a friend you mentioned
79 Localized Strings BoopInfo Kitty will react with a counter
80 Localized Strings BoopMultiple %s booped several others - %s!
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

@@ -1,4 +1,4 @@
package commands.general; package commands.beans;
import java.awt.Font; import java.awt.Font;
import java.awt.FontMetrics; import java.awt.FontMetrics;
@@ -118,9 +118,9 @@ public class CommandBeansShow extends Command
Font beanFont = new Font("font", Font.BOLD, 45); Font beanFont = new Font("font", Font.BOLD, 45);
beanGraphics.setFont(beanFont); beanGraphics.setFont(beanFont);
drawCenteredString(beanGraphics, "YOU HAVE", rect, beanFont, .25); drawCenteredString(beanGraphics, LocStrings.stub("BeansImageTopText"), rect, beanFont, .25);
drawCenteredString(beanGraphics, "" + beans, rect, beanFont, .5); drawCenteredString(beanGraphics, "" + beans, rect, beanFont, .5);
drawCenteredString(beanGraphics, "BEANS!", rect, beanFont, .75); drawCenteredString(beanGraphics, LocStrings.stub("BeansImageBottomText"), rect, beanFont, .75);
ImageIO.write(beanImage, "PNG", new File("beanImage.png")); ImageIO.write(beanImage, "PNG", new File("beanImage.png"));
return new File("beanImage.png"); return new File("beanImage.png");
@@ -1,4 +1,4 @@
package commands.general; package commands.beans;
import java.util.Random; import java.util.Random;
@@ -1,25 +1,45 @@
package commands.general; package commands.beans;
import core.Command; import java.io.File;
import core.LocStrings;
import dataStructures.KittyChannel; import core.Command;
import dataStructures.KittyGuild; import core.LocStrings;
import dataStructures.KittyRating; import dataStructures.KittyChannel;
import dataStructures.KittyRole; import dataStructures.KittyGuild;
import dataStructures.KittyUser; import dataStructures.KittyRating;
import dataStructures.Response; import dataStructures.KittyRole;
import dataStructures.UserInput; import dataStructures.KittyUser;
import dataStructures.Response;
public class CommandBetHistory extends Command import dataStructures.UserInput;
{ import utils.GlobalLog;
public CommandBetHistory(KittyRole level, KittyRating rating) { super(level, rating); } import utils.LogFilter;
@Override public class CommandBetHistory extends Command
public String getHelpText() { return LocStrings.stub("BetHistoryInfo"); } {
public CommandBetHistory(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) @Override
{ public String getHelpText() { return LocStrings.stub("BetHistoryInfo"); }
res.send(String.format(LocStrings.stub("BetHistoryOutput"), guild.beans.get()));
} @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
// Send primary response
res.send(String.format(LocStrings.stub("BetHistoryOutput"), guild.beans.get()));
// Look up extra information to see if we ahve a flair image
String optional = LocStrings.stub("BetHistoryOptionalPNGPath");
if(optional != null && optional.length() > 0)
{
File responseImage = new File(optional);
if(responseImage.exists())
{
res.sendFile(responseImage, ".png");
}
else
{
GlobalLog.warn(LogFilter.Command, "Optional PNG image for bet history was specified, but the file could not be found.");
}
}
}
} }
@@ -1,4 +1,4 @@
package commands.general; package commands.beans;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general; package commands.beans;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
@@ -1,35 +1,35 @@
package commands.general; package commands.dev;
import core.Command; import core.Command;
import core.Constants; import core.Constants;
import core.DatabaseManager; import core.DatabaseManager;
import core.LocStrings; import core.LocStrings;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyEmbed; import dataStructures.KittyEmbed;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
public class CommandDBFlush extends Command public class CommandDBFlush extends Command
{ {
public CommandDBFlush(KittyRole level, KittyRating rating) { super(level, rating); } public CommandDBFlush(KittyRole level, KittyRating rating) { super(level, rating); }
@Override @Override
public String getHelpText() { return LocStrings.stub("DBFlushInfo"); } public String getHelpText() { return LocStrings.stub("DBFlushInfo"); }
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
int numUpdated = DatabaseManager.instance.upkeep(); int numUpdated = DatabaseManager.instance.upkeep();
KittyEmbed embed = new KittyEmbed(); KittyEmbed embed = new KittyEmbed();
embed.title = "Database queue flushed"; embed.title = "Database queue flushed";
embed.descriptionText = "**Dirty:** " + numUpdated; embed.descriptionText = "**Dirty:** " + numUpdated;
embed.color = Constants.ColorDefault; embed.color = Constants.ColorDefault;
res.send(embed); res.send(embed);
} }
} }
@@ -1,43 +1,43 @@
package commands.general; package commands.dev;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import core.Command; import core.Command;
import core.Constants; import core.Constants;
import core.DatabaseManager; import core.DatabaseManager;
import core.LocStrings; import core.LocStrings;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyEmbed; import dataStructures.KittyEmbed;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
public class CommandDBStats extends Command public class CommandDBStats extends Command
{ {
DateFormat dateFormat; DateFormat dateFormat;
public CommandDBStats(KittyRole level, KittyRating rating) public CommandDBStats(KittyRole level, KittyRating rating)
{ {
super(level, rating); super(level, rating);
dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
} }
@Override @Override
public String getHelpText() { return LocStrings.stub("DBStatsInfo"); } public String getHelpText() { return LocStrings.stub("DBStatsInfo"); }
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
KittyEmbed embed = new KittyEmbed(); KittyEmbed embed = new KittyEmbed();
embed.title = "Database Info"; embed.title = "Database Info";
embed.descriptionText = "**Tracked Items:** " + DatabaseManager.instance.getTrackedObjectsSize(); embed.descriptionText = "**Tracked Items:** " + DatabaseManager.instance.getTrackedObjectsSize();
embed.descriptionText += "\n"; embed.descriptionText += "\n";
embed.descriptionText += "**Last Upkeep:** " + dateFormat.format(DatabaseManager.instance.getLastUpkeep()) + " UTC-7"; embed.descriptionText += "**Last Upkeep:** " + dateFormat.format(DatabaseManager.instance.getLastUpkeep()) + " UTC-7";
embed.color = Constants.ColorDefault; embed.color = Constants.ColorDefault;
res.send(embed); res.send(embed);
} }
} }
@@ -1,33 +1,33 @@
package commands.general; package commands.dev;
import core.*; import core.*;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
public class CommandDoWork extends Command public class CommandDoWork extends Command
{ {
// Required constructor // Required constructor
public CommandDoWork(KittyRole level, KittyRating rating) { super(level, rating); } public CommandDoWork(KittyRole level, KittyRating rating) { super(level, rating); }
@Override @Override
public String getHelpText() { return LocStrings.stub("DoWorkInfo"); } public String getHelpText() { return LocStrings.stub("DoWorkInfo"); }
// Called when the command is run! // Called when the command is run!
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
long thispieceofshit = 0; long thispieceofshit = 0;
for(int i = 0; i < 200000000 + Math.random() * 30; i ++) for(int i = 0; i < 200000000 + Math.random() * 30; i ++)
{ {
thispieceofshit += Math.log((double)i); thispieceofshit += Math.log((double)i);
} }
res.send(LocStrings.stub("DoWorkFinished")); res.send(LocStrings.stub("DoWorkFinished"));
} }
} }
@@ -1,136 +1,136 @@
package commands.general; package commands.dev;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
import core.Stats; import core.Stats;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.GlobalLog; import utils.GlobalLog;
import utils.ImageUtils; import utils.ImageUtils;
public class CommandHelpBuilder extends Command { public class CommandHelpBuilder extends Command {
public CommandHelpBuilder(KittyRole role, KittyRating rating) { public CommandHelpBuilder(KittyRole role, KittyRating rating) {
super(role, rating); super(role, rating);
} }
@Override @Override
public String getHelpText() { return LocStrings.stub("HelpBuilderInfo"); } public String getHelpText() { return LocStrings.stub("HelpBuilderInfo"); }
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
// Holds command groups // Holds command groups
HashMap<KittyRole, ArrayList<Command>> commandsByRole = new HashMap<KittyRole, ArrayList<Command>>(); HashMap<KittyRole, ArrayList<Command>> commandsByRole = new HashMap<KittyRole, ArrayList<Command>>();
// Populate w/ empty array lists // Populate w/ empty array lists
for(int i = 0; i < KittyRole.values().length; ++i) for(int i = 0; i < KittyRole.values().length; ++i)
commandsByRole.put(KittyRole.values()[i], new ArrayList<Command>()); commandsByRole.put(KittyRole.values()[i], new ArrayList<Command>());
// Sort commands out // Sort commands out
ArrayList<Command> commands = Stats.instance.getAllCommands(); ArrayList<Command> commands = Stats.instance.getAllCommands();
for(int i = 0; i < commands.size(); ++i) for(int i = 0; i < commands.size(); ++i)
{ {
Command current = commands.get(i); Command current = commands.get(i);
commandsByRole.get(current.requiredRole()).add(current); commandsByRole.get(current.requiredRole()).add(current);
} }
// Format outstring and send it back for now // Format outstring and send it back for now
String out = ""; String out = "";
out += populateSection(KittyRole.Admin, commandsByRole, true) + "\n"; out += populateSection(KittyRole.Admin, commandsByRole, true) + "\n";
out += populateSection(KittyRole.Mod, commandsByRole, true) + "\n"; out += populateSection(KittyRole.Mod, commandsByRole, true) + "\n";
out += populateSection(KittyRole.General, commandsByRole, false) + "\n"; out += populateSection(KittyRole.General, commandsByRole, false) + "\n";
// Write out file // Write out file
String filename = "buildhelp_out.txt"; String filename = "buildhelp_out.txt";
try { try {
PrintWriter writer = new PrintWriter(filename); PrintWriter writer = new PrintWriter(filename);
writer.println(out); writer.println(out);
writer.flush(); writer.flush();
writer.close(); writer.close();
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
{ {
GlobalLog.error(e.toString()); GlobalLog.error(e.toString());
return; return;
} }
File file = new File(filename); File file = new File(filename);
res.sendFile(file, "txt"); res.sendFile(file, "txt");
ImageUtils.blockingFileDelete(file); ImageUtils.blockingFileDelete(file);
} }
// Generates the section for a specific role, optionally adding spacing after for another section // Generates the section for a specific role, optionally adding spacing after for another section
private String populateSection(KittyRole role, HashMap<KittyRole, ArrayList<Command>> commandsByRole, boolean delimitSection) private String populateSection(KittyRole role, HashMap<KittyRole, ArrayList<Command>> commandsByRole, boolean delimitSection)
{ {
// Formatting variables // Formatting variables
final String headerStart = "<h2>"; final String headerStart = "<h2>";
final String headerEnd = "</h2>\n"; final String headerEnd = "</h2>\n";
final String sectionStart = "<p>\n"; final String sectionStart = "<p>\n";
final String sectionEnd = "</p>"; final String sectionEnd = "</p>";
final String indent = " "; final String indent = " ";
final String leadStart = "<code>"; final String leadStart = "<code>";
final String leadEnd = "</code>"; final String leadEnd = "</code>";
final String leadFollow = ": "; final String leadFollow = ": ";
final String lineDelimiter = "<br/>\n"; final String lineDelimiter = "<br/>\n";
final String sectionDelimiter = "\n\n"; final String sectionDelimiter = "\n\n";
String accumulated = ""; String accumulated = "";
ArrayList<Command> commands = commandsByRole.get(role); ArrayList<Command> commands = commandsByRole.get(role);
ArrayList<Command> commandsSoFar = new ArrayList<Command>(); ArrayList<Command> commandsSoFar = new ArrayList<Command>();
if(commands.size() > 0) if(commands.size() > 0)
{ {
String roleStr = role.toString(); String roleStr = role.toString();
roleStr = roleStr.substring(0, 1).toUpperCase() + roleStr.toLowerCase().substring(1); roleStr = roleStr.substring(0, 1).toUpperCase() + roleStr.toLowerCase().substring(1);
// Section header // Section header
accumulated += headerStart + roleStr + " commands" + headerEnd; accumulated += headerStart + roleStr + " commands" + headerEnd;
accumulated += sectionStart; accumulated += sectionStart;
// Section content // Section content
for(int i = 0; i < commands.size(); ++i) for(int i = 0; i < commands.size(); ++i)
{ {
accumulated += indent; accumulated += indent;
Command command = commands.get(i); Command command = commands.get(i);
// Skip multiples // Skip multiples
if(commandsSoFar.contains(command)) if(commandsSoFar.contains(command))
continue; continue;
else else
commandsSoFar.add(command); commandsSoFar.add(command);
// Write out all the keys and the help text // Write out all the keys and the help text
ArrayList<String> keys = command.registeredNames(); ArrayList<String> keys = command.registeredNames();
for(int j = 0; j < keys.size(); ++j) for(int j = 0; j < keys.size(); ++j)
{ {
if(j != 0) if(j != 0)
accumulated += ", "; accumulated += ", ";
accumulated += leadStart + keys.get(j) + leadEnd; accumulated += leadStart + keys.get(j) + leadEnd;
} }
accumulated += leadFollow + commands.get(i).getHelpText() + lineDelimiter;; accumulated += leadFollow + commands.get(i).getHelpText() + lineDelimiter;;
} }
accumulated += sectionEnd; accumulated += sectionEnd;
// Add spaces after if needed // Add spaces after if needed
if(delimitSection) if(delimitSection)
accumulated += sectionDelimiter; accumulated += sectionDelimiter;
} }
return accumulated; return accumulated;
} }
} }
@@ -1,4 +1,4 @@
package commands.general; package commands.dev;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
@@ -1,60 +1,60 @@
package commands.general; package commands.dev;
import core.Command; import core.Command;
import core.DatabaseManager; import core.DatabaseManager;
import core.LocStrings; import core.LocStrings;
import core.Stats; import core.Stats;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.GlobalLog; import utils.GlobalLog;
import utils.LogFilter; import utils.LogFilter;
// NOTE(wisp): This is a sort of special command. // NOTE(wisp): This is a sort of special command.
public class CommandShutdown extends Command public class CommandShutdown extends Command
{ {
public CommandShutdown(KittyRole level, KittyRating rating) { super(level, rating); } public CommandShutdown(KittyRole level, KittyRating rating) { super(level, rating); }
@Override @Override
public String getHelpText() { return LocStrings.stub("ShutdownInfo"); } public String getHelpText() { return LocStrings.stub("ShutdownInfo"); }
// Called when the command is run! // Called when the command is run!
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
// Flag the shutdown immediately. // Flag the shutdown immediately.
Stats.instance.indicateShutdown(); Stats.instance.indicateShutdown();
boolean isSafe = false; boolean isSafe = false;
switch(input.args.toLowerCase().trim()) switch(input.args.toLowerCase().trim())
{ {
case "s": case "s":
case "safe": case "safe":
case "-s": case "-s":
case "-safe": case "-safe":
case "snafe": case "snafe":
isSafe = true; isSafe = true;
break; break;
} }
if(isSafe) if(isSafe)
{ {
// Force upkeep, this works so long as upkeep is on the main thread. // Force upkeep, this works so long as upkeep is on the main thread.
res.sendImmediate(LocStrings.stub("ShutdownSafe")); res.sendImmediate(LocStrings.stub("ShutdownSafe"));
DatabaseManager.instance.upkeep(); DatabaseManager.instance.upkeep();
GlobalLog.warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe")); GlobalLog.warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe"));
System.exit(0); System.exit(0);
} }
else else
{ {
res.sendImmediate(LocStrings.stub("ShutdownUnsafe"));// "``"); res.sendImmediate(LocStrings.stub("ShutdownUnsafe"));// "``");
GlobalLog.warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe")); GlobalLog.warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe"));
System.exit(0); System.exit(0);
} }
} }
} }
@@ -1,89 +1,89 @@
package commands.general; package commands.dev;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
import core.CommandManager.ThreadData; import core.CommandManager.ThreadData;
import core.Constants; import core.Constants;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyEmbed; import dataStructures.KittyEmbed;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import core.Stats; import core.Stats;
public class CommandStats extends Command public class CommandStats extends Command
{ {
public CommandStats(KittyRole level, KittyRating rating) { super(level, rating); } public CommandStats(KittyRole level, KittyRating rating) { super(level, rating); }
@Override @Override
public String getHelpText() { return LocStrings.stub("StatsInfo"); } public String getHelpText() { return LocStrings.stub("StatsInfo"); }
// Called when the command is run! // Called when the command is run!
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
// Variables // Variables
Stats stats = Stats.instance; Stats stats = Stats.instance;
String out = ""; String out = "";
long seen = stats.getMessagesSeen(); long seen = stats.getMessagesSeen();
long processed = stats.getCommandsProcessed(); long processed = stats.getCommandsProcessed();
// General // General
out += "General"; out += "General";
out += "```\n"; out += "```\n";
out += " Messages observed: " + seen + "\n"; out += " Messages observed: " + seen + "\n";
out += "Commands processed: " + processed + "\n"; out += "Commands processed: " + processed + "\n";
out += " Command invoke %: " + ((int)((processed / (float)seen) * 1000)) / 10.0f + "%\n"; out += " Command invoke %: " + ((int)((processed / (float)seen) * 1000)) / 10.0f + "%\n";
out += " Bot uptime: " + stats.getFormattedUptime() + "\n"; out += " Bot uptime: " + stats.getFormattedUptime() + "\n";
out += "```\n"; out += "```\n";
// Health // Health
out += "Health"; out += "Health";
out += "```\n"; out += "```\n";
out += " SMT cores: " + stats.getCPUAvailable() + "\n"; out += " SMT cores: " + stats.getCPUAvailable() + "\n";
// If CPU load works on this OS, list it. -1.0 is the error state // If CPU load works on this OS, list it. -1.0 is the error state
double CPULoad = stats.getSystemCPULoad(); double CPULoad = stats.getSystemCPULoad();
out += CPULoad > -0.9 out += CPULoad > -0.9
? " CPU Load: " + (CPULoad * 100) + "%\n" : ""; ? " CPU Load: " + (CPULoad * 100) + "%\n" : "";
ThreadData data = stats.getThreadData(); ThreadData data = stats.getThreadData();
Integer terminated = data.states.get(Thread.State.TERMINATED); Integer terminated = data.states.get(Thread.State.TERMINATED);
Integer runnable = data.states.get(Thread.State.RUNNABLE); Integer runnable = data.states.get(Thread.State.RUNNABLE);
Integer blocked = data.states.get(Thread.State.BLOCKED); Integer blocked = data.states.get(Thread.State.BLOCKED);
Integer timed_waiting = data.states.get(Thread.State.TIMED_WAITING); Integer timed_waiting = data.states.get(Thread.State.TIMED_WAITING);
Integer waiting = data.states.get(Thread.State.WAITING); Integer waiting = data.states.get(Thread.State.WAITING);
out += " Threads:" out += " Threads:"
+ " run-" + (runnable == null ? 0 : runnable) + " run-" + (runnable == null ? 0 : runnable)
+ " block-" + (blocked == null ? 0 : blocked) + " block-" + (blocked == null ? 0 : blocked)
+ " sleep-" + (timed_waiting == null ? 0 : timed_waiting) + " sleep-" + (timed_waiting == null ? 0 : timed_waiting)
+ " wait-" + (waiting == null ? 0 : waiting) + " wait-" + (waiting == null ? 0 : waiting)
+ " term-" + (terminated == null ? 0 : terminated) + " term-" + (terminated == null ? 0 : terminated)
+ "\n"; + "\n";
out += "```\n"; out += "```\n";
// Cache // Cache
Integer guildCount = stats.getGuildCount(); Integer guildCount = stats.getGuildCount();
Integer userCount = stats.getUserCount(); Integer userCount = stats.getUserCount();
out += "Cache"; out += "Cache";
out += "```\n" out += "```\n"
+ "Cached Guilds: " + guildCount + "\n" + "Cached Guilds: " + guildCount + "\n"
+ " Cached Users: " + userCount; + " Cached Users: " + userCount;
out += "\n```"; out += "\n```";
KittyEmbed embed = new KittyEmbed(); KittyEmbed embed = new KittyEmbed();
embed.title = "Bot Stats"; embed.title = "Bot Stats";
embed.descriptionText = out; embed.descriptionText = out;
embed.color = Constants.ColorDefault; embed.color = Constants.ColorDefault;
res.send(embed); res.send(embed);
} }
} }
@@ -1,4 +1,4 @@
package commands.general; package commands.dev;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
+1 -1
View File
@@ -43,4 +43,4 @@ public class CommandChoose extends Command
res.send(String.format(LocStrings.stub("ChooseChoice"), (choices[(int) (Math.random()*choices.length)]).toString())); res.send(String.format(LocStrings.stub("ChooseChoice"), (choices[(int) (Math.random()*choices.length)]).toString()));
} }
} }
+2 -2
View File
@@ -7,7 +7,7 @@ import core.Command;
import core.Constants; import core.Constants;
import core.DatabaseManager; import core.DatabaseManager;
import core.LocStrings; import core.LocStrings;
import core.ObjectBuilderFactory; import core.ObjectBuilder;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyEmbed; import dataStructures.KittyEmbed;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
@@ -98,7 +98,7 @@ public class CommandLeaderboard extends Command
{ {
// Only now that we've sorted do we do the full construction and caching of users // Only now that we've sorted do we do the full construction and caching of users
Pair<Long, String> userPair = users.get(i); Pair<Long, String> userPair = users.get(i);
KittyUser cachedUser = ObjectBuilderFactory.getKittyUser(guildID, userPair.Second); KittyUser cachedUser = ObjectBuilder.getKittyUser(guildID, userPair.Second);
if(cachedUser == null) if(cachedUser == null)
continue; continue;
@@ -1,4 +1,4 @@
package commands.general; package commands.images;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@@ -1,71 +1,71 @@
package commands.general; package commands.images;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.ImageOverlayBuilder; import utils.ImageOverlayBuilder;
import utils.ImageUtils; import utils.ImageUtils;
public class CommandCatch extends Command public class CommandCatch extends Command
{ {
// Required constructor // Required constructor
public CommandCatch(KittyRole level, KittyRating rating) { super(level, rating); } public CommandCatch(KittyRole level, KittyRating rating) { super(level, rating); }
private static Long num = 0l; private static Long num = 0l;
@Override @Override
public String getHelpText() { return LocStrings.stub("CatchInfo"); } public String getHelpText() { return LocStrings.stub("CatchInfo"); }
// Called when the command is run! // Called when the command is run!
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
String name = null; String name = null;
File catchFile = null; File catchFile = null;
File catcheeFile = null; File catcheeFile = null;
synchronized(num) synchronized(num)
{ {
name = "catch_" + num + ".gif"; name = "catch_" + num + ".gif";
++num; ++num;
} }
try try
{ {
KittyUser person = null; KittyUser person = null;
if(input.mentions == null) if(input.mentions == null)
person = user; person = user;
else else
person = input.mentions[0]; person = input.mentions[0];
String catchFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); String catchFilename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(catchFilename == null) if(catchFilename == null)
return; return;
catcheeFile = new File(catchFilename); catcheeFile = new File(catchFilename);
ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/catch/frames/", "catch ", 92, 18); ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/catch/frames/", "catch ", 92, 18);
builder.overlay(ImageIO.read(catcheeFile), name); builder.overlay(ImageIO.read(catcheeFile), name);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
catchFile = new File (name); catchFile = new File (name);
res.sendFile(catchFile, "gif"); res.sendFile(catchFile, "gif");
// Thread cleanup... // Thread cleanup...
ImageUtils.blockingFileDelete(catchFile); ImageUtils.blockingFileDelete(catchFile);
ImageUtils.blockingFileDelete(catcheeFile); ImageUtils.blockingFileDelete(catcheeFile);
} }
} }
@@ -1,71 +1,71 @@
package commands.general; package commands.images;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.ImageOverlayBuilder; import utils.ImageOverlayBuilder;
import utils.ImageUtils; import utils.ImageUtils;
public class CommandDefaultDance extends Command public class CommandDefaultDance extends Command
{ {
// Required constructor // Required constructor
public CommandDefaultDance(KittyRole level, KittyRating rating) { super(level, rating); } public CommandDefaultDance(KittyRole level, KittyRating rating) { super(level, rating); }
private static Long num = 0l; private static Long num = 0l;
@Override @Override
public String getHelpText() { return LocStrings.stub("DefaultDanceInfo"); } public String getHelpText() { return LocStrings.stub("DefaultDanceInfo"); }
// Called when the command is run! // Called when the command is run!
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
String name = null; String name = null;
File dancerFile = null; File dancerFile = null;
File danceeFile = null; File danceeFile = null;
synchronized(num) synchronized(num)
{ {
name = "defaultDance_" + num + ".gif"; name = "defaultDance_" + num + ".gif";
++num; ++num;
} }
try try
{ {
KittyUser person = null; KittyUser person = null;
if(input.mentions == null) if(input.mentions == null)
person = user; person = user;
else else
person = input.mentions[0]; person = input.mentions[0];
String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(yeeteeFilename == null) if(yeeteeFilename == null)
return; return;
danceeFile = new File(yeeteeFilename); danceeFile = new File(yeeteeFilename);
ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/dance/default/", "defaultDance ", 118, 18); ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/dance/default/", "defaultDance ", 118, 18);
builder.overlay(ImageIO.read(danceeFile), name); builder.overlay(ImageIO.read(danceeFile), name);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
dancerFile = new File (name); dancerFile = new File (name);
res.sendFile(dancerFile, "gif"); res.sendFile(dancerFile, "gif");
// Thread cleanup... // Thread cleanup...
ImageUtils.blockingFileDelete(dancerFile); ImageUtils.blockingFileDelete(dancerFile);
ImageUtils.blockingFileDelete(danceeFile); ImageUtils.blockingFileDelete(danceeFile);
} }
} }
@@ -1,105 +1,105 @@
package commands.general; package commands.images;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.ImageUtils; import utils.ImageUtils;
public class CommandPerish extends Command public class CommandPerish extends Command
{ {
public CommandPerish(KittyRole level, KittyRating rating) { super(level, rating); } public CommandPerish(KittyRole level, KittyRating rating) { super(level, rating); }
@Override @Override
public String getHelpText() { return LocStrings.stub("PerishInfo"); }; public String getHelpText() { return LocStrings.stub("PerishInfo"); };
private static Long num = 0l; private static Long num = 0l;
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
String name = null; String name = null;
String filename = null; String filename = null;
File preProcessed = null; File preProcessed = null;
File postProcessed = null; File postProcessed = null;
synchronized(num) synchronized(num)
{ {
name = "perish_" + num + ".png"; name = "perish_" + num + ".png";
++num; ++num;
} }
try try
{ {
try try
{ {
filename = ImageUtils.downloadFromURL(input.args.split(" ")[0], ".png"); filename = ImageUtils.downloadFromURL(input.args.split(" ")[0], ".png");
preProcessed = new File(filename); preProcessed = new File(filename);
} }
catch(Exception e) catch(Exception e)
{ {
KittyUser person = user; KittyUser person = user;
if(input.mentions != null) if(input.mentions != null)
person = input.mentions[0]; person = input.mentions[0];
filename = ImageUtils.downloadFromURL(person.avatarID, ".png"); filename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(filename == null) if(filename == null)
return; return;
} }
preProcessed = new File(filename); preProcessed = new File(filename);
applyTintEffect(ImageIO.read(preProcessed), name); applyTintEffect(ImageIO.read(preProcessed), name);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
postProcessed = new File(name); postProcessed = new File(name);
res.sendFile(postProcessed, "png"); res.sendFile(postProcessed, "png");
ImageUtils.blockingFileDelete(preProcessed); ImageUtils.blockingFileDelete(preProcessed);
ImageUtils.blockingFileDelete(postProcessed); ImageUtils.blockingFileDelete(postProcessed);
} }
private static void applyTintEffect(BufferedImage image, String name) throws IOException private static void applyTintEffect(BufferedImage image, String name) throws IOException
{ {
// Iterate over each column left to right and touch up each pixel // Iterate over each column left to right and touch up each pixel
for(int x = 0; x < image.getWidth(); ++x) for(int x = 0; x < image.getWidth(); ++x)
{ {
for(int y = 0; y < image.getHeight(); ++y) for(int y = 0; y < image.getHeight(); ++y)
{ {
Color c = new Color(image.getRGB(x, y), true); Color c = new Color(image.getRGB(x, y), true);
int red = c.getRed(); int red = c.getRed();
red += 100; red += 100;
if(red > 255) if(red > 255)
red = 255; red = 255;
int green = c.getGreen(); int green = c.getGreen();
int blue = c.getBlue(); int blue = c.getBlue();
blue += 20; blue += 20;
if(blue > 255) if(blue > 255)
blue = 255; blue = 255;
Color tinted = new Color(red, green, blue, c.getAlpha()); Color tinted = new Color(red, green, blue, c.getAlpha());
image.setRGB(x, y, tinted.getRGB()); image.setRGB(x, y, tinted.getRGB());
} }
} }
File outputfile = new File(name); File outputfile = new File(name);
ImageIO.write(image, "png", outputfile); ImageIO.write(image, "png", outputfile);
} }
} }
@@ -1,4 +1,4 @@
package commands.general; package commands.images;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@@ -1,72 +1,72 @@
package commands.general; package commands.images;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import core.Command; import core.Command;
import core.Constants; import core.Constants;
import core.LocStrings; import core.LocStrings;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.ImageOverlayBuilder; import utils.ImageOverlayBuilder;
import utils.ImageUtils; import utils.ImageUtils;
public class CommandTeey extends Command public class CommandTeey extends Command
{ {
// Required constructor // Required constructor
public CommandTeey(KittyRole level, KittyRating rating) { super(level, rating); } public CommandTeey(KittyRole level, KittyRating rating) { super(level, rating); }
private static Long num = 0l; private static Long num = 0l;
@Override @Override
public String getHelpText() { return LocStrings.stub("TeeyInfo"); } public String getHelpText() { return LocStrings.stub("TeeyInfo"); }
// Called when the command is run! // Called when the command is run!
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
String name = null; String name = null;
File teeyFile = null; File teeyFile = null;
File teeyeeFile = null; File teeyeeFile = null;
synchronized(num) synchronized(num)
{ {
name = "teey_" + num + ".gif"; name = "teey_" + num + ".gif";
++num; ++num;
} }
try try
{ {
KittyUser person = null; KittyUser person = null;
if(input.mentions == null) if(input.mentions == null)
person = user; person = user;
else else
person = input.mentions[0]; person = input.mentions[0];
String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(yeeteeFilename == null) if(yeeteeFilename == null)
return; return;
teeyeeFile = new File(yeeteeFilename); teeyeeFile = new File(yeeteeFilename);
ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "teey/frames/", "teey ", 24, 18); ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "teey/frames/", "teey ", 24, 18);
builder.overlay(ImageIO.read(teeyeeFile), name); builder.overlay(ImageIO.read(teeyeeFile), name);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
teeyFile = new File (name); teeyFile = new File (name);
res.sendFile(teeyFile, "gif"); res.sendFile(teeyFile, "gif");
// Thread cleanup... // Thread cleanup...
ImageUtils.blockingFileDelete(teeyFile); ImageUtils.blockingFileDelete(teeyFile);
ImageUtils.blockingFileDelete(teeyeeFile); ImageUtils.blockingFileDelete(teeyeeFile);
} }
} }
@@ -1,72 +1,72 @@
package commands.general; package commands.images;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import core.Command; import core.Command;
import core.Constants; import core.Constants;
import core.LocStrings; import core.LocStrings;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.ImageOverlayBuilder; import utils.ImageOverlayBuilder;
import utils.ImageUtils; import utils.ImageUtils;
public class CommandYeet extends Command public class CommandYeet extends Command
{ {
// Required constructor // Required constructor
public CommandYeet(KittyRole level, KittyRating rating) { super(level, rating); } public CommandYeet(KittyRole level, KittyRating rating) { super(level, rating); }
private static Long num = 0l; private static Long num = 0l;
@Override @Override
public String getHelpText() { return LocStrings.stub("YeetInfo"); } public String getHelpText() { return LocStrings.stub("YeetInfo"); }
// Called when the command is run! // Called when the command is run!
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
String name = null; String name = null;
File yeetFile = null; File yeetFile = null;
File yeeteeFile = null; File yeeteeFile = null;
synchronized(num) synchronized(num)
{ {
name = "yeet_" + num + ".gif"; name = "yeet_" + num + ".gif";
++num; ++num;
} }
try try
{ {
KittyUser person = null; KittyUser person = null;
if(input.mentions == null) if(input.mentions == null)
person = user; person = user;
else else
person = input.mentions[0]; person = input.mentions[0];
String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(yeeteeFilename == null) if(yeeteeFilename == null)
return; return;
yeeteeFile = new File(yeeteeFilename); yeeteeFile = new File(yeeteeFilename);
ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "yeet/frames/", "yeet ", 24, 18); ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "yeet/frames/", "yeet ", 24, 18);
builder.overlay(ImageIO.read(yeeteeFile), name); builder.overlay(ImageIO.read(yeeteeFile), name);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
yeetFile = new File (name); yeetFile = new File (name);
res.sendFile(yeetFile, "gif"); res.sendFile(yeetFile, "gif");
// Thread cleanup... // Thread cleanup...
ImageUtils.blockingFileDelete(yeetFile); ImageUtils.blockingFileDelete(yeetFile);
ImageUtils.blockingFileDelete(yeeteeFile); ImageUtils.blockingFileDelete(yeeteeFile);
} }
} }
@@ -1,4 +1,4 @@
package commands.general; package commands.network;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general; package commands.network;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general; package commands.network;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general; package commands.network;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general; package commands.network;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
@@ -1,4 +1,4 @@
package commands.general; package commands.network;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
+26
View File
@@ -4,11 +4,37 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import commands.beans.CommandBeansShow;
import commands.beans.CommandBetBeans;
import commands.beans.CommandBetHistory;
import commands.beans.CommandGiveBeans;
import commands.beans.CommandTradeBeans;
import commands.characters.CommandCharacterMain; import commands.characters.CommandCharacterMain;
import commands.dev.CommandDBFlush;
import commands.dev.CommandDBStats;
import commands.dev.CommandDoWork;
import commands.dev.CommandHelpBuilder;
import commands.dev.CommandInvite;
import commands.dev.CommandShutdown;
import commands.dev.CommandStats;
import commands.dev.CommandTweet;
import commands.general.*; import commands.general.*;
import commands.guildrole.CommandGuildRoleMain; import commands.guildrole.CommandGuildRoleMain;
import commands.images.CommandBlurry;
import commands.images.CommandCatch;
import commands.images.CommandDefaultDance;
import commands.images.CommandPerish;
import commands.images.CommandStark;
import commands.images.CommandTeey;
import commands.images.CommandYeet;
import commands.mod.CommandModMain; import commands.mod.CommandModMain;
import commands.music.CommandMusicMain; import commands.music.CommandMusicMain;
import commands.network.CommandColiru;
import commands.network.CommandDerpi;
import commands.network.CommandE6;
import commands.network.CommandGetSauce;
import commands.network.CommandJDoodle;
import commands.network.CommandWolfram;
import commands.poll.CommandPollMain; import commands.poll.CommandPollMain;
import commands.raffle.CommandRaffleMain; import commands.raffle.CommandRaffleMain;
import dataStructures.*; import dataStructures.*;
+35 -1
View File
@@ -18,13 +18,20 @@ public class ConfigGlobals implements IConfigSection
private static final String startupStyleKey = "mode (dev or release)"; private static final String startupStyleKey = "mode (dev or release)";
private KittyStartupMode startupStyleValue = KittyStartupMode.Dev; private KittyStartupMode startupStyleValue = KittyStartupMode.Dev;
// Constructor private static final String activityKey = "activity";
private String activityValue = "with a laser pointer"; // Appears as "Playing with a laser pointer"
// Singleton Constructor - explode if there's a problem.
public ConfigGlobals() public ConfigGlobals()
{ {
if(instance == null) if(instance == null)
{
instance = this; instance = this;
}
else else
{
GlobalLog.error("Attempted to initialize a second config globals! Probably don't do this!"); GlobalLog.error("Attempted to initialize a second config globals! Probably don't do this!");
}
} }
@Override @Override
@@ -38,6 +45,11 @@ public class ConfigGlobals implements IConfigSection
return instance.startupStyleValue; return instance.startupStyleValue;
} }
public static String getActivity()
{
return instance.activityValue;
}
@Override @Override
public void consume(List<ConfigItem> pairs) public void consume(List<ConfigItem> pairs)
{ {
@@ -52,8 +64,29 @@ public class ConfigGlobals implements IConfigSection
startupStyleValue = KittyStartupMode.Dev; startupStyleValue = KittyStartupMode.Dev;
if(value.equalsIgnoreCase(KittyStartupMode.Release.name())) if(value.equalsIgnoreCase(KittyStartupMode.Release.name()))
{
startupStyleValue = KittyStartupMode.Release; startupStyleValue = KittyStartupMode.Release;
}
if(value.equalsIgnoreCase(KittyStartupMode.PoguRelease.name()))
{
startupStyleValue = KittyStartupMode.PoguRelease;
}
continue;
} }
// Parse text for 'playing'
if(key.equalsIgnoreCase(activityKey))
{
activityValue = value;
}
}
// If we change any globals, update anything we need to.
if(ObjectBuilder.getHasInitialized())
{
ObjectBuilder.updateActivity();
} }
} }
@@ -62,6 +95,7 @@ public class ConfigGlobals implements IConfigSection
{ {
List<ConfigItem> items = new ArrayList<ConfigItem>(); List<ConfigItem> items = new ArrayList<ConfigItem>();
items.add(new ConfigItem(getSectionTitle(), startupStyleKey, startupStyleValue.name().toLowerCase())); items.add(new ConfigItem(getSectionTitle(), startupStyleKey, startupStyleValue.name().toLowerCase()));
items.add(new ConfigItem(getSectionTitle(), activityKey, activityValue));
return items; return items;
} }
@@ -23,15 +23,15 @@ import dataStructures.KittyRole;
import dataStructures.KittyStartupMode; import dataStructures.KittyStartupMode;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import main.Main; import main.Main;
import net.dv8tion.jda.core.AccountType; import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.core.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.core.entities.Emote; import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.core.entities.Game; import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.core.entities.User; import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import offline.Ref; import offline.Ref;
import utils.AdminControl; import utils.AdminControl;
//import utils.AudioUtils; //import utils.AudioUtils;
@@ -39,11 +39,11 @@ import utils.GlobalLog;
import utils.LogFilter; import utils.LogFilter;
import utils.audio.AudioUtils; import utils.audio.AudioUtils;
// NOTE(wisp): Isolated factory to assist with storage and caching if needed. // NOTE: Isolated factory to assist with storage and caching if needed.
// This also minimizes the number of places JDA interacts with our codebase. // 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. // As it stands, if the object name begins with Kitty, it's constructed here.
// TODO: Make all methods ID based instead of event based // TODO: Make all methods ID based instead of event based
public class ObjectBuilderFactory public class ObjectBuilder
{ {
// Key: guild string id, Value: guild information // Key: guild string id, Value: guild information
private static HashMap<String, KittyGuild> guildCache; private static HashMap<String, KittyGuild> guildCache;
@@ -82,15 +82,20 @@ public class ObjectBuilderFactory
// Lazy initialization multithreaded mutex stuff to prevent explosions. // Lazy initialization multithreaded mutex stuff to prevent explosions.
// TODO: Investigate using 'synchronized' instead potentially // TODO: Investigate using 'synchronized' instead potentially
private static boolean hasInitialized; private static Boolean hasInitialized = false;
private static Semaphore initMutex = new Semaphore(1); private static Semaphore initMutex = new Semaphore(1);
private static JDA kitty; private static JDA kitty;
// This is it, this is how the lazy init starts! // This is it, this is how the lazy init starts!
private static void lazyInit() private static void lazyInit()
{ {
if(hasInitialized) synchronized(hasInitialized)
return; {
if(hasInitialized)
{
return;
}
}
try try
{ {
@@ -109,14 +114,17 @@ public class ObjectBuilderFactory
AudioSourceManagers.registerLocalSource(playerManager); AudioSourceManagers.registerLocalSource(playerManager);
// Start by reading from things that are external. Because // Start by reading from things that are external. Because
// we require these things to be resolved before the rest of the application, // we require these things to be resolved before the rest of
// we place them here. // the application, we place them here.
config = new Config(); config = new Config();
} }
finally finally
{ {
initMutex.release(); initMutex.release();
hasInitialized = true; synchronized(hasInitialized)
{
hasInitialized = true;
}
} }
} }
catch(InterruptedException ie) catch(InterruptedException ie)
@@ -126,6 +134,14 @@ public class ObjectBuilderFactory
} }
} }
public static boolean getHasInitialized()
{
synchronized(hasInitialized)
{
return hasInitialized;
}
}
//////////////////////// ////////////////////////
// Extraction Methods // // Extraction Methods //
//////////////////////// ////////////////////////
@@ -167,7 +183,7 @@ public class ObjectBuilderFactory
else else
{ {
// Construct a new guild with defaults // Construct a new guild with defaults
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString, guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString,
new AudioUtils(event.getGuild(), playerManager), channels); new AudioUtils(event.getGuild(), playerManager), channels);
DatabaseManager.instance.globalRegister(guild); DatabaseManager.instance.globalRegister(guild);
guildCache.put(uid, guild); guildCache.put(uid, guild);
@@ -188,8 +204,8 @@ public class ObjectBuilderFactory
// the guild if not, they're assumed to be // the guild if not, they're assumed to be
// allowed to use the bot at a general level. // allowed to use the bot at a general level.
KittyRole role = KittyRole.General; KittyRole role = KittyRole.General;
if(event.getAuthor().getId() == event.getGuild().getOwner().getUser().getId()) if(event.getAuthor().getId() == event.getGuild().getOwnerId())
{ {
role = KittyRole.Admin; role = KittyRole.Admin;
} }
@@ -389,21 +405,32 @@ public class ObjectBuilderFactory
// Determine token based on config. Default to test token. // Determine token based on config. Default to test token.
String tokenToUse = Ref.TestToken; String tokenToUse = Ref.TestToken;
if(ConfigGlobals.getStartupMode() == KittyStartupMode.Release) switch(ConfigGlobals.getStartupMode())
tokenToUse = Ref.Token; {
if(ConfigGlobals.getStartupMode() == KittyStartupMode.PoguRelease) case Release: tokenToUse = Ref.Token; break;
tokenToUse = Ref.PoguToken; case PoguRelease: tokenToUse = Ref.PoguToken; break;
default: tokenToUse = Ref.TestToken; break;
}
// Construct bot based on token using the JDA Builder
JDABuilder builder = JDABuilder.createDefault(tokenToUse);
kitty = builder.build();
// Construct bot based on token // Set activity, and add primariy event listener.
kitty = new JDABuilder(AccountType.BOT) updateActivity();
.setToken(tokenToUse).buildBlocking();
kitty.getPresence().setGame(Game.playing("with a laser pointer"));
kitty.addEventListener(new Main()); kitty.addEventListener(new Main());
return new KittyCore(kitty); return new KittyCore(kitty);
} }
// Updates the bots current activity based on the globals value.
public static void updateActivity()
{
String activity = ConfigGlobals.getActivity();
GlobalLog.log(LogFilter.Core, "Updating activity to " + activity);
kitty.getPresence().setActivity(Activity.playing(activity));
}
// Default construction of the command manager. In order to remotely resolve command enabling // 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 // 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 // the CommandEnabler object passed in. In theory, we could have multiple CommandManagers, tho we can
+2 -2
View File
@@ -107,12 +107,12 @@ public class Stats
public int getGuildCount() public int getGuildCount()
{ {
return ObjectBuilderFactory.getGuildCount(); return ObjectBuilder.getGuildCount();
} }
public int getUserCount() public int getUserCount()
{ {
return ObjectBuilderFactory.getUserCount(); return ObjectBuilder.getUserCount();
} }
public ArrayList<Command> getAllCommands() public ArrayList<Command> getAllCommands()
+13 -13
View File
@@ -1,13 +1,13 @@
package dataStructures; package dataStructures;
import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.api.JDA;
public class KittyCore public class KittyCore
{ {
public final JDA jda; public final JDA jda;
public KittyCore(JDA kitty) public KittyCore(JDA kitty)
{ {
this.jda = kitty; this.jda = kitty;
} }
} }
+11 -6
View File
@@ -3,11 +3,12 @@ package dataStructures;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.core.MessageBuilder; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.core.entities.TextChannel; import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.core.events.message.guild.*; import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.core.EmbedBuilder; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.utils.AttachmentOption;
import utils.GlobalLog; import utils.GlobalLog;
import utils.LogFilter; import utils.LogFilter;
@@ -72,10 +73,14 @@ public class Response
embed.setThumbnail(thumbPath); embed.setThumbnail(thumbPath);
message.setEmbed(embed.build()); message.setEmbed(embed.build());
GlobalLog.log("We're trying to send a response that has a locally defined thumbnail file...");
File thumbImage = new File(thumbName); File thumbImage = new File(thumbName);
if(thumbImage.exists()) if(thumbImage.exists())
{ {
event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue(); // Used to eb as follows:
//event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
event.getChannel().sendMessage(message.build()).queue();
} }
} }
else else
+100 -100
View File
@@ -1,100 +1,100 @@
package dataStructures; package dataStructures;
import java.util.List; import java.util.List;
import core.ObjectBuilderFactory; import core.ObjectBuilder;
import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class UserInput public class UserInput
{ {
// Variables // Variables
public String key; public String key;
public String args; public String args;
public KittyUser [] mentions; public KittyUser [] mentions;
private boolean isValid; private boolean isValid;
public String message; public String message;
// NOTE(wisp): Designed to parse a string as it's constructed. // NOTE(wisp): Designed to parse a string as it's constructed.
// If a user enters the command "!ping some stuff here :D" // If a user enters the command "!ping some stuff here :D"
// and if the command indicator is !, then... // and if the command indicator is !, then...
// //
// key=ping // key=ping
// args=some stuff here :D // args=some stuff here :D
// //
// The CommandIndicator and spaces between the key and args are dropped. // The CommandIndicator and spaces between the key and args are dropped.
public UserInput(GuildMessageReceivedEvent event, KittyGuild guildContext) public UserInput(GuildMessageReceivedEvent event, KittyGuild guildContext)
{ {
String toParse = event.getMessage().getContentRaw(); String toParse = event.getMessage().getContentRaw();
message = toParse; message = toParse;
key = ""; key = "";
args = ""; args = "";
if(toParse.length() <= 0) if(toParse.length() <= 0)
return; return;
if(!event.getMessage().getMentionedMembers().isEmpty()) if(!event.getMessage().getMentionedMembers().isEmpty())
mentions = findMentionedUsers(event); mentions = findMentionedUsers(event);
toParse = toParse.trim(); toParse = toParse.trim();
String commandIndicator = guildContext.getCommandIndicator(); String commandIndicator = guildContext.getCommandIndicator();
if(toParse.startsWith(commandIndicator)) if(toParse.startsWith(commandIndicator))
{ {
int loc = findFirstWhitespace(toParse); int loc = findFirstWhitespace(toParse);
if(loc <= 0) if(loc <= 0)
{ {
key = toParse.substring(commandIndicator.length()).trim().toLowerCase(); key = toParse.substring(commandIndicator.length()).trim().toLowerCase();
} }
else else
{ {
key = toParse.substring(commandIndicator.length(), loc).trim().toLowerCase(); key = toParse.substring(commandIndicator.length(), loc).trim().toLowerCase();
args = toParse.substring(loc).trim(); args = toParse.substring(loc).trim();
} }
isValid = true; isValid = true;
} }
else else
{ {
isValid = false; isValid = false;
} }
} }
// Used for injecting direct commands from plugins // Used for injecting direct commands from plugins
public UserInput(String input, KittyGuild contextGuild) public UserInput(String input, KittyGuild contextGuild)
{ {
int loc = findFirstWhitespace(input); int loc = findFirstWhitespace(input);
key = input.substring(0, loc); key = input.substring(0, loc);
args = input.substring(loc); args = input.substring(loc);
isValid = true; isValid = true;
} }
public boolean isValid() public boolean isValid()
{ {
return isValid; return isValid;
} }
// Finds first whitespace in the string // Finds first whitespace in the string
private int findFirstWhitespace(String str) private int findFirstWhitespace(String str)
{ {
for (int i = 0; i < str.length(); ++i) for (int i = 0; i < str.length(); ++i)
{ {
if (Character.isWhitespace(str.charAt(i))) if (Character.isWhitespace(str.charAt(i)))
return i; return i;
} }
return -1; return -1;
} }
private KittyUser[] findMentionedUsers(GuildMessageReceivedEvent event) private KittyUser[] findMentionedUsers(GuildMessageReceivedEvent event)
{ {
List <Member> JDAMentions = event.getMessage().getMentionedMembers(); List <Member> JDAMentions = event.getMessage().getMentionedMembers();
KittyUser [] KittyMentions = new KittyUser[JDAMentions.size()]; KittyUser [] KittyMentions = new KittyUser[JDAMentions.size()];
for(int i = 0; i < KittyMentions.length; i ++) for(int i = 0; i < KittyMentions.length; i ++)
{ {
KittyMentions [i] = ObjectBuilderFactory.getKittyUser(event.getGuild().getId(), JDAMentions.get(i).getUser().getId()); KittyMentions [i] = ObjectBuilder.getKittyUser(event.getGuild().getId(), JDAMentions.get(i).getUser().getId());
} }
return KittyMentions; return KittyMentions;
} }
} }
+12 -33
View File
@@ -1,26 +1,14 @@
package main; package main;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.security.auth.login.LoginException; 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.CharacterManager;
import core.CommandEnabler; import core.CommandEnabler;
import core.CommandManager; import core.CommandManager;
import core.DatabaseManager; import core.DatabaseManager;
import core.ObjectBuilderFactory; import core.ObjectBuilder;
import core.RPManager; import core.RPManager;
import core.Stats; import core.Stats;
import core.lua.PluginManager; import core.lua.PluginManager;
@@ -30,17 +18,8 @@ import dataStructures.KittyGuild;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import net.dv8tion.jda.core.AccountType; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.api.hooks.ListenerAdapter;
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; import utils.GlobalLog;
// http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation. // http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation.
@@ -64,15 +43,15 @@ public class Main extends ListenerAdapter
{ {
// Factory startup. The ordering is intentional. // Factory startup. The ordering is intentional.
GlobalLog.initialize(); GlobalLog.initialize();
databaseManager = ObjectBuilderFactory.constructDatabaseManager(); databaseManager = ObjectBuilder.constructDatabaseManager();
commandManager = ObjectBuilderFactory.constructCommandManager(CommandEnabler.instance); // TODO: Untangle this singleton commandManager = ObjectBuilder.constructCommandManager(CommandEnabler.instance); // TODO: Untangle this singleton
stats = ObjectBuilderFactory.constructStats(commandManager); stats = ObjectBuilder.constructStats(commandManager);
charManager = new CharacterManager(); charManager = new CharacterManager();
rpManager = ObjectBuilderFactory.constructRPManager(); rpManager = ObjectBuilder.constructRPManager();
pluginManager = ObjectBuilderFactory.constructPluginManager(); pluginManager = ObjectBuilder.constructPluginManager();
// Bot startup // Bot startup
kittyCore = ObjectBuilderFactory.constructKittyCore(); kittyCore = ObjectBuilder.constructKittyCore();
} }
// When a message is sent in a server that kitty is in, this is what's called. // When a message is sent in a server that kitty is in, this is what's called.
@@ -84,9 +63,9 @@ public class Main extends ListenerAdapter
return; return;
// Factory objects // Factory objects
KittyUser user = ObjectBuilderFactory.extractUser(event); KittyUser user = ObjectBuilder.extractUser(event);
KittyGuild guild = ObjectBuilderFactory.extractGuild(event); KittyGuild guild = ObjectBuilder.extractGuild(event);
KittyChannel channel = ObjectBuilderFactory.extractChannel(event); KittyChannel channel = ObjectBuilder.extractChannel(event);
// Specialized uncached objects // Specialized uncached objects
Response response = new Response(event, kittyCore); Response response = new Response(event, kittyCore);
+1 -1
View File
@@ -14,7 +14,7 @@ import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import offline.Ref; import offline.Ref;
// Manages the fiddly bits and upkeep of the bot - while not // Manages the fiddly bits and upkeep of the bot - while not
+21 -10
View File
@@ -1,24 +1,30 @@
package utils; package utils;
import net.dv8tion.jda.core.entities.Guild; import java.util.*;
import net.dv8tion.jda.core.managers.GuildController; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.internal.handle.GuildSetupController;
public class AdminControl public class AdminControl
{ {
private GuildController guildCon;
private Guild guild; private Guild guild;
public AdminControl(Guild guild) public AdminControl(Guild guild)
{ {
this.guild = guild; this.guild = guild;
guildCon = guild.getController();
} }
public boolean addRole(String memberID, String roleName) public boolean addRole(String memberID, String roleName)
{ {
try try
{ {
guildCon.addRolesToMember(guild.getMemberById(memberID), guild.getRolesByName(roleName, true)).complete(); Member member = guild.getMemberById(memberID);
List<Role> roles = guild.getRolesByName(roleName, true);
for(Role role : roles)
{
guild.addRoleToMember(member, role).complete();// submit instead? We need to queue.
}
} }
catch(Exception e) catch(Exception e)
{ {
@@ -31,7 +37,12 @@ public class AdminControl
{ {
try try
{ {
guildCon.removeRolesFromMember(guild.getMemberById(memberID), guild.getRolesByName(roleName, true)).complete(); Member member = guild.getMemberById(memberID);
List<Role> roles = guild.getRolesByName(roleName, true);
for(Role role : roles)
{
guild.removeRoleFromMember(member, role).complete();
}
} }
catch(Exception e) catch(Exception e)
{ {
@@ -44,7 +55,7 @@ public class AdminControl
{ {
try try
{ {
guildCon.kick(guild.getMemberById(memberID)).complete(); guild.kick(guild.getMemberById(memberID)).complete();
} }
catch(Exception e) catch(Exception e)
{ {
@@ -57,7 +68,7 @@ public class AdminControl
{ {
try try
{ {
guildCon.setMute(guild.getMemberById(memberID), true); guild.mute(guild.getMemberById(memberID), true);
return true; return true;
} }
catch(Exception e) catch(Exception e)
@@ -70,7 +81,7 @@ public class AdminControl
{ {
try try
{ {
guildCon.ban(guild.getMemberById(memberID), 0).complete(); guild.ban(guild.getMemberById(memberID), 0).complete();
return true; return true;
} }
catch(Exception e) catch(Exception e)
+2
View File
@@ -36,11 +36,13 @@ public class GlobalLog
System.out.println(logLine); System.out.println(logLine);
} }
public static void log(LogFilter filter, Object obj) { write(log, filter, obj.toString()); }
public static void log(LogFilter filter, String msg) { write(log, filter, msg); } 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 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 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 fatal(LogFilter filter, String msg) throws Exception { write(fatal, filter, msg); throw new Exception(msg); }
public static void log(Object obj) { log(LogFilter.Debug, obj); }
public static void log(String msg) { log(LogFilter.Debug, msg); } public static void log(String msg) { log(LogFilter.Debug, msg); }
public static void warn(String msg) { warn(LogFilter.Debug, msg); } public static void warn(String msg) { warn(LogFilter.Debug, msg); }
public static void error(String msg) { error(LogFilter.Debug, msg); } public static void error(String msg) { error(LogFilter.Debug, msg); }
+10 -6
View File
@@ -1,4 +1,5 @@
package utils.audio; package utils.audio;
import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
@@ -9,10 +10,11 @@ import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
import net.dv8tion.jda.core.audio.AudioSendHandler; import net.dv8tion.jda.api.audio.AudioSendHandler;
import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.core.entities.VoiceChannel; import net.dv8tion.jda.api.entities.VoiceChannel;
import net.dv8tion.jda.core.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
public class AudioUtils public class AudioUtils
{ {
@@ -72,9 +74,11 @@ public class AudioUtils
return lastFrame != null; return lastFrame != null;
} }
@Override public byte[] provide20MsAudio() @Override
public ByteBuffer provide20MsAudio()
{ {
return lastFrame.getData(); ByteBuffer outputBuffer = ByteBuffer.wrap(lastFrame.getData());
return outputBuffer;
} }
@Override public boolean isOpus() @Override public boolean isOpus()