Cleanup.
This commit is contained in:
parent
ced0aa97f8
commit
968823828a
2 changed files with 43 additions and 36 deletions
|
@ -92,7 +92,7 @@ public class Weather2 extends ThreadedModule {
|
|||
@SuppressWarnings("AvoidEscapedUnicodeCharacters")
|
||||
private static String getTemps(final Double d) {
|
||||
final double c = (d - 32) * 5 / 9;
|
||||
return Math.round(d) + " \u00B0F, " + Math.round(c) + " \u00B0C";
|
||||
return Math.round(d) + " °F, " + Math.round(c) + " °C";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,7 +138,8 @@ public class Weather2 extends ThreadedModule {
|
|||
cwd = owm.currentWeatherByCityName(city, getCountry(country));
|
||||
}
|
||||
if (cwd.hasCityName()) {
|
||||
messages.add(new PublicMessage("City: " + cwd.getCityName() + " [" + country + "]"));
|
||||
messages.add(new PublicMessage(
|
||||
"City: " + cwd.getCityName() + " [" + StringUtils.upperCase(country) + "]"));
|
||||
|
||||
final Main main = cwd.getMainData();
|
||||
if (main != null) {
|
||||
|
@ -159,15 +160,13 @@ public class Weather2 extends ThreadedModule {
|
|||
}
|
||||
|
||||
if (cwd.hasWeatherList()) {
|
||||
final StringBuilder condition = new StringBuilder("Condition: ");
|
||||
final StringBuilder condition = new StringBuilder("Condition:");
|
||||
final List<Weather> list = cwd.getWeatherList();
|
||||
if (list != null) {
|
||||
for (final Weather w : list) {
|
||||
if (condition.indexOf(",") == -1) {
|
||||
condition.append(StringUtils.capitalize(w.getDescription()));
|
||||
} else {
|
||||
condition.append(", ").append(w.getDescription());
|
||||
}
|
||||
condition.append(' ')
|
||||
.append(StringUtils.capitalize(w.getDescription()))
|
||||
.append('.');
|
||||
}
|
||||
messages.add(new NoticeMessage(condition.toString()));
|
||||
}
|
||||
|
@ -182,7 +181,8 @@ public class Weather2 extends ThreadedModule {
|
|||
"https://openweathermap.org/find"))
|
||||
.newBuilder()
|
||||
.addQueryParameter("q",
|
||||
city + ',' + country)
|
||||
city + ','
|
||||
+ StringUtils.upperCase(country))
|
||||
.build();
|
||||
messages.add(new NoticeMessage(url.toString(), Colors.GREEN));
|
||||
}
|
||||
|
@ -210,26 +210,28 @@ public class Weather2 extends ThreadedModule {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) {
|
||||
bot.send(sender, bold("To display weather information:"));
|
||||
bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + WEATHER_CMD + " <city> [, <country code>]"));
|
||||
bot.send(sender, "For example:");
|
||||
bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + WEATHER_CMD + " paris, fr"));
|
||||
public void helpResponse(final Mobibot bot, final String sender, final boolean isPrivate) {
|
||||
bot.send(sender, "To display weather information:", isPrivate);
|
||||
bot.send(sender,
|
||||
Utils.helpIndent(bot.getNick() + ": " + WEATHER_CMD + " <city> [, <country code>]"),
|
||||
isPrivate);
|
||||
bot.send(sender, "For example:", isPrivate);
|
||||
bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + WEATHER_CMD + " paris, fr"), isPrivate);
|
||||
bot.send(sender,
|
||||
"The default ISO 3166 country code is " + bold("US")
|
||||
+ ". Zip codes are supported in most countries.");
|
||||
+ ". Zip codes are supported in most countries.", isPrivate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the weather data from a specific city.
|
||||
*/
|
||||
@Override
|
||||
void run(final Mobibot bot, final String sender, final String cmd, final String args) {
|
||||
void run(final Mobibot bot, final String sender, final String cmd, final String args, final boolean isPrivate) {
|
||||
if (StringUtils.isNotBlank(args)) {
|
||||
try {
|
||||
final List<Message> messages = getWeather(args, properties.get(OWM_API_KEY_PROP));
|
||||
if (messages.get(0).isError()) {
|
||||
helpResponse(bot, sender, args, true);
|
||||
helpResponse(bot, sender, isPrivate);
|
||||
} else {
|
||||
for (final Message msg : messages) {
|
||||
bot.send(sender, msg);
|
||||
|
@ -240,7 +242,7 @@ public class Weather2 extends ThreadedModule {
|
|||
bot.send(e.getMessage());
|
||||
}
|
||||
} else {
|
||||
helpResponse(bot, sender, args, true);
|
||||
helpResponse(bot, sender, isPrivate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,12 +44,11 @@ import java.time.ZoneId;
|
|||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static net.thauvin.erik.mobibot.Utils.bold;
|
||||
|
||||
/**
|
||||
* The WorldTime module.
|
||||
*
|
||||
|
@ -195,14 +194,16 @@ public final class WorldTime extends AbstractModule {
|
|||
|
||||
if (tz != null) {
|
||||
if (BEATS_KEYWORD.equals(tz)) {
|
||||
response = ("The current Internet Time is: " + internetTime() + ' ' + BEATS_KEYWORD);
|
||||
response = ("The current Internet Time is: " + Utils.bold(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('_', ' ');
|
||||
DateTimeFormatter
|
||||
.ofPattern("'The time is " + Utils.bold("'HH:mm'") + " on " + Utils.bold(
|
||||
"'EEEE, d MMMM yyyy'") + " in '"))
|
||||
+ Utils.bold(tz.substring(tz.indexOf('/') + 1).replace('_', ' '));
|
||||
}
|
||||
} else {
|
||||
return new ErrorMessage("The supported countries/zones are: " + COUNTRIES_MAP.keySet());
|
||||
return new ErrorMessage("Unsupported country/zone. Please try again.");
|
||||
}
|
||||
|
||||
return new PublicMessage(response);
|
||||
|
@ -217,15 +218,19 @@ public final class WorldTime extends AbstractModule {
|
|||
final String cmd,
|
||||
final String args,
|
||||
final boolean isPrivate) {
|
||||
final Message msg = worldTime(args);
|
||||
|
||||
if (isPrivate) {
|
||||
bot.send(sender, msg.getMessage(), true);
|
||||
if (args.length() == 0) {
|
||||
bot.send(sender, "The supported countries/zones are: ", isPrivate);
|
||||
bot.sendCommandsList(sender, new ArrayList<>(COUNTRIES_MAP.keySet()), 17, false, false);
|
||||
} else {
|
||||
if (msg.isError()) {
|
||||
bot.send(sender, msg.getMessage());
|
||||
final Message msg = worldTime(args);
|
||||
if (isPrivate) {
|
||||
bot.send(sender, msg.getMessage(), true);
|
||||
} else {
|
||||
bot.send(msg.getMessage());
|
||||
if (msg.isError()) {
|
||||
bot.send(sender, msg.getMessage(), false);
|
||||
} else {
|
||||
bot.send(msg.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -234,12 +239,12 @@ public final class WorldTime extends AbstractModule {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void helpResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) {
|
||||
bot.send(sender, bold("To display a country's current date/time:"));
|
||||
bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TIME_CMD) + " [<country code>]");
|
||||
public void helpResponse(final Mobibot bot, final String sender, final boolean isPrivate) {
|
||||
bot.send(sender, "To display a country's current date/time:", isPrivate);
|
||||
bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TIME_CMD) + " [<country code>]", isPrivate);
|
||||
|
||||
bot.send(sender, bold("For a listing of the supported countries:"));
|
||||
bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TIME_CMD));
|
||||
bot.send(sender, "For a listing of the supported countries:", isPrivate);
|
||||
bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TIME_CMD), isPrivate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue