Bladeren bron

Suport regexes for !stalk.

tags/v0.3
Ben Kurtovic 9 jaren geleden
bovenliggende
commit
c40ba21a09
2 gewijzigde bestanden met toevoegingen van 12 en 7 verwijderingen
  1. +1
    -0
      CHANGELOG
  2. +11
    -7
      earwigbot/commands/stalk.py

+ 1
- 0
CHANGELOG Bestand weergeven

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



+ 11
- 7
earwigbot/commands/stalk.py Bestand weergeven

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

from ast import literal_eval
import re

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

class Stalk(Command):
"""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"
commands = ["stalk", "watch", "unstalk", "unwatch", "stalks", "watches",
"allstalks", "allwatches", "unstalkall", "unwatchall"]
@@ -79,9 +80,12 @@ class Stalk(Command):
target = " ".join(data.args).replace("_", " ")
if target.startswith("[[") and target.endswith("]]"):
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.is_private:
@@ -119,12 +123,12 @@ class Stalk(Command):
else:
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):
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)

chans = {}


Laden…
Annuleren
Opslaan