Made Tell an actual command.
This commit is contained in:
parent
d9b1cbceff
commit
0ec1e75106
2 changed files with 73 additions and 65 deletions
|
@ -258,6 +258,9 @@ public class Mobibot extends PircBot {
|
||||||
commands.add(new Comment());
|
commands.add(new Comment());
|
||||||
commands.add(new Posting());
|
commands.add(new Posting());
|
||||||
commands.add(new Tags());
|
commands.add(new Tags());
|
||||||
|
// Get the tell command settings
|
||||||
|
tell = new Tell(this, p.getProperty("tell-max-days"), p.getProperty("tell-max-size"));
|
||||||
|
commands.add(tell);
|
||||||
commands.add(new UrlMgr(p.getProperty("tags", ""), p.getProperty("tags-keywords", "")));
|
commands.add(new UrlMgr(p.getProperty("tags", ""), p.getProperty("tags-keywords", "")));
|
||||||
commands.add(new View());
|
commands.add(new View());
|
||||||
|
|
||||||
|
@ -290,9 +293,6 @@ public class Mobibot extends PircBot {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get the tell command settings
|
|
||||||
tell = new Tell(this, p.getProperty("tell-max-days"), p.getProperty("tell-max-size"));
|
|
||||||
|
|
||||||
// Save the entries
|
// Save the entries
|
||||||
UrlMgr.saveEntries(this, true);
|
UrlMgr.saveEntries(this, true);
|
||||||
}
|
}
|
||||||
|
@ -624,8 +624,7 @@ public class Mobibot extends PircBot {
|
||||||
send(sender, "Type a URL on " + ircChannel + " to post it.", isPrivate);
|
send(sender, "Type a URL on " + ircChannel + " to post it.", isPrivate);
|
||||||
send(sender, "For more information on a specific command, type:", isPrivate);
|
send(sender, "For more information on a specific command, type:", isPrivate);
|
||||||
send(sender,
|
send(sender,
|
||||||
Utils.helpIndent(
|
Utils.helpIndent(Utils.botCommand(getNick(), isPrivate) + Constants.HELP_CMD + " <command>"),
|
||||||
((isPrivate) ? "/msg " + getNick() : getNick() + ':') + " " + Constants.HELP_CMD + " <command>"),
|
|
||||||
isPrivate);
|
isPrivate);
|
||||||
send(sender, "The commands are:", isPrivate);
|
send(sender, "The commands are:", isPrivate);
|
||||||
|
|
||||||
|
@ -702,8 +701,6 @@ public class Mobibot extends PircBot {
|
||||||
if (lcTopic.equals(getChannelName())) {
|
if (lcTopic.equals(getChannelName())) {
|
||||||
send(sender, "To list the last 5 posts from the channel's weblog:", isPrivate);
|
send(sender, "To list the last 5 posts from the channel's weblog:", isPrivate);
|
||||||
send(sender, Utils.helpIndent(getNick() + ": " + getChannelName()), isPrivate);
|
send(sender, Utils.helpIndent(getNick() + ": " + getChannelName()), isPrivate);
|
||||||
} else if (Tell.TELL_CMD.equals(lcTopic) && tell.isEnabled()) {
|
|
||||||
tell.helpResponse(sender, isPrivate);
|
|
||||||
} else {
|
} else {
|
||||||
// Command, Modules or Default
|
// Command, Modules or Default
|
||||||
if (!helpCommands(sender, topic, isPrivate) && !helpModules(sender, lcTopic, isPrivate)) {
|
if (!helpCommands(sender, topic, isPrivate) && !helpModules(sender, lcTopic, isPrivate)) {
|
||||||
|
@ -796,8 +793,6 @@ public class Mobibot extends PircBot {
|
||||||
helpResponse(sender, args, false);
|
helpResponse(sender, args, false);
|
||||||
} else if (cmd.equalsIgnoreCase(getChannelName())) { // mobibot: <channel>
|
} else if (cmd.equalsIgnoreCase(getChannelName())) { // mobibot: <channel>
|
||||||
feedResponse(sender);
|
feedResponse(sender);
|
||||||
} else if (cmd.startsWith(Tell.TELL_CMD) && tell.isEnabled()) { // mobibot: tell
|
|
||||||
tell.response(sender, args, false);
|
|
||||||
} else {
|
} else {
|
||||||
boolean skip = false;
|
boolean skip = false;
|
||||||
// Commands
|
// Commands
|
||||||
|
@ -820,8 +815,7 @@ public class Mobibot extends PircBot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else { // Commands
|
||||||
// Commands
|
|
||||||
for (final AbstractCommand command : commands) {
|
for (final AbstractCommand command : commands) {
|
||||||
if (command.matches(message)) {
|
if (command.matches(message)) {
|
||||||
command.commandResponse(this, sender, login, message, isOp(sender), false);
|
command.commandResponse(this, sender, login, message, isOp(sender), false);
|
||||||
|
@ -880,8 +874,6 @@ public class Mobibot extends PircBot {
|
||||||
sleep(3);
|
sleep(3);
|
||||||
quitServer("The Bot Is Out There!");
|
quitServer("The Bot Is Out There!");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
} else if (Tell.TELL_CMD.equals(cmd) && tell.isEnabled()) { // tell
|
|
||||||
tell.response(sender, args, true);
|
|
||||||
} else {
|
} else {
|
||||||
for (final AbstractCommand command : commands) {
|
for (final AbstractCommand command : commands) {
|
||||||
if (command.getCommand().startsWith(cmd)) {
|
if (command.getCommand().startsWith(cmd)) {
|
||||||
|
|
|
@ -34,8 +34,10 @@ package net.thauvin.erik.mobibot.commands.tell;
|
||||||
|
|
||||||
import net.thauvin.erik.mobibot.Mobibot;
|
import net.thauvin.erik.mobibot.Mobibot;
|
||||||
import net.thauvin.erik.mobibot.Utils;
|
import net.thauvin.erik.mobibot.Utils;
|
||||||
|
import net.thauvin.erik.mobibot.commands.AbstractCommand;
|
||||||
import net.thauvin.erik.mobibot.commands.links.View;
|
import net.thauvin.erik.mobibot.commands.links.View;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
@ -47,7 +49,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
* @created 2016-07-02
|
* @created 2016-07-02
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class Tell {
|
public class Tell extends AbstractCommand {
|
||||||
/**
|
/**
|
||||||
* The tell command.
|
* The tell command.
|
||||||
*/
|
*/
|
||||||
|
@ -111,8 +113,8 @@ public class Tell {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete message.
|
// Delete message.
|
||||||
private void deleteMessage(final String sender, final String cmds, final boolean isPrivate) {
|
private void deleteMessage(final String sender, final String args, final boolean isOp, final boolean isPrivate) {
|
||||||
final String[] split = cmds.split(" ");
|
final String[] split = args.split(" ");
|
||||||
|
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
final String id = split[1];
|
final String id = split[1];
|
||||||
|
@ -158,26 +160,65 @@ public class Tell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
helpResponse(sender, isPrivate);
|
helpResponse(bot, args, sender, isOp, isPrivate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@NotNull
|
||||||
* Responds with Constants.
|
@Override
|
||||||
*
|
public String getCommand() {
|
||||||
* @param sender The sender.
|
return TELL_CMD;
|
||||||
* @param isPrivate The private flag.
|
}
|
||||||
*/
|
|
||||||
public void helpResponse(final String sender, final boolean isPrivate) {
|
|
||||||
bot.send(sender, "To send a message to someone when they join the channel:", isPrivate);
|
|
||||||
bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TELL_CMD + " <nick> <message>"), isPrivate);
|
|
||||||
|
|
||||||
bot.send(sender, "To view queued and sent messages:", isPrivate);
|
@NotNull
|
||||||
bot.send(sender, Utils.helpIndent(bot.getNick() + ": " + TELL_CMD + ' ' + View.VIEW_CMD), isPrivate);
|
@Override
|
||||||
|
public List<String> getHelp() {
|
||||||
|
return List.of("To send a message to someone when they join the channel:",
|
||||||
|
Utils.helpIndent("%s " + TELL_CMD + " <nick> <message>"),
|
||||||
|
"To view queued and sent messages:",
|
||||||
|
Utils.helpIndent("%s " + TELL_CMD + ' ' + View.VIEW_CMD),
|
||||||
|
"Messages are kept for " + Utils.bold(maxDays) + Utils.plural(maxDays, " day.", " days."));
|
||||||
|
}
|
||||||
|
|
||||||
bot.send(sender,
|
@Override
|
||||||
"Messages are kept for " + Utils.bold(maxDays) + Utils.plural(maxDays, " day.", " days."),
|
public boolean isOp() {
|
||||||
isPrivate);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPublic() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVisible() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void commandResponse(@NotNull final Mobibot bot,
|
||||||
|
@NotNull final String sender,
|
||||||
|
@NotNull final String login,
|
||||||
|
@NotNull final String args,
|
||||||
|
final boolean isOp,
|
||||||
|
final boolean isPrivate) {
|
||||||
|
if (StringUtils.isBlank(args)) {
|
||||||
|
helpResponse(bot, args, sender, isOp, isPrivate);
|
||||||
|
} else if (args.startsWith(View.VIEW_CMD)) {
|
||||||
|
if (bot.isOp(sender) && (View.VIEW_CMD + ' ' + TELL_ALL_KEYWORD).equals(args)) {
|
||||||
|
viewAll(sender, isPrivate);
|
||||||
|
} else {
|
||||||
|
viewMessages(sender, isPrivate);
|
||||||
|
}
|
||||||
|
} else if (args.startsWith(TELL_DEL_KEYWORD + ' ')) {
|
||||||
|
deleteMessage(sender, args, isOp, isPrivate);
|
||||||
|
} else {
|
||||||
|
newMessage(sender, args, isOp, isPrivate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clean()) {
|
||||||
|
save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -190,8 +231,8 @@ public class Tell {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New message.
|
// New message.
|
||||||
private void newMessage(final String sender, final String cmds, final boolean isPrivate) {
|
private void newMessage(final String sender, final String args, final boolean isOp, final boolean isPrivate) {
|
||||||
final String[] split = cmds.split(" ", 2);
|
final String[] split = args.split(" ", 2);
|
||||||
|
|
||||||
if (split.length == 2 && (StringUtils.isNotBlank(split[1]) && split[1].contains(" "))) {
|
if (split.length == 2 && (StringUtils.isNotBlank(split[1]) && split[1].contains(" "))) {
|
||||||
if (messages.size() < maxSize) {
|
if (messages.size() < maxSize) {
|
||||||
|
@ -202,39 +243,12 @@ public class Tell {
|
||||||
save();
|
save();
|
||||||
|
|
||||||
bot.send(sender, "Message [ID " + message.getId() + "] was queued for "
|
bot.send(sender, "Message [ID " + message.getId() + "] was queued for "
|
||||||
+ Utils.bold(message.getRecipient()), true);
|
+ Utils.bold(message.getRecipient()), isPrivate);
|
||||||
} else {
|
} else {
|
||||||
bot.send(sender, "Sorry, the messages queue is currently full.", true);
|
bot.send(sender, "Sorry, the messages queue is currently full.", isPrivate);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
helpResponse(sender, isPrivate);
|
helpResponse(bot, args, sender, isOp, isPrivate);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Processes the commands.
|
|
||||||
*
|
|
||||||
* @param sender The sender's nick.
|
|
||||||
* @param cmds The commands string.
|
|
||||||
* @param isPrivate The private flag.
|
|
||||||
*/
|
|
||||||
public void response(final String sender, final String cmds, final boolean isPrivate) {
|
|
||||||
if (StringUtils.isBlank(cmds)) {
|
|
||||||
helpResponse(sender, isPrivate);
|
|
||||||
} else if (cmds.startsWith(View.VIEW_CMD)) {
|
|
||||||
if (bot.isOp(sender) && (View.VIEW_CMD + ' ' + TELL_ALL_KEYWORD).equals(cmds)) {
|
|
||||||
viewAll(sender, isPrivate);
|
|
||||||
} else {
|
|
||||||
viewMessages(sender, isPrivate);
|
|
||||||
}
|
|
||||||
} else if (cmds.startsWith(TELL_DEL_KEYWORD + ' ')) {
|
|
||||||
deleteMessage(sender, cmds, isPrivate);
|
|
||||||
} else {
|
|
||||||
newMessage(sender, cmds, isPrivate);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clean()) {
|
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,8 +374,10 @@ public class Tell {
|
||||||
} else {
|
} else {
|
||||||
bot.send(sender, "To delete one or all delivered messages:", isPrivate);
|
bot.send(sender, "To delete one or all delivered messages:", isPrivate);
|
||||||
bot.send(sender,
|
bot.send(sender,
|
||||||
Utils.helpIndent(bot.getNick() + ": " + TELL_CMD + ' ' + TELL_DEL_KEYWORD + " <id|"
|
Utils.helpIndent(
|
||||||
+ TELL_ALL_KEYWORD + '>'), isPrivate);
|
Utils.botCommand(bot.getNick(), isPrivate) + TELL_CMD + ' ' + TELL_DEL_KEYWORD + " <id|"
|
||||||
|
+ TELL_ALL_KEYWORD + '>'),
|
||||||
|
isPrivate);
|
||||||
bot.send(sender,
|
bot.send(sender,
|
||||||
"Messages are kept for " + Utils.bold(maxDays) + Utils.plural(maxDays, " day.", " days."),
|
"Messages are kept for " + Utils.bold(maxDays) + Utils.plural(maxDays, " day.", " days."),
|
||||||
isPrivate);
|
isPrivate);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue