Added ChannelFeed command.
This commit is contained in:
parent
bcf659c5a8
commit
34636ea9f9
3 changed files with 103 additions and 81 deletions
|
@ -48,7 +48,7 @@ import java.util.List;
|
||||||
* @created Feb 1, 2004
|
* @created Feb 1, 2004
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
class FeedReader implements Runnable {
|
public class FeedReader implements Runnable {
|
||||||
// Maximum number of feed items to display
|
// Maximum number of feed items to display
|
||||||
private static final int MAX_ITEMS = 5;
|
private static final int MAX_ITEMS = 5;
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class FeedReader implements Runnable {
|
||||||
* @param sender The nick of the person who sent the message.
|
* @param sender The nick of the person who sent the message.
|
||||||
* @param url The URL to fetch.
|
* @param url The URL to fetch.
|
||||||
*/
|
*/
|
||||||
FeedReader(final Mobibot bot, final String sender, final String url) {
|
public FeedReader(final Mobibot bot, final String sender, final String url) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
|
|
@ -168,8 +168,6 @@ public class Mobibot extends PircBot {
|
||||||
private final Twitter twitterModule;
|
private final Twitter twitterModule;
|
||||||
// Backlogs URL
|
// Backlogs URL
|
||||||
private String backLogsUrl = "";
|
private String backLogsUrl = "";
|
||||||
// Feed URL
|
|
||||||
private String feedUrl = "";
|
|
||||||
// Ident message
|
// Ident message
|
||||||
private String identMsg = "";
|
private String identMsg = "";
|
||||||
// Ident nick
|
// Ident nick
|
||||||
|
@ -229,41 +227,41 @@ public class Mobibot extends PircBot {
|
||||||
|
|
||||||
// Set the URLs
|
// Set the URLs
|
||||||
setWeblogUrl(getVersion());
|
setWeblogUrl(getVersion());
|
||||||
setFeedUrl(p.getProperty("feed", ""));
|
|
||||||
setBacklogsUrl(Utils.ensureDir(p.getProperty("backlogs", weblogUrl), true));
|
setBacklogsUrl(Utils.ensureDir(p.getProperty("backlogs", weblogUrl), true));
|
||||||
|
|
||||||
// Set the pinboard authentication
|
// Set the pinboard authentication
|
||||||
setPinboardAuth(p.getProperty("pinboard-api-token"));
|
setPinboardAuth(p.getProperty("pinboard-api-token"));
|
||||||
|
|
||||||
// Set the ignored nicks
|
|
||||||
ignoreCommand = new Ignore(p.getProperty("ignore", ""));
|
|
||||||
|
|
||||||
// Load the commands
|
// Load the commands
|
||||||
commands.add(new AddLog());
|
addCommand(new AddLog());
|
||||||
commands.add(new Cycle());
|
addCommand(new ChannelFeed(getChannelName(), p.getProperty("feed", "")));
|
||||||
commands.add(ignoreCommand);
|
addCommand(new Cycle());
|
||||||
commands.add(new Info());
|
addCommand(new Info());
|
||||||
commands.add(new Me());
|
addCommand(new Me());
|
||||||
commands.add(new Modules());
|
addCommand(new Modules());
|
||||||
commands.add(new Msg());
|
addCommand(new Msg());
|
||||||
commands.add(new Nick());
|
addCommand(new Nick());
|
||||||
commands.add(new Recap());
|
addCommand(new Recap());
|
||||||
commands.add(new Say());
|
addCommand(new Say());
|
||||||
commands.add(new Users());
|
addCommand(new Users());
|
||||||
commands.add(new Versions());
|
addCommand(new Versions());
|
||||||
|
|
||||||
// Tell
|
// Ignore command
|
||||||
|
ignoreCommand = new Ignore(p.getProperty("ignore", ""));
|
||||||
|
addCommand(ignoreCommand);
|
||||||
|
|
||||||
|
// Tell command
|
||||||
tell = new Tell(this, p.getProperty("tell-max-days"), p.getProperty("tell-max-size"));
|
tell = new Tell(this, p.getProperty("tell-max-days"), p.getProperty("tell-max-size"));
|
||||||
if (tell.isEnabled()) {
|
if (tell.isEnabled()) {
|
||||||
commands.add(tell);
|
addCommand(tell);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the links commands
|
// Load the links commands
|
||||||
commands.add(new Comment());
|
addCommand(new Comment());
|
||||||
commands.add(new Posting());
|
addCommand(new Posting());
|
||||||
commands.add(new Tags());
|
addCommand(new Tags());
|
||||||
commands.add(new UrlMgr(p.getProperty("tags", ""), p.getProperty("tags-keywords", "")));
|
addCommand(new UrlMgr(p.getProperty("tags", ""), p.getProperty("tags-keywords", "")));
|
||||||
commands.add(new View());
|
addCommand(new View());
|
||||||
|
|
||||||
// Load the modules
|
// Load the modules
|
||||||
addModule(new Calc());
|
addModule(new Calc());
|
||||||
|
@ -485,19 +483,6 @@ public class Mobibot extends PircBot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Responds with the title and links from the RSS feed.
|
|
||||||
*
|
|
||||||
* @param sender The nick of the person who sent the message.
|
|
||||||
*/
|
|
||||||
private void feedResponse(final String sender) {
|
|
||||||
if (isNotBlank(feedUrl)) {
|
|
||||||
new Thread(new FeedReader(this, sender, feedUrl)).start();
|
|
||||||
} else {
|
|
||||||
send(sender, "There is no feed setup for this channel.", false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the backlogs URL.
|
* Returns the backlogs URL.
|
||||||
*
|
*
|
||||||
|
@ -695,19 +680,13 @@ public class Mobibot extends PircBot {
|
||||||
final boolean isOp = isOp(sender);
|
final boolean isOp = isOp(sender);
|
||||||
if (StringUtils.isBlank(topic)) {
|
if (StringUtils.isBlank(topic)) {
|
||||||
helpDefault(sender, isOp, isPrivate);
|
helpDefault(sender, isOp, isPrivate);
|
||||||
} else {
|
|
||||||
final String lcTopic = lowerCase(topic).trim();
|
|
||||||
if (lcTopic.equals(getChannelName())) {
|
|
||||||
send(sender, "To list the last 5 posts from the channel's weblog:", isPrivate);
|
|
||||||
send(sender, Utils.helpIndent(getNick() + ": " + getChannelName()), 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, lowerCase(topic).trim(), isPrivate)) {
|
||||||
helpDefault(sender, isOp, isPrivate);
|
helpDefault(sender, isOp, isPrivate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies the bot.
|
* Identifies the bot.
|
||||||
|
@ -790,49 +769,37 @@ public class Mobibot extends PircBot {
|
||||||
|
|
||||||
if (cmd.startsWith(Constants.HELP_CMD)) { // mobibot: help
|
if (cmd.startsWith(Constants.HELP_CMD)) { // mobibot: help
|
||||||
helpResponse(sender, args, false);
|
helpResponse(sender, args, false);
|
||||||
} else if (cmd.equalsIgnoreCase(getChannelName())) { // mobibot: <channel>
|
|
||||||
feedResponse(sender);
|
|
||||||
} else {
|
} else {
|
||||||
boolean skip = false;
|
|
||||||
// Commands
|
// Commands
|
||||||
for (final AbstractCommand command : commands) {
|
for (final AbstractCommand command : commands) {
|
||||||
if (command.isPublic() && command.getCommand().startsWith(cmd)) {
|
if (command.isPublic() && command.getCommand().startsWith(cmd)) {
|
||||||
command.commandResponse(this, sender, login, args, isOp(sender), false);
|
command.commandResponse(this, sender, login, args, isOp(sender), false);
|
||||||
skip = true;
|
return;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!skip) {
|
|
||||||
// Modules
|
// Modules
|
||||||
for (final AbstractModule module : modules) { // modules
|
for (final AbstractModule module : modules) { // modules
|
||||||
for (final String c : module.getCommands()) {
|
for (final String c : module.getCommands()) {
|
||||||
if (cmd.startsWith(c)) {
|
if (cmd.startsWith(c)) {
|
||||||
module.commandResponse(this, sender, cmd, args, false);
|
module.commandResponse(this, sender, cmd, args, false);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else { // Commands
|
// Commands, e.g.: https://www.example.com/
|
||||||
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);
|
||||||
isCommand = true;
|
return;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isCommand) {
|
|
||||||
Recap.storeRecap(sender, message, false);
|
Recap.storeRecap(sender, message, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tell.isEnabled()) {
|
|
||||||
tell.send(sender, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -1014,15 +981,6 @@ public class Mobibot extends PircBot {
|
||||||
backLogsUrl = url;
|
backLogsUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the feed URL.
|
|
||||||
*
|
|
||||||
* @param feedUrl The feed URL.
|
|
||||||
*/
|
|
||||||
final void setFeedUrl(final String feedUrl) {
|
|
||||||
this.feedUrl = feedUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the bot's identification.
|
* Sets the bot's identification.
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Feed.kt
|
||||||
|
*
|
||||||
|
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* Neither the name of this project nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software without
|
||||||
|
* specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.thauvin.erik.mobibot.commands
|
||||||
|
|
||||||
|
import net.thauvin.erik.mobibot.FeedReader
|
||||||
|
import net.thauvin.erik.mobibot.Mobibot
|
||||||
|
import net.thauvin.erik.mobibot.Utils
|
||||||
|
import org.apache.commons.lang3.StringUtils.isNotBlank
|
||||||
|
|
||||||
|
class ChannelFeed(channel: String, private val feedUrl: String) : AbstractCommand() {
|
||||||
|
override val command = channel
|
||||||
|
override val help = listOf(
|
||||||
|
"To list the last 5 posts from the channel's weblog feed:",
|
||||||
|
Utils.helpIndent("%c $channel")
|
||||||
|
)
|
||||||
|
override val isOp = false
|
||||||
|
override val isPublic = true
|
||||||
|
override val isVisible = true
|
||||||
|
|
||||||
|
override fun commandResponse(
|
||||||
|
bot: Mobibot,
|
||||||
|
sender: String,
|
||||||
|
login: String,
|
||||||
|
args: String,
|
||||||
|
isOp: Boolean,
|
||||||
|
isPrivate: Boolean
|
||||||
|
) {
|
||||||
|
if (isNotBlank(feedUrl)) {
|
||||||
|
Thread(FeedReader(bot, sender, feedUrl)).start()
|
||||||
|
} else {
|
||||||
|
bot.send(sender, "There is no feed setup for this channel.", false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue