This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/disabled_stuff/correction.py

38 lines
981 B
Python
Raw Normal View History

from util import hook
import re
2014-02-28 08:08:50 +01:00
CORRECTION_RE = r'^(s|S)/.*/.*/?\S*$'
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):
split = input.msg.split("/")
2014-02-28 08:08:50 +01:00
if len(split) == 4:
nick = split[3].lower()
else:
nick = None
find = split[1]
replace = split[2]
2014-03-01 06:40:36 +01:00
for item in conn.history[input.chan].__reversed__():
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
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
else:
continue
2014-02-28 07:48:46 +01:00
return u"Did not find {} in any recent messages.".format(find)