Browse Source

Suport regexes for !stalk.

tags/v0.3
Ben Kurtovic 9 years ago
parent
commit
c40ba21a09
2 changed files with 12 additions and 7 deletions
  1. +1
    -0
      CHANGELOG
  2. +11
    -7
      earwigbot/commands/stalk.py

+ 1
- 0
CHANGELOG View File

@@ -3,6 +3,7 @@ v0.3 (unreleased):
- Copyvio detector: improved sentence splitting algorithm. - Copyvio detector: improved sentence splitting algorithm.
- IRC > !remind: Added !remind all. Fixed multithreading efficiency issues. - IRC > !remind: Added !remind all. Fixed multithreading efficiency issues.
Improved time detection. Improved time detection.
- IRC > !stalk: Allow regular expressions as page titles or usernames.
- IRC: Improved detection of maximum IRC message length. - IRC: Improved detection of maximum IRC message length.
- IRC: Improved some help commands. - IRC: Improved some help commands.




+ 11
- 7
earwigbot/commands/stalk.py View File

@@ -21,13 +21,14 @@
# SOFTWARE. # SOFTWARE.


from ast import literal_eval from ast import literal_eval
import re


from earwigbot.commands import Command from earwigbot.commands import Command
from earwigbot.irc import RC from earwigbot.irc import RC


class Stalk(Command): class Stalk(Command):
"""Stalk a particular user (!stalk/!unstalk) or page (!watch/!unwatch) for """Stalk a particular user (!stalk/!unstalk) or page (!watch/!unwatch) for
edits. Applies to the current bot session only."""
edits. Prefix regular expressions with "re:" (uses re.match)."""
name = "stalk" name = "stalk"
commands = ["stalk", "watch", "unstalk", "unwatch", "stalks", "watches", commands = ["stalk", "watch", "unstalk", "unwatch", "stalks", "watches",
"allstalks", "allwatches", "unstalkall", "unwatchall"] "allstalks", "allwatches", "unstalkall", "unwatchall"]
@@ -79,9 +80,12 @@ class Stalk(Command):
target = " ".join(data.args).replace("_", " ") target = " ".join(data.args).replace("_", " ")
if target.startswith("[[") and target.endswith("]]"): if target.startswith("[[") and target.endswith("]]"):
target = target[2:-2] target = target[2:-2]
if target.startswith("User:") and "stalk" in data.command:
target = target[5:]
target = target[0].upper() + target[1:]
if target.startswith("re:"):
target = "re:" + target[3:].lstrip()
else:
if target.startswith("User:") and "stalk" in data.command:
target = target[5:]
target = target[0].upper() + target[1:]


if data.command in ["stalk", "watch"]: if data.command in ["stalk", "watch"]:
if data.is_private: if data.is_private:
@@ -119,12 +123,12 @@ class Stalk(Command):
else: else:
chans[item[0]] = None chans[item[0]] = None


def _wildcard_match(target, tag):
return target[-1] == "*" and tag.startswith(target[:-1])
def _regex_match(target, tag):
return target.startswith("re:") and re.match(target[3:], tag)


def _process(table, tag): def _process(table, tag):
for target, stalks in table.iteritems(): for target, stalks in table.iteritems():
if target == tag or _wildcard_match(target, tag):
if target == tag or _regex_match(target, tag):
_update_chans(stalks) _update_chans(stalks)


chans = {} chans = {}


Loading…
Cancel
Save