Fix message hooks
This commit is contained in:
parent
db7bb4ad3a
commit
68c88fc864
6
hooks.py
6
hooks.py
@ -138,16 +138,18 @@ class MessagesHook:
|
|||||||
|
|
||||||
def treat_answer(self, msg):
|
def treat_answer(self, msg):
|
||||||
"""Treat a normal message"""
|
"""Treat a normal message"""
|
||||||
|
treated = False
|
||||||
|
|
||||||
# First, treat simple hook
|
# First, treat simple hook
|
||||||
if msg.content in self.msg_hook:
|
if msg.content in self.msg_hook:
|
||||||
for h in self.msg_hook[msg.content]:
|
for h in self.msg_hook[msg.content]:
|
||||||
h.run(msg)
|
treated |= h.run(msg)
|
||||||
self.check_rest_times(self.msg_hook, h)
|
self.check_rest_times(self.msg_hook, h)
|
||||||
|
|
||||||
# Then, treat regexp based hook
|
# Then, treat regexp based hook
|
||||||
for hook in self.msg_rgxp:
|
for hook in self.msg_rgxp:
|
||||||
if hook.is_matching(msg.content, msg.channel):
|
if hook.is_matching(msg.content, msg.channel):
|
||||||
hook.run(msg)
|
treated |= hook.run(msg)
|
||||||
self.check_rest_times(self.msg_rgxp, hook)
|
self.check_rest_times(self.msg_rgxp, hook)
|
||||||
|
|
||||||
# Finally, treat default hooks if not catched before
|
# Finally, treat default hooks if not catched before
|
||||||
|
@ -214,7 +214,7 @@ def register_hooks(module, context, prompt):
|
|||||||
if hasattr(module, "parseask"):
|
if hasattr(module, "parseask"):
|
||||||
context.hooks.add_hook(context.hooks.ask_default, Hook(module.parseask))
|
context.hooks.add_hook(context.hooks.ask_default, Hook(module.parseask))
|
||||||
if hasattr(module, "parselisten"):
|
if hasattr(module, "parselisten"):
|
||||||
context.hooks.add_hook(context.hooks.ask_default, Hook(module.parselisten))
|
context.hooks.add_hook(context.hooks.msg_default, Hook(module.parselisten))
|
||||||
|
|
||||||
##########################
|
##########################
|
||||||
# #
|
# #
|
||||||
|
@ -19,7 +19,7 @@ def help_full ():
|
|||||||
def reload():
|
def reload():
|
||||||
imp.reload(Tinyfier)
|
imp.reload(Tinyfier)
|
||||||
|
|
||||||
def cmd_ycc(data, msg):
|
def cmd_ycc(msg):
|
||||||
global LAST_URLS
|
global LAST_URLS
|
||||||
if len(msg.cmd) == 1:
|
if len(msg.cmd) == 1:
|
||||||
if msg.channel in LAST_URLS and len(LAST_URLS[msg.channel]) > 0:
|
if msg.channel in LAST_URLS and len(LAST_URLS[msg.channel]) > 0:
|
||||||
@ -27,7 +27,7 @@ def cmd_ycc(data, msg):
|
|||||||
t = Tinyfier.Tinyfier(url, msg)
|
t = Tinyfier.Tinyfier(url, msg)
|
||||||
t.start()
|
t.start()
|
||||||
else:
|
else:
|
||||||
msg.send_chn("%s: je n'ai pas d'autre URL reduire" % msg.nick)
|
msg.send_chn("%s: je n'ai pas d'autre URL à réduire" % msg.nick)
|
||||||
else:
|
else:
|
||||||
if len(msg.cmd) < 6:
|
if len(msg.cmd) < 6:
|
||||||
for url in msg.cmd[1:]:
|
for url in msg.cmd[1:]:
|
||||||
@ -41,7 +41,7 @@ def cmd_ycc(data, msg):
|
|||||||
|
|
||||||
LAST_URLS = dict()
|
LAST_URLS = dict()
|
||||||
|
|
||||||
def parselisten(data, msg):
|
def parselisten(msg):
|
||||||
global LAST_URLS
|
global LAST_URLS
|
||||||
if re.match(".*(https?://|www\.)[^ ]+.*", msg.content) is not None:
|
if re.match(".*(https?://|www\.)[^ ]+.*", msg.content) is not None:
|
||||||
res = re.match(".*(((ht|f)tps?://|www\.)[^ ]+).*", msg.content)
|
res = re.match(".*(((ht|f)tps?://|www\.)[^ ]+).*", msg.content)
|
||||||
|
Loading…
Reference in New Issue
Block a user