2013-08-07 15:29:51 +02:00
|
|
|
from util import hook
|
|
|
|
|
2014-02-28 01:59:31 +01:00
|
|
|
import re
|
|
|
|
|
2014-02-28 08:08:50 +01:00
|
|
|
CORRECTION_RE = r'^(s|S)/.*/.*/?\S*$'
|
2014-02-28 01:59:31 +01:00
|
|
|
|
2013-08-07 15:29:51 +02:00
|
|
|
|
2014-02-28 07:48:46 +01:00
|
|
|
@hook.regex(CORRECTION_RE)
|
2014-03-01 06:40:36 +01:00
|
|
|
def correction(match, input=None, conn=None, message=None):
|
2014-02-28 01:59:31 +01:00
|
|
|
split = input.msg.split("/")
|
|
|
|
|
2014-02-28 08:08:50 +01:00
|
|
|
if len(split) == 4:
|
|
|
|
nick = split[3].lower()
|
|
|
|
else:
|
|
|
|
nick = None
|
|
|
|
|
2014-02-28 01:59:31 +01:00
|
|
|
find = split[1]
|
|
|
|
replace = split[2]
|
|
|
|
|
2014-03-01 06:40:36 +01:00
|
|
|
for item in conn.history[input.chan].__reversed__():
|
2014-02-28 01:59:31 +01:00
|
|
|
name, timestamp, msg = item
|
2014-02-28 07:48:46 +01:00
|
|
|
if msg.startswith("s/"):
|
|
|
|
# don't correct corrections, it gets really confusing
|
|
|
|
continue
|
2014-02-28 08:08:50 +01:00
|
|
|
if nick:
|
|
|
|
if nick != name.lower():
|
|
|
|
continue
|
2014-02-28 01:59:31 +01:00
|
|
|
if find in msg:
|
|
|
|
if "\x01ACTION" in msg:
|
|
|
|
msg = msg.replace("\x01ACTION ", "/me ").replace("\x01", "")
|
|
|
|
message(u"Correction, <{}> {}".format(name, msg.replace(find, "\x02" + replace + "\x02")))
|
|
|
|
return
|
2013-08-10 20:52:43 +02:00
|
|
|
else:
|
2014-02-28 01:59:31 +01:00
|
|
|
continue
|
|
|
|
|
2014-02-28 07:48:46 +01:00
|
|
|
return u"Did not find {} in any recent messages.".format(find)
|
2014-02-28 01:59:31 +01:00
|
|
|
|