Reworked info command.

This commit is contained in:
Erik C. Thauvin 2020-07-21 17:57:58 -07:00
parent 62417e76f7
commit aea73acce5
9 changed files with 157 additions and 122 deletions

View file

@ -13,14 +13,19 @@ import java.time.*;
*/
public final class ReleaseInfo {
public static final String PROJECT = "mobibot";
public static final String VERSION = "0.8.0-beta+085";
public static final LocalDateTime BUILDDATE =
LocalDateTime.ofInstant(Instant.ofEpochMilli(1592617191604L), ZoneId.systemDefault());
LocalDateTime.ofInstant(Instant.ofEpochMilli(1595378887339L), ZoneId.systemDefault());
public static final int MAJOR = 0;
public static final int MINOR = 8;
public static final int PATCH = 0;
public static final String BUILDMETA = "085";
public static final String PRERELEASE = "beta";
public static final String BUILDMETA = "047";
public static final String VERSION = "0.8.0-beta+047";
public static final String WEBSITE = "https://www.mobitopia.org/mobibot/";
public static final String AUTHOR = "Erik C. Thauvin";
public static final String AUTHOR_URL = "https://erik.thauvin.net/";
/**
* Disables the default constructor.

View file

@ -114,15 +114,6 @@ import static org.apache.commons.lang3.StringUtils.lowerCase;
@Version(properties = "version.properties",
className = "ReleaseInfo")
public class Mobibot extends PircBot {
/**
* Info Strings.
*/
@SuppressWarnings("indentation")
public static final List<String> INFO =
List.of(
ReleaseInfo.PROJECT + " v" + ReleaseInfo.VERSION
+ " (" + Utils.green("https://www.mobitopia.org/mobibot/") + ')',
"Written by Erik C. Thauvin (" + Utils.green("https://erik.thauvin.net/") + ')');
// Logger
private static final Logger LOGGER = LogManager.getLogger(Mobibot.class);
// Maximum number of times the bot will try to reconnect, if disconnected
@ -303,9 +294,9 @@ public class Mobibot extends PircBot {
// Output the usage
new HelpFormatter().printHelp(Mobibot.class.getName(), options);
} else if (commandLine.hasOption(Constants.VERSION_ARG.charAt(0))) {
for (final String s : INFO) {
System.out.println(s);
}
System.out.println(ReleaseInfo.PROJECT + ' ' + ReleaseInfo.VERSION
+ " (" + Utils.isoLocalDate(ReleaseInfo.BUILDDATE) + ')');
System.out.println(ReleaseInfo.WEBSITE);
} else {
final Properties p = new Properties();
@ -413,7 +404,7 @@ public class Mobibot extends PircBot {
}
}
}
setVersion(INFO.get(0));
setVersion(ReleaseInfo.PROJECT + ' ' + ReleaseInfo.VERSION);
identify();
joinChannel();
}
@ -749,7 +740,7 @@ public class Mobibot extends PircBot {
if (cmd.startsWith(Constants.HELP_CMD)) { // help
helpResponse(sender, args, true);
} else if (isOp && "kill".equals(cmd)) { // kill
twitter.notification("%1$s killed by " + sender + "on %3$s");
twitter.notification("%1$s killed by " + sender + " on %3$s");
sendRawLine("QUIT : Poof!");
System.exit(0);
} else if (isOp && Constants.DEBUG_CMD.equals(cmd)) { // debug
@ -763,7 +754,7 @@ public class Mobibot extends PircBot {
send(sender + " has just signed my death sentence.");
TIMER.cancel();
twitter.shutdown();
twitter.notification("%1$s stopped by " + sender + "on %3$s");
twitter.notification("%1$s stopped by " + sender + " on %3$s");
sleep(3);
quitServer("The Bot Is Out There!");
System.exit(0);

View file

@ -0,0 +1,115 @@
/*
* InfoJ.java
*
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of this project nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.thauvin.erik.mobibot.commands;
import net.thauvin.erik.mobibot.Mobibot;
import net.thauvin.erik.mobibot.ReleaseInfo;
import net.thauvin.erik.mobibot.Utils;
import net.thauvin.erik.mobibot.commands.links.LinksMgr;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.lang.management.ManagementFactory;
import java.util.List;
public class Info extends AbstractCommand {
private final List<String> version = List.of(
StringUtils.capitalize(ReleaseInfo.PROJECT) + " " + ReleaseInfo.VERSION + " ("
+ Utils.green(ReleaseInfo.WEBSITE) + ')',
"Written by " + ReleaseInfo.AUTHOR + " (" + Utils.green(ReleaseInfo.AUTHOR_URL) + ')');
public Info(@NotNull final Mobibot bot) {
super(bot);
}
@NotNull
@Override
public String getName() {
return "info";
}
@NotNull
@Override
public List<String> getHelp() {
return List.of("To view information about the bot:", Utils.helpIndent("%c " + getName()));
}
@Override
public boolean isOp() {
return false;
}
@Override
public boolean isPublic() {
return true;
}
@Override
public boolean isVisible() {
return true;
}
@Override
public void commandResponse(@NotNull final String sender,
@NotNull final String login,
@NotNull final String args,
final boolean isOp,
final boolean isPrivate) {
for (final String v : version) {
getBot().send(sender, v, isPrivate);
}
final StringBuilder info = new StringBuilder("Uptime: ");
info.append(Utils.uptime(ManagementFactory.getRuntimeMXBean().getUptime()))
.append(" [Entries: ")
.append(LinksMgr.getEntriesCount());
if (isOp) {
if (getBot().getTell().isEnabled()) {
info.append(", Messages: ")
.append(getBot().getTell().size());
}
if (getBot().getTwitter().isAutoPost()) {
info.append(", Twitter: ")
.append(getBot().getTwitter().entriesCount());
}
}
info.append(", Recap: ")
.append(Recap.recapCount())
.append(']');
getBot().send(sender, info.toString(), isPrivate);
}
}

View file

@ -1,86 +0,0 @@
/*
* Info.kt
*
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of this project nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.thauvin.erik.mobibot.commands
import net.thauvin.erik.mobibot.Mobibot
import net.thauvin.erik.mobibot.Utils
import net.thauvin.erik.mobibot.commands.links.LinksMgr
import java.lang.management.ManagementFactory
class Info(bot: Mobibot) : AbstractCommand(bot) {
override val name = "info"
override val help = listOf(
"To view information about the bot:",
Utils.helpIndent("%c $name")
)
override val isOp = false
override val isPublic = true
override val isVisible = true
override fun commandResponse(
sender: String,
login: String,
args: String,
isOp: Boolean,
isPrivate: Boolean
) {
for (info in Mobibot.INFO) {
bot.send(sender, info, isPrivate)
}
val info = StringBuilder("Uptime: ")
with(info) {
append(Utils.uptime(ManagementFactory.getRuntimeMXBean().uptime))
append(" [Entries: ")
append(LinksMgr.entriesCount)
if (isOp) {
if (bot.tell.isEnabled()) {
append(", Messages: ")
append(bot.tell.size())
}
if (bot.twitter.isAutoPost) {
append(", Twitter: ")
append(bot.twitter.entriesCount())
}
}
append(", Recap: ")
append(Recap.recapCount())
append(']')
}
bot.send(sender, info.toString(), isPrivate)
}
}