This repository has been archived on 2023-04-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CloudBot/disabled_stuff/correction.py

38 lines
981 B
Python
Raw Permalink Normal View History

from util import hook
import re
2014-02-28 20:08:50 +13:00
CORRECTION_RE = r'^(s|S)/.*/.*/?\S*$'
2014-02-28 19:48:46 +13:00
@hook.regex(CORRECTION_RE)
2014-03-01 18:40:36 +13:00
def correction(match, input=None, conn=None, message=None):
split = input.msg.split("/")
2014-02-28 20:08:50 +13:00
if len(split) == 4:
nick = split[3].lower()
else:
nick = None
find = split[1]
replace = split[2]
2014-03-01 18:40:36 +13:00
for item in conn.history[input.chan].__reversed__():
name, timestamp, msg = item
2014-02-28 19:48:46 +13:00
if msg.startswith("s/"):
# don't correct corrections, it gets really confusing
continue
2014-02-28 20:08:50 +13: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 19:48:46 +13:00
return u"Did not find {} in any recent messages.".format(find)