Added more details to info command.
This commit is contained in:
parent
3f0c9102cd
commit
86fdde261d
8 changed files with 124 additions and 86 deletions
|
@ -13,8 +13,8 @@ import java.util.Date;
|
|||
* Annotation Processor</a>
|
||||
*/
|
||||
public final class ReleaseInfo {
|
||||
private final static String buildmeta = "004";
|
||||
private final static Date date = new Date(1467595869139L);
|
||||
private final static String buildmeta = "006";
|
||||
private final static Date date = new Date(1467669326019L);
|
||||
private final static int major = 0;
|
||||
private final static int minor = 7;
|
||||
private final static int patch = 0;
|
||||
|
|
|
@ -135,7 +135,6 @@ final class Commands
|
|||
*/
|
||||
public static final String SAY_CMD = "say";
|
||||
|
||||
|
||||
/**
|
||||
* The users command.
|
||||
*/
|
||||
|
|
|
@ -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));
|
||||
|
@ -1019,7 +1019,7 @@ public class Mobibot extends PircBot
|
|||
|
||||
sb.append(commandsList.get(i));
|
||||
|
||||
// 5 commands per line or last command
|
||||
// 6 commands per line or last command
|
||||
if (sb.length() > 0 && (cmdCount == 6 || i == (commandsList.size() - 1)))
|
||||
{
|
||||
send(sender, helpIndent(sb.toString()));
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1127,21 +1127,60 @@ public class Mobibot extends PircBot
|
|||
}
|
||||
}
|
||||
|
||||
final StringBuilder info = new StringBuilder("Uptime: ");
|
||||
|
||||
long timeInSeconds = (System.currentTimeMillis() - START_TIME) / 1000L;
|
||||
|
||||
final long years = timeInSeconds / 31540000L;
|
||||
|
||||
if (years > 0)
|
||||
{
|
||||
info.append(years).append(Utils.plural(years, " year ", " years "));
|
||||
timeInSeconds -= (years * 31540000L);
|
||||
}
|
||||
|
||||
|
||||
final long weeks = timeInSeconds / 604800L;
|
||||
|
||||
if (weeks > 0)
|
||||
{
|
||||
info.append(weeks).append(Utils.plural(weeks, " week ", " weeks "));
|
||||
timeInSeconds -= (weeks * 604800L);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
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(minutes).append(Utils.plural(minutes, " minute ", " minutes "));
|
||||
|
||||
info.append("[Entries: ").append(entries.size());
|
||||
|
||||
if (tell.isEnabled() && isOp(sender))
|
||||
{
|
||||
info.append(", Messages: ").append(tell.size());
|
||||
}
|
||||
|
||||
info.append(']');
|
||||
|
||||
send(sender, info.toString(), isPrivate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -216,7 +216,8 @@ public class Tell
|
|||
bot.send(sender,
|
||||
bot.helpIndent(bot.getNick() + ": " + TELL_CMD + ' ' + TELL_DEL_KEYWORD + " <id|"
|
||||
+ TELL_ALL_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."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <code>true</code> if the given string is <em>not</em> blank or null.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -5,4 +5,4 @@ version.major=0
|
|||
version.minor=7
|
||||
version.patch=0
|
||||
version.prerelease=beta
|
||||
version.buildmeta=004
|
||||
version.buildmeta=006
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue