Converted Tell to an actual command.

This commit is contained in:
Erik C. Thauvin 2020-03-31 22:30:09 -07:00
parent 37f3c49413
commit 559634fbfe
2 changed files with 33 additions and 27 deletions

View file

@ -254,17 +254,19 @@ public class Mobibot extends PircBot {
commands.add(new Users()); commands.add(new Users());
commands.add(new Versions()); commands.add(new Versions());
// Tell
tell = new Tell(this, p.getProperty("tell-max-days"), p.getProperty("tell-max-size"));
if (tell.isEnabled()) {
commands.add(tell);
}
// Load the links commands // Load the links commands
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());
// Load the modules // Load the modules
addModule(new Calc()); addModule(new Calc());
addModule(new CurrencyConverter()); addModule(new CurrencyConverter());
@ -647,11 +649,6 @@ public class Mobibot extends PircBot {
modules.stream().filter(AbstractModule::isEnabled) modules.stream().filter(AbstractModule::isEnabled)
.forEach(module -> commandsNames.addAll(module.getCommands())); .forEach(module -> commandsNames.addAll(module.getCommands()));
// Tell command
if (tell.isEnabled()) {
commandsNames.add(Tell.TELL_CMD);
}
Collections.sort(commandsNames); Collections.sort(commandsNames);
Collections.sort(opsCommandsNames); Collections.sort(opsCommandsNames);
} }
@ -829,8 +826,10 @@ public class Mobibot extends PircBot {
Recap.storeRecap(sender, message, false); Recap.storeRecap(sender, message, false);
} }
if (tell.isEnabled()) {
tell.send(sender, true); tell.send(sender, true);
} }
}
/** /**
* {@inheritDoc} * {@inheritDoc}
@ -911,16 +910,20 @@ public class Mobibot extends PircBot {
*/ */
@Override @Override
protected void onJoin(final String channel, final String sender, final String login, final String hostname) { protected void onJoin(final String channel, final String sender, final String login, final String hostname) {
if (tell.isEnabled()) {
tell.send(sender); tell.send(sender);
} }
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected void onNickChange(final String oldNick, final String login, final String hostname, final String newNick) { protected void onNickChange(final String oldNick, final String login, final String hostname, final String newNick) {
if (tell.isEnabled()) {
tell.send(newNick); tell.send(newNick);
} }
}
/** /**
* Sends a private message or notice. * Sends a private message or notice.

View file

@ -85,6 +85,7 @@ public class Tell extends AbstractCommand {
* @param maxSize Max size. * @param maxSize Max size.
*/ */
public Tell(final Mobibot bot, final String maxDays, final String maxSize) { public Tell(final Mobibot bot, final String maxDays, final String maxSize) {
super();
this.bot = bot; this.bot = bot;
this.maxDays = Utils.getIntProperty(maxDays, DEFAULT_TELL_MAX_DAYS); this.maxDays = Utils.getIntProperty(maxDays, DEFAULT_TELL_MAX_DAYS);
this.maxSize = Utils.getIntProperty(maxSize, DEFAULT_TELL_MAX_SIZE); this.maxSize = Utils.getIntProperty(maxSize, DEFAULT_TELL_MAX_SIZE);
@ -187,12 +188,12 @@ public class Tell extends AbstractCommand {
@Override @Override
public boolean isPublic() { public boolean isPublic() {
return true; return isEnabled();
} }
@Override @Override
public boolean isVisible() { public boolean isVisible() {
return true; return isEnabled();
} }
@Override @Override
@ -202,6 +203,7 @@ public class Tell extends AbstractCommand {
@NotNull final String args, @NotNull final String args,
final boolean isOp, final boolean isOp,
final boolean isPrivate) { final boolean isPrivate) {
if (isEnabled()) {
if (StringUtils.isBlank(args)) { if (StringUtils.isBlank(args)) {
helpResponse(bot, args, sender, isOp, isPrivate); helpResponse(bot, args, sender, isOp, isPrivate);
} else if (args.startsWith(View.VIEW_CMD)) { } else if (args.startsWith(View.VIEW_CMD)) {
@ -220,6 +222,7 @@ public class Tell extends AbstractCommand {
save(); save();
} }
} }
}
/** /**
* Returns <code>true</code> if enabled. * Returns <code>true</code> if enabled.