Compare commits
83
Commits
feature/dew
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d481fec0af | ||
|
|
127bdb74fb | ||
|
|
2b53b01178 | ||
|
|
36445d618c | ||
|
|
c168ef8ecb | ||
|
|
f6b35109bf | ||
|
|
e3ddf5d10e | ||
|
|
03d03e629d | ||
|
|
59009a2408 | ||
|
|
37ecb12ae1 | ||
|
|
0e92eb5075 | ||
|
|
edaf312a93 | ||
|
|
2872ab8b03 | ||
|
|
6ddb0fc532 | ||
|
|
20a16f2c74 | ||
|
|
67f1e083e9 | ||
|
|
b917a3b4ee | ||
|
|
39abf08b35 | ||
|
|
d86adaf3e2 | ||
|
|
cab2370f89 | ||
|
|
d0d2b9498d | ||
|
|
4c4835e342 | ||
|
|
844edc8084 | ||
|
|
2981a7bdc4 | ||
|
|
6ff38f09eb | ||
|
|
ef4b216cb3 | ||
|
|
0d3c16c4da | ||
|
|
99e3566188 | ||
|
|
0728370bf2 | ||
|
|
fa5057ea9e | ||
|
|
02f9b09199 | ||
|
|
9ec1198969 | ||
|
|
dc56532ed0 | ||
|
|
22f8e0b9df | ||
|
|
3e48056b15 | ||
|
|
6be6bd4033 | ||
|
|
462f23274e | ||
|
|
1a2366f5ee | ||
|
|
a77725791a | ||
|
|
c0f0b16892 | ||
|
|
d5346b3727 | ||
|
|
26b258bdcb | ||
|
|
bcc7959c00 | ||
|
|
de2f3f4515 | ||
|
|
c8061770ed | ||
|
|
10c0fa58b2 | ||
|
|
35c74e89f4 | ||
|
|
2c6091a258 | ||
|
|
86d7e58838 | ||
|
|
0d4015fff0 | ||
|
|
3a03793124 | ||
|
|
46cf6f8c97 | ||
|
|
a63afd3a2b | ||
|
|
d15336f4b6 | ||
|
|
d63a531a81 | ||
|
|
c8af9da196 | ||
|
|
595b1e3958 | ||
|
|
d6fd5ae436 | ||
|
|
74a5750824 | ||
|
|
7f2251732e | ||
|
|
ee60721897 | ||
|
|
d656ccb323 | ||
|
|
6e7b6fce29 | ||
|
|
55487a017e | ||
|
|
c7ed9785dc | ||
|
|
7b179b10ee | ||
|
|
bd1bcc1bd3 | ||
|
|
462bb58ead | ||
|
|
6a84f3759a | ||
|
|
dfbf646abc | ||
|
|
12e0ec98bd | ||
|
|
0ff71abfb0 | ||
|
|
94a3f1afcd | ||
|
|
4d36bb0cb9 | ||
|
|
248814b9e3 | ||
|
|
a1fa8b29b2 | ||
|
|
4ed18b8acc | ||
|
|
afb27df33d | ||
|
|
8cfa25a51b | ||
|
|
bbbb138f5e | ||
|
|
343308c433 | ||
|
|
52fdaefe75 | ||
|
|
a73fca7851 |
+4
-2
@@ -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"/>
|
||||||
@@ -24,7 +23,10 @@
|
|||||||
<classpathentry kind="lib" path="lib/commons-collections4-4.3.jar"/>
|
<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-lang3-3.9.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/commons-text-1.6.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/google-api-services-youtube-v3-rev212-1.25.0.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/lavaplayer-1.3.19.jar"/>
|
<classpathentry kind="lib" path="lib/nanohttpd-2.3.1.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>
|
||||||
|
|||||||
@@ -68,3 +68,5 @@ rP\.txt
|
|||||||
*.log
|
*.log
|
||||||
|
|
||||||
cloc\.exe
|
cloc\.exe
|
||||||
|
|
||||||
|
beanImage.png
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
+23
-1
@@ -1,4 +1,6 @@
|
|||||||
"Type","Key","Value"
|
"Type","Key","Value"
|
||||||
|
"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",""
|
||||||
@@ -16,9 +18,12 @@
|
|||||||
"Localized Commands","dbstats",""
|
"Localized Commands","dbstats",""
|
||||||
"Localized Commands","defaultdance",""
|
"Localized Commands","defaultdance",""
|
||||||
"Localized Commands","derp",""
|
"Localized Commands","derp",""
|
||||||
|
"Localized Commands","derpi",""
|
||||||
|
"Localized Commands","e6",""
|
||||||
"Localized Commands","e621",""
|
"Localized Commands","e621",""
|
||||||
"Localized Commands","eightball, 8ball",""
|
"Localized Commands","eightball, 8ball",""
|
||||||
"Localized Commands","fetch",""
|
"Localized Commands","fetch",""
|
||||||
|
"Localized Commands","getsauce",""
|
||||||
"Localized Commands","givebeans",""
|
"Localized Commands","givebeans",""
|
||||||
"Localized Commands","help",""
|
"Localized Commands","help",""
|
||||||
"Localized Commands","indicator",""
|
"Localized Commands","indicator",""
|
||||||
@@ -46,12 +51,15 @@
|
|||||||
"Localized Commands","stats",""
|
"Localized Commands","stats",""
|
||||||
"Localized Commands","teey",""
|
"Localized Commands","teey",""
|
||||||
"Localized Commands","tony, stark, dontfeelgood, dontfeelsogood","tony, stark, dontfeelgood, dontfeelsogood, snap"
|
"Localized Commands","tony, stark, dontfeelgood, dontfeelsogood","tony, stark, dontfeelgood, dontfeelsogood, snap"
|
||||||
|
"Localized Commands","tradebeans, trade",""
|
||||||
"Localized Commands","tweet",""
|
"Localized Commands","tweet",""
|
||||||
"Localized Commands","vote",""
|
"Localized Commands","vote",""
|
||||||
"Localized Commands","wolfram",""
|
"Localized Commands","wolfram",""
|
||||||
"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!"
|
||||||
@@ -60,11 +68,13 @@
|
|||||||
"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","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","BetBeansLose","Sorry, you didn't win, try again!"
|
||||||
"Localized Strings","BetBeansLowBet","Please bet with at least 20 beans!"
|
"Localized Strings","BetBeansLowBet","Please bet with at least 20 beans!"
|
||||||
|
"Localized Strings","BetBeansMinThreshold",""
|
||||||
"Localized Strings","BetBeansNotEnough","You don't have enough beans!"
|
"Localized Strings","BetBeansNotEnough","You don't have enough beans!"
|
||||||
"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!"
|
||||||
@@ -107,8 +117,10 @@
|
|||||||
"Localized Strings","DBFlushInfo","Takes all objects queued for the database and writes them to the database, then says how many were written."
|
"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","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","DefaultDanceInfo","y'all know forknife, get ready to dance, or make a friend dance with @!"
|
||||||
|
"Localized Strings","DerpiError",""
|
||||||
"Localized Strings","DoWorkFinished","I finished with my work! :D"
|
"Localized Strings","DoWorkFinished","I finished with my work! :D"
|
||||||
"Localized Strings","DoWorkInfo","Occupies a core for a few seconds"
|
"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","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","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."
|
"Localized Strings","EightBallMaybe1","Reply hazy, try again."
|
||||||
@@ -139,6 +151,7 @@
|
|||||||
"Localized Strings","FetchInfo","Throw a custom emote and I'll try to bring it back.... maybe"
|
"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","FetchRunAway","*Runs away and doesn't return for a long time*"
|
||||||
"Localized Strings","FetchStare","*Stares at %s*"
|
"Localized Strings","FetchStare","*Stares at %s*"
|
||||||
|
"Localized Strings","GetSauceInfo",""
|
||||||
"Localized Strings","GiveBeansInfo","Gives beans to the mentioned users!"
|
"Localized Strings","GiveBeansInfo","Gives beans to the mentioned users!"
|
||||||
"Localized Strings","GiveBeansInvalid","That's not a valid number!"
|
"Localized Strings","GiveBeansInvalid","That's not a valid number!"
|
||||||
"Localized Strings","GiveBeansNoneMentioned","You didn't mention anyone!"
|
"Localized Strings","GiveBeansNoneMentioned","You didn't mention anyone!"
|
||||||
@@ -178,7 +191,11 @@
|
|||||||
"Localized Strings","MapVersion","Using mapgen v0.1"
|
"Localized Strings","MapVersion","Using mapgen v0.1"
|
||||||
"Localized Strings","MapWidth",""
|
"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","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","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","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","PingInfo","Will respond with Pong!"
|
||||||
"Localized Strings","PingResponse","Pong!"
|
"Localized Strings","PingResponse","Pong!"
|
||||||
@@ -234,6 +251,7 @@
|
|||||||
"Localized Strings","TeeyInfo","Teey yourself back into existance, or teey a friend with @!"
|
"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","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","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","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","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","TradeBeansStealingBeans","Hey %s! Stealing is wrong! Let's see how you like it! *steals 10 beans*"
|
||||||
@@ -267,9 +285,12 @@
|
|||||||
"Command Enabler","dbstats","1"
|
"Command Enabler","dbstats","1"
|
||||||
"Command Enabler","defaultdance","1"
|
"Command Enabler","defaultdance","1"
|
||||||
"Command Enabler","derp","1"
|
"Command Enabler","derp","1"
|
||||||
|
"Command Enabler","derpi","1"
|
||||||
|
"Command Enabler","e6","1"
|
||||||
"Command Enabler","e621","1"
|
"Command Enabler","e621","1"
|
||||||
"Command Enabler","eightball, 8ball","1"
|
"Command Enabler","eightball, 8ball","1"
|
||||||
"Command Enabler","fetch","1"
|
"Command Enabler","fetch","1"
|
||||||
|
"Command Enabler","getsauce","1"
|
||||||
"Command Enabler","givebeans","1"
|
"Command Enabler","givebeans","1"
|
||||||
"Command Enabler","guildroleadd","1"
|
"Command Enabler","guildroleadd","1"
|
||||||
"Command Enabler","guildroleallowed","1"
|
"Command Enabler","guildroleallowed","1"
|
||||||
@@ -308,6 +329,7 @@
|
|||||||
"Command Enabler","stats","1"
|
"Command Enabler","stats","1"
|
||||||
"Command Enabler","teey","1"
|
"Command Enabler","teey","1"
|
||||||
"Command Enabler","tony, stark, dontfeelgood, dontfeelsogood","1"
|
"Command Enabler","tony, stark, dontfeelgood, dontfeelsogood","1"
|
||||||
|
"Command Enabler","tradebeans, trade","1"
|
||||||
"Command Enabler","tweet","1"
|
"Command Enabler","tweet","1"
|
||||||
"Command Enabler","vote","1"
|
"Command Enabler","vote","1"
|
||||||
"Command Enabler","wolfram","1"
|
"Command Enabler","wolfram","1"
|
||||||
|
|||||||
|
Binary file not shown.
@@ -0,0 +1,22 @@
|
|||||||
|
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
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,138 @@
|
|||||||
|
package commands.beans;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class CommandBeansShow extends Command
|
||||||
|
{
|
||||||
|
public CommandBeansShow(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpText() { return LocStrings.stub("BeansShowInfo"); };
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String mentionedBeans = "";
|
||||||
|
for(KittyUser mentioned:input.mentions)
|
||||||
|
{
|
||||||
|
mentionedBeans += mentioned.name + " has " + mentioned.getBeans() + " ";
|
||||||
|
}
|
||||||
|
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, LocStrings.stub("BeansImageTopText"), rect, beanFont, .25);
|
||||||
|
drawCenteredString(beanGraphics, "" + beans, rect, beanFont, .5);
|
||||||
|
drawCenteredString(beanGraphics, LocStrings.stub("BeansImageBottomText"), 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package commands.general;
|
package commands.beans;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ public class CommandBetBeans extends Command
|
|||||||
{
|
{
|
||||||
String call = "";
|
String call = "";
|
||||||
|
|
||||||
int min = 50;
|
int min = 20;
|
||||||
int bet = 0;
|
int bet = 0;
|
||||||
int win = 0;
|
int win = 0;
|
||||||
|
|
||||||
@@ -36,7 +36,8 @@ public class CommandBetBeans extends Command
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
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
|
try
|
||||||
+44
-24
@@ -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
-1
@@ -1,4 +1,4 @@
|
|||||||
package commands.general;
|
package commands.beans;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
+18
-4
@@ -1,4 +1,4 @@
|
|||||||
package commands.general;
|
package commands.beans;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
@@ -25,15 +25,29 @@ public class CommandTradeBeans extends Command
|
|||||||
res.send(LocStrings.stub("TradeBeansNoTargetError"));
|
res.send(LocStrings.stub("TradeBeansNoTargetError"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(input.mentions.length > 1)
|
||||||
|
{
|
||||||
|
res.send(LocStrings.stub("TradeBeansMultipleUsersTagged"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int beans = 0;
|
int beans = 0;
|
||||||
try {
|
|
||||||
|
try
|
||||||
|
{
|
||||||
beans = Integer.parseInt(input.args.split(" ")[0]);
|
beans = Integer.parseInt(input.args.split(" ")[0]);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
res.send(LocStrings.stub("TradeBeansIntParseError"));
|
try
|
||||||
return;
|
{
|
||||||
|
beans = Integer.parseInt(input.args.split(" ")[1]);
|
||||||
|
}
|
||||||
|
catch(Exception eInner)
|
||||||
|
{
|
||||||
|
res.send(LocStrings.stub("TradeBeansIntParseError"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(user.getBeans() < beans)
|
if(user.getBeans() < beans)
|
||||||
@@ -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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+135
-135
@@ -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,29 +0,0 @@
|
|||||||
package commands.general;
|
|
||||||
|
|
||||||
import core.Command;
|
|
||||||
import core.LocStrings;
|
|
||||||
import dataStructures.*;
|
|
||||||
|
|
||||||
public class CommandBeansShow extends Command
|
|
||||||
{
|
|
||||||
public CommandBeansShow(KittyRole level, KittyRating rating) { super(level, rating); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getHelpText() { return LocStrings.stub("BeansShowInfo"); };
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
|
||||||
{
|
|
||||||
if(input.mentions == null)
|
|
||||||
res.send(String.format(LocStrings.stub("BeansShowDisplay"), user.getBeans()));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
String mentionedBeans = "";
|
|
||||||
for(KittyUser mentioned:input.mentions)
|
|
||||||
{
|
|
||||||
mentionedBeans += mentioned.name + " has " + mentioned.getBeans() + " ";
|
|
||||||
}
|
|
||||||
res.send(String.format(LocStrings.stub("BeansShowMentioned"), mentionedBeans));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -68,22 +68,23 @@ public class CommandBoop extends Command
|
|||||||
{
|
{
|
||||||
if(input.mentions == null)
|
if(input.mentions == null)
|
||||||
{
|
{
|
||||||
|
// No one is booped, just the bot!
|
||||||
boopTracker.applyBoop();
|
boopTracker.applyBoop();
|
||||||
res.send(String.format(LocStrings.stub("BoopStandard"), user.name, boopTracker.howMany()));
|
res.send(String.format(LocStrings.stub("BoopStandard"), user.name, boopTracker.howMany()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// When someone boops one other person
|
||||||
if(input.mentions.length == 1)
|
if(input.mentions.length == 1)
|
||||||
{
|
{
|
||||||
boopTracker.applyBoop();
|
|
||||||
res.send(String.format(LocStrings.stub("BoopPerson"), user.name, input.mentions[0].name));
|
res.send(String.format(LocStrings.stub("BoopPerson"), user.name, input.mentions[0].name));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A number of people have been booped
|
||||||
String booped = "";
|
String booped = "";
|
||||||
for(int i = 0; i < input.mentions.length; i++)
|
for(int i = 0; i < input.mentions.length; i++)
|
||||||
{
|
{
|
||||||
boopTracker.applyBoop();
|
|
||||||
if(i < input.mentions.length-1)
|
if(i < input.mentions.length-1)
|
||||||
booped += input.mentions[i].name + ", ";
|
booped += input.mentions[i].name + ", ";
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -27,12 +27,20 @@ public class CommandChoose extends Command
|
|||||||
|
|
||||||
String [] choices = input.args.split(",");
|
String [] choices = input.args.split(",");
|
||||||
|
|
||||||
if(choices.length == 1)
|
if(choices.length <= 1)
|
||||||
{
|
{
|
||||||
res.send(LocStrings.stub("ChooseOne"));
|
res.send(LocStrings.stub("ChooseOne"));
|
||||||
return;
|
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()));
|
res.send(String.format(LocStrings.stub("ChooseChoice"), (choices[(int) (Math.random()*choices.length)]).toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ public class CommandColor extends Command
|
|||||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||||
{
|
{
|
||||||
// First, try and parse out the color to make sure we can even get it.
|
// First, try and parse out the color to make sure we can even get it.
|
||||||
ColorData colorData = theColorAPI.lookupHex(input.args.trim());
|
ColorData colorData = theColorAPI.lookupHex(input.args);
|
||||||
|
|
||||||
// Verify the color was even found
|
// Verify the color was even found
|
||||||
if(colorData == null)
|
if(colorData == null)
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ public class CommandRoll extends Command
|
|||||||
{
|
{
|
||||||
KittyEmbed embed = new KittyEmbed();
|
KittyEmbed embed = new KittyEmbed();
|
||||||
embed.title = user.name +"'s roll!";
|
embed.title = user.name +"'s roll!";
|
||||||
|
System.out.println("HERE");
|
||||||
embed.descriptionText = rollDice(input.args);
|
embed.descriptionText = rollDice(input.args);
|
||||||
|
System.out.println("THERE");
|
||||||
Random numGen = new Random(user.name.hashCode());
|
Random numGen = new Random(user.name.hashCode());
|
||||||
float hue = numGen.nextFloat();
|
float hue = numGen.nextFloat();
|
||||||
float sat = .7f;
|
float sat = .7f;
|
||||||
@@ -41,10 +43,11 @@ public class CommandRoll extends Command
|
|||||||
Stack<Integer> values = new Stack<Integer>();
|
Stack<Integer> values = new Stack<Integer>();
|
||||||
Stack<Character> operators = new Stack<Character>();
|
Stack<Character> operators = new Stack<Character>();
|
||||||
String steps = "";
|
String steps = "";
|
||||||
|
|
||||||
for(int i = 0; i < thing.length(); i ++)
|
for(int i = 0; i < thing.length(); i ++)
|
||||||
{
|
{
|
||||||
char current = thing.charAt(i);
|
char current = thing.charAt(i);
|
||||||
|
System.out.println("ROLLING");
|
||||||
switch(current)
|
switch(current)
|
||||||
{
|
{
|
||||||
case '+':
|
case '+':
|
||||||
@@ -122,8 +125,11 @@ public class CommandRoll extends Command
|
|||||||
{
|
{
|
||||||
steps += "\n" + calculate(values, operators);
|
steps += "\n" + calculate(values, operators);
|
||||||
}
|
}
|
||||||
|
if(steps != "")
|
||||||
return "Roll```" + thing + "```" + "Steps```" + steps + "```" + "Final value ```" + values.pop() +"```";
|
{
|
||||||
|
return "Roll```" + thing + "```" + "Steps```" + steps + "```" + "Final value ```" + values.pop() +"```";
|
||||||
|
}
|
||||||
|
return "That's not a roll that's just " + values.pop() +"!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -173,7 +179,7 @@ public class CommandRoll extends Command
|
|||||||
int roll = 0;
|
int roll = 0;
|
||||||
int dice = first;
|
int dice = first;
|
||||||
int sides = second;
|
int sides = second;
|
||||||
int [] rolls = new int [sides];
|
int [] rolls = new int [dice];
|
||||||
|
|
||||||
if(dice < 1)
|
if(dice < 1)
|
||||||
return new int[0];
|
return new int[0];
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+71
-71
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+105
-105
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package commands.music;
|
|||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
|
import core.SubCommandFormattable;
|
||||||
import core.SubCommandFramework;
|
import core.SubCommandFramework;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
|
|
||||||
@@ -9,18 +10,24 @@ public class CommandMusicMain extends Command
|
|||||||
{
|
{
|
||||||
SubCommandFramework framework = new SubCommandFramework();
|
SubCommandFramework framework = new SubCommandFramework();
|
||||||
public CommandMusicMain(KittyRole level, KittyRating rating)
|
public CommandMusicMain(KittyRole level, KittyRating rating)
|
||||||
{
|
{
|
||||||
super(level, rating);
|
super(level, rating);
|
||||||
framework.addCommand("join", new SubCommandJoin(KittyRole.General, KittyRating.Safe));
|
framework.addCommand("join", new SubCommandJoin(KittyRole.General, KittyRating.Safe));
|
||||||
framework.addCommand("leave", new SubCommandLeave(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
|
@Override
|
||||||
public String getHelpText() { return LocStrings.stub("MusicInfo"); }
|
public String getHelpText() {return LocStrings.stub("MusicInfo"); }
|
||||||
|
|
||||||
@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)
|
||||||
{
|
{
|
||||||
framework.run(guild, channel, user, input).Call(res);
|
SubCommandFormattable scf = framework.run(guild, channel, user, input);
|
||||||
|
scf.Call(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package commands.music;
|
package commands.music;
|
||||||
|
|
||||||
import com.google.api.services.youtube.YouTube;
|
import core.LocStrings;
|
||||||
|
|
||||||
import core.SubCommand;
|
import core.SubCommand;
|
||||||
import core.SubCommandFormattable;
|
import core.SubCommandFormattable;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
@@ -10,16 +9,25 @@ import dataStructures.KittyRating;
|
|||||||
import dataStructures.KittyRole;
|
import dataStructures.KittyRole;
|
||||||
import dataStructures.KittyUser;
|
import dataStructures.KittyUser;
|
||||||
import dataStructures.UserInput;
|
import dataStructures.UserInput;
|
||||||
|
import network.NetworkYoutube;
|
||||||
|
|
||||||
public class SubCommandAddTrack extends SubCommand
|
public class SubCommandAddTrack extends SubCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
public SubCommandAddTrack(KittyRole level, KittyRating rating) { super(level, rating); }
|
public SubCommandAddTrack(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
|
NetworkYoutube YT = new NetworkYoutube();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||||
{
|
{
|
||||||
|
//Get track from Youtube
|
||||||
return null;
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package commands.general;
|
package commands.network;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package commands.network;
|
||||||
|
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package commands.network;
|
||||||
|
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package commands.network;
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
@@ -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.*;
|
||||||
@@ -107,6 +133,11 @@ public class CommandManager
|
|||||||
this.register(LocCommands.stub("poll"), new CommandPollMain(KittyRole.General, KittyRating.Safe));
|
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("music"), new CommandMusicMain(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("defaultdance"), new CommandDefaultDance(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));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands)
|
// 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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,7 @@ public class Config
|
|||||||
sections = new Vector<IConfigSection>();
|
sections = new Vector<IConfigSection>();
|
||||||
|
|
||||||
// Add all sections
|
// Add all sections
|
||||||
|
sections.add(new ConfigGlobals());
|
||||||
sections.add(new LocCommands());
|
sections.add(new LocCommands());
|
||||||
sections.add(new LocStrings());
|
sections.add(new LocStrings());
|
||||||
sections.add(new CommandEnabler());
|
sections.add(new CommandEnabler());
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getActivity()
|
||||||
|
{
|
||||||
|
return instance.activityValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ConfigItem> produce()
|
||||||
|
{
|
||||||
|
List<ConfigItem> items = new ArrayList<ConfigItem>();
|
||||||
|
items.add(new ConfigItem(getSectionTitle(), startupStyleKey, startupStyleValue.name().toLowerCase()));
|
||||||
|
items.add(new ConfigItem(getSectionTitle(), activityKey, activityValue));
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,9 @@ import utils.StringUtils;
|
|||||||
// perform any parsing past naming columns, and just holds the raw data.
|
// perform any parsing past naming columns, and just holds the raw data.
|
||||||
public class ConfigItem
|
public class ConfigItem
|
||||||
{
|
{
|
||||||
public String type;
|
public String type; // The section this specific key/value pair belongs to. This almost certainly will appear in multiple places.
|
||||||
public String key;
|
public String key; // A unique key for a given lookup value for the specified section. Keys, within sections, are unique.
|
||||||
public String value;
|
public String value; // The value assocaited with the key.
|
||||||
public static final int items = 3;
|
public static final int items = 3;
|
||||||
public static final String[] header = {"Type","Key","Value"};
|
public static final String[] header = {"Type","Key","Value"};
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import dataStructures.Pair;
|
|||||||
public class LocCommands extends BaseLocFile implements IConfigSection
|
public class LocCommands extends BaseLocFile implements IConfigSection
|
||||||
{
|
{
|
||||||
// Defined const variables
|
// Defined const variables
|
||||||
public static final String HeaderName = "Localized Commands";
|
public static final String header = "Localized Commands";
|
||||||
public static final String function = "LocCommands.stub";
|
public static final String function = "LocCommands.stub";
|
||||||
|
|
||||||
// Instance
|
// Instance
|
||||||
@@ -20,7 +20,7 @@ public class LocCommands extends BaseLocFile implements IConfigSection
|
|||||||
// Constructor
|
// Constructor
|
||||||
public LocCommands()
|
public LocCommands()
|
||||||
{
|
{
|
||||||
super(HeaderName, function);
|
super(header, function);
|
||||||
|
|
||||||
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
||||||
|
|
||||||
|
|||||||
@@ -1,453 +1,512 @@
|
|||||||
package core;
|
package core;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
|
|
||||||
//import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||||
//import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||||
|
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
||||||
import core.lua.PluginManager;
|
|
||||||
import dataStructures.*;
|
//import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||||
import main.Main;
|
//import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||||
import net.dv8tion.jda.core.AccountType;
|
|
||||||
import net.dv8tion.jda.core.JDA;
|
import core.lua.PluginManager;
|
||||||
import net.dv8tion.jda.core.JDABuilder;
|
import dataStructures.KittyChannel;
|
||||||
import net.dv8tion.jda.core.entities.*;
|
import dataStructures.KittyCore;
|
||||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
import dataStructures.KittyGuild;
|
||||||
import offline.Ref;
|
import dataStructures.KittyRating;
|
||||||
import utils.AdminControl;
|
import dataStructures.KittyRole;
|
||||||
//import utils.AudioUtils;
|
import dataStructures.KittyStartupMode;
|
||||||
import utils.GlobalLog;
|
import dataStructures.KittyUser;
|
||||||
import utils.LogFilter;
|
import main.Main;
|
||||||
|
import net.dv8tion.jda.api.AccountType;
|
||||||
// NOTE(wisp): Isolated factory to assist with storage and caching if needed.
|
import net.dv8tion.jda.api.JDA;
|
||||||
// This also minimizes the number of places JDA interacts with our codebase.
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
// As it stands, if the object name begins with Kitty, it's constructed here.
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
// TODO: Make all methods ID based instead of event based
|
import net.dv8tion.jda.api.entities.Emote;
|
||||||
public class ObjectBuilderFactory
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
{
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
// Key: guild string id, Value: guild information
|
import net.dv8tion.jda.api.entities.User;
|
||||||
private static HashMap<String, KittyGuild> guildCache;
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import offline.Ref;
|
||||||
// Key: channel string id, Value: channel information
|
import utils.AdminControl;
|
||||||
private static HashMap<String, KittyChannel> channelCache;
|
//import utils.AudioUtils;
|
||||||
|
import utils.GlobalLog;
|
||||||
// Key: guild string id + user string id, Value: user information
|
import utils.LogFilter;
|
||||||
private static HashMap<String, KittyUser> userCache;
|
import utils.audio.AudioUtils;
|
||||||
|
|
||||||
// For tracking and managing object sync
|
// NOTE: Isolated factory to assist with storage and caching if needed.
|
||||||
private static DatabaseManager database;
|
// 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.
|
||||||
// Stats tracking and whatnot... for setting stats too internally potentially
|
// TODO: Make all methods ID based instead of event based
|
||||||
private static Stats stats;
|
public class ObjectBuilder
|
||||||
|
{
|
||||||
// RPManger for tracking RP system
|
// Key: guild string id, Value: guild information
|
||||||
private static RPManager rpManager;
|
private static HashMap<String, KittyGuild> guildCache;
|
||||||
|
|
||||||
// Plugin manager
|
// Key: channel string id, Value: channel information
|
||||||
private static PluginManager pluginManager;
|
private static HashMap<String, KittyChannel> channelCache;
|
||||||
|
|
||||||
// Command manager
|
// Key: guild string id + user string id, Value: user information
|
||||||
private static CommandManager commandManager;
|
private static HashMap<String, KittyUser> userCache;
|
||||||
|
|
||||||
//Audio track manager
|
// For tracking and managing object sync
|
||||||
// private static AudioPlayerManager audioPlayer = new DefaultAudioPlayerManager();
|
private static DatabaseManager database;
|
||||||
|
|
||||||
// Localization classes - these are singletons, but should be initialized before almost all other
|
// Stats tracking and whatnot... for setting stats too internally potentially
|
||||||
// things so their inclusion in the factory is to ensure they're started at the correct time.
|
private static Stats stats;
|
||||||
@SuppressWarnings("unused") private static LocStrings locStrings;
|
|
||||||
@SuppressWarnings("unused") private static LocCommands locCommands;
|
// RPManger for tracking RP system
|
||||||
|
private static RPManager rpManager;
|
||||||
// Config
|
|
||||||
@SuppressWarnings("unused") private static Config config;
|
// Plugin manager
|
||||||
|
private static PluginManager pluginManager;
|
||||||
// Lazy initialization multithreaded mutex stuff to prevent explosions.
|
|
||||||
// TODO: Investigate using 'synchronized' instead potentially
|
// Command manager
|
||||||
private static boolean hasInitialized;
|
private static CommandManager commandManager;
|
||||||
private static Semaphore initMutex = new Semaphore(1);
|
|
||||||
private static JDA kitty;
|
//Audio track manager
|
||||||
|
private static AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
|
||||||
// This is it, this is how the lazy init starts!
|
|
||||||
private static void lazyInit()
|
// 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.
|
||||||
if(hasInitialized)
|
@SuppressWarnings("unused") private static LocStrings locStrings;
|
||||||
return;
|
@SuppressWarnings("unused") private static LocCommands locCommands;
|
||||||
|
|
||||||
try
|
// Config
|
||||||
{
|
@SuppressWarnings("unused") private static Config config;
|
||||||
initMutex.acquire();
|
|
||||||
try
|
// Lazy initialization multithreaded mutex stuff to prevent explosions.
|
||||||
{
|
// TODO: Investigate using 'synchronized' instead potentially
|
||||||
// structure initialization
|
private static Boolean hasInitialized = false;
|
||||||
// Construct necessary data structures.
|
private static Semaphore initMutex = new Semaphore(1);
|
||||||
guildCache = new HashMap<String, KittyGuild>();
|
private static JDA kitty;
|
||||||
userCache = new HashMap<String, KittyUser>();
|
|
||||||
channelCache = new HashMap<String, KittyChannel>();
|
// This is it, this is how the lazy init starts!
|
||||||
database = null;
|
private static void lazyInit()
|
||||||
stats = null;
|
{
|
||||||
|
synchronized(hasInitialized)
|
||||||
// Start by reading from things that are external. Because
|
{
|
||||||
// we require these things to be resolved before the rest of the application,
|
if(hasInitialized)
|
||||||
// we place them here.
|
{
|
||||||
config = new Config();
|
return;
|
||||||
}
|
}
|
||||||
finally
|
}
|
||||||
{
|
|
||||||
initMutex.release();
|
try
|
||||||
hasInitialized = true;
|
{
|
||||||
}
|
initMutex.acquire();
|
||||||
}
|
try
|
||||||
catch(InterruptedException ie)
|
{
|
||||||
{
|
// structure initialization
|
||||||
GlobalLog.error(LogFilter.Core, "Issue during object builder lazy initialization."
|
// Construct necessary data structures.
|
||||||
+ " The factory was not initialized, and kitty will not be able to continue functionally.");
|
guildCache = new HashMap<String, KittyGuild>();
|
||||||
}
|
userCache = new HashMap<String, KittyUser>();
|
||||||
}
|
channelCache = new HashMap<String, KittyChannel>();
|
||||||
|
database = null;
|
||||||
////////////////////////
|
stats = null;
|
||||||
// Extraction Methods //
|
|
||||||
////////////////////////
|
AudioSourceManagers.registerRemoteSources(playerManager);
|
||||||
|
AudioSourceManagers.registerLocalSource(playerManager);
|
||||||
// Explicitly locks: guildCache
|
|
||||||
public static KittyGuild extractGuild(GuildMessageReceivedEvent event)
|
// Start by reading from things that are external. Because
|
||||||
{
|
// we require these things to be resolved before the rest of
|
||||||
lazyInit();
|
// the application, we place them here.
|
||||||
|
config = new Config();
|
||||||
// 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
|
finally
|
||||||
// look up the guild.
|
{
|
||||||
String uid = event.getGuild().getId();
|
initMutex.release();
|
||||||
|
synchronized(hasInitialized)
|
||||||
List<Emote> emotes = event.getGuild().getEmotes();
|
{
|
||||||
ArrayList<String> emotesString = new ArrayList<String>();
|
hasInitialized = true;
|
||||||
String emote;
|
}
|
||||||
String emoteFix;
|
}
|
||||||
for(int i = 0; i < emotes.size(); i++)
|
}
|
||||||
{
|
catch(InterruptedException ie)
|
||||||
emote = emotes.get(i).toString();
|
{
|
||||||
emoteFix = "<:" + emote.substring(2, emote.indexOf("("));
|
GlobalLog.error(LogFilter.Core, "Issue during object builder lazy initialization."
|
||||||
emoteFix += ":" + emote.substring(emote.indexOf("(")+1, emote.length()-1) + ">";
|
+ " The factory was not initialized, and kitty will not be able to continue functionally.");
|
||||||
emotesString.add(emoteFix);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// once we're lazily initialized, we can synchronize w/ the
|
public static boolean getHasInitialized()
|
||||||
// guildCache object now instead of having to use a mutex.
|
{
|
||||||
KittyGuild guild = null;
|
synchronized(hasInitialized)
|
||||||
synchronized (guildCache)
|
{
|
||||||
{
|
return hasInitialized;
|
||||||
KittyGuild cachedGuild = guildCache.get(uid);
|
}
|
||||||
if(cachedGuild != null)
|
}
|
||||||
{
|
|
||||||
guild = cachedGuild;
|
////////////////////////
|
||||||
}
|
// Extraction Methods //
|
||||||
else
|
////////////////////////
|
||||||
{
|
|
||||||
// Construct a new guild with defaults
|
// Explicitly locks: guildCache
|
||||||
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString);
|
public static KittyGuild extractGuild(GuildMessageReceivedEvent event)
|
||||||
DatabaseManager.instance.globalRegister(guild);
|
{
|
||||||
guildCache.put(uid, guild);
|
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
|
||||||
return guild;
|
// look up the guild.
|
||||||
}
|
String uid = event.getGuild().getId();
|
||||||
|
|
||||||
// Explicitly locks: guildCache
|
List<Emote> emotes = event.getGuild().getEmotes();
|
||||||
public static KittyRole extractRole(GuildMessageReceivedEvent event)
|
ArrayList<String> emotesString = new ArrayList<String>();
|
||||||
{
|
HashMap<Long, KittyChannel> channels = new HashMap<Long, KittyChannel>();
|
||||||
lazyInit();
|
String emote;
|
||||||
|
String emoteFix;
|
||||||
// Looks up the user role. If none is found we check to see if they own
|
channels.put(Long.getLong(uid), extractChannel(event));
|
||||||
// the guild if not, they're assumed to be
|
for(int i = 0; i < emotes.size(); i++)
|
||||||
// allowed to use the bot at a general level.
|
{
|
||||||
KittyRole role = KittyRole.General;
|
emote = emotes.get(i).toString();
|
||||||
|
emoteFix = "<:" + emote.substring(2, emote.indexOf("("));
|
||||||
if(event.getAuthor().getId() == event.getGuild().getOwner().getUser().getId())
|
emoteFix += ":" + emote.substring(emote.indexOf("(")+1, emote.length()-1) + ">";
|
||||||
{
|
emotesString.add(emoteFix);
|
||||||
role = KittyRole.Admin;
|
}
|
||||||
}
|
|
||||||
|
// once we're lazily initialized, we can synchronize w/ the
|
||||||
String uid = event.getGuild().getId() + event.getAuthor().getId();
|
// guildCache object now instead of having to use a mutex.
|
||||||
synchronized(userCache)
|
KittyGuild guild = null;
|
||||||
{
|
synchronized (guildCache)
|
||||||
KittyUser cachedUser = userCache.get(uid);
|
{
|
||||||
if(cachedUser != null)
|
KittyGuild cachedGuild = guildCache.get(uid);
|
||||||
role = cachedUser.getRole();
|
if(cachedGuild != null)
|
||||||
}
|
{
|
||||||
|
guild = cachedGuild;
|
||||||
return role;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
// Explicitly locks: guildCache
|
// Construct a new guild with defaults
|
||||||
// Extracts the content rating information it can from the provided event.
|
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString,
|
||||||
public static KittyRating extractContentRating(GuildMessageReceivedEvent event)
|
new AudioUtils(event.getGuild(), playerManager), channels);
|
||||||
{
|
DatabaseManager.instance.globalRegister(guild);
|
||||||
lazyInit();
|
guildCache.put(uid, guild);
|
||||||
|
}
|
||||||
// Look up content rating of the guild, returns a safe content rating.
|
}
|
||||||
KittyRating contentRating = KittyRating.Safe;
|
|
||||||
String uid = event.getGuild().getId();
|
return guild;
|
||||||
synchronized(guildCache)
|
}
|
||||||
{
|
|
||||||
KittyGuild cachedGuild = guildCache.get(uid);
|
|
||||||
if(cachedGuild != null)
|
|
||||||
contentRating = cachedGuild.contentRating;
|
// Explicitly locks: guildCache
|
||||||
}
|
public static KittyRole extractRole(GuildMessageReceivedEvent event)
|
||||||
|
{
|
||||||
return contentRating;
|
lazyInit();
|
||||||
}
|
|
||||||
|
// Looks up the user role. If none is found we check to see if they own
|
||||||
// Implicitly locks guild cache by calling ExtractGuild
|
// the guild if not, they're assumed to be
|
||||||
public static KittyChannel extractChannel(GuildMessageReceivedEvent event)
|
// allowed to use the bot at a general level.
|
||||||
{
|
KittyRole role = KittyRole.General;
|
||||||
lazyInit();
|
|
||||||
|
if(event.getAuthor().getId() == event.getGuild().getOwnerId())
|
||||||
String channelID = event.getChannel().getId();
|
{
|
||||||
String guildID = event.getGuild().getId();
|
role = KittyRole.Admin;
|
||||||
KittyChannel channel = null;
|
}
|
||||||
|
|
||||||
synchronized(channelCache)
|
String uid = event.getGuild().getId() + event.getAuthor().getId();
|
||||||
{
|
synchronized(userCache)
|
||||||
KittyChannel cachedChannel = channelCache.get(channelID);
|
{
|
||||||
|
KittyUser cachedUser = userCache.get(uid);
|
||||||
if(cachedChannel != null)
|
if(cachedUser != null)
|
||||||
{
|
role = cachedUser.getRole();
|
||||||
channel = cachedChannel;
|
}
|
||||||
}
|
|
||||||
else
|
return role;
|
||||||
{
|
}
|
||||||
KittyGuild cachedGuild = guildCache.get(guildID);
|
|
||||||
channel = new KittyChannel(channelID, cachedGuild);
|
// Explicitly locks: guildCache
|
||||||
channelCache.put(channelID, channel);
|
// Extracts the content rating information it can from the provided event.
|
||||||
}
|
public static KittyRating extractContentRating(GuildMessageReceivedEvent event)
|
||||||
}
|
{
|
||||||
|
lazyInit();
|
||||||
return channel;
|
|
||||||
}
|
// Look up content rating of the guild, returns a safe content rating.
|
||||||
|
KittyRating contentRating = KittyRating.Safe;
|
||||||
// Implicitly locks guild cache by calling ExtractRole and ExtractGuild
|
String uid = event.getGuild().getId();
|
||||||
public static KittyUser extractUser(GuildMessageReceivedEvent event)
|
synchronized(guildCache)
|
||||||
{
|
{
|
||||||
lazyInit();
|
KittyGuild cachedGuild = guildCache.get(uid);
|
||||||
|
if(cachedGuild != null)
|
||||||
String uid = event.getGuild().getId() + event.getAuthor().getId();
|
contentRating = cachedGuild.contentRating;
|
||||||
KittyUser user = null;
|
}
|
||||||
synchronized(userCache)
|
|
||||||
{
|
return contentRating;
|
||||||
KittyUser cachedUser = userCache.get(uid);
|
}
|
||||||
if(cachedUser != null)
|
|
||||||
{
|
// Implicitly locks guild cache by calling ExtractGuild
|
||||||
updateUser(cachedUser, event.getMember());
|
public static KittyChannel extractChannel(GuildMessageReceivedEvent event)
|
||||||
user = cachedUser;
|
{
|
||||||
}
|
lazyInit();
|
||||||
else
|
String channelID = event.getChannel().getId();
|
||||||
{
|
KittyChannel channel = null;
|
||||||
KittyRole role = extractRole(event);
|
|
||||||
KittyGuild guild = extractGuild(event);
|
synchronized(channelCache)
|
||||||
|
{
|
||||||
String name;
|
KittyChannel cachedChannel = channelCache.get(channelID);
|
||||||
if(event.getMember().getNickname() == null)
|
boolean mature;
|
||||||
name = event.getAuthor().getName();
|
|
||||||
else
|
if(cachedChannel != null)
|
||||||
name = event.getMember().getNickname();
|
{
|
||||||
|
channel = cachedChannel;
|
||||||
String discordID = event.getMember().getUser().getId();
|
}
|
||||||
String avatarID = event.getAuthor().getAvatarUrl();
|
else
|
||||||
user = new KittyUser(name, guild, role, uid, avatarID, discordID);
|
{
|
||||||
DatabaseManager.instance.globalRegister(user);
|
mature = event.getChannel().isNSFW();
|
||||||
userCache.put(uid, user);
|
channel = new KittyChannel(channelID, mature);
|
||||||
}
|
channelCache.put(channelID, channel);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(event.getMessage().getMentionedMembers().isEmpty())
|
|
||||||
return user;
|
return channel;
|
||||||
|
}
|
||||||
Member mentioned;
|
|
||||||
for(int i = 0; i < event.getMessage().getMentionedMembers().size(); i++)
|
// Implicitly locks guild cache by calling ExtractRole and ExtractGuild
|
||||||
{
|
public static KittyUser extractUser(GuildMessageReceivedEvent event)
|
||||||
mentioned = event.getMessage().getMentionedMembers().get(i);
|
{
|
||||||
if(mentioned.getNickname() != null)
|
lazyInit();
|
||||||
extractUserByJDAUser(event.getGuild().getId(), mentioned.getNickname(),
|
|
||||||
mentioned.getUser().getId(), mentioned.getUser().getAvatarUrl(), mentioned.getUser().getId());
|
String uid = event.getGuild().getId() + event.getAuthor().getId();
|
||||||
else
|
KittyUser user = null;
|
||||||
extractUserByJDAUser(event.getGuild().getId(), mentioned.getUser().getName(),
|
synchronized(userCache)
|
||||||
mentioned.getUser().getId(), mentioned.getUser().getAvatarUrl(), mentioned.getUser().getId());
|
{
|
||||||
}
|
KittyUser cachedUser = userCache.get(uid);
|
||||||
|
if(cachedUser != null)
|
||||||
return user;
|
{
|
||||||
}
|
updateUser(cachedUser, event.getMember());
|
||||||
|
user = cachedUser;
|
||||||
// TODO: Clean up
|
}
|
||||||
public static KittyUser extractUserByJDAUser(String guildID, String name, String userID, String avatarID, String discordID)
|
else
|
||||||
{
|
{
|
||||||
lazyInit();
|
KittyRole role = extractRole(event);
|
||||||
|
KittyGuild guild = extractGuild(event);
|
||||||
String uid = guildID + userID;
|
|
||||||
KittyUser user = null;
|
String name;
|
||||||
synchronized(userCache)
|
if(event.getMember().getNickname() == null)
|
||||||
{
|
name = event.getAuthor().getName();
|
||||||
KittyUser cachedUser = userCache.get(uid);
|
else
|
||||||
if(cachedUser != null)
|
name = event.getMember().getNickname();
|
||||||
{
|
|
||||||
if(name != null)
|
String discordID = event.getMember().getUser().getId();
|
||||||
cachedUser.name = name;
|
String avatarID = event.getAuthor().getAvatarUrl();
|
||||||
|
user = new KittyUser(name, guild, role, uid, avatarID, discordID);
|
||||||
cachedUser.avatarID = avatarID;
|
DatabaseManager.instance.globalRegister(user);
|
||||||
user = cachedUser;
|
userCache.put(uid, user);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
KittyRole role = KittyRole.General;
|
if(event.getMessage().getMentionedMembers().isEmpty())
|
||||||
KittyGuild guild = guildCache.get(guildID);
|
return user;
|
||||||
user = new KittyUser(name, guild, role, uid, avatarID, discordID);
|
|
||||||
DatabaseManager.instance.globalRegister(user);
|
Member mentioned;
|
||||||
userCache.put(uid, user);
|
for(int i = 0; i < event.getMessage().getMentionedMembers().size(); i++)
|
||||||
}
|
{
|
||||||
}
|
mentioned = event.getMessage().getMentionedMembers().get(i);
|
||||||
|
if(mentioned.getNickname() != null)
|
||||||
return user;
|
extractUserByJDAUser(event.getGuild().getId(), mentioned.getNickname(),
|
||||||
}
|
mentioned.getUser().getId(), mentioned.getUser().getAvatarUrl(), mentioned.getUser().getId());
|
||||||
|
else
|
||||||
// There is some redundant lookup occurring. If the user isn't cached yet, then we construct them and cache them.
|
extractUserByJDAUser(event.getGuild().getId(), mentioned.getUser().getName(),
|
||||||
// The assumption is made that the user does, in fact, exist.
|
mentioned.getUser().getId(), mentioned.getUser().getAvatarUrl(), mentioned.getUser().getId());
|
||||||
public static KittyUser getKittyUser(String guildID, String userID)
|
}
|
||||||
{
|
|
||||||
String uid = guildID + userID;
|
return user;
|
||||||
KittyUser user = null;
|
}
|
||||||
synchronized(userCache)
|
|
||||||
{
|
// TODO: Clean up
|
||||||
user = userCache.get(uid);
|
public static KittyUser extractUserByJDAUser(String guildID, String name, String userID, String avatarID, String discordID)
|
||||||
}
|
{
|
||||||
|
lazyInit();
|
||||||
if(user == null)
|
|
||||||
{
|
String uid = guildID + userID;
|
||||||
Guild jdaGuild = kitty.getGuildById(guildID);
|
KittyUser user = null;
|
||||||
if(jdaGuild == null) return null;
|
synchronized(userCache)
|
||||||
|
{
|
||||||
Member jdaMember = jdaGuild.getMemberById(userID);
|
KittyUser cachedUser = userCache.get(uid);
|
||||||
if(jdaMember == null) return null;
|
if(cachedUser != null)
|
||||||
|
{
|
||||||
User jdaUser = jdaMember.getUser();
|
if(name != null)
|
||||||
if(jdaUser == null) return null;
|
cachedUser.name = name;
|
||||||
|
|
||||||
user = extractUserByJDAUser(guildID, jdaMember.getNickname(), jdaUser.getId(), jdaUser.getAvatarUrl(), jdaUser.getId());
|
cachedUser.avatarID = avatarID;
|
||||||
updateUser(user, jdaMember);
|
user = cachedUser;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return user;
|
{
|
||||||
}
|
KittyRole role = KittyRole.General;
|
||||||
|
KittyGuild guild = guildCache.get(guildID);
|
||||||
// Updates a user's name appropriately based on nickname if available
|
user = new KittyUser(name, guild, role, uid, avatarID, discordID);
|
||||||
public static void updateUser(KittyUser user, Member member)
|
DatabaseManager.instance.globalRegister(user);
|
||||||
{
|
userCache.put(uid, user);
|
||||||
if(member.getNickname() == null)
|
}
|
||||||
{
|
}
|
||||||
user.name = member.getUser().getName();
|
|
||||||
}
|
return user;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
user.name = member.getNickname();
|
// 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)
|
||||||
user.avatarID = member.getUser().getAvatarUrl();
|
{
|
||||||
}
|
String uid = guildID + userID;
|
||||||
|
KittyUser user = null;
|
||||||
|
synchronized(userCache)
|
||||||
//////////////////////////
|
{
|
||||||
// Construction Methods //
|
user = userCache.get(uid);
|
||||||
//////////////////////////
|
}
|
||||||
// Builds the core of the bot
|
|
||||||
public static KittyCore constructKittyCore() throws LoginException, InterruptedException
|
if(user == null)
|
||||||
{
|
{
|
||||||
lazyInit();
|
Guild jdaGuild = kitty.getGuildById(guildID);
|
||||||
|
if(jdaGuild == null) return null;
|
||||||
kitty = new JDABuilder(AccountType.BOT).setToken(Ref.TestToken).buildBlocking();
|
|
||||||
kitty.getPresence().setGame(Game.playing("with digital yarn"));
|
Member jdaMember = jdaGuild.getMemberById(userID);
|
||||||
kitty.addEventListener(new Main());
|
if(jdaMember == null) return null;
|
||||||
|
|
||||||
return new KittyCore(kitty);
|
User jdaUser = jdaMember.getUser();
|
||||||
}
|
if(jdaUser == null) return null;
|
||||||
|
|
||||||
// Default construction of the command manager. In order to remotely resolve command enabling
|
user = extractUserByJDAUser(guildID, jdaMember.getNickname(), jdaUser.getId(), jdaUser.getAvatarUrl(), jdaUser.getId());
|
||||||
// and disabling, what we do is construct the commands with a localized pair that is checked against
|
updateUser(user, jdaMember);
|
||||||
// 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)
|
return user;
|
||||||
{
|
}
|
||||||
lazyInit();
|
|
||||||
|
// Updates a user's name appropriately based on nickname if available
|
||||||
if(commandManager == null)
|
public static void updateUser(KittyUser user, Member member)
|
||||||
commandManager = new CommandManager(commandEnabler);
|
{
|
||||||
|
if(member.getNickname() == null)
|
||||||
return commandManager;
|
{
|
||||||
}
|
user.name = member.getUser().getName();
|
||||||
|
}
|
||||||
// Default database manager construction. It can be constructed
|
else
|
||||||
// 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.
|
user.name = member.getNickname();
|
||||||
// Effectively we cache the database here.
|
}
|
||||||
public static DatabaseManager constructDatabaseManager()
|
|
||||||
{
|
user.avatarID = member.getUser().getAvatarUrl();
|
||||||
lazyInit();
|
}
|
||||||
|
|
||||||
if(database == null)
|
|
||||||
database = new DatabaseManager();
|
//////////////////////////
|
||||||
|
// Construction Methods //
|
||||||
return database;
|
//////////////////////////
|
||||||
}
|
// Builds the core of the bot
|
||||||
|
public static KittyCore constructKittyCore() throws LoginException, InterruptedException
|
||||||
public static Stats constructStats(CommandManager manager)
|
{
|
||||||
{
|
lazyInit();
|
||||||
lazyInit();
|
|
||||||
|
// Determine token based on config. Default to test token.
|
||||||
if(stats == null)
|
String tokenToUse = Ref.TestToken;
|
||||||
stats = new Stats(manager);
|
switch(ConfigGlobals.getStartupMode())
|
||||||
|
{
|
||||||
return stats;
|
case Release: tokenToUse = Ref.Token; break;
|
||||||
}
|
case PoguRelease: tokenToUse = Ref.PoguToken; break;
|
||||||
|
default: tokenToUse = Ref.TestToken; break;
|
||||||
public static RPManager constructRPManager()
|
}
|
||||||
{
|
|
||||||
lazyInit();
|
// Construct bot based on token using the JDA Builder
|
||||||
|
JDABuilder builder = JDABuilder.createDefault(tokenToUse);
|
||||||
if(rpManager == null)
|
kitty = builder.build();
|
||||||
rpManager = new RPManager();
|
|
||||||
|
// Set activity, and add primariy event listener.
|
||||||
return rpManager;
|
updateActivity();
|
||||||
}
|
kitty.addEventListener(new Main());
|
||||||
|
|
||||||
public static PluginManager constructPluginManager()
|
return new KittyCore(kitty);
|
||||||
{
|
}
|
||||||
lazyInit();
|
|
||||||
|
// Updates the bots current activity based on the globals value.
|
||||||
if(pluginManager == null)
|
public static void updateActivity()
|
||||||
pluginManager = new PluginManager(Constants.AssetDirectory + "plugins/");
|
{
|
||||||
|
String activity = ConfigGlobals.getActivity();
|
||||||
return pluginManager;
|
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
|
||||||
// Utility Methods //
|
// 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.
|
||||||
// Returns number of cached guilds (does not equal total users in the database, only what's in memory)
|
public static CommandManager constructCommandManager(CommandEnabler commandEnabler)
|
||||||
public static Integer getGuildCount()
|
{
|
||||||
{ synchronized(guildCache)
|
lazyInit();
|
||||||
{
|
|
||||||
return guildCache.size();
|
if(commandManager == null)
|
||||||
}
|
commandManager = new CommandManager(commandEnabler);
|
||||||
}
|
|
||||||
|
return commandManager;
|
||||||
// Returns number of cached users (does not equal total users in the database, only what's in memory)
|
}
|
||||||
public static Integer getUserCount()
|
|
||||||
{ synchronized(userCache)
|
// Default database manager construction. It can be constructed
|
||||||
{
|
// in different ways, and so we construct it outside of the constructor for
|
||||||
return userCache.size();
|
// 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -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()
|
||||||
|
|||||||
@@ -1,40 +1,57 @@
|
|||||||
package dataStructures;
|
package dataStructures;
|
||||||
|
|
||||||
// This is a structure representing an image reponse for handing around.
|
import java.awt.Color;
|
||||||
|
|
||||||
|
// This is a structure representing an image response for handing around.
|
||||||
public class GenericImage
|
public class GenericImage
|
||||||
{
|
{
|
||||||
private String artist;
|
private KittyEmbed response= new KittyEmbed();
|
||||||
private String postURL;
|
|
||||||
private String imageURL;
|
|
||||||
|
|
||||||
public GenericImage(String artist, String postURL, String imageURL)
|
public GenericImage(String artist, String postURL, String imageURL)
|
||||||
{
|
{
|
||||||
this.artist = artist;
|
response.authorText = null;
|
||||||
this.postURL = postURL;
|
response.color = new Color(0,0,0);
|
||||||
this.imageURL = imageURL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editArtist(String artist)
|
public void editArtist(String artist)
|
||||||
{
|
{
|
||||||
this.artist = artist;
|
response.authorText = artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void editAuthorImage(String URL)
|
||||||
|
{
|
||||||
|
response.authorImage = URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editPostURL(String postURL)
|
public void editPostURL(String postURL)
|
||||||
{
|
{
|
||||||
this.postURL = postURL;
|
response.authorLink = postURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editImageURL(String imageURL)
|
public void editImageURL(String imageURL)
|
||||||
{
|
{
|
||||||
this.imageURL = imageURL;
|
response.imageURL = imageURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString()
|
public void editDescriptionText(String score)
|
||||||
{
|
{
|
||||||
if(imageURL.isEmpty())
|
response.descriptionText = score;
|
||||||
{
|
}
|
||||||
return "I couldn't find anything! Please try again!";
|
|
||||||
}
|
public void editFooterText(String tags)
|
||||||
return "Artist: " + artist + "\n<" + postURL.trim() + ">\n" + imageURL;
|
{
|
||||||
|
response.footerText = tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KittyEmbed output()
|
||||||
|
{
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValid()
|
||||||
|
{
|
||||||
|
if(response.title != null)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,15 @@
|
|||||||
package dataStructures;
|
package dataStructures;
|
||||||
|
|
||||||
//import core.DatabaseTrackedObject;
|
|
||||||
|
public class KittyChannel
|
||||||
public class KittyChannel //extends DatabaseTrackedObject
|
{
|
||||||
{
|
public String uniqueID;
|
||||||
public String uniqueID;
|
public boolean mature;
|
||||||
public KittyGuild guild;
|
|
||||||
|
public KittyChannel(String uniqueID, boolean mature)
|
||||||
//public KittyRating rating;
|
{
|
||||||
//public bool isVoice;
|
//super(uniqueID);
|
||||||
|
this.uniqueID = uniqueID;
|
||||||
public KittyChannel(String uniqueID, KittyGuild guild)
|
this.mature = false;
|
||||||
{
|
}
|
||||||
//super(uniqueID);
|
}
|
||||||
this.uniqueID = uniqueID;
|
|
||||||
this.guild = guild;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public String serialize()
|
|
||||||
// {
|
|
||||||
// return "";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void deSerialzie(String string)
|
|
||||||
// {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+182
-173
@@ -1,173 +1,182 @@
|
|||||||
package dataStructures;
|
package dataStructures;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import core.DatabaseManager;
|
|
||||||
import core.DatabaseTrackedObject;
|
import core.DatabaseManager;
|
||||||
import utils.AdminControl;
|
import core.DatabaseTrackedObject;
|
||||||
import utils.AudioUtils;
|
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
|
// Context for a given guild for kittybot. Primarily designed to hold guild-specific settings.
|
||||||
{
|
public class KittyGuild extends DatabaseTrackedObject
|
||||||
// Variables
|
{
|
||||||
public final String uniqueID;
|
// Variables
|
||||||
public KittyRating contentRating;
|
public final String uniqueID;
|
||||||
public KittyUser guildOwner;
|
public KittyRating contentRating;
|
||||||
public boolean polling;
|
public KittyUser guildOwner;
|
||||||
public String poll;
|
public boolean polling;
|
||||||
public boolean raffling;
|
public String poll;
|
||||||
public int raffleCost;
|
public boolean raffling;
|
||||||
public ArrayList<String> hasVoted = new ArrayList<String>();
|
public int raffleCost;
|
||||||
public ArrayList<String> emoji = new ArrayList<String>();
|
public ArrayList<String> hasVoted = new ArrayList<String>();
|
||||||
public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>();
|
public ArrayList<String> emoji = new ArrayList<String>();
|
||||||
public AdminControl control;
|
public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>();
|
||||||
public AudioUtils audio;
|
public HashMap <Long, KittyChannel> channels;
|
||||||
public ArrayList <KittyUser> raffleUsersUnchosen = new ArrayList<KittyUser>();
|
public AdminControl control;
|
||||||
public ArrayList <KittyUser> raffleUsersChosen = new ArrayList<KittyUser>();
|
public AudioUtils audio;
|
||||||
|
public ArrayList <KittyUser> raffleUsersUnchosen = new ArrayList<KittyUser>();
|
||||||
// Database synced info
|
public ArrayList <KittyUser> raffleUsersChosen = new ArrayList<KittyUser>();
|
||||||
private final String roleListName = "guildRoles";
|
|
||||||
public final KittyTrackedVector roleList;
|
// Database synced info
|
||||||
|
private final String roleListName = "guildRoles";
|
||||||
private final String beansName = "guildBeans";
|
public final KittyTrackedVector roleList;
|
||||||
public final KittyTrackedLong beans;
|
|
||||||
|
private final String beansName = "guildBeans";
|
||||||
private String commandIndicator;
|
public final KittyTrackedLong beans;
|
||||||
|
|
||||||
private void registerTrackedObjects()
|
private String commandIndicator;
|
||||||
{
|
|
||||||
DatabaseManager.instance.globalRegister(roleList);
|
private void registerTrackedObjects()
|
||||||
DatabaseManager.instance.globalRegister(beans);
|
{
|
||||||
}
|
DatabaseManager.instance.globalRegister(roleList);
|
||||||
|
DatabaseManager.instance.globalRegister(beans);
|
||||||
// Default content for a guild
|
}
|
||||||
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji)
|
|
||||||
{
|
// Default content for a guild
|
||||||
super(uniqueID);
|
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji,
|
||||||
this.uniqueID = uniqueID;
|
AudioUtils audio, HashMap<Long, KittyChannel> channels)
|
||||||
roleList = new KittyTrackedVector(roleListName, uniqueID);
|
{
|
||||||
beans = new KittyTrackedLong(beansName, uniqueID);
|
|
||||||
registerTrackedObjects();
|
super(uniqueID);
|
||||||
|
this.uniqueID = uniqueID;
|
||||||
control = adminControl;
|
roleList = new KittyTrackedVector(roleListName, uniqueID);
|
||||||
this.contentRating = KittyRating.Safe;
|
beans = new KittyTrackedLong(beansName, uniqueID);
|
||||||
this.polling = false;
|
registerTrackedObjects();
|
||||||
this.emoji = emoji;
|
|
||||||
setCommandIndicator("!");
|
control = adminControl;
|
||||||
}
|
this.contentRating = KittyRating.Safe;
|
||||||
|
this.polling = false;
|
||||||
// Explicit constructor
|
this.emoji = emoji;
|
||||||
public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner, String uniqueID)
|
this.audio = audio;
|
||||||
{
|
this.channels = channels;
|
||||||
super(uniqueID);
|
setCommandIndicator("!");
|
||||||
this.uniqueID = uniqueID;
|
}
|
||||||
roleList = new KittyTrackedVector(roleListName, uniqueID);
|
|
||||||
beans = new KittyTrackedLong(beansName, uniqueID);
|
// Explicit constructor
|
||||||
registerTrackedObjects();
|
public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner,
|
||||||
|
String uniqueID, AudioUtils audio, HashMap<Long, KittyChannel> channels)
|
||||||
setCommandIndicator(commandIndicator);
|
{
|
||||||
this.contentRating = contentRating;
|
super(uniqueID);
|
||||||
this.polling = false;
|
this.uniqueID = uniqueID;
|
||||||
this.guildOwner = guildOwner;
|
roleList = new KittyTrackedVector(roleListName, uniqueID);
|
||||||
}
|
beans = new KittyTrackedLong(beansName, uniqueID);
|
||||||
|
registerTrackedObjects();
|
||||||
public String startPoll(String poll)
|
|
||||||
{
|
setCommandIndicator(commandIndicator);
|
||||||
polling = true;
|
this.contentRating = contentRating;
|
||||||
this.poll = poll;
|
this.polling = false;
|
||||||
return "Poll `" + poll + "` started! Don't forget to add choices with `!poll choice`~";
|
this.guildOwner = guildOwner;
|
||||||
}
|
this.audio = audio;
|
||||||
|
this.channels = channels;
|
||||||
public String addChoiceToPoll(String choice)
|
}
|
||||||
{
|
|
||||||
choices.add(new KittyPoll(choice));
|
public String startPoll(String poll)
|
||||||
return "Added `" + choice + "` to poll!";
|
{
|
||||||
}
|
polling = true;
|
||||||
|
this.poll = poll;
|
||||||
public String endPoll()
|
return "Poll `" + poll + "` started! Don't forget to add choices with `!poll choice`~";
|
||||||
{
|
}
|
||||||
choices.clear();
|
|
||||||
hasVoted.clear();
|
public String addChoiceToPoll(String choice)
|
||||||
this.polling = false;
|
{
|
||||||
poll = null;
|
choices.add(new KittyPoll(choice));
|
||||||
return "Poll ended!";
|
return "Added `" + choice + "` to poll!";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Raffle methods
|
public String endPoll()
|
||||||
public boolean startRaffle(int beanCost)
|
{
|
||||||
{
|
choices.clear();
|
||||||
if(raffling)
|
hasVoted.clear();
|
||||||
{
|
this.polling = false;
|
||||||
return false;
|
poll = null;
|
||||||
}
|
return "Poll ended!";
|
||||||
raffleCost = beanCost;
|
}
|
||||||
raffling = true;
|
|
||||||
return true;
|
//Raffle methods
|
||||||
}
|
public boolean startRaffle(int beanCost)
|
||||||
|
{
|
||||||
public boolean endRaffle()
|
if(raffling)
|
||||||
{
|
{
|
||||||
if(raffling)
|
return false;
|
||||||
{
|
}
|
||||||
raffleCost = 0;
|
raffleCost = beanCost;
|
||||||
raffling = false;
|
raffling = true;
|
||||||
raffleUsersChosen.removeAll(raffleUsersChosen);
|
return true;
|
||||||
raffleUsersUnchosen.removeAll(raffleUsersUnchosen);
|
}
|
||||||
return true;
|
|
||||||
}
|
public boolean endRaffle()
|
||||||
return false;
|
{
|
||||||
}
|
if(raffling)
|
||||||
|
{
|
||||||
public boolean joinRaffle(KittyUser user)
|
raffleCost = 0;
|
||||||
{
|
raffling = false;
|
||||||
if(!raffleUsersChosen.contains(user) && !raffleUsersUnchosen.contains(user) && user.getBeans() > raffleCost && raffling)
|
raffleUsersChosen.removeAll(raffleUsersChosen);
|
||||||
{
|
raffleUsersUnchosen.removeAll(raffleUsersUnchosen);
|
||||||
user.changeBeans(raffleCost);
|
return true;
|
||||||
raffleUsersUnchosen.add(user);
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
public boolean joinRaffle(KittyUser user)
|
||||||
|
{
|
||||||
public KittyUser chooseRaffleWinner()
|
if(!raffleUsersChosen.contains(user) && !raffleUsersUnchosen.contains(user) && user.getBeans() > raffleCost && raffling)
|
||||||
{
|
{
|
||||||
if(!raffleUsersUnchosen.isEmpty())
|
user.changeBeans(-raffleCost);
|
||||||
{
|
raffleUsersUnchosen.add(user);
|
||||||
KittyUser chosen = raffleUsersUnchosen.get((int) (Math.random() * raffleUsersUnchosen.size()));
|
return true;
|
||||||
raffleUsersUnchosen.remove(chosen);
|
}
|
||||||
raffleUsersChosen.add(chosen);
|
return false;
|
||||||
return chosen;
|
}
|
||||||
}
|
|
||||||
return null;
|
public KittyUser chooseRaffleWinner()
|
||||||
}
|
{
|
||||||
|
if(!raffleUsersUnchosen.isEmpty())
|
||||||
@Override
|
{
|
||||||
public String serialize()
|
KittyUser chosen = raffleUsersUnchosen.get((int) (Math.random() * raffleUsersUnchosen.size()));
|
||||||
{
|
raffleUsersUnchosen.remove(chosen);
|
||||||
return commandIndicator;
|
raffleUsersChosen.add(chosen);
|
||||||
}
|
return chosen;
|
||||||
|
}
|
||||||
@Override
|
return null;
|
||||||
public void deSerialzie(String string)
|
}
|
||||||
{
|
|
||||||
if(string == null || string.length() == 0)
|
@Override
|
||||||
setCommandIndicator("!");
|
public String serialize()
|
||||||
else
|
{
|
||||||
setCommandIndicator(string);
|
return commandIndicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCommandIndicator()
|
@Override
|
||||||
{
|
public void deSerialzie(String string)
|
||||||
return commandIndicator;
|
{
|
||||||
}
|
if(string == null || string.length() == 0)
|
||||||
|
setCommandIndicator("!");
|
||||||
public void setCommandIndicator(String newIndicator)
|
else
|
||||||
{
|
setCommandIndicator(string);
|
||||||
if(newIndicator != commandIndicator)
|
}
|
||||||
{
|
|
||||||
commandIndicator = newIndicator;
|
public String getCommandIndicator()
|
||||||
markDirty();
|
{
|
||||||
}
|
return commandIndicator;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void setCommandIndicator(String newIndicator)
|
||||||
|
{
|
||||||
|
if(newIndicator != commandIndicator)
|
||||||
|
{
|
||||||
|
commandIndicator = newIndicator;
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+158
-146
@@ -1,146 +1,158 @@
|
|||||||
package dataStructures;
|
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 utils.GlobalLog;
|
import net.dv8tion.jda.api.utils.AttachmentOption;
|
||||||
import utils.LogFilter;
|
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
|
// This isn't constructed with the factory at this time, mostly because we need it
|
||||||
// commands aren't exposed to the GuildMessageReceivedEvent then we should be fine.
|
// to handle all the response queue behavior and everything internally. So long as
|
||||||
public class Response
|
// commands aren't exposed to the GuildMessageReceivedEvent then we should be fine.
|
||||||
{
|
public class Response
|
||||||
// Variables
|
{
|
||||||
private GuildMessageReceivedEvent event;
|
// Variables
|
||||||
private final int discordMessageMax = 2000;
|
private GuildMessageReceivedEvent event;
|
||||||
private final int kittyMessageMax = 1950;
|
private final int discordMessageMax = 2000;
|
||||||
private JDA kitty;
|
private final int kittyMessageMax = 1950;
|
||||||
|
private JDA kitty;
|
||||||
// Constructor
|
|
||||||
public Response(GuildMessageReceivedEvent event, KittyCore kitty)
|
// Constructor
|
||||||
{
|
public Response(GuildMessageReceivedEvent event, KittyCore kitty)
|
||||||
this.event = event;
|
{
|
||||||
this.kitty = kitty.jda;
|
this.event = event;
|
||||||
}
|
this.kitty = kitty.jda;
|
||||||
|
}
|
||||||
// Builds a nicely formatted embedded message based on information provided
|
|
||||||
public void send(KittyEmbed embedInfo)
|
// Builds a nicely formatted embedded message based on information provided
|
||||||
{
|
public void send(KittyEmbed embedInfo)
|
||||||
EmbedBuilder embed = new EmbedBuilder();
|
{
|
||||||
|
EmbedBuilder embed = new EmbedBuilder();
|
||||||
if(embedInfo.title != null && !embedInfo.title.isEmpty())
|
|
||||||
{
|
if(embedInfo.title != null && !embedInfo.title.isEmpty())
|
||||||
embed.setTitle(embedInfo.title);
|
{
|
||||||
}
|
embed.setTitle(embedInfo.title);
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
// We have to set the title to at least something that's not empty.
|
{
|
||||||
// By defualt, this creates nothing really visible.
|
// We have to set the title to at least something that's not empty.
|
||||||
embed.setTitle(" ");
|
// By defualt, this creates nothing really visible.
|
||||||
}
|
embed.setTitle(" ");
|
||||||
|
}
|
||||||
if(embedInfo.color != null)
|
|
||||||
embed.setColor(embedInfo.color);
|
if(embedInfo.color != null)
|
||||||
|
embed.setColor(embedInfo.color);
|
||||||
if(embedInfo.descriptionText != null)
|
|
||||||
embed.setDescription(embedInfo.descriptionText);
|
if(embedInfo.descriptionText != null)
|
||||||
|
embed.setDescription(embedInfo.descriptionText);
|
||||||
if(embedInfo.footerText != null)
|
|
||||||
embed.setFooter(embedInfo.footerText, null);
|
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.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.imageURL != null)
|
||||||
|
embed.setImage(embedInfo.imageURL);
|
||||||
if(embedInfo.thumbnailURL != null && embedInfo.thumbnailURL.contains("attachment://"))
|
|
||||||
{
|
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.
|
// This is the case where you have a thumbnail image, but you want it to be a local file.
|
||||||
String thumbPath = embedInfo.thumbnailURL;
|
// TODO: Make this more generic. Consider message builder for the entire thing.
|
||||||
String thumbName = thumbPath.replace("attachment://", "");
|
String thumbPath = embedInfo.thumbnailURL;
|
||||||
|
String thumbName = thumbPath.replace("attachment://", "");
|
||||||
// Build the message and send if the file is valid
|
|
||||||
MessageBuilder message = new MessageBuilder();
|
// Build the message and send if the file is valid
|
||||||
embed.setThumbnail(thumbPath);
|
MessageBuilder message = new MessageBuilder();
|
||||||
message.setEmbed(embed.build());
|
embed.setThumbnail(thumbPath);
|
||||||
|
message.setEmbed(embed.build());
|
||||||
File thumbImage = new File(thumbName);
|
|
||||||
if(thumbImage.exists())
|
GlobalLog.log("We're trying to send a response that has a locally defined thumbnail file...");
|
||||||
{
|
|
||||||
event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
|
File thumbImage = new File(thumbName);
|
||||||
}
|
if(thumbImage.exists())
|
||||||
}
|
{
|
||||||
else
|
// Used to eb as follows:
|
||||||
{
|
//event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
|
||||||
if(embedInfo.thumbnailURL != null)
|
event.getChannel().sendMessage(message.build()).queue();
|
||||||
embed.setThumbnail(embedInfo.thumbnailURL);
|
}
|
||||||
|
}
|
||||||
event.getChannel().sendMessage(embed.build()).queue();
|
else
|
||||||
}
|
{
|
||||||
}
|
if(embedInfo.thumbnailURL != null)
|
||||||
|
embed.setThumbnail(embedInfo.thumbnailURL);
|
||||||
// Queues a standard text-based message response to the channel that issued the command.
|
|
||||||
public void send(String toRespondWith)
|
event.getChannel().sendMessage(embed.build()).queue();
|
||||||
{
|
}
|
||||||
GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
|
}
|
||||||
if(toRespondWith.length() > discordMessageMax)
|
|
||||||
{
|
// Queues a standard text-based message response to the channel that issued the command.
|
||||||
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
public void send(String toRespondWith)
|
||||||
}
|
{
|
||||||
else
|
GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
|
||||||
{
|
if(toRespondWith.length() > discordMessageMax)
|
||||||
event.getChannel().sendMessage(toRespondWith).queue();
|
{
|
||||||
}
|
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// Queues a standard text-based message response to the specified channel.
|
{
|
||||||
public void sendToChannel(String toRespondWith, String channelID)
|
event.getChannel().sendMessage(toRespondWith).queue();
|
||||||
{
|
}
|
||||||
TextChannel channel;
|
}
|
||||||
channel = kitty.getTextChannelById(Long.parseLong(channelID));
|
|
||||||
if(toRespondWith.length() > discordMessageMax)
|
// Queues a standard text-based message response to the specified channel.
|
||||||
{
|
public void sendToChannel(String toRespondWith, String channelID)
|
||||||
channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
{
|
||||||
}
|
TextChannel channel;
|
||||||
else
|
channel = kitty.getTextChannelById(Long.parseLong(channelID));
|
||||||
{
|
if(toRespondWith.length() > discordMessageMax)
|
||||||
channel.sendMessage(toRespondWith).queue();
|
{
|
||||||
}
|
channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// Immediately dispatches the message to the channel that issued the command.
|
{
|
||||||
public void sendImmediate(String toRespondWith)
|
channel.sendMessage(toRespondWith).queue();
|
||||||
{
|
}
|
||||||
GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
|
}
|
||||||
if(toRespondWith.length() > discordMessageMax)
|
|
||||||
{
|
// Immediately dispatches the message to the channel that issued the command.
|
||||||
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!");
|
public void sendImmediate(String toRespondWith)
|
||||||
}
|
{
|
||||||
else
|
GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
|
||||||
{
|
if(toRespondWith.length() > discordMessageMax)
|
||||||
event.getChannel().sendMessage(toRespondWith).complete();
|
{
|
||||||
}
|
event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// Queues a file response to the channel that issued the command.
|
{
|
||||||
public void sendFile(File toRespondWith, String extension)
|
event.getChannel().sendMessage(toRespondWith).complete();
|
||||||
{
|
}
|
||||||
GlobalLog.log(LogFilter.Response, "Sending file response");
|
}
|
||||||
event.getChannel().sendFile(toRespondWith, "return." + extension).queue();
|
|
||||||
}
|
// Queues a file response to the channel that issued the command.
|
||||||
|
public void sendFile(File toRespondWith, String 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 file response");
|
||||||
{
|
event.getChannel().sendFile(toRespondWith, "return." + extension).queue();
|
||||||
GlobalLog.log(LogFilter.Response, "Sending input stream response");
|
}
|
||||||
event.getChannel().sendFile(in, "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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+100
-100
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+114
-117
@@ -1,118 +1,115 @@
|
|||||||
package main;
|
package main;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
|
|
||||||
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;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyCore;
|
import dataStructures.KittyCore;
|
||||||
import dataStructures.KittyGuild;
|
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 utils.GlobalLog;
|
||||||
import net.dv8tion.jda.core.entities.Game;
|
|
||||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
// http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation.
|
||||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
// This is the application entry point, and bot startup location!
|
||||||
import offline.Ref;
|
|
||||||
import utils.GlobalLog;
|
@SuppressWarnings("unused")
|
||||||
|
public class Main extends ListenerAdapter
|
||||||
// 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!
|
// Variables and bot specific objects
|
||||||
|
private static KittyCore kittyCore;
|
||||||
@SuppressWarnings("unused")
|
private static DatabaseManager databaseManager;
|
||||||
public class Main extends ListenerAdapter
|
private static CommandManager commandManager;
|
||||||
{
|
private static Stats stats;
|
||||||
// Variables and bot specific objects
|
private static RPManager rpManager;
|
||||||
private static KittyCore kittyCore;
|
private static PluginManager pluginManager;
|
||||||
private static DatabaseManager databaseManager;
|
private static CharacterManager charManager;
|
||||||
private static CommandManager commandManager;
|
|
||||||
private static Stats stats;
|
|
||||||
private static RPManager rpManager;
|
// Initialization and setup
|
||||||
private static PluginManager pluginManager;
|
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
||||||
private static CharacterManager charManager;
|
{
|
||||||
|
// Factory startup. The ordering is intentional.
|
||||||
// Initialization and setup
|
GlobalLog.initialize();
|
||||||
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
databaseManager = ObjectBuilder.constructDatabaseManager();
|
||||||
{
|
commandManager = ObjectBuilder.constructCommandManager(CommandEnabler.instance); // TODO: Untangle this singleton
|
||||||
// Factory startup. The ordering is intentional.
|
stats = ObjectBuilder.constructStats(commandManager);
|
||||||
GlobalLog.initialize();
|
charManager = new CharacterManager();
|
||||||
databaseManager = ObjectBuilderFactory.constructDatabaseManager();
|
rpManager = ObjectBuilder.constructRPManager();
|
||||||
commandManager = ObjectBuilderFactory.constructCommandManager(CommandEnabler.instance); // TODO: Untangle this singleton
|
pluginManager = ObjectBuilder.constructPluginManager();
|
||||||
stats = ObjectBuilderFactory.constructStats(commandManager);
|
|
||||||
charManager = new CharacterManager();
|
// Bot startup
|
||||||
rpManager = ObjectBuilderFactory.constructRPManager();
|
kittyCore = ObjectBuilder.constructKittyCore();
|
||||||
pluginManager = ObjectBuilderFactory.constructPluginManager();
|
}
|
||||||
|
|
||||||
// Bot startup
|
// When a message is sent in a server that kitty is in, this is what's called.
|
||||||
kittyCore = ObjectBuilderFactory.constructKittyCore();
|
@Override
|
||||||
}
|
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
|
||||||
|
{
|
||||||
// When a message is sent in a server that kitty is in, this is what's called.
|
// Tweak the event as necessary
|
||||||
@Override
|
if(!Superintendent.preProcessSetup(event, stats))
|
||||||
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
|
return;
|
||||||
{
|
|
||||||
// Tweak the event as necessary
|
// Factory objects
|
||||||
if(!Superintendent.preProcessSetup(event, stats))
|
KittyUser user = ObjectBuilder.extractUser(event);
|
||||||
return;
|
KittyGuild guild = ObjectBuilder.extractGuild(event);
|
||||||
|
KittyChannel channel = ObjectBuilder.extractChannel(event);
|
||||||
// Factory objects
|
|
||||||
KittyUser user = ObjectBuilderFactory.extractUser(event);
|
// Specialized uncached objects
|
||||||
KittyGuild guild = ObjectBuilderFactory.extractGuild(event);
|
Response response = new Response(event, kittyCore);
|
||||||
KittyChannel channel = ObjectBuilderFactory.extractChannel(event);
|
UserInput input = new UserInput(event, guild);
|
||||||
|
|
||||||
// Specialized uncached objects
|
// Tweak object construction as necessary
|
||||||
Response response = new Response(event, kittyCore);
|
if(!Superintendent.postProcessSetup(event, user, guild, channel, response, input))
|
||||||
UserInput input = new UserInput(event, guild);
|
return;
|
||||||
|
|
||||||
// Tweak object construction as necessary
|
// Track beans!
|
||||||
if(!Superintendent.postProcessSetup(event, user, guild, channel, response, input))
|
user.changeBeans(1);
|
||||||
return;
|
|
||||||
|
// RP logging system
|
||||||
// Track beans!
|
RPManager.instance.addLine(channel, user, input);
|
||||||
user.changeBeans(1);
|
|
||||||
|
// Run any pre-emptive upkeep we need to
|
||||||
// RP logging system
|
if(!Superintendent.perCommandUpkeepPre(pluginManager))
|
||||||
RPManager.instance.addLine(channel, user, input);
|
return;
|
||||||
|
|
||||||
// Run any pre-emptive upkeep we need to
|
// Attempt to spin up a command. If the command doesn't exist.
|
||||||
if(!Superintendent.perCommandUpkeepPre(pluginManager))
|
// Run plugins right before invoking the commands but after all other setup.
|
||||||
return;
|
if(commandManager.invokeOnNewThread(guild, channel, user, input, response) == false)
|
||||||
|
{
|
||||||
// Attempt to spin up a command. If the command doesn't exist.
|
List<String> pluginOutput = pluginManager.runAll(input.message, user);
|
||||||
// Run plugins right before invoking the commands but after all other setup.
|
|
||||||
if(commandManager.invokeOnNewThread(guild, channel, user, input, response) == false)
|
if(pluginOutput != null && pluginOutput.size() > 0)
|
||||||
{
|
{
|
||||||
List<String> pluginOutput = pluginManager.runAll(input.message, user);
|
for(int i = 0; i < pluginOutput.size(); ++i)
|
||||||
|
{
|
||||||
if(pluginOutput != null && pluginOutput.size() > 0)
|
if(pluginOutput.get(i).startsWith("!"))
|
||||||
{
|
{
|
||||||
for(int i = 0; i < pluginOutput.size(); ++i)
|
commandManager.invokeOnNewThread(guild, channel, user,
|
||||||
{
|
new UserInput(pluginOutput.get(i).substring(1), guild), response);
|
||||||
if(pluginOutput.get(i).startsWith("!"))
|
}
|
||||||
{
|
else
|
||||||
commandManager.invokeOnNewThread(guild, channel, user, new UserInput(pluginOutput.get(i).substring(1), guild), response);
|
{
|
||||||
}
|
response.send(pluginOutput.get(i));
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
response.send(pluginOutput.get(i));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
// Run any upkeep in post we need to
|
||||||
}
|
if(!Superintendent.perCommandUpkeepPost(kittyCore, databaseManager))
|
||||||
|
return;
|
||||||
// Run any upkeep in post we need to
|
}
|
||||||
if(!Superintendent.perCommandUpkeepPost(kittyCore, databaseManager))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -6,14 +6,41 @@ public class NetworkColiru
|
|||||||
{
|
{
|
||||||
public String compileCPlusPlus(String query)
|
public String compileCPlusPlus(String query)
|
||||||
{
|
{
|
||||||
// Escape characters that need escaping.
|
// Escape characters that need escaping - mostly whitespace.
|
||||||
// Primarily types of whitespace.
|
|
||||||
query = query.replace("\\n", "\\\\n");
|
query = query.replace("\\n", "\\\\n");
|
||||||
query = query.replace("\\t", "\\\\t");
|
query = query.replace("\\t", "\\\\t");
|
||||||
query = query.replace("\n", "\\n");
|
query = query.replace("\n", "\\n");
|
||||||
query = query.replace("\"", "\\\"");
|
query = query.replace("\"", "\\\"");
|
||||||
query = query.replace("\t", "\\t");
|
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!
|
// Send the compilation request!
|
||||||
String result = HTTPUtils.sendPOSTRequest("http://coliru.stacked-crooked.com/compile"
|
String result = HTTPUtils.sendPOSTRequest("http://coliru.stacked-crooked.com/compile"
|
||||||
, "{ \"cmd\": \"g++ main.cpp && ./a.out\", \"src\": \"" + query + "\" }");
|
, "{ \"cmd\": \"g++ main.cpp && ./a.out\", \"src\": \"" + query + "\" }");
|
||||||
@@ -21,7 +48,7 @@ public class NetworkColiru
|
|||||||
// If we got a valid response...
|
// If we got a valid response...
|
||||||
if(!result.isEmpty())
|
if(!result.isEmpty())
|
||||||
{
|
{
|
||||||
result = "Here's what happened when I went to compiled that! \n```" + result + "```";
|
result = "Here's what happened when I went to compile that! \n```" + result + "```";
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import utils.*;
|
|||||||
|
|
||||||
public class NetworkDerpi
|
public class NetworkDerpi
|
||||||
{
|
{
|
||||||
private final String mainURL = "https://derpibooru.org/search.json?q=";
|
private final String mainURL = "https://derpibooru.org/api/v1/json/search/images?q=";
|
||||||
private static final Gson jsonParser_ = new Gson();
|
private static final Gson jsonParser_ = new Gson();
|
||||||
|
|
||||||
private class DerpiResponseObject
|
private class DerpiResponseObject
|
||||||
{
|
{
|
||||||
public String image;
|
public String image;
|
||||||
public String tags;
|
public String tags;
|
||||||
|
public String score;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class InitialRequest
|
private class InitialRequest
|
||||||
@@ -23,22 +24,41 @@ public class NetworkDerpi
|
|||||||
|
|
||||||
public GenericImage getDerpi(String query)
|
public GenericImage getDerpi(String query)
|
||||||
{
|
{
|
||||||
|
String res;
|
||||||
GenericImage image = new GenericImage(" ", " ", " ");
|
GenericImage image = new GenericImage(" ", " ", " ");
|
||||||
query = query.trim();
|
query = query.trim();
|
||||||
query = query.replace(" ", ",");
|
query = query.replace(" ", ",");
|
||||||
String res = HTTPUtils.sendGETRequest(mainURL + query + "&random_image=1&key=" + Ref.derpiKey);
|
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);
|
||||||
if(res != null)
|
if(res != null)
|
||||||
{
|
{
|
||||||
|
InitialRequest obj;
|
||||||
// Use class evaluation on an array of the response object to be able to hold multiple.
|
// Use class evaluation on an array of the response object to be able to hold multiple.
|
||||||
InitialRequest obj = jsonParser_.fromJson(res, InitialRequest.class);
|
try
|
||||||
|
{
|
||||||
|
obj = jsonParser_.fromJson(res, InitialRequest.class);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if(res != null)
|
if(res != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
String res2 = HTTPUtils.sendGETRequest("https://derpibooru.org/" + obj.id + ".json");
|
String res2 = HTTPUtils.sendGETRequest("https://derpibooru.org/" + obj.id + ".json");
|
||||||
image.editPostURL("<https://derpibooru.org/" + obj.id +">");
|
image.editPostURL("https://derpibooru.org/" + obj.id);
|
||||||
DerpiResponseObject imageObj = jsonParser_.fromJson(res2, DerpiResponseObject.class);
|
DerpiResponseObject imageObj = jsonParser_.fromJson(res2, DerpiResponseObject.class);
|
||||||
|
|
||||||
image.editImageURL("https:" + imageObj.image.substring(0, imageObj.image.indexOf('_')) + imageObj.image.substring(imageObj.image.lastIndexOf('.')));
|
image.editImageURL("https:" + imageObj.image.substring(0, imageObj.image.indexOf('_')) +
|
||||||
|
imageObj.image.substring(imageObj.image.lastIndexOf('.')));
|
||||||
if(imageObj.tags.contains("artist:"))
|
if(imageObj.tags.contains("artist:"))
|
||||||
{
|
{
|
||||||
String [] sepTags = imageObj.tags.split(",");
|
String [] sepTags = imageObj.tags.split(",");
|
||||||
@@ -54,8 +74,20 @@ public class NetworkDerpi
|
|||||||
artists += sepTags[i].substring(sepTags[i].indexOf(":")+1);
|
artists += sepTags[i].substring(sepTags[i].indexOf(":")+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
image.editAuthorImage("https://derpicdn.net/favicon.ico");
|
||||||
|
|
||||||
image.editArtist(artists);
|
image.editArtist(artists);
|
||||||
|
String tags = "";
|
||||||
|
for(int i = 0; i < sepTags.length && i < 15; i++)
|
||||||
|
{
|
||||||
|
if(!sepTags[i].contains("artist:"))
|
||||||
|
{
|
||||||
|
tags += sepTags[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
image.editFooterText("[Tags]" + tags);
|
||||||
|
image.editDescriptionText("Score: " + imageObj.score);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -66,4 +98,46 @@ public class NetworkDerpi
|
|||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GenericImage getDerpiByID(String id)
|
||||||
|
{
|
||||||
|
GenericImage image = new GenericImage(" ", " ", " ");
|
||||||
|
String artists = "";
|
||||||
|
image.editAuthorImage("https://derpicdn.net/favicon.ico");
|
||||||
|
String res;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
res = HTTPUtils.sendGETRequest("https://derpibooru.org/" + id + ".json");
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DerpiResponseObject imageObj = jsonParser_.fromJson(res, DerpiResponseObject.class);
|
||||||
|
if(imageObj.tags.contains("artist:"))
|
||||||
|
{
|
||||||
|
String [] sepTags = imageObj.tags.split(",");
|
||||||
|
for(int i = 0; i < sepTags.length; i++)
|
||||||
|
{
|
||||||
|
if(sepTags[i].contains("artist:"))
|
||||||
|
{
|
||||||
|
if(!artists.equals(""))
|
||||||
|
{
|
||||||
|
artists += " and ";
|
||||||
|
}
|
||||||
|
artists += sepTags[i].substring(sepTags[i].indexOf(":")+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(artists != "")
|
||||||
|
image.editArtist(artists);
|
||||||
|
else
|
||||||
|
image.editArtist("Artist Unknown!");
|
||||||
|
|
||||||
|
image.editFooterText("[Tags]" + imageObj.tags);
|
||||||
|
image.editDescriptionText("Score: " + imageObj.score);
|
||||||
|
image.editImageURL("https:" + imageObj.image.substring(0, imageObj.image.indexOf('_')) +
|
||||||
|
imageObj.image.substring(imageObj.image.lastIndexOf('.')));
|
||||||
|
return image;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
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,9 +73,36 @@ public class NetworkTheColorAPI
|
|||||||
|
|
||||||
public ColorData lookupHex(String hex)
|
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
|
try
|
||||||
{
|
{
|
||||||
hex = hex.replace("#", "");
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
String response = HTTPUtils.sendGETRequest("https://www.thecolorapi.com/id?hex=" + hex);
|
String response = HTTPUtils.sendGETRequest("https://www.thecolorapi.com/id?hex=" + hex);
|
||||||
|
|
||||||
ColorData data = jsonParser.fromJson(response, ColorData.class);
|
ColorData data = jsonParser.fromJson(response, ColorData.class);
|
||||||
|
|||||||
@@ -1,14 +1,56 @@
|
|||||||
package network;
|
package network;
|
||||||
|
|
||||||
import com.google.api.services.youtube.YouTube;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import offline.Ref;
|
import offline.Ref;
|
||||||
|
import utils.HTTPUtils;
|
||||||
|
|
||||||
public class NetworkYoutube
|
public class NetworkYoutube
|
||||||
{
|
{
|
||||||
private static YouTube youtube;
|
///////////////////////////////////////
|
||||||
|
// Internal JSON class and variables //
|
||||||
|
//////////////////////////////////.////
|
||||||
|
|
||||||
public NetworkYoutube()
|
//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
|
||||||
{
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+21
-10
@@ -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)
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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); }
|
||||||
|
|||||||
@@ -0,0 +1,192 @@
|
|||||||
|
package utils.audio;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
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.api.audio.AudioSendHandler;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||||
|
import net.dv8tion.jda.api.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 ByteBuffer provide20MsAudio()
|
||||||
|
{
|
||||||
|
ByteBuffer outputBuffer = ByteBuffer.wrap(lastFrame.getData());
|
||||||
|
return outputBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
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