Added call to super() in constructor (PMD)
This commit is contained in:
parent
bc4399f798
commit
1ba412d1f0
15 changed files with 125 additions and 88 deletions
|
@ -54,6 +54,7 @@ public class Calc extends AbstractModule {
|
|||
* The default constructor.
|
||||
*/
|
||||
public Calc() {
|
||||
super();
|
||||
commands.add(CALC_CMD);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ public final class Dice extends AbstractModule {
|
|||
* The default constructor.
|
||||
*/
|
||||
public Dice() {
|
||||
super();
|
||||
commands.add(DICE_CMD);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ import java.net.URLConnection;
|
|||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The GoogleSearch module.
|
||||
|
@ -71,11 +72,46 @@ public final class GoogleSearch extends ThreadedModule {
|
|||
* Creates a new {@link GoogleSearch} instance.
|
||||
*/
|
||||
public GoogleSearch() {
|
||||
super();
|
||||
commands.add(GOOGLE_CMD);
|
||||
properties.put(GOOGLE_API_KEY_PROP, "");
|
||||
properties.put(GOOGLE_CSE_KEY_PROP, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) {
|
||||
if (isEnabled()) {
|
||||
bot.send(sender, "To search Google:");
|
||||
bot.send(sender, bot.helpIndent(bot.getNick() + ": " + GOOGLE_CMD + " <query>"));
|
||||
} else {
|
||||
bot.send(sender, "The Google search module is disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches Google.
|
||||
*/
|
||||
@Override
|
||||
void run(final Mobibot bot, final String sender, final String query) {
|
||||
if (Utils.isValidString(query)) {
|
||||
try {
|
||||
final List<Message> results = searchGoogle(query, properties.get(GOOGLE_API_KEY_PROP),
|
||||
properties.get(GOOGLE_CSE_KEY_PROP));
|
||||
for (final Message msg : results) {
|
||||
bot.send(sender, msg);
|
||||
}
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
bot.send(sender, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
helpResponse(bot, sender, query, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a search on Google.
|
||||
*
|
||||
|
@ -85,8 +121,9 @@ public final class GoogleSearch extends ThreadedModule {
|
|||
* @return The {@link Message} array containing the search results.
|
||||
* @throws ModuleException If an error occurs while searching.
|
||||
*/
|
||||
@SuppressFBWarnings(value = {"URLCONNECTION_SSRF_FD", "REC_CATCH_EXCEPTION"})
|
||||
static ArrayList<Message> searchGoogle(final String query, final String apiKey, final String cseKey)
|
||||
@SuppressFBWarnings({"URLCONNECTION_SSRF_FD", "REC_CATCH_EXCEPTION"})
|
||||
@SuppressWarnings(("PMD.AvoidInstantiatingObjectsInLoops"))
|
||||
static List<Message> searchGoogle(final String query, final String apiKey, final String cseKey)
|
||||
throws ModuleException {
|
||||
if (!Utils.isValidString(apiKey) || !Utils.isValidString(cseKey)) {
|
||||
throw new ModuleException(Utils.capitalize(GOOGLE_CMD) + " is disabled. The API keys are missing.");
|
||||
|
@ -134,37 +171,4 @@ public final class GoogleSearch extends ThreadedModule {
|
|||
throw new ModuleException("Invalid query.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) {
|
||||
if (isEnabled()) {
|
||||
bot.send(sender, "To search Google:");
|
||||
bot.send(sender, bot.helpIndent(bot.getNick() + ": " + GOOGLE_CMD + " <query>"));
|
||||
} else {
|
||||
bot.send(sender, "The Google search module is disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches Google.
|
||||
*/
|
||||
void run(final Mobibot bot, final String sender, final String query) {
|
||||
if (Utils.isValidString(query)) {
|
||||
try {
|
||||
final ArrayList<Message> results = searchGoogle(query, properties.get(GOOGLE_API_KEY_PROP),
|
||||
properties.get(GOOGLE_CSE_KEY_PROP));
|
||||
for (final Message msg : results) {
|
||||
bot.send(sender, msg);
|
||||
}
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
bot.send(sender, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
helpResponse(bot, sender, query, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public final class Joke extends ThreadedModule {
|
|||
* Creates a new {@link Joke} instance.
|
||||
*/
|
||||
public Joke() {
|
||||
super();
|
||||
commands.add(JOKE_CMD);
|
||||
}
|
||||
|
||||
|
@ -107,6 +108,7 @@ public final class Joke extends ThreadedModule {
|
|||
/**
|
||||
* Returns a random joke from <a href="http://www.icndb.com/">The Internet Chuck Norris Database</a>.
|
||||
*/
|
||||
@Override
|
||||
void run(final Mobibot bot, final String sender, final String arg) {
|
||||
try {
|
||||
bot.send(Utils.cyan(randomJoke().getMessage()));
|
||||
|
|
|
@ -60,6 +60,7 @@ public final class Lookup extends AbstractModule {
|
|||
* The default constructor.
|
||||
*/
|
||||
public Lookup() {
|
||||
super();
|
||||
commands.add(LOOKUP_CMD);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,11 +46,6 @@ import java.util.List;
|
|||
* @since 1.0
|
||||
*/
|
||||
public class Ping extends AbstractModule {
|
||||
/**
|
||||
* The ping command.
|
||||
*/
|
||||
private static final String PING_CMD = "ping";
|
||||
|
||||
/**
|
||||
* The ping responses.
|
||||
*/
|
||||
|
@ -68,11 +63,16 @@ public class Ping extends AbstractModule {
|
|||
"is hibernating.",
|
||||
"is saving energy: apathetic mode activated.",
|
||||
"is busy. Go away!");
|
||||
/**
|
||||
* The ping command.
|
||||
*/
|
||||
private static final String PING_CMD = "ping";
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
*/
|
||||
public Ping() {
|
||||
super();
|
||||
commands.add(PING_CMD);
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ public final class StockQuote extends ThreadedModule {
|
|||
* Creates a new {@link StockQuote} instance.
|
||||
*/
|
||||
public StockQuote() {
|
||||
super();
|
||||
commands.add(STOCK_CMD);
|
||||
properties.put(ALPHAVANTAGE_API_KEY_PROP, "");
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ public final class Twitter extends ThreadedModule {
|
|||
* Creates a new {@link Twitter} instance.
|
||||
*/
|
||||
public Twitter() {
|
||||
super();
|
||||
commands.add(TWITTER_CMD);
|
||||
properties.put(CONSUMER_SECRET_PROP, "");
|
||||
properties.put(CONSUMER_KEY_PROP, "");
|
||||
|
|
|
@ -57,6 +57,7 @@ public final class War extends AbstractModule {
|
|||
* The default constructor.
|
||||
*/
|
||||
public War() {
|
||||
super();
|
||||
commands.add(WAR_CMD);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ public class Weather2 extends ThreadedModule {
|
|||
* Creates a new {@link Weather2} instance.
|
||||
*/
|
||||
public Weather2() {
|
||||
super();
|
||||
commands.add(WEATHER_CMD);
|
||||
properties.put(OWM_API_KEY_PROP, "");
|
||||
}
|
||||
|
@ -183,11 +184,6 @@ public class Weather2 extends ThreadedModule {
|
|||
return messages;
|
||||
}
|
||||
|
||||
private static String wind(final Double w) {
|
||||
final double kmh = w * 1.60934;
|
||||
return Math.round(w) + " mph, " + Math.round(kmh) + " km/h";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -224,4 +220,9 @@ public class Weather2 extends ThreadedModule {
|
|||
helpResponse(bot, sender, args, true);
|
||||
}
|
||||
}
|
||||
|
||||
private static String wind(final Double w) {
|
||||
final double kmh = w * 1.60934;
|
||||
return Math.round(w) + " mph, " + Math.round(kmh) + " km/h";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,12 +54,14 @@ import java.util.TreeMap;
|
|||
* @created 2014-04-27
|
||||
* @since 1.0
|
||||
*/
|
||||
@SuppressWarnings("PMD.UseConcurrentHashMap")
|
||||
public final class WorldTime extends AbstractModule {
|
||||
// The beats (Internet Time) keyword.
|
||||
private static final String BEATS_KEYWORD = ".beats";
|
||||
// The supported countries.
|
||||
private static final Map<String, String> COUNTRIES_MAP;
|
||||
|
||||
|
||||
/**
|
||||
* The time command.
|
||||
*/
|
||||
|
@ -155,52 +157,10 @@ public final class WorldTime extends AbstractModule {
|
|||
* Creates a new {@link WorldTime} instance.
|
||||
*/
|
||||
public WorldTime() {
|
||||
super();
|
||||
commands.add(TIME_CMD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current Internet (beat) Time.
|
||||
*
|
||||
* @return The Internet Time string.
|
||||
*/
|
||||
private static String internetTime() {
|
||||
final ZonedDateTime zdt = ZonedDateTime.now(ZoneId.of("UTC+01:00"));
|
||||
final int beats = (int) ((zdt.get(ChronoField.SECOND_OF_MINUTE) + (zdt.get(ChronoField.MINUTE_OF_HOUR) * 60)
|
||||
+ (zdt.get(ChronoField.HOUR_OF_DAY) * 3600)) / 86.4);
|
||||
return String.format("%c%03d", '@', beats);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the world time.
|
||||
*
|
||||
* <ul>
|
||||
* <li>PST</li>
|
||||
* <li>BEATS</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param query The query.
|
||||
* @return The {@link Message} containing the world time.
|
||||
*/
|
||||
@SuppressFBWarnings(value = "STT_STRING_PARSING_A_FIELD")
|
||||
static Message worldTime(final String query) {
|
||||
final String tz = (COUNTRIES_MAP.get((query.substring(query.indexOf(' ') + 1).trim().toUpperCase())));
|
||||
final String response;
|
||||
|
||||
if (tz != null) {
|
||||
if (BEATS_KEYWORD.equals(tz)) {
|
||||
response = ("The current Internet Time is: " + internetTime() + ' ' + BEATS_KEYWORD);
|
||||
} else {
|
||||
response = ZonedDateTime.now().withZoneSameInstant(ZoneId.of(tz)).format(
|
||||
DateTimeFormatter.ofPattern("'The time is 'HH:mm' on 'EEEE, d MMMM yyyy' in '"))
|
||||
+ tz.substring(tz.indexOf('/') + 1).replace('_', ' ');
|
||||
}
|
||||
} else {
|
||||
return new ErrorMessage("The supported countries/zones are: " + COUNTRIES_MAP.keySet());
|
||||
}
|
||||
|
||||
return new PublicMessage(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds with the current time in the specified timezone/country.
|
||||
*
|
||||
|
@ -243,4 +203,48 @@ public final class WorldTime extends AbstractModule {
|
|||
public boolean isPrivateMsgEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current Internet (beat) Time.
|
||||
*
|
||||
* @return The Internet Time string.
|
||||
*/
|
||||
private static String internetTime() {
|
||||
final ZonedDateTime zdt = ZonedDateTime.now(ZoneId.of("UTC+01:00"));
|
||||
final int beats = (int) ((zdt.get(ChronoField.SECOND_OF_MINUTE) + (zdt.get(ChronoField.MINUTE_OF_HOUR) * 60)
|
||||
+ (zdt.get(ChronoField.HOUR_OF_DAY) * 3600)) / 86.4);
|
||||
return String.format("%c%03d", '@', beats);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the world time.
|
||||
*
|
||||
* <ul>
|
||||
* <li>PST</li>
|
||||
* <li>BEATS</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param query The query.
|
||||
* @return The {@link Message} containing the world time.
|
||||
*/
|
||||
@SuppressFBWarnings("STT_STRING_PARSING_A_FIELD")
|
||||
static Message worldTime(final String query) {
|
||||
final String tz = (COUNTRIES_MAP.get((query.substring(query.indexOf(' ') + 1).trim()
|
||||
.toUpperCase(Constants.LOCALE))));
|
||||
final String response;
|
||||
|
||||
if (tz != null) {
|
||||
if (BEATS_KEYWORD.equals(tz)) {
|
||||
response = ("The current Internet Time is: " + internetTime() + ' ' + BEATS_KEYWORD);
|
||||
} else {
|
||||
response = ZonedDateTime.now().withZoneSameInstant(ZoneId.of(tz)).format(
|
||||
DateTimeFormatter.ofPattern("'The time is 'HH:mm' on 'EEEE, d MMMM yyyy' in '"))
|
||||
+ tz.substring(tz.indexOf('/') + 1).replace('_', ' ');
|
||||
}
|
||||
} else {
|
||||
return new ErrorMessage("The supported countries/zones are: " + COUNTRIES_MAP.keySet());
|
||||
}
|
||||
|
||||
return new PublicMessage(response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public class ErrorMessage extends Message {
|
|||
* @param message The error message.
|
||||
*/
|
||||
public ErrorMessage(final String message) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setError(true);
|
||||
this.setNotice(true);
|
||||
|
@ -59,6 +60,7 @@ public class ErrorMessage extends Message {
|
|||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public ErrorMessage(final String message, final String color) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setError(true);
|
||||
this.setNotice(true);
|
||||
|
|
|
@ -46,6 +46,7 @@ public class NoticeMessage extends Message {
|
|||
* @param message The notice's message.
|
||||
*/
|
||||
public NoticeMessage(final String message) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setNotice(true);
|
||||
}
|
||||
|
@ -57,6 +58,7 @@ public class NoticeMessage extends Message {
|
|||
* @param color The color.
|
||||
*/
|
||||
public NoticeMessage(final String message, final String color) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setNotice(true);
|
||||
this.setColor(color);
|
||||
|
|
|
@ -42,10 +42,18 @@ package net.thauvin.erik.mobibot.msg;
|
|||
@SuppressWarnings("unused")
|
||||
public class PrivateMessage extends Message {
|
||||
public PrivateMessage(final String message) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new private message.
|
||||
*
|
||||
* @param message The message.
|
||||
* @param color The message color.
|
||||
*/
|
||||
public PrivateMessage(final String message, final String color) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setColor(color);
|
||||
}
|
||||
|
|
|
@ -41,11 +41,19 @@ package net.thauvin.erik.mobibot.msg;
|
|||
*/
|
||||
public class PublicMessage extends Message {
|
||||
public PublicMessage(final String message) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new public message.
|
||||
*
|
||||
* @param message The message.
|
||||
* @param color The message color.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public PublicMessage(final String message, final String color) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setColor(color);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue