From fc36badd683547f6c9a0f9d39a9be7c722094cd8 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Tue, 27 Oct 2015 23:02:38 -0500 Subject: [PATCH] !stalk: a little safer; support wildcards --- earwigbot/commands/stalk.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/earwigbot/commands/stalk.py b/earwigbot/commands/stalk.py index 2573214..2b04782 100644 --- a/earwigbot/commands/stalk.py +++ b/earwigbot/commands/stalk.py @@ -76,11 +76,12 @@ class Stalk(Command): self.reply(data, self._current_stalks(data.nick)) return - target = " ".join(data.args) + 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 data.command in ["stalk", "watch"]: if data.is_private: @@ -118,11 +119,18 @@ class Stalk(Command): else: chans[item[0]] = None + def _wildcard_match(target, tag): + return target[-1] == "*" and tag.startswith(target[:-1]) + + def _process(table, tag): + for target, stalks in table.iteritems(): + if target == tag or _wildcard_match(target, tag): + _update_chans(stalks) + chans = {} - if rc.user in self._users: - _update_chans(self._users[rc.user]) - if rc.is_edit and rc.page in self._pages: - _update_chans(self._pages[rc.page]) + _process(self._users, rc.user) + if rc.is_edit: + _process(self._pages, rc.page) if not chans: return