Cleaned up msg.
This commit is contained in:
parent
d843c65f6f
commit
d6a85ef4af
21 changed files with 68 additions and 154 deletions
|
@ -14,13 +14,13 @@ import java.time.*;
|
|||
public final class ReleaseInfo {
|
||||
public static final String PROJECT = "mobibot";
|
||||
public static final LocalDateTime BUILDDATE =
|
||||
LocalDateTime.ofInstant(Instant.ofEpochMilli(1592038362460L), ZoneId.systemDefault());
|
||||
LocalDateTime.ofInstant(Instant.ofEpochMilli(1592043035449L), ZoneId.systemDefault());
|
||||
public static final int MAJOR = 0;
|
||||
public static final int MINOR = 8;
|
||||
public static final int PATCH = 0;
|
||||
public static final String PRERELEASE = "alpha";
|
||||
public static final String BUILDMETA = "370";
|
||||
public static final String VERSION = "0.8.0-alpha+370";
|
||||
public static final String PRERELEASE = "beta";
|
||||
public static final String BUILDMETA = "004";
|
||||
public static final String VERSION = "0.8.0-beta+004";
|
||||
|
||||
/**
|
||||
* Disables the default constructor.
|
||||
|
|
|
@ -850,7 +850,7 @@ public class Mobibot extends PircBot {
|
|||
* @param message The message.
|
||||
*/
|
||||
public final void send(final String who, final Message message) {
|
||||
send(message.isNotice() ? who : getChannel(), message.getText(), message.getColor(), message.isPrivate());
|
||||
send(message.isNotice() ? who : getChannel(), message.getMsg(), message.getColor(), message.isPrivate());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -101,7 +101,7 @@ public final class Joke extends ThreadedModule {
|
|||
@Override
|
||||
void run(final String sender, final String cmd, final String arg, final boolean isPrivate) {
|
||||
try {
|
||||
bot.send(Utils.cyan(randomJoke().getText()));
|
||||
bot.send(Utils.cyan(randomJoke().getMsg()));
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
bot.send(sender, e.getMessage(), isPrivate);
|
||||
|
|
|
@ -258,7 +258,7 @@ public final class Twitter extends ThreadedModule {
|
|||
void run(final String sender, final String cmd, final String message, final boolean isPrivate) {
|
||||
try {
|
||||
bot.send(sender,
|
||||
post(sender, message + " (by " + sender + " on " + bot.getChannel() + ')', false).getText(),
|
||||
post(sender, message + " (by " + sender + " on " + bot.getChannel() + ')', false).getMsg(),
|
||||
isPrivate);
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
|
|
|
@ -226,12 +226,12 @@ public final class WorldTime extends AbstractModule {
|
|||
} else {
|
||||
final Message msg = worldTime(args);
|
||||
if (isPrivate) {
|
||||
bot.send(sender, msg.getText(), true);
|
||||
bot.send(sender, msg.getMsg(), true);
|
||||
} else {
|
||||
if (msg.isError()) {
|
||||
bot.send(sender, msg.getText(), false);
|
||||
bot.send(sender, msg.getMsg(), false);
|
||||
} else {
|
||||
bot.send(msg.getText());
|
||||
bot.send(msg.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,29 +38,11 @@ package net.thauvin.erik.mobibot.msg
|
|||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
class ErrorMessage : Message {
|
||||
/**
|
||||
* Creates a new error message.
|
||||
*
|
||||
* @param text The error message.
|
||||
*/
|
||||
constructor(text: String) : super() {
|
||||
this.text = text
|
||||
isError = true
|
||||
isNotice = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new error message.
|
||||
*
|
||||
* @param text The message.
|
||||
* @param color The message color.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
constructor(text: String, color: String) : super() {
|
||||
this.text = text
|
||||
isError = true
|
||||
isNotice = true
|
||||
class ErrorMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
||||
init {
|
||||
this.msg = msg
|
||||
this.color = color
|
||||
isError = true
|
||||
isNotice = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,8 +41,12 @@ import org.jibble.pircbot.Colors
|
|||
* @since 1.0
|
||||
*/
|
||||
open class Message {
|
||||
companion object {
|
||||
var DEFAULT_COLOR = Colors.NORMAL
|
||||
}
|
||||
|
||||
/** Color */
|
||||
var color = Colors.NORMAL
|
||||
var color = DEFAULT_COLOR
|
||||
|
||||
/** Error */
|
||||
var isError = false
|
||||
|
@ -54,7 +58,7 @@ open class Message {
|
|||
var isPrivate = false
|
||||
|
||||
/** Message text*/
|
||||
var text = ""
|
||||
var msg = ""
|
||||
|
||||
/** Creates a new message. */
|
||||
constructor() {
|
||||
|
@ -64,42 +68,18 @@ open class Message {
|
|||
/**
|
||||
* Creates a new message.
|
||||
*
|
||||
* @param text The message.
|
||||
* @param isNotice The notice flag.
|
||||
* @param isError The error flag.
|
||||
* @param isPrivate The Private message
|
||||
*/
|
||||
constructor(text: String, isNotice: Boolean, isError: Boolean, isPrivate: Boolean) {
|
||||
this.text = text
|
||||
this.isNotice = isNotice
|
||||
this.isError = isError
|
||||
this.isPrivate = isPrivate
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new message.
|
||||
*
|
||||
* @param text The message.
|
||||
* @param isNotice The notice flag.
|
||||
* @param isError The error flag.
|
||||
* @param isPrivate The Private message
|
||||
* @param msg The message.
|
||||
* @param color The color.
|
||||
* @param isNotice The notice flag.
|
||||
* @param isError The error flag.
|
||||
* @param isPrivate The private flag.
|
||||
*/
|
||||
constructor(
|
||||
text: String,
|
||||
isNotice: Boolean,
|
||||
isError: Boolean,
|
||||
isPrivate: Boolean,
|
||||
color: String
|
||||
) {
|
||||
this.text = text
|
||||
@JvmOverloads
|
||||
constructor(msg: String, color: String = DEFAULT_COLOR, isNotice: Boolean, isError: Boolean, isPrivate: Boolean) {
|
||||
this.msg = msg
|
||||
this.color = color
|
||||
this.isNotice = isNotice
|
||||
this.isError = isError
|
||||
this.isPrivate = isPrivate
|
||||
this.color = color
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "Message(color='$color', isError=$isError, isNotice=$isNotice, isPrivate=$isPrivate, message='$text')"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,26 +38,10 @@ package net.thauvin.erik.mobibot.msg
|
|||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
class NoticeMessage : Message {
|
||||
/**
|
||||
* Creates a new notice.
|
||||
*
|
||||
* @param text The notice's message.
|
||||
*/
|
||||
constructor(text: String) : super() {
|
||||
this.text = text
|
||||
isNotice = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new notice.
|
||||
*
|
||||
* @param text The notice's message.
|
||||
* @param color The color.
|
||||
*/
|
||||
constructor(text: String, color: String) : super() {
|
||||
this.text = text
|
||||
isNotice = true
|
||||
class NoticeMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
||||
init {
|
||||
this.msg = msg
|
||||
this.color = color
|
||||
isNotice = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,25 +39,9 @@ package net.thauvin.erik.mobibot.msg
|
|||
* @since 1.0
|
||||
*/
|
||||
@Suppress("unused")
|
||||
class PrivateMessage : Message {
|
||||
/**
|
||||
* Creates a new private message.
|
||||
*
|
||||
* @param text The message.
|
||||
*/
|
||||
constructor(text: String) : super() {
|
||||
this.text = text
|
||||
isPrivate = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new private message.
|
||||
*
|
||||
* @param text The message.
|
||||
* @param color The message color.
|
||||
*/
|
||||
constructor(text: String, color: String) : super() {
|
||||
this.text = text
|
||||
class PrivateMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
||||
init {
|
||||
this.msg = msg
|
||||
this.color = color
|
||||
isPrivate = true
|
||||
}
|
||||
|
|
|
@ -38,25 +38,9 @@ package net.thauvin.erik.mobibot.msg
|
|||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
class PublicMessage : Message {
|
||||
/**
|
||||
* Creates a new public message.
|
||||
*
|
||||
* @param text The message.
|
||||
*/
|
||||
constructor(text: String) : super() {
|
||||
this.text = text
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new public message.
|
||||
*
|
||||
* @param text The message.
|
||||
* @param color The message color.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
constructor(text: String, color: String) : super() {
|
||||
this.text = text
|
||||
class PublicMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
||||
init {
|
||||
this.msg = msg
|
||||
this.color = color
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,11 +54,11 @@ public class CurrencyConverterTest {
|
|||
@Test
|
||||
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
|
||||
public void testConvertCurrency() {
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to EUR").getText())
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to EUR").getMsg())
|
||||
.as("100 USD to EUR").matches("100\\.00 USD = \\d{2,3}\\.\\d{2} EUR");
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to USD").getText())
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to USD").getMsg())
|
||||
.as("100 USD to USD").contains("You're kidding, right?");
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD").getText())
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD").getMsg())
|
||||
.as("100 USD").contains("Invalid query.");
|
||||
assertThat(CurrencyConverter.currencyRates().size())
|
||||
.as("currencyRates().size() == 33").isEqualTo(33);
|
||||
|
|
|
@ -63,11 +63,11 @@ public class GoogleSearchTest extends LocalProperties {
|
|||
try {
|
||||
List<Message> messages = GoogleSearch.searchGoogle("mobibot site:github.com", apiKey, cseKey);
|
||||
assertThat(messages).as("mobibot results not empty").isNotEmpty();
|
||||
assertThat(messages.get(0).getText()).as("found mobitopia").contains("mobibot");
|
||||
assertThat(messages.get(0).getMsg()).as("found mobitopia").contains("mobibot");
|
||||
|
||||
messages = GoogleSearch.searchGoogle("aapl", apiKey, cseKey);
|
||||
assertThat(messages).as("aapl results not empty").isNotEmpty();
|
||||
assertThat(messages.get(0).getText()).as("found apple").containsIgnoringCase("apple");
|
||||
assertThat(messages.get(0).getMsg()).as("found apple").containsIgnoringCase("apple");
|
||||
|
||||
assertThatThrownBy(() -> GoogleSearch.searchGoogle("test", "", "apiKey")).as("no API key").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
|
|
|
@ -51,7 +51,7 @@ public class JokeTest {
|
|||
|
||||
@Test
|
||||
public void testRamdomJoke() throws ModuleException {
|
||||
assertThat(Joke.randomJoke().getText().length() > 0).as("randomJoke() > 0").isTrue();
|
||||
assertThat(Joke.randomJoke().getText()).as("randomJoke()").containsIgnoringCase("chuck");
|
||||
assertThat(Joke.randomJoke().getMsg().length() > 0).as("randomJoke() > 0").isTrue();
|
||||
assertThat(Joke.randomJoke().getMsg()).as("randomJoke()").containsIgnoringCase("chuck");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class StockQuoteTest extends LocalProperties {
|
|||
try {
|
||||
final List<Message> messages = StockQuote.getQuote("apple inc", apiKey);
|
||||
assertThat(messages).as("response not empty").isNotEmpty();
|
||||
assertThat(messages.get(0).getText()).as("same stock symbol").contains("AAPL").contains("Apple Inc.");
|
||||
assertThat(messages.get(0).getMsg()).as("same stock symbol").contains("AAPL").contains("Apple Inc.");
|
||||
|
||||
try {
|
||||
StockQuote.getQuote("blahfoo", apiKey);
|
||||
|
|
|
@ -73,6 +73,6 @@ public class TwitterTest extends LocalProperties {
|
|||
getProperty(Twitter.TOKEN_SECRET_PROP),
|
||||
getProperty(Twitter.HANDLE_PROP),
|
||||
msg,
|
||||
true).getText()).as("twitterPost(" + msg + ')').isEqualTo(msg);
|
||||
true).getMsg()).as("twitterPost(" + msg + ')').isEqualTo(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,12 +54,12 @@ public class Weather2Test extends LocalProperties {
|
|||
@Test
|
||||
public void testWeather() throws ModuleException {
|
||||
List<Message> messages = Weather2.getWeather("98204", getProperty(Weather2.OWM_API_KEY_PROP));
|
||||
assertThat(messages.get(0).getText()).as("is Everett").contains("Everett").contains("US");
|
||||
assertThat(messages.get(messages.size() - 1).getText()).as("is City Search").endsWith("98204%2CUS");
|
||||
assertThat(messages.get(0).getMsg()).as("is Everett").contains("Everett").contains("US");
|
||||
assertThat(messages.get(messages.size() - 1).getMsg()).as("is City Search").endsWith("98204%2CUS");
|
||||
|
||||
messages = Weather2.getWeather("London, UK", getProperty(Weather2.OWM_API_KEY_PROP));
|
||||
assertThat(messages.get(0).getText()).as("is UK").contains("London").contains("UK");
|
||||
assertThat(messages.get(messages.size() - 1).getText()).as("is City Code").endsWith("4517009");
|
||||
assertThat(messages.get(0).getMsg()).as("is UK").contains("London").contains("UK");
|
||||
assertThat(messages.get(messages.size() - 1).getMsg()).as("is City Code").endsWith("4517009");
|
||||
|
||||
assertThatThrownBy(() -> Weather2.getWeather("Montpellier, FR", getProperty(Weather2.OWM_API_KEY_PROP)))
|
||||
.as("Montpellier not found").hasCauseInstanceOf(APIException.class);
|
||||
|
|
|
@ -47,9 +47,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
public class WordTimeTest {
|
||||
@Test
|
||||
public void testWorldTime() {
|
||||
assertThat(WorldTime.worldTime("PST").getText()).as("PST").endsWith(Utils.bold("Los Angeles"));
|
||||
assertThat(WorldTime.worldTime("PST").getMsg()).as("PST").endsWith(Utils.bold("Los Angeles"));
|
||||
assertThat(WorldTime.worldTime("BLAH").isError()).as("BLAH").isTrue();
|
||||
assertThat(WorldTime.worldTime("BEATS").getText()).as("BEATS").contains("@");
|
||||
assertThat(WorldTime.worldTime("BEATS").getMsg()).as("BEATS").contains("@");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue