Added tags keywords.
This commit is contained in:
parent
72961dadc9
commit
68ddcd1ccc
2 changed files with 36 additions and 32 deletions
|
@ -12,6 +12,7 @@ ident=changepwd
|
||||||
logs=./logs
|
logs=./logs
|
||||||
ignore=chanserv,nickserv
|
ignore=chanserv,nickserv
|
||||||
tags=mobile mobitopia
|
tags=mobile mobitopia
|
||||||
|
tags-keywords=android ios apple google
|
||||||
|
|
||||||
weblog=http://www.mobitopia.org/
|
weblog=http://www.mobitopia.org/
|
||||||
feed=http://www.mobitopia.org/rss.xml
|
feed=http://www.mobitopia.org/rss.xml
|
||||||
|
|
|
@ -111,34 +111,25 @@ public class Mobibot extends PircBot {
|
||||||
|
|
||||||
// Default port
|
// Default port
|
||||||
private static final int DEFAULT_PORT = 6667;
|
private static final int DEFAULT_PORT = 6667;
|
||||||
|
|
||||||
// Default server
|
// Default server
|
||||||
private static final String DEFAULT_SERVER = "irc.freenode.net";
|
private static final String DEFAULT_SERVER = "irc.freenode.net";
|
||||||
|
|
||||||
// Info strings
|
// Info strings
|
||||||
@SuppressWarnings("indentation")
|
@SuppressWarnings("indentation")
|
||||||
private static final String[] INFO_STRS = {
|
private static final String[] INFO_STRS = {
|
||||||
ReleaseInfo.PROJECT + " v" + ReleaseInfo.VERSION + " by Erik C. Thauvin (erik@thauvin.net)",
|
ReleaseInfo.PROJECT + " v" + ReleaseInfo.VERSION + " by Erik C. Thauvin (erik@thauvin.net)",
|
||||||
"https://www.mobitopia.org/mobibot/" };
|
"https://www.mobitopia.org/mobibot/" };
|
||||||
|
|
||||||
// Link match string
|
// Link match string
|
||||||
private static final String LINK_MATCH = "^[hH][tT][tT][pP](|[sS])://.*";
|
private static final String LINK_MATCH = "^[hH][tT][tT][pP](|[sS])://.*";
|
||||||
|
|
||||||
// Default maximum number of entries to display
|
// Default maximum number of entries to display
|
||||||
private static final int MAX_ENTRIES = 8;
|
private static final int MAX_ENTRIES = 8;
|
||||||
|
|
||||||
// Default maximum recap entries
|
// Default maximum recap entries
|
||||||
private static final int MAX_RECAP = 10;
|
private static final int MAX_RECAP = 10;
|
||||||
|
|
||||||
// Maximum number of times the bot will try to reconnect, if disconnected
|
// Maximum number of times the bot will try to reconnect, if disconnected
|
||||||
private static final int MAX_RECONNECT = 10;
|
private static final int MAX_RECONNECT = 10;
|
||||||
|
|
||||||
// Number of milliseconds to delay between consecutive messages
|
// Number of milliseconds to delay between consecutive messages
|
||||||
private static final long MESSAGE_DELAY = 1000L;
|
private static final long MESSAGE_DELAY = 1000L;
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
private static final List<AbstractModule> MODULES = new ArrayList<>(0);
|
private static final List<AbstractModule> MODULES = new ArrayList<>(0);
|
||||||
|
|
||||||
// Tags/categories marker
|
// Tags/categories marker
|
||||||
private static final String TAGS_MARKER = "tags:";
|
private static final String TAGS_MARKER = "tags:";
|
||||||
// Version strings
|
// Version strings
|
||||||
|
@ -175,10 +166,12 @@ public class Mobibot extends PircBot {
|
||||||
private final String logsDir;
|
private final String logsDir;
|
||||||
// Recap array
|
// Recap array
|
||||||
private final List<String> recap = new ArrayList<>(0);
|
private final List<String> recap = new ArrayList<>(0);
|
||||||
|
// Tags keywords matches
|
||||||
|
private final List<String> tagsKeywords = new ArrayList<>();
|
||||||
// Tell object
|
// Tell object
|
||||||
private final Tell tell;
|
private final Tell tell;
|
||||||
// The Twitter auto-posts list.
|
// The Twitter auto-posts list.
|
||||||
private final List<Integer> twitterAutoLinks = Collections.synchronizedList(new ArrayList<>());
|
private final List<Integer> twitterAutoLinks = new ArrayList<>();
|
||||||
// Automatically post links to Twitter
|
// Automatically post links to Twitter
|
||||||
private final boolean twitterAutoPost;
|
private final boolean twitterAutoPost;
|
||||||
// Twitter handle for channel join notifications
|
// Twitter handle for channel join notifications
|
||||||
|
@ -308,6 +301,7 @@ public class Mobibot extends PircBot {
|
||||||
|
|
||||||
// Set the tags
|
// Set the tags
|
||||||
setTags(p.getProperty("tags", ""));
|
setTags(p.getProperty("tags", ""));
|
||||||
|
setTagsKeywords(p.getProperty("tags-keywords", ""));
|
||||||
|
|
||||||
// Set the ignored nicks
|
// Set the ignored nicks
|
||||||
setIgnoredNicks(p.getProperty("ignore", ""));
|
setIgnoredNicks(p.getProperty("ignore", ""));
|
||||||
|
@ -895,7 +889,6 @@ public class Mobibot extends PircBot {
|
||||||
*/
|
*/
|
||||||
public final void joinChannel() {
|
public final void joinChannel() {
|
||||||
joinChannel(ircChannel);
|
joinChannel(ircChannel);
|
||||||
|
|
||||||
twitterNotification("has joined " + ircChannel);
|
twitterNotification("has joined " + ircChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -983,6 +976,14 @@ public class Mobibot extends PircBot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!tagsKeywords.isEmpty()) {
|
||||||
|
for (final String match : tagsKeywords) {
|
||||||
|
if (title.matches("(?i).*\\b" + match.trim() + "\\b.*")) {
|
||||||
|
tags.append(' ').append(match.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entries.add(new EntryLink(link, title, sender, login, channel, tags.toString()));
|
entries.add(new EntryLink(link, title, sender, login, channel, tags.toString()));
|
||||||
|
|
||||||
final int index = entries.size() - 1;
|
final int index = entries.size() - 1;
|
||||||
|
@ -1023,7 +1024,6 @@ public class Mobibot extends PircBot {
|
||||||
args = cmds[1].trim();
|
args = cmds[1].trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (cmd.startsWith(Commands.HELP_CMD)) { // mobibot: help
|
if (cmd.startsWith(Commands.HELP_CMD)) { // mobibot: help
|
||||||
helpResponse(sender, args);
|
helpResponse(sender, args);
|
||||||
} else if (Commands.RECAP_CMD.equals(cmd)) { // mobibot: recap
|
} else if (Commands.RECAP_CMD.equals(cmd)) { // mobibot: recap
|
||||||
|
@ -1093,8 +1093,6 @@ public class Mobibot extends PircBot {
|
||||||
entries.remove(index);
|
entries.remove(index);
|
||||||
send(channel, "Entry " + Commands.LINK_CMD + (index + 1) + " removed.");
|
send(channel, "Entry " + Commands.LINK_CMD + (index + 1) + " removed.");
|
||||||
saveEntries(false);
|
saveEntries(false);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
send(sender, "Please ask a channel op to remove this entry for you.");
|
send(sender, "Please ask a channel op to remove this entry for you.");
|
||||||
}
|
}
|
||||||
|
@ -1265,7 +1263,7 @@ public class Mobibot extends PircBot {
|
||||||
twitterShutdown();
|
twitterShutdown();
|
||||||
twitterNotification("killed by " + sender + " on " + ircChannel);
|
twitterNotification("killed by " + sender + " on " + ircChannel);
|
||||||
saveEntries(true);
|
saveEntries(true);
|
||||||
sleep(10);
|
sleep(3);
|
||||||
quitServer("The Bot Is Out There!");
|
quitServer("The Bot Is Out There!");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
} else if (Commands.CYCLE_CMD.equals(cmd)) {
|
} else if (Commands.CYCLE_CMD.equals(cmd)) {
|
||||||
|
@ -1337,7 +1335,6 @@ public class Mobibot extends PircBot {
|
||||||
Configurator.setLevel(logger.getName(), Level.DEBUG);
|
Configurator.setLevel(logger.getName(), Level.DEBUG);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
send(sender, "Debug logging is " + (logger.isDebugEnabled() ? "enabled." : "disabled."), true);
|
send(sender, "Debug logging is " + (logger.isDebugEnabled() ? "enabled." : "disabled."), true);
|
||||||
} else {
|
} else {
|
||||||
for (final AbstractModule module : MODULES) {
|
for (final AbstractModule module : MODULES) {
|
||||||
|
@ -1553,6 +1550,19 @@ public class Mobibot extends PircBot {
|
||||||
defaultTags = tags;
|
defaultTags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the tags keywords matches.
|
||||||
|
*
|
||||||
|
* @param matches The tags keywords.
|
||||||
|
*/
|
||||||
|
final void setTagsKeywords(final String matches) {
|
||||||
|
if (isNotBlank(matches)) {
|
||||||
|
tagsKeywords.addAll(Arrays.asList(matches.split(", +?| +")));
|
||||||
|
} else {
|
||||||
|
tagsKeywords.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the weblog URL.
|
* Sets the weblog URL.
|
||||||
*
|
*
|
||||||
|
@ -1630,13 +1640,11 @@ public class Mobibot extends PircBot {
|
||||||
*/
|
*/
|
||||||
final void twitterShutdown() {
|
final void twitterShutdown() {
|
||||||
if (twitterModule.isEnabled() && isNotBlank(twitterHandle)) {
|
if (twitterModule.isEnabled() && isNotBlank(twitterHandle)) {
|
||||||
synchronized (twitterAutoLinks) {
|
|
||||||
for (final int i : twitterAutoLinks) {
|
for (final int i : twitterAutoLinks) {
|
||||||
twitterAutoPost(i);
|
twitterAutoPost(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responds with the users on a channel.
|
* Responds with the users on a channel.
|
||||||
|
@ -1649,22 +1657,17 @@ public class Mobibot extends PircBot {
|
||||||
final String[] nicks = new String[users.length];
|
final String[] nicks = new String[users.length];
|
||||||
|
|
||||||
for (int i = 0; i < users.length; i++) {
|
for (int i = 0; i < users.length; i++) {
|
||||||
|
final String nick = users[i].getNick();
|
||||||
|
if (isOp(nick)) {
|
||||||
|
nicks[i] = '@' + users[i].getNick();
|
||||||
|
} else {
|
||||||
nicks[i] = users[i].getNick();
|
nicks[i] = users[i].getNick();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Arrays.sort(nicks, String.CASE_INSENSITIVE_ORDER);
|
Arrays.sort(nicks, String.CASE_INSENSITIVE_ORDER);
|
||||||
|
|
||||||
final StringBuilder buff = new StringBuilder(0);
|
send(sender, String.join(" ", nicks), isPrivate);
|
||||||
|
|
||||||
for (final String nick : nicks) {
|
|
||||||
if (isOp(nick)) {
|
|
||||||
buff.append('@');
|
|
||||||
}
|
|
||||||
|
|
||||||
buff.append(nick).append(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
send(sender, buff.toString(), isPrivate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue