From e89d6337441473b0e40b11afb8048a02d2b10e4e Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 3 Jul 2016 21:10:51 -0700 Subject: [PATCH] Added more details to info command. --- .../net/thauvin/erik/mobibot/ReleaseInfo.java | 4 +- .../net/thauvin/erik/mobibot/Commands.java | 1 - .../net/thauvin/erik/mobibot/Mobibot.java | 40 +++++++++--- .../java/net/thauvin/erik/mobibot/Tell.java | 3 +- .../java/net/thauvin/erik/mobibot/Utils.java | 64 ++++--------------- .../thauvin/erik/mobibot/modules/Twitter.java | 28 ++++---- .../erik/mobibot/modules/WorldTime.java | 43 ++++++++++++- version.properties | 2 +- 8 files changed, 102 insertions(+), 83 deletions(-) diff --git a/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java b/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java index 94fd13a..79fb3bf 100644 --- a/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java +++ b/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java @@ -13,8 +13,8 @@ import java.util.Date; * Annotation Processor */ public final class ReleaseInfo { - private final static String buildmeta = "004"; - private final static Date date = new Date(1467595869139L); + private final static String buildmeta = "005"; + private final static Date date = new Date(1467605028612L); private final static int major = 0; private final static int minor = 7; private final static int patch = 0; diff --git a/src/main/java/net/thauvin/erik/mobibot/Commands.java b/src/main/java/net/thauvin/erik/mobibot/Commands.java index 05d94a3..e9dc7f3 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Commands.java +++ b/src/main/java/net/thauvin/erik/mobibot/Commands.java @@ -135,7 +135,6 @@ final class Commands */ public static final String SAY_CMD = "say"; - /** * The users command. */ diff --git a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java index d4c7276..65e125c 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Mobibot.java +++ b/src/main/java/net/thauvin/erik/mobibot/Mobibot.java @@ -925,7 +925,7 @@ public class Mobibot extends PircBot send(sender, "To list the users present on the channel:"); send(sender, helpIndent(getNick() + ": " + Commands.USERS_CMD)); } - else if (lcTopic.equals(Commands.INFO_CMD) && isOp(sender)) + else if (lcTopic.equals(Commands.INFO_CMD)) { send(sender, "To view information about the bot:"); send(sender, helpIndent(getNick() + ": " + Commands.INFO_CMD)); @@ -1033,8 +1033,8 @@ public class Mobibot extends PircBot { send(sender, "The op commands are:"); send(sender, - helpIndent(Commands.CYCLE_CMD + " " + Commands.INFO_CMD + " " + Commands.ME_CMD + " " - + Commands.MSG_CMD + " " + Commands.SAY_CMD + " " + Commands.VERSION_CMD)); + helpIndent(Commands.CYCLE_CMD + " " + Commands.ME_CMD + " " + Commands.MSG_CMD + " " + + Commands.SAY_CMD + " " + Commands.VERSION_CMD)); } } } @@ -1119,29 +1119,49 @@ public class Mobibot extends PircBot { if (info.startsWith("http://")) { - send(sender, Utils.green(info), isPrivate); + send(sender, Utils.green(info), isPrivate); } else { send(sender, info, isPrivate); - } + } } + final StringBuilder info = new StringBuilder("Uptime: "); + long timeInSeconds = (System.currentTimeMillis() - START_TIME) / 1000L; final long days = timeInSeconds / 86400L; + + if (days > 0) + { + info.append(days).append(Utils.plural(days, " day ", " days ")); + } + timeInSeconds -= (days * 86400L); final long hours = timeInSeconds / 3600L; + + if (hours > 0) + { + info.append(hours).append(Utils.plural(hours, " hour ", " hours ")); + } + timeInSeconds -= (hours * 3600L); final long minutes = timeInSeconds / 60L; + info.append(minutes).append(Utils.plural(minutes, " minute ", " minutes ")); - send(sender, - "Uptime: " + days + Utils.plural(days, " day ", " days ") + hours + Utils.plural(hours, " hour ", " hours ") - + minutes + Utils.plural(minutes, " minute ", " minutes ") + "[Entries: " + entries.size() - + (tell.isEnabled() && isOp(sender) ? ", Messages: " + tell.size() : "") + ']', - isPrivate); + info.append("[Entries: ").append(entries.size()); + + if (tell.isEnabled() && isOp(sender)) + { + info.append(", Messages: ").append(tell.size()); + } + + info.append(']'); + + send(sender, info.toString(), isPrivate); } /** diff --git a/src/main/java/net/thauvin/erik/mobibot/Tell.java b/src/main/java/net/thauvin/erik/mobibot/Tell.java index 804cefd..dff6317 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Tell.java +++ b/src/main/java/net/thauvin/erik/mobibot/Tell.java @@ -216,7 +216,8 @@ public class Tell bot.send(sender, bot.helpIndent(bot.getNick() + ": " + TELL_CMD + ' ' + TELL_DEL_KEYWORD + " ')); - bot.send(sender, "Messages are kept for " + Utils.bold(maxDays) + Utils.plural(maxDays, " day.", " days.")); + bot.send(sender, + "Messages are kept for " + Utils.bold(maxDays) + Utils.plural(maxDays, " day.", " days.")); } } } diff --git a/src/main/java/net/thauvin/erik/mobibot/Utils.java b/src/main/java/net/thauvin/erik/mobibot/Utils.java index e2e7531..174d373 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Utils.java +++ b/src/main/java/net/thauvin/erik/mobibot/Utils.java @@ -46,16 +46,16 @@ import java.util.Calendar; */ final public class Utils { - /** - * The timestamp simple date format. - */ - public static final SimpleDateFormat TIMESTAMP_SDF = new SimpleDateFormat("yyyyMMddHHmmss"); - /** * The ISO (YYYY-MM-DD) simple date format. */ public static final SimpleDateFormat ISO_SDF = new SimpleDateFormat("yyyy-MM-dd"); + /** + * The timestamp simple date format. + */ + public static final SimpleDateFormat TIMESTAMP_SDF = new SimpleDateFormat("yyyyMMddHHmmss"); + /** * The UTC (yyyy-MM-dd HH:mm) simple date format. */ @@ -245,46 +245,6 @@ final public class Utils return prop; } - /** - * Returns the current Internet (beat) Time. - * - * @return The Internet Time string. - */ - public static String internetTime() - { - final Calendar gc = Calendar.getInstance(); - - final int offset = (gc.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)); - int hh = gc.get(Calendar.HOUR_OF_DAY); - final int mm = gc.get(Calendar.MINUTE); - final int ss = gc.get(Calendar.SECOND); - - hh -= offset; // GMT - hh += 1; // BMT - - long beats = Math.round(Math.floor((double) ((((hh * 3600) + (mm * 60) + ss) * 1000) / 86400))); - - if (beats >= 1000) - { - beats -= (long) 1000; - } - else if (beats < 0) - { - beats += (long) 1000; - } - - if (beats < 10) - { - return ("@00" + beats); - } - else if (beats < 100) - { - return ("@0" + beats); - } - - return ('@' + String.valueOf(beats)); - } - /** * Returns true if the given string is not blank or null. * @@ -310,12 +270,12 @@ final public class Utils } /** - * Returns the plural form of a word, if count > 1. - * - * @param count The count. - * @param word The word. - * @param plural The plural word. - */ + * Returns the plural form of a word, if count > 1. + * + * @param count The count. + * @param word The word. + * @param plural The plural word. + */ public static String plural(final long count, final String word, final String plural) { if (count > 1) @@ -326,7 +286,7 @@ final public class Utils { return word; } - } + } /** * Makes the given string reverse color. diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.java b/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.java index 4be0165..646c89b 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.java @@ -71,20 +71,6 @@ final public class Twitter extends AbstractModule properties.put(TOKEN_SECRET_PROP, ""); } - @Override - public boolean isEnabled() - { - for (final String s : getPropertyKeys()) - { - if (!Utils.isValidString(properties.get(s))) - { - return false; - } - } - - return true; - } - @Override public void commandResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { @@ -114,6 +100,20 @@ final public class Twitter extends AbstractModule } } + @Override + public boolean isEnabled() + { + for (final String s : getPropertyKeys()) + { + if (!Utils.isValidString(properties.get(s))) + { + return false; + } + } + + return true; + } + /** * Posts to twitter. */ diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.java b/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.java index 19fbcd0..0ab5a10 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.java @@ -32,7 +32,6 @@ package net.thauvin.erik.mobibot.modules; import net.thauvin.erik.mobibot.Mobibot; -import net.thauvin.erik.mobibot.Utils; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -166,7 +165,7 @@ final public class WorldTime extends AbstractModule { if (tz.equals(BEATS_KEYWORD)) { - response = ("The current Internet Time is: " + Utils.internetTime() + ' ' + BEATS_KEYWORD); + response = ("The current Internet Time is: " + internetTime() + ' ' + BEATS_KEYWORD); } else { @@ -198,6 +197,46 @@ final public class WorldTime extends AbstractModule } } + /** + * Returns the current Internet (beat) Time. + * + * @return The Internet Time string. + */ + private String internetTime() + { + final Calendar gc = Calendar.getInstance(); + + final int offset = (gc.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)); + int hh = gc.get(Calendar.HOUR_OF_DAY); + final int mm = gc.get(Calendar.MINUTE); + final int ss = gc.get(Calendar.SECOND); + + hh -= offset; // GMT + hh += 1; // BMT + + long beats = Math.round(Math.floor((double) ((((hh * 3600) + (mm * 60) + ss) * 1000) / 86400))); + + if (beats >= 1000) + { + beats -= (long) 1000; + } + else if (beats < 0) + { + beats += (long) 1000; + } + + if (beats < 10) + { + return ("@00" + beats); + } + else if (beats < 100) + { + return ("@0" + beats); + } + + return ('@' + String.valueOf(beats)); + } + @Override public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { diff --git a/version.properties b/version.properties index eece5fb..6d69796 100644 --- a/version.properties +++ b/version.properties @@ -5,4 +5,4 @@ version.major=0 version.minor=7 version.patch=0 version.prerelease=beta -version.buildmeta=004 +version.buildmeta=005