diff --git a/CHANGELOG.md b/CHANGELOG.md
index b75fa82..5cf8b7a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,15 @@
# Changelog
+### 5.4.0
+- Added **_vote_** command.
+- Added discord bot list api.
+- Added support for multiple dye images.
+
+### 5.3.6
+- Added the StatusImage object, will need to add a
+RESTful api in order to use it, most likely will use
+spring boot for this.
+
### 5.3.5
- Renamed bot and changes some picture URLs.
diff --git a/pom.xml b/pom.xml
index 6119671..cb1d5d0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,14 @@
com.gmail.zastrixarundell
ToramBot
- 5.3.5
+ 5.4.0
+
+
+
+ jitpack.io
+ https://jitpack.io
+
+
@@ -34,7 +41,17 @@
2.10.3
compile
-
+
+ org.discordbots
+ DBL-Java-Library
+ 2.0.1
+
+
+ com.github.coobird
+ thumbnailator
+ 0.4.8
+ compile
+
diff --git a/src/main/java/com/github/zastrixarundell/torambot/ToramBot.java b/src/main/java/com/github/zastrixarundell/torambot/ToramBot.java
index c6a1005..1f16476 100644
--- a/src/main/java/com/github/zastrixarundell/torambot/ToramBot.java
+++ b/src/main/java/com/github/zastrixarundell/torambot/ToramBot.java
@@ -24,7 +24,10 @@
import com.github.zastrixarundell.torambot.commands.search.items.gear.ShieldCommand;
import com.github.zastrixarundell.torambot.commands.search.items.gear.SpecialCommand;
+import com.github.zastrixarundell.torambot.commands.torambot.VoteCommand;
import com.github.zastrixarundell.torambot.entities.ToramForumsUser;
+import com.github.zastrixarundell.torambot.utils.AESHelper;
+import org.discordbots.api.client.DiscordBotListAPI;
import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
import org.javacord.api.entity.server.Server;
@@ -41,7 +44,7 @@ public static void main(String[] args)
if(args.length == 0)
{
System.out.println("The token is not specified... shutting down!");
- return;
+ System.exit(-1);
}
if(args.length > 1) { Values.setPrefix(args[1]); }
@@ -64,53 +67,14 @@ public static void main(String[] args)
bot.updateActivity("Starting up! Please wait!");
- //Crafting
- bot.addListener(new ProficiencyCommand());
- bot.addListener(new CookingCommand());
- bot.addListener(new MatsCommand());
+ updateCount(bot);
+ addCommands(bot);
- //items
- bot.addListener(new ItemCommand());
- bot.addListener(new AdditionalCommand());
- bot.addListener(new ArmorCommand());
- bot.addListener(new ArrowCommand());
- bot.addListener(new BowCommand());
- bot.addListener(new BowGunCommand());
- bot.addListener(new DaggerCommand());
- bot.addListener(new GemCommand());
- bot.addListener(new HalberdCommand());
- bot.addListener(new KatanaCommand());
- bot.addListener(new KnucklesCommand());
- bot.addListener(new MagicDeviceCommand());
- bot.addListener(new OneHandedSwordCommand());
- bot.addListener(new ShieldCommand());
- bot.addListener(new SpecialCommand());
- bot.addListener(new StaffCommand());
- bot.addListener(new TwoHandedSwordCommand());
- bot.addListener(new XtalCommand());
- bot.addListener(new UpgradeCommand());
+ //vote command is here
+ setupDiscordBotListApi(bot);
- //monsters
- bot.addListener(new MonsterCommand());
- bot.addListener(new NormalMonsterComand());
- bot.addListener(new MiniBossCommand());
- bot.addListener(new BossCommand());
-
- //player
- bot.addListener(new LevelCommand());
- bot.addListener(new PointsCommand());
-
- //torambot
- bot.addListener(new HelpCommand());
- bot.addListener(new InviteCommand());
- bot.addListener(new DonateCommand());
- bot.addListener(new SupportCommand());
-
- //gameinfo
- bot.addListener(new NewsCommand());
- bot.addListener(new LatestCommand());
- bot.addListener(new MaintenanceCommand());
- bot.addListener(new EventsCommand());
+ //Just to refresh
+ updateCount(bot);
System.out.println("Started! Type in \"stop\" to stop the bot!");
@@ -129,7 +93,7 @@ public static void main(String[] args)
bot.disconnect();
activity.cancel();
dyeImage.cancel();
- return;
+ System.exit(0);
}
}
}
@@ -145,34 +109,27 @@ private static Timer updateActivity(DiscordApi bot)
@Override
public void run()
{
+ updateCount(bot);
+
+ if(Values.getApi() != null)
+ Values.getApi().setStats(bot.getServers().size());
switch(status)
{
case 0:
-
- List doNotCheckThese =Arrays.asList
- (
- "264445053596991498",
- "446425626988249089"
- );
-
- long userCount = 0;
-
- for (Server server : bot.getServers())
- if(!doNotCheckThese.contains(server.getIdAsString()))
- for (User user : server.getMembers())
- if (!user.isBot())
- userCount++;
-
- bot.updateActivity(Values.getPrefix() + "help | " + userCount + " users!");
+ bot.updateActivity(Values.getPrefix() + "help | " + Values.getUserCount() + " users!");
break;
case 1:
- bot.updateActivity(Values.getPrefix() + "invite | " + bot.getServers().size() + " servers!");
+ bot.updateActivity(Values.getPrefix() + "invite | " + Values.getGuildCount() + " servers!");
break;
+ case 2:
+ Values.getApi().getBot("600302983305101323").whenComplete((bot1, throwable) -> bot.updateActivity(Values.getPrefix() + "vote | " + bot1.getMonthlyPoints() + " votes this month!"));
}
status ++;
- status = status % 2;
+ status = status % (Values.getApi() != null ? 3 : 2);
+
+ System.gc();
}
};
@@ -190,14 +147,16 @@ public void run()
{
try
{
- System.out.println("Starting dye!");
+ System.out.println("Starting user!");
ToramForumsUser user = new ToramForumsUser(token);
+ System.out.println("Starting dye!");
user.setDye();
+ System.out.println("Finished dye!");
user.close();
- if(Values.getDyeImage() == null)
+ if(Values.getDyeImages() == null)
{
- System.out.println("An error happened while updating the dye data!");
+ System.out.println("There are no dyes!");
if(DyeCommand.instance != null)
{
@@ -214,6 +173,7 @@ public void run()
}
catch (Exception e)
{
+ Values.setDyeImages(null);
System.out.println("An error happened while updating the dye data!");
e.printStackTrace();
@@ -223,6 +183,8 @@ public void run()
DyeCommand.instance = null;
}
}
+
+ System.gc();
}
};
@@ -230,4 +192,102 @@ public void run()
return timer;
}
+ private static void updateCount(DiscordApi bot)
+ {
+ List doNotCheckThese =Arrays.asList
+ (
+ "264445053596991498",
+ "446425626988249089"
+ );
+
+ int userCount = 0;
+
+ for (Server server : bot.getServers())
+ if(!doNotCheckThese.contains(server.getIdAsString()))
+ for (User user : server.getMembers())
+ if (!user.isBot())
+ userCount++;
+
+ Values.setUserCount(userCount);
+
+ Values.setGuildCount(bot.getServers().size());
+
+ Values.setCommandCount(bot.getListeners().size());
+ }
+
+ private static void addCommands(DiscordApi bot)
+ {
+ //Crafting
+ bot.addListener(new ProficiencyCommand());
+ bot.addListener(new CookingCommand());
+ bot.addListener(new MatsCommand());
+
+ //items
+ bot.addListener(new ItemCommand());
+ bot.addListener(new AdditionalCommand());
+ bot.addListener(new ArmorCommand());
+ bot.addListener(new ArrowCommand());
+ bot.addListener(new BowCommand());
+ bot.addListener(new BowGunCommand());
+ bot.addListener(new DaggerCommand());
+ bot.addListener(new GemCommand());
+ bot.addListener(new HalberdCommand());
+ bot.addListener(new KatanaCommand());
+ bot.addListener(new KnucklesCommand());
+ bot.addListener(new MagicDeviceCommand());
+ bot.addListener(new OneHandedSwordCommand());
+ bot.addListener(new ShieldCommand());
+ bot.addListener(new SpecialCommand());
+ bot.addListener(new StaffCommand());
+ bot.addListener(new TwoHandedSwordCommand());
+ bot.addListener(new XtalCommand());
+ bot.addListener(new UpgradeCommand());
+
+ //monsters
+ bot.addListener(new MonsterCommand());
+ bot.addListener(new NormalMonsterComand());
+ bot.addListener(new MiniBossCommand());
+ bot.addListener(new BossCommand());
+
+ //player
+ bot.addListener(new LevelCommand());
+ bot.addListener(new PointsCommand());
+
+ //torambot
+ bot.addListener(new HelpCommand());
+ bot.addListener(new InviteCommand());
+ bot.addListener(new DonateCommand());
+ bot.addListener(new SupportCommand());
+
+ //gameinfo
+ bot.addListener(new NewsCommand());
+ bot.addListener(new LatestCommand());
+ bot.addListener(new MaintenanceCommand());
+ bot.addListener(new EventsCommand());
+ }
+
+ private static void setupDiscordBotListApi(DiscordApi bot)
+ {
+ try
+ {
+ AESHelper aesHelper = new AESHelper(bot.getToken());
+ String token = aesHelper.decryptData("OjImYbN/dPbEBjjxc+X5sjV5dHC+lU95tnSXwpt2PmQlJXwaXgBRAwdpZtmAGmkYEuu5PU+GMD/+RFibTqrM0367bNnkEE2Hrr77BtP7zyvXocbkRW8G0BRedaLf3EMndt0G/39av7zbWCo2RVYQ99LYhzG8gXWbfd04pJtd6JaXILD0Z3VBfElICQm7D/lS/WufLRG7n2YZsC+jrURXfg==");
+
+ DiscordBotListAPI api = new DiscordBotListAPI.Builder()
+ .token(token)
+ .botId("600302983305101323")
+ .build();
+
+ Values.setApi(api);
+
+ api.setStats(bot.getServers().size());
+
+ if(Values.getApi() != null)
+ bot.addListener(new VoteCommand());
+ }
+ catch (Exception ignore)
+ {
+
+ }
+ }
}
diff --git a/src/main/java/com/github/zastrixarundell/torambot/Values.java b/src/main/java/com/github/zastrixarundell/torambot/Values.java
index 86401de..631e1f0 100644
--- a/src/main/java/com/github/zastrixarundell/torambot/Values.java
+++ b/src/main/java/com/github/zastrixarundell/torambot/Values.java
@@ -1,16 +1,24 @@
package com.github.zastrixarundell.torambot;
+import org.discordbots.api.client.DiscordBotListAPI;
import org.joda.time.DateTime;
import java.awt.image.BufferedImage;
-import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
public class Values
{
+ private static DiscordBotListAPI api = null;
+
private static String version = "";
+ private static int userCount, guildCount, commandCount;
+
+ public static final String profileImageURL = "https://raw.githubusercontent.com/ZastrixArundell/ToramBot/master/images/profile.png";
+
public final static String footerMessage = "Support me by going on: http://corneey.com/w2ObhY";
public final static String toramLogo = "https://toramonline.com/index.php?media/toram-online-logo.50/full&d=1463410056";
@@ -25,7 +33,7 @@ public class Values
private static DateTime lastDyeUpdate;
- private static BufferedImage dyeImage = null;
+ private static BufferedImage[] dyeImages = null;
private static String prefix = ">";
@@ -33,9 +41,9 @@ public class Values
public static String getPrefix() { return prefix; }
- public static BufferedImage getDyeImage() { return dyeImage; }
+ public static BufferedImage[] getDyeImages() { return dyeImages; }
- public static void setDyeImage(BufferedImage dyeImage) { Values.dyeImage = dyeImage; }
+ public static void setDyeImages(BufferedImage[] dyeImage) { Values.dyeImages = dyeImage; }
public static void getMavenVersion()
{
@@ -57,4 +65,38 @@ public static void getMavenVersion()
public static DateTime getLastDyeUpdate() { return lastDyeUpdate; }
public static void setLastDyeUpdate(DateTime lastDyeUpdate) { Values.lastDyeUpdate = lastDyeUpdate; }
+
+ public static int getUserCount()
+ {
+ return userCount;
+ }
+
+ public static void setUserCount(int userCount)
+ {
+ Values.userCount = userCount;
+ }
+
+ public static int getGuildCount()
+ {
+ return guildCount;
+ }
+
+ public static void setGuildCount(int guildCount)
+ {
+ Values.guildCount = guildCount;
+ }
+
+ public static int getCommandCount()
+ {
+ return commandCount;
+ }
+
+ public static void setCommandCount(int commandCount)
+ {
+ Values.commandCount = commandCount;
+ }
+
+ public static DiscordBotListAPI getApi() { return api; }
+
+ public static void setApi(DiscordBotListAPI api) { Values.api = api; }
}
diff --git a/src/main/java/com/github/zastrixarundell/torambot/commands/HelpCommand.java b/src/main/java/com/github/zastrixarundell/torambot/commands/HelpCommand.java
index a32feb8..8afa82c 100644
--- a/src/main/java/com/github/zastrixarundell/torambot/commands/HelpCommand.java
+++ b/src/main/java/com/github/zastrixarundell/torambot/commands/HelpCommand.java
@@ -205,7 +205,7 @@ private void sendGameInfoCommands(MessageCreateEvent messageCreateEvent)
.addField(Values.getPrefix() + "news", "This command is used to show the latest big news on the site. Big events, " +
"new chapter in the story line, etc.");
- if (Values.getDyeImage() != null)
+ if (Values.getDyeImages() != null)
embed.addField(Values.getPrefix() + "dye", "Get the latest monthly dyes!");
Parser.parseThumbnail(embed, messageCreateEvent);
@@ -225,6 +225,9 @@ private void sendBotInfoCommands(MessageCreateEvent messageCreateEvent)
.addField(Values.getPrefix() + "donate", "You can use this command to donate to the developer (it would help)!")
.addField(Values.getPrefix() + "support", "You can use this command to get the support sever for this bot!");
+ if(Values.getApi() != null)
+ embed.addField(Values.getPrefix() + "vote", "You can use this command to vote for this bot!");
+
Parser.parseThumbnail(embed, messageCreateEvent);
Parser.parseFooter(embed, messageCreateEvent);
Parser.parseColor(embed, messageCreateEvent);
diff --git a/src/main/java/com/github/zastrixarundell/torambot/commands/gameinfo/DyeCommand.java b/src/main/java/com/github/zastrixarundell/torambot/commands/gameinfo/DyeCommand.java
index 9ae4819..7943454 100644
--- a/src/main/java/com/github/zastrixarundell/torambot/commands/gameinfo/DyeCommand.java
+++ b/src/main/java/com/github/zastrixarundell/torambot/commands/gameinfo/DyeCommand.java
@@ -31,21 +31,25 @@ public void onMessageCreate(MessageCreateEvent messageCreateEvent)
DateTime time = new DateTime();
Period period = new Period(Values.getLastDyeUpdate(), time);
- EmbedBuilder embed = new EmbedBuilder()
- .setTitle("Latest monthly dyes")
- .setDescription("Here is the image of the latest monthly dyes!\n\n\n" +
- "Note: This can be late so check the title of the image.");
+ for(int i = 0; i < Values.getDyeImages().length; i++)
+ {
+ EmbedBuilder embed = new EmbedBuilder()
+ .setTitle("Latest monthly dyes" + (Values.getDyeImages().length <= 1 ? "" : " (" + (i+1) + "/" + Values.getDyeImages().length + ")"))
+ .setDescription("Here is the image of the latest monthly dyes!\n\n\n" +
+ "Note: This can be late so check the title of the image.");
- Parser.parseColor(embed, messageCreateEvent);
- embed.setImage(Values.getDyeImage());
+ Parser.parseColor(embed, messageCreateEvent);
+ embed.setImage(Values.getDyeImages()[i]);
- int hours = period.getHours();
- int minutes = period.getMinutes();
+ int hours = period.getHours();
+ int minutes = period.getMinutes();
- embed.setFooter("Last check was " + hours + (hours == 1 ? " hour" : " hours") + " and " +
- minutes + (minutes == 1 ? " minute" : " minutes") + " ago.");
+ embed.setFooter("Last check was " + hours + (hours == 1 ? " hour" : " hours") + " and " +
+ minutes + (minutes == 1 ? " minute" : " minutes") + " ago.");
+
+ messageCreateEvent.getChannel().sendMessage(embed);
+ }
- messageCreateEvent.getChannel().sendMessage(embed);
};
(new Thread(runnable)).start();
diff --git a/src/main/java/com/github/zastrixarundell/torambot/commands/search/items/extra/UpgradeCommand.java b/src/main/java/com/github/zastrixarundell/torambot/commands/search/items/extra/UpgradeCommand.java
index dd12c1b..d462504 100644
--- a/src/main/java/com/github/zastrixarundell/torambot/commands/search/items/extra/UpgradeCommand.java
+++ b/src/main/java/com/github/zastrixarundell/torambot/commands/search/items/extra/UpgradeCommand.java
@@ -19,16 +19,19 @@ public class UpgradeCommand implements MessageCreateListener
private static final int sizeOfPage = 2000;
- private Document document = null;
+ private Element body = null;
public UpgradeCommand()
{
try
{
- document = Jsoup.connect("http://coryn.club/item.php")
+ Document document = Jsoup.connect("http://coryn.club/item.php")
.data("special", "xtal")
.data("show", String.valueOf(sizeOfPage))
.get();
+
+ Element table = document.getElementsByClass("table table-striped").first();
+ body = table.getElementsByTag("tbody").first();
}
catch (Exception ignore)
{
@@ -64,14 +67,16 @@ public void onMessageCreate(MessageCreateEvent messageCreateEvent)
{
try
{
- if(document == null)
- document = Jsoup.connect("http://coryn.club/item.php")
+ if(body == null)
+ {
+ Document document = Jsoup.connect("http://coryn.club/item.php")
.data("special", "xtal")
.data("show", String.valueOf(sizeOfPage))
.get();
- Element table = document.getElementsByClass("table table-striped").first();
- Element body = table.getElementsByTag("tbody").first();
+ Element table = document.getElementsByClass("table table-striped").first();
+ body = table.getElementsByTag("tbody").first();
+ }
List- itemList = getItems(body, data);
@@ -86,7 +91,7 @@ public void onMessageCreate(MessageCreateEvent messageCreateEvent)
catch (Exception e)
{
sendErrorMessage(messageCreateEvent);
- document = null;
+ body = null;
}
};
diff --git a/src/main/java/com/github/zastrixarundell/torambot/commands/torambot/InviteCommand.java b/src/main/java/com/github/zastrixarundell/torambot/commands/torambot/InviteCommand.java
index cfe675a..d3ebbdb 100644
--- a/src/main/java/com/github/zastrixarundell/torambot/commands/torambot/InviteCommand.java
+++ b/src/main/java/com/github/zastrixarundell/torambot/commands/torambot/InviteCommand.java
@@ -23,7 +23,8 @@ public void onMessageCreate(MessageCreateEvent messageCreateEvent)
EmbedBuilder embed = new EmbedBuilder()
.setTitle("Invite link for " + name)
- .setDescription("You can invite " + name + " on your server with [this link](" +
+ .setDescription("Each invite helps this bot grow and will ultimately help this bot be used on a lot of " +
+ "Discord guilds, so every invite is appreciated! You can invite " + name + " on your server with [this link](" +
Values.inviteLink + ").");
Parser.parseFooter(embed, messageCreateEvent);
diff --git a/src/main/java/com/github/zastrixarundell/torambot/commands/torambot/VoteCommand.java b/src/main/java/com/github/zastrixarundell/torambot/commands/torambot/VoteCommand.java
new file mode 100644
index 0000000..00070bc
--- /dev/null
+++ b/src/main/java/com/github/zastrixarundell/torambot/commands/torambot/VoteCommand.java
@@ -0,0 +1,52 @@
+package com.github.zastrixarundell.torambot.commands.torambot;
+
+import com.github.zastrixarundell.torambot.Parser;
+import com.github.zastrixarundell.torambot.Values;
+import org.discordbots.api.client.DiscordBotListAPI;
+import org.javacord.api.entity.message.embed.EmbedBuilder;
+import org.javacord.api.event.message.MessageCreateEvent;
+import org.javacord.api.listener.message.MessageCreateListener;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+public class VoteCommand implements MessageCreateListener
+{
+
+ @Override
+ public void onMessageCreate(MessageCreateEvent messageCreateEvent)
+ {
+
+ if (!messageCreateEvent.getMessageContent().toLowerCase().startsWith(Values.getPrefix() + "vote"))
+ return;
+
+ if (!messageCreateEvent.getMessageAuthor().isRegularUser())
+ return;
+
+ DiscordBotListAPI api = Values.getApi();
+
+ sendToVoteEmbed(messageCreateEvent, api);
+
+ }
+
+ private void sendToVoteEmbed(MessageCreateEvent messageCreateEvent, DiscordBotListAPI api)
+ {
+ String name = messageCreateEvent.getApi().getYourself().getName();
+
+ AtomicBoolean multiplier = new AtomicBoolean(false);
+
+ api.getVotingMultiplier().whenComplete(((votingMultiplier, throwable) -> multiplier.set(votingMultiplier.isWeekend())));
+
+ EmbedBuilder embed = new EmbedBuilder()
+ .setTitle("Vote for: " + name)
+ .setDescription("Every vote helps this bot to show people how useful it is! To vote, just go to [this link](https://discordbots.org/bot/600302983305101323). " +
+ "And remember, you can vote every 12 hours (during the weekends your vote is worth 2x more)!")
+ .addField("Vote multiplier:", multiplier.get() ? "Active (votes are worth 2x more)." : "Not active.");
+
+ Parser.parseFooter(embed, messageCreateEvent);
+ Parser.parseThumbnail(embed, messageCreateEvent);
+ Parser.parseColor(embed, messageCreateEvent);
+
+ messageCreateEvent.getChannel().sendMessage(embed);
+ }
+
+}
diff --git a/src/main/java/com/github/zastrixarundell/torambot/entities/ToramForumsUser.java b/src/main/java/com/github/zastrixarundell/torambot/entities/ToramForumsUser.java
index cc31e51..7440839 100644
--- a/src/main/java/com/github/zastrixarundell/torambot/entities/ToramForumsUser.java
+++ b/src/main/java/com/github/zastrixarundell/torambot/entities/ToramForumsUser.java
@@ -3,15 +3,15 @@
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.*;
import com.github.zastrixarundell.torambot.Values;
+import com.github.zastrixarundell.torambot.utils.AESHelper;
+import net.coobird.thumbnailator.Thumbnails;
import org.joda.time.DateTime;
-import javax.crypto.Cipher;
-import javax.crypto.spec.SecretKeySpec;
import javax.imageio.ImageReader;
import java.awt.image.BufferedImage;
import java.io.Closeable;
-import java.security.Key;
-import java.util.Base64;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.logging.Level;
public class ToramForumsUser implements Closeable
@@ -22,9 +22,8 @@ public class ToramForumsUser implements Closeable
public ToramForumsUser(String token) throws Exception
{
- String key = token.substring(0, 32);
- AESHelper aesHelper = new AESHelper(key);
+ AESHelper aesHelper = new AESHelper(token);
String username, password;
@@ -37,14 +36,14 @@ public ToramForumsUser(String token) throws Exception
//Try for main first
try
{
- username = aesHelper.decryptData("3OztJIxzzY79H9YYEJs5Jr5QkWgsx5eU/hYy1zgEkN4=");
- password = aesHelper.decryptData("L41kztOpWabG6q+r6HvLqQ==");
+ username = aesHelper.decryptData("81CjhzuvgfRKambn82RJ7/kjZQwia4ihURY1evbP20I=");
+ password = aesHelper.decryptData("rrXWhM2/o14taNAPd0XGfg==");
}
//It is most likely the beta bot
catch(Exception e)
{
- username = aesHelper.decryptData("qCzlHTvYtB51mrv2eBpZYqmpE27WNzh+JvUcgs1GiMg=");
- password = aesHelper.decryptData("yglXjxiQk4x71B3S8ogorQ==");
+ username = aesHelper.decryptData("vhiSaT+EaYprsfOqwV6IcciaE/bTVHcGry3SjaFatJ4=");
+ password = aesHelper.decryptData("ZJcf6FCERMvGSEg/qEFIMA==");
}
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
@@ -80,50 +79,28 @@ public void setDye() throws Exception
for(HtmlElement element : li.getElementsByTagName("div"))
if(element.getAttribute("class").equalsIgnoreCase("messagecontent"))
{
- HtmlImage htmlImage = (HtmlImage) element.getElementsByTagName("img")
- .get(element.getElementsByTagName("img").getLength() - 1);
- ImageReader reader = htmlImage.getImageReader();
- BufferedImage image = reader.read(0);
- Values.setDyeImage(image);
+ ArrayList images = new ArrayList<>();
+
+ for(int i = 1; i < element.getElementsByTagName("img").size(); i++)
+ {
+ HtmlImage htmlImage = (HtmlImage) element.getElementsByTagName("img").get(i);
+ ImageReader reader = htmlImage.getImageReader();
+ BufferedImage image = reader.read(0);
+ images.add(resize(image, image.getWidth() / 2, image.getHeight() / 2));
+ }
+
+ Values.setDyeImages(images.toArray(new BufferedImage[0]));
break;
}
Values.setLastDyeUpdate(new DateTime());
}
- @Override
- public void close() { webClient.close(); }
-
- private static class AESHelper
+ static BufferedImage resize(BufferedImage img, int newW, int newH) throws IOException
{
-
- private static final String algorithm = "AES";
-
- private Key key;
-
- AESHelper(String aesKey)
- {
- key = new SecretKeySpec(aesKey.getBytes(), algorithm);
- }
-
- /*
- public String encryptData(String data) throws Exception
- {
- Cipher cipher = Cipher.getInstance(algorithm);
- cipher.init(Cipher.ENCRYPT_MODE, key);
- byte[] encryptedBytes = cipher.doFinal(data.getBytes());
- return Base64.getEncoder().encodeToString(encryptedBytes);
- }
- */
-
- String decryptData(String data) throws Exception
- {
- Cipher cipher = Cipher.getInstance(algorithm);
- cipher.init(Cipher.DECRYPT_MODE, key);
- byte[] decodedBaseValues = Base64.getDecoder().decode(data);
- byte[] deciphered = cipher.doFinal(decodedBaseValues);
- return new String(deciphered);
- }
-
+ return Thumbnails.of(img).size(newW, newH).asBufferedImage();
}
+
+ @Override
+ public void close() { webClient.close(); }
}
diff --git a/src/main/java/com/github/zastrixarundell/torambot/objects/StatusImage.java b/src/main/java/com/github/zastrixarundell/torambot/objects/StatusImage.java
new file mode 100644
index 0000000..9772aaf
--- /dev/null
+++ b/src/main/java/com/github/zastrixarundell/torambot/objects/StatusImage.java
@@ -0,0 +1,60 @@
+package com.github.zastrixarundell.torambot.objects;
+
+import com.github.zastrixarundell.torambot.Values;
+
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.net.URL;
+
+public class StatusImage
+{
+
+ //Will be used in the future
+
+ private BufferedImage bufferedImage;
+
+ public StatusImage() throws Exception
+ {
+ bufferedImage = new BufferedImage(700, 400, BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
+
+ graphics.setColor(new Color(39,40,45));
+ graphics.fillRect(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight());
+
+ graphics.setColor(new Color(47, 48, 54));
+ graphics.fillRect(39, 39, 322, 322);
+
+ BufferedImage image = ImageIO.read(new URL(Values.profileImageURL));
+
+ graphics.drawImage(image, 50, 50, null);
+
+ graphics.setColor(Color.white);
+
+ Font font = new Font("DejaVu Sans", Font.TYPE1_FONT, 24);
+ graphics.setFont(font);
+
+ graphics.drawString("Toram-sensei", 452, 62);
+
+ graphics.drawString("Guilds: " + Values.getGuildCount(), 393, 180+20);
+ graphics.drawString("Users: " + Values.getUserCount(), 393, 240+20);
+ graphics.drawString("Commands: " + Values.getCommandCount(), 393, 299+20);
+
+ graphics.dispose();
+ }
+
+ public void drawFrame()
+ {
+ JFrame jFrame = new JFrame("Image");
+ JLabel label = new JLabel(new ImageIcon(bufferedImage));
+ jFrame.setSize(bufferedImage.getWidth() + 100, bufferedImage.getHeight() + 100);
+ jFrame.add(label);
+ jFrame.setVisible(true);
+ }
+
+ public BufferedImage getBufferedImage()
+ {
+ return bufferedImage;
+ }
+}
diff --git a/src/main/java/com/github/zastrixarundell/torambot/utils/AESHelper.java b/src/main/java/com/github/zastrixarundell/torambot/utils/AESHelper.java
new file mode 100644
index 0000000..7671a1a
--- /dev/null
+++ b/src/main/java/com/github/zastrixarundell/torambot/utils/AESHelper.java
@@ -0,0 +1,39 @@
+package com.github.zastrixarundell.torambot.utils;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import java.security.Key;
+import java.util.Base64;
+
+public class AESHelper
+{
+
+ private final String algorithm = "AES";
+ private Key key;
+
+ public AESHelper(String token)
+ {
+ String password = token.substring(0, 32);
+ key = new SecretKeySpec(password.getBytes(), algorithm);
+ }
+
+ public String encryptData(String data) throws Exception
+ {
+ Cipher cipher = Cipher.getInstance(algorithm);
+ cipher.init(Cipher.ENCRYPT_MODE, key);
+ byte[] encryptedBytes = cipher.doFinal(data.getBytes());
+ return Base64.getEncoder().encodeToString(encryptedBytes);
+ }
+
+ public String decryptData(String data) throws Exception
+ {
+ Cipher cipher = Cipher.getInstance(algorithm);
+ cipher.init(Cipher.DECRYPT_MODE, key);
+ byte[] decodedBaseValues = Base64.getDecoder().decode(data);
+ byte[] deciphered = cipher.doFinal(decodedBaseValues);
+ return new String(deciphered);
+ }
+
+
+
+}