diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Dice.java b/src/main/java/net/thauvin/erik/mobibot/modules/Dice.java index 2447c89..b68b579 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Dice.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Dice.java @@ -34,7 +34,7 @@ package net.thauvin.erik.mobibot.modules; import net.thauvin.erik.mobibot.Mobibot; import net.thauvin.erik.mobibot.Utils; -import java.util.Random; +import java.security.SecureRandom; /** * The Dice module. @@ -66,22 +66,22 @@ final public class Dice extends AbstractModule { */ @Override public void commandResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { - final Random r = new Random(); + final SecureRandom r = new SecureRandom(); int i = r.nextInt(6) + 1; int y = r.nextInt(6) + 1; final int playerTotal = i + y; bot.send(bot.getChannel(), - sender + " rolled two dice: " + Utils.bold(i) + " and " + Utils.bold(y) + " for a total of " + Utils - .bold(playerTotal)); + sender + " rolled two dice: " + Utils.bold(i) + " and " + Utils.bold(y) + " for a total of " + Utils + .bold(playerTotal)); i = r.nextInt(6) + 1; y = r.nextInt(6) + 1; final int total = i + y; bot.action( - "rolled two dice: " + Utils.bold(i) + " and " + Utils.bold(y) + " for a total of " + Utils.bold(total)); + "rolled two dice: " + Utils.bold(i) + " and " + Utils.bold(y) + " for a total of " + Utils.bold(total)); if (playerTotal < total) { bot.action("wins."); diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java b/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java index 5d6cc5f..3588f29 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Joke.java @@ -39,6 +39,7 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; /** * The Joke module. @@ -55,7 +56,7 @@ final public class Joke extends AbstractModule { // The ICNDB URL. private static final String JOKE_URL = - "http://api.icndb.com/jokes/random?escape=javascript&exclude=[explicit]&limitTo=[nerdy]"; + "http://api.icndb.com/jokes/random?escape=javascript&exclude=[explicit]&limitTo=[nerdy]"; /** * Creates a new {@link Joke} instance. @@ -90,7 +91,8 @@ final public class Joke extends AbstractModule { final URLConnection conn = url.openConnection(); final StringBuilder sb = new StringBuilder(); - try (final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) { + try (final BufferedReader reader = + new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { String line; while ((line = reader.readLine()) != null) { sb.append(line); @@ -99,10 +101,10 @@ final public class Joke extends AbstractModule { final JSONObject json = new JSONObject(sb.toString()); bot.send(bot.getChannel(), - Colors.CYAN - + json.getJSONObject("value").get("joke").toString().replaceAll("\\'", "'") - .replaceAll("\\\"", "\"") - + Colors.NORMAL); + Colors.CYAN + + json.getJSONObject("value").get("joke").toString().replaceAll("\\'", "'") + .replaceAll("\\\"", "\"") + + Colors.NORMAL); } } catch (Exception e) { bot.getLogger().warn("Unable to retrieve random joke.", e); diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Ping.java b/src/main/java/net/thauvin/erik/mobibot/modules/Ping.java index 7bb9cbe..697309b 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Ping.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Ping.java @@ -33,9 +33,9 @@ package net.thauvin.erik.mobibot.modules; import net.thauvin.erik.mobibot.Mobibot; +import java.security.SecureRandom; import java.util.Arrays; import java.util.List; -import java.util.Random; /** * The Ping module. @@ -52,19 +52,19 @@ public class Ping extends AbstractModule { // The ping responses. private static final List PINGS = - Arrays.asList( - "is barely alive.", - "is trying to stay awake.", - "has gone fishing.", - "is somewhere over the rainbow.", - "has fallen and can't get up.", - "is running. You better go chase it.", - "has just spontaneously combusted.", - "is talking to itself... don't interrupt. That's rude.", - "is bartending at an AA meeting.", - "is hibernating.", - "is saving energy: apathetic mode activated.", - "is busy. Go away!"); + Arrays.asList( + "is barely alive.", + "is trying to stay awake.", + "has gone fishing.", + "is somewhere over the rainbow.", + "has fallen and can't get up.", + "is running. You better go chase it.", + "has just spontaneously combusted.", + "is talking to itself... don't interrupt. That's rude.", + "is bartending at an AA meeting.", + "is hibernating.", + "is saving energy: apathetic mode activated.", + "is busy. Go away!"); /** * The default constructor. @@ -78,7 +78,7 @@ public class Ping extends AbstractModule { */ @Override public void commandResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { - final Random r = new Random(); + final SecureRandom r = new SecureRandom(); bot.action(PINGS.get(r.nextInt(PINGS.size()))); } @@ -91,4 +91,4 @@ public class Ping extends AbstractModule { bot.send(sender, "To ping the bot:"); bot.send(sender, bot.helpIndent(bot.getNick() + ": " + PING_CMD)); } -} \ No newline at end of file +}