Change factoids.py to use regex commands

This commit is contained in:
jesopo 2019-05-18 20:18:55 +01:00
parent 6f0b31cb9a
commit 3b9efe769a

View file

@ -1,8 +1,6 @@
import re import re
from src import ModuleManager, utils from src import ModuleManager, utils
REGEX_FACTOID = re.compile("{!factoid ([^}]+)}", re.I)
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
def _get_factoid(self, server, factoid): def _get_factoid(self, server, factoid):
name = factoid.lower().strip() name = factoid.lower().strip()
@ -26,17 +24,13 @@ class Module(ModuleManager.BaseModule):
raise utils.EventError("Unknown factoid '%s'" % name) raise utils.EventError("Unknown factoid '%s'" % name)
event["stdout"].write("%s: %s" % (name, value)) event["stdout"].write("%s: %s" % (name, value))
@utils.hook("received.message.channel") @utils.hook("command.regex")
def channel_message(self, event): def channel_message(self, event):
match = REGEX_FACTOID.search(event["message"]) """
if match: :command: factoid
is_ignored_f = short_url = self.exports.get_one("is-ignored", :pattern: {!factoid ([^}]+)}
lambda _1, _2: False) """
if is_ignored_f(event["server"], event["user"], "factoid"): name, value = self._get_factoid(event["server"],
return event["match"].group(1))
if not value == None:
name, value = self._get_factoid(event["server"], match.group(1)) event["stdout"].write("%s: %s" % (name, value))
if not value == None:
self.events.on("send.stdout").call(target=event["channel"],
module_name="Factoids", server=event["server"],
message="%s: %s" % (name, value))