Renamed PrivateMessage to NoticeMessage.
This commit is contained in:
parent
dabdf9ae34
commit
7085f3a294
6 changed files with 42 additions and 37 deletions
|
@ -36,7 +36,7 @@ import net.thauvin.erik.mobibot.Mobibot;
|
|||
import net.thauvin.erik.mobibot.Utils;
|
||||
import net.thauvin.erik.mobibot.msg.ErrorMessage;
|
||||
import net.thauvin.erik.mobibot.msg.Message;
|
||||
import net.thauvin.erik.mobibot.msg.PrivateMessage;
|
||||
import net.thauvin.erik.mobibot.msg.NoticeMessage;
|
||||
import net.thauvin.erik.mobibot.msg.PublicMessage;
|
||||
import org.jdom2.Document;
|
||||
import org.jdom2.Element;
|
||||
|
@ -157,7 +157,7 @@ public final class CurrencyConverter extends AbstractModule {
|
|||
i++;
|
||||
}
|
||||
|
||||
return new PrivateMessage(buff.toString());
|
||||
return new NoticeMessage(buff.toString());
|
||||
}
|
||||
}
|
||||
return new ErrorMessage("The supported currencies are: " + EXCHANGE_RATES.keySet().toString());
|
||||
|
@ -205,7 +205,7 @@ public final class CurrencyConverter extends AbstractModule {
|
|||
if (msg.isError()) {
|
||||
helpResponse(bot, sender, CURRENCY_CMD + ' ' + query, true);
|
||||
}
|
||||
bot.send(msg.isPrivate() ? sender : bot.getChannel(), msg.getMessage());
|
||||
bot.send(msg.isNotice() ? sender : bot.getChannel(), msg.getMessage());
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
bot.send(sender, e.getMessage());
|
||||
|
|
|
@ -35,7 +35,7 @@ import net.thauvin.erik.mobibot.Mobibot;
|
|||
import net.thauvin.erik.mobibot.Utils;
|
||||
import net.thauvin.erik.mobibot.msg.ErrorMessage;
|
||||
import net.thauvin.erik.mobibot.msg.Message;
|
||||
import net.thauvin.erik.mobibot.msg.PrivateMessage;
|
||||
import net.thauvin.erik.mobibot.msg.NoticeMessage;
|
||||
import net.thauvin.erik.mobibot.msg.PublicMessage;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
@ -122,13 +122,13 @@ public final class StockQuote extends AbstractModule {
|
|||
messages.add(new PublicMessage(" Price: " + Utils.unescapeXml(quote.getString("05. price"))));
|
||||
messages.add(new PublicMessage(" Previous: "
|
||||
+ Utils.unescapeXml(quote.getString("08. previous close"))));
|
||||
messages.add(new PrivateMessage(" Open: " + Utils.unescapeXml(quote.getString("02. open"))));
|
||||
messages.add(new PrivateMessage(" High: " + Utils.unescapeXml(quote.getString("03. high"))));
|
||||
messages.add(new PrivateMessage(" Low: " + Utils.unescapeXml(quote.getString("04. low"))));
|
||||
messages.add(new PrivateMessage(" Volume: " + Utils.unescapeXml(quote.getString("06. volume"))));
|
||||
messages.add(new PrivateMessage(" Latest: "
|
||||
messages.add(new NoticeMessage(" Open: " + Utils.unescapeXml(quote.getString("02. open"))));
|
||||
messages.add(new NoticeMessage(" High: " + Utils.unescapeXml(quote.getString("03. high"))));
|
||||
messages.add(new NoticeMessage(" Low: " + Utils.unescapeXml(quote.getString("04. low"))));
|
||||
messages.add(new NoticeMessage(" Volume: " + Utils.unescapeXml(quote.getString("06. volume"))));
|
||||
messages.add(new NoticeMessage(" Latest: "
|
||||
+ Utils.unescapeXml(quote.getString("07. latest trading day"))));
|
||||
messages.add(new PrivateMessage(" Change: " + Utils.unescapeXml(quote.getString("09. change"))
|
||||
messages.add(new NoticeMessage(" Change: " + Utils.unescapeXml(quote.getString("09. change"))
|
||||
+ " [" + Utils.unescapeXml(quote.getString("10. change percent")) + ']'));
|
||||
} catch (IOException e) {
|
||||
throw new ModuleException(debugMessage, "An error has occurred retrieving a stock quote.", e);
|
||||
|
@ -165,11 +165,7 @@ public final class StockQuote extends AbstractModule {
|
|||
final ArrayList<Message> messages =
|
||||
getQuote(symbol, properties.get(ALPHAVANTAGE_API_KEY_PROP));
|
||||
for (Message msg : messages) {
|
||||
if (msg.isPrivate() || msg.isError()) {
|
||||
bot.send(sender, msg.getMessage());
|
||||
} else {
|
||||
bot.send(bot.getChannel(), msg.getMessage());
|
||||
}
|
||||
bot.send(msg.isNoticeOrError() ? sender : bot.getChannel(), msg.getMessage());
|
||||
}
|
||||
|
||||
} catch (ModuleException e) {
|
||||
|
|
|
@ -40,7 +40,7 @@ package net.thauvin.erik.mobibot.msg;
|
|||
*/
|
||||
public class Message {
|
||||
private boolean isError;
|
||||
private boolean isPrivate;
|
||||
private boolean isNotice;
|
||||
private String msg = "";
|
||||
|
||||
/**
|
||||
|
@ -54,11 +54,11 @@ public class Message {
|
|||
* Creates a new message.
|
||||
*
|
||||
* @param message The message.
|
||||
* @param isPrivate The private flag.
|
||||
* @param isNotice The notice flag.
|
||||
*/
|
||||
public Message(String message, boolean isPrivate, boolean isError) {
|
||||
public Message(String message, boolean isNotice, boolean isError) {
|
||||
msg = message;
|
||||
this.isPrivate = isPrivate;
|
||||
this.isNotice = isNotice;
|
||||
this.isError = isError;
|
||||
}
|
||||
|
||||
|
@ -99,20 +99,29 @@ public class Message {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the private message flag.
|
||||
* Returns the message notice flag.
|
||||
*
|
||||
* @return The private flag.
|
||||
* @return The notice flag.
|
||||
*/
|
||||
public boolean isPrivate() {
|
||||
return isPrivate;
|
||||
public boolean isNotice() {
|
||||
return isNotice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the private message flag.
|
||||
* Set the message notice flag.
|
||||
*
|
||||
* @param isPrivate The private flag.
|
||||
* @param isNotice The notice flag.
|
||||
*/
|
||||
public void setPrivate(boolean isPrivate) {
|
||||
this.isPrivate = isPrivate;
|
||||
public void setNotice(boolean isNotice) {
|
||||
this.isNotice = isNotice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the message is an error or a notice.
|
||||
*
|
||||
* @return <code>true</code> or <code>false</code>
|
||||
*/
|
||||
public boolean isNoticeOrError() {
|
||||
return (isNotice || isError);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,15 +32,15 @@
|
|||
package net.thauvin.erik.mobibot.msg;
|
||||
|
||||
/**
|
||||
* The <code>PrivateMessage</code> class.
|
||||
* The <code>NoticeMessage</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
public class PrivateMessage extends Message {
|
||||
public PrivateMessage(String message) {
|
||||
public class NoticeMessage extends Message {
|
||||
public NoticeMessage(String message) {
|
||||
this.setMessage(message);
|
||||
this.setPrivate(true);
|
||||
this.setNotice(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,6 @@ package net.thauvin.erik.mobibot.msg;
|
|||
public class PublicMessage extends Message {
|
||||
public PublicMessage(String message) {
|
||||
this.setMessage(message);
|
||||
this.setPrivate(false);
|
||||
this.setNotice(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,8 +57,8 @@ public class CurrentConverterTest {
|
|||
public void testConvertCurrency() throws ModuleException {
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to EUR").getMessage())
|
||||
.as("100 USD to EUR").startsWith("100.00 USD = ");
|
||||
assertThat(CurrencyConverter.convertCurrency(CurrencyConverter.CURRENCY_RATES_KEYWORD).isPrivate())
|
||||
.as(CurrencyConverter.CURRENCY_RATES_KEYWORD + " is private").isTrue();
|
||||
assertThat(CurrencyConverter.convertCurrency(CurrencyConverter.CURRENCY_RATES_KEYWORD).isNotice())
|
||||
.as(CurrencyConverter.CURRENCY_RATES_KEYWORD + " is notice").isTrue();
|
||||
assertThat(CurrencyConverter.convertCurrency(CurrencyConverter.CURRENCY_RATES_KEYWORD).getMessage())
|
||||
.as(CurrencyConverter.CURRENCY_RATES_KEYWORD).contains("USD: ");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue