Implemented new send methods.
This commit is contained in:
parent
2b4f1af63c
commit
a4907ce111
10 changed files with 59 additions and 31 deletions
|
@ -34,12 +34,14 @@ package net.thauvin.erik.mobibot;
|
|||
import com.rometools.rome.io.FeedException;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import net.thauvin.erik.mobibot.modules.*;
|
||||
import net.thauvin.erik.mobibot.msg.Message;
|
||||
import net.thauvin.erik.semver.Version;
|
||||
import org.apache.commons.cli.*;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.jibble.pircbot.Colors;
|
||||
import org.jibble.pircbot.PircBot;
|
||||
import org.jibble.pircbot.User;
|
||||
import org.jsoup.Jsoup;
|
||||
|
@ -796,7 +798,7 @@ public class Mobibot extends PircBot {
|
|||
private void infoResponse(final String sender, final boolean isPrivate) {
|
||||
for (final String info : INFO_STRS) {
|
||||
if (info.startsWith("https://")) {
|
||||
send(sender, Utils.green(info), isPrivate);
|
||||
send(sender, info, Colors.DARK_GREEN, isPrivate);
|
||||
} else {
|
||||
send(sender, info, isPrivate);
|
||||
}
|
||||
|
@ -1429,20 +1431,54 @@ public class Mobibot extends PircBot {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a notice to the channel.
|
||||
*
|
||||
* @param notice The notice message.
|
||||
*/
|
||||
public final void send(final String notice) {
|
||||
send(getChannel(), notice);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message.
|
||||
*
|
||||
* @param who The channel or nick of the person who sent the message.
|
||||
* @param who The channel or nick of the person who sent the command.
|
||||
* @param message The actual message.
|
||||
*/
|
||||
public final void send(final String who, final String message) {
|
||||
send(who, message, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends a message.
|
||||
*
|
||||
* @param who The channel or nick of the person who sent the message.
|
||||
* @param who The channel or nick of the person who sent the command.
|
||||
* @param message The message.
|
||||
*/
|
||||
public final void send(final String who, final Message message) {
|
||||
send(message.isNotice() ? who : getChannel(), message.getMessage(), message.getColor(), message.isPrivate());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message.
|
||||
*
|
||||
* @param who The channel or nick of the person who sent the command.
|
||||
* @param message The actual message.
|
||||
* @param color The message's color.
|
||||
* @param isPrivate The private flag.
|
||||
*/
|
||||
public final void send(final String who, final String message, final String color, boolean isPrivate) {
|
||||
send(who, Utils.colorize(message, color), isPrivate);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends a message.
|
||||
*
|
||||
* @param who The channel or nick of the person who sent the command.
|
||||
* @param message The actual message.
|
||||
* @param color The message's color.
|
||||
*/
|
||||
|
|
|
@ -60,7 +60,7 @@ class Pinboard {
|
|||
* @param apiToken The API end point.
|
||||
* @param ircServer The IRC server.
|
||||
*/
|
||||
public Pinboard(final Mobibot bot, final String apiToken, final String ircServer) {
|
||||
Pinboard(final Mobibot bot, final String apiToken, final String ircServer) {
|
||||
pinboard = new PinboardPoster(apiToken);
|
||||
this.ircServer = ircServer;
|
||||
|
||||
|
@ -78,11 +78,10 @@ class Pinboard {
|
|||
*
|
||||
* @param entry The entry to add.
|
||||
*/
|
||||
public final void addPost(final EntryLink entry) {
|
||||
final void addPost(final EntryLink entry) {
|
||||
final SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
|
||||
@Override
|
||||
protected Boolean doInBackground()
|
||||
throws Exception {
|
||||
protected Boolean doInBackground() {
|
||||
return pinboard.addPin(entry.getLink(),
|
||||
entry.getTitle(),
|
||||
postedBy(entry),
|
||||
|
@ -99,13 +98,12 @@ class Pinboard {
|
|||
*
|
||||
* @param entry The entry to delete.
|
||||
*/
|
||||
public final void deletePost(final EntryLink entry) {
|
||||
final void deletePost(final EntryLink entry) {
|
||||
final String link = entry.getLink();
|
||||
|
||||
final SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
|
||||
@Override
|
||||
protected Boolean doInBackground()
|
||||
throws Exception {
|
||||
protected Boolean doInBackground() {
|
||||
return pinboard.deletePin(link);
|
||||
}
|
||||
};
|
||||
|
@ -139,11 +137,10 @@ class Pinboard {
|
|||
* @param oldUrl The old post URL.
|
||||
* @param entry The entry to add.
|
||||
*/
|
||||
public final void updatePost(final String oldUrl, final EntryLink entry) {
|
||||
final void updatePost(final String oldUrl, final EntryLink entry) {
|
||||
final SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
|
||||
@Override
|
||||
protected Boolean doInBackground()
|
||||
throws Exception {
|
||||
protected Boolean doInBackground() {
|
||||
if (!oldUrl.equals(entry.getLink())) {
|
||||
pinboard.deletePin(oldUrl);
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ public class Calc extends AbstractModule {
|
|||
@Override
|
||||
public void commandResponse(final Mobibot bot, final String sender, final String args, final boolean isPrivate) {
|
||||
if (Utils.isValidString(args)) {
|
||||
bot.send(bot.getChannel(), calc(args));
|
||||
bot.send(calc(args));
|
||||
|
||||
} else {
|
||||
helpResponse(bot, sender, args, isPrivate);
|
||||
|
|
|
@ -199,7 +199,7 @@ public final class CurrencyConverter extends ThreadedModule {
|
|||
if (msg.isError()) {
|
||||
helpResponse(bot, sender, CURRENCY_CMD + ' ' + query, false);
|
||||
}
|
||||
bot.send(msg.isNotice() ? sender : bot.getChannel(), msg.getMessage());
|
||||
bot.send(sender, msg);
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
bot.send(sender, e.getMessage());
|
||||
|
|
|
@ -36,6 +36,7 @@ import net.thauvin.erik.mobibot.Mobibot;
|
|||
import net.thauvin.erik.mobibot.Utils;
|
||||
import net.thauvin.erik.mobibot.msg.Message;
|
||||
import net.thauvin.erik.mobibot.msg.NoticeMessage;
|
||||
import org.jibble.pircbot.Colors;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -118,7 +119,8 @@ public final class GoogleSearch extends ThreadedModule {
|
|||
for (int i = 0; i < ja.length(); i++) {
|
||||
final JSONObject j = ja.getJSONObject(i);
|
||||
results.add(new NoticeMessage(Utils.unescapeXml(j.getString("title"))));
|
||||
results.add(new NoticeMessage(j.getString("link")));
|
||||
results.add(
|
||||
new NoticeMessage(TAB_INDENT + j.getString("link"), Colors.DARK_GREEN));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -152,15 +154,8 @@ public final class GoogleSearch extends ThreadedModule {
|
|||
try {
|
||||
final ArrayList<Message> results = searchGoogle(query, properties.get(GOOGLE_API_KEY_PROP),
|
||||
properties.get(GOOGLE_CSE_KEY_PROP));
|
||||
|
||||
int i = 0;
|
||||
for (final Message msg : results) {
|
||||
if (i % 2 == 0) {
|
||||
bot.send(sender, Utils.green(TAB_INDENT + msg.getMessage()));
|
||||
} else {
|
||||
bot.send(sender, msg.getMessage());
|
||||
}
|
||||
i++;
|
||||
bot.send(sender, msg);
|
||||
}
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
|
|
|
@ -108,7 +108,7 @@ public final class Joke extends ThreadedModule {
|
|||
*/
|
||||
void run(final Mobibot bot, final String sender, String arg) {
|
||||
try {
|
||||
bot.send(bot.getChannel(), Utils.cyan(randomJoke().getMessage()));
|
||||
bot.send(Utils.cyan(randomJoke().getMessage()));
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
bot.send(sender, e.getMessage());
|
||||
|
|
|
@ -170,11 +170,11 @@ public final class StockQuote extends ThreadedModule {
|
|||
try {
|
||||
final ArrayList<Message> messages = getQuote(symbol, properties.get(ALPHAVANTAGE_API_KEY_PROP));
|
||||
for (final Message msg : messages) {
|
||||
bot.send(msg.isNotice() ? sender : bot.getChannel(), msg.getMessage());
|
||||
bot.send(sender, msg);
|
||||
}
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
bot.send(bot.getChannel(), e.getMessage());
|
||||
bot.send(e.getMessage());
|
||||
}
|
||||
} else {
|
||||
helpResponse(bot, sender, symbol, true);
|
||||
|
|
|
@ -86,7 +86,7 @@ public final class War extends AbstractModule {
|
|||
break;
|
||||
}
|
||||
|
||||
bot.send(bot.getChannel(), "This means " + Utils.bold("WAR") + '!');
|
||||
bot.send("This means " + Utils.bold("WAR") + '!');
|
||||
}
|
||||
|
||||
if (i < y) {
|
||||
|
|
|
@ -197,12 +197,12 @@ public class Weather2 extends ThreadedModule {
|
|||
helpResponse(bot, sender, args, true);
|
||||
} else {
|
||||
for (final Message msg : messages) {
|
||||
bot.send(msg.isNotice() ? bot.getChannel() : sender, msg.getMessage(), msg.getColor());
|
||||
bot.send(sender, msg);
|
||||
}
|
||||
}
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().debug(e.getDebugMessage(), e);
|
||||
bot.send(bot.getChannel(), e.getMessage());
|
||||
bot.send(e.getMessage());
|
||||
}
|
||||
} else {
|
||||
helpResponse(bot, sender, args, true);
|
||||
|
|
|
@ -200,7 +200,7 @@ public final class WorldTime extends AbstractModule {
|
|||
if (msg.isError()) {
|
||||
bot.send(sender, msg.getMessage());
|
||||
} else {
|
||||
bot.send(bot.getChannel(), msg.getMessage());
|
||||
bot.send(msg.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue