Code cleanup.

This commit is contained in:
Erik C. Thauvin 2019-04-09 23:03:45 -07:00
parent 07944f6530
commit 9b2866e30c
2 changed files with 15 additions and 16 deletions

View file

@ -71,8 +71,8 @@ public final class Dice extends AbstractModule {
final int playerTotal = i + y; final int playerTotal = i + y;
bot.send(bot.getChannel(), bot.send(bot.getChannel(),
sender + " rolled two dice: " + Utils.bold(i) + " and " + Utils.bold(y) + " for a total of " + Utils sender + " rolled two dice: " + Utils.bold(i) + " and " + Utils.bold(y) + " for a total of "
.bold(playerTotal)); + Utils.bold(playerTotal));
i = r.nextInt(6) + 1; i = r.nextInt(6) + 1;
y = r.nextInt(6) + 1; y = r.nextInt(6) + 1;

View file

@ -116,25 +116,24 @@ public final class Lookup extends AbstractModule {
* @return The IP whois data, if any. * @return The IP whois data, if any.
* @throws java.io.IOException If a connection error occurs. * @throws java.io.IOException If a connection error occurs.
*/ */
@SuppressWarnings("SameParameterValue")
public static String[] whois(final String query, final String host) public static String[] whois(final String query, final String host)
throws IOException { throws IOException {
final WhoisClient whois = new WhoisClient(); final WhoisClient whoisClient = new WhoisClient();
final String[] lines; final String[] lines;
try { try {
whois.setDefaultTimeout(Mobibot.CONNECT_TIMEOUT); whoisClient.setDefaultTimeout(Mobibot.CONNECT_TIMEOUT);
whois.connect(host); whoisClient.connect(host);
whois.setSoTimeout(Mobibot.CONNECT_TIMEOUT); whoisClient.setSoTimeout(Mobibot.CONNECT_TIMEOUT);
whois.setSoLinger(false, 0); whoisClient.setSoLinger(false, 0);
if (host.equals(WHOIS_HOST)) { if (host.equals(WHOIS_HOST)) {
lines = whois.query("n - " + query).split("\n"); lines = whoisClient.query("n - " + query).split("\n");
} else { } else {
lines = whois.query(query).split("\n"); lines = whoisClient.query(query).split("\n");
} }
} finally { } finally {
whois.disconnect(); whoisClient.disconnect();
} }
return lines; return lines;
@ -152,7 +151,7 @@ public final class Lookup extends AbstractModule {
public void commandResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) { public void commandResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) {
if (args.matches("(\\S.)+(\\S)+")) { if (args.matches("(\\S.)+(\\S)+")) {
try { try {
bot.send(bot.getChannel(), Lookup.lookup(args)); bot.send(Lookup.lookup(args));
} catch (UnknownHostException ignore) { } catch (UnknownHostException ignore) {
if (args.matches( if (args.matches(
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." +
@ -167,21 +166,21 @@ public final class Lookup extends AbstractModule {
line = rawLine.trim(); line = rawLine.trim();
if ((line.length() > 0) && (line.charAt(0) != '#')) { if ((line.length() > 0) && (line.charAt(0) != '#')) {
bot.send(bot.getChannel(), line); bot.send(line);
} }
} }
} else { } else {
bot.send(bot.getChannel(), "Unknown host."); bot.send("Unknown host.");
} }
} catch (IOException ioe) { } catch (IOException ioe) {
if (bot.getLogger().isDebugEnabled()) { if (bot.getLogger().isDebugEnabled()) {
bot.getLogger().debug("Unable to perform whois IP lookup: " + args, ioe); bot.getLogger().debug("Unable to perform whois IP lookup: " + args, ioe);
} }
bot.send(bot.getChannel(), "Unable to perform whois IP lookup: " + ioe.getMessage()); bot.send("Unable to perform whois IP lookup: " + ioe.getMessage());
} }
} else { } else {
bot.send(bot.getChannel(), "Unknown host."); bot.send("Unknown host.");
} }
} }
} else { } else {