rewrite correction to use new history tracker
This commit is contained in:
parent
914bc255ab
commit
b9bf09e6b6
2 changed files with 25 additions and 25 deletions
|
@ -1,30 +1,30 @@
|
||||||
from util import hook
|
from util import hook
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
CORRECTION_RE = re.compile(r'^(s|S)/.*/.*/\S*$')
|
||||||
|
|
||||||
|
|
||||||
@hook.regex(r'^(s|S)/.*/.*/\S*$')
|
@hook.regex(r'^(s|S)/.*/.*/\S*$')
|
||||||
def correction(inp, message=None, input=None, notice=None, db=None):
|
def correction(inp, input=None, bot=None, message=None):
|
||||||
splitinput = input.msg.split("/")
|
split = input.msg.split("/")
|
||||||
if splitinput[3]:
|
|
||||||
nick = splitinput[3]
|
|
||||||
else:
|
|
||||||
nick = input.nick
|
|
||||||
last_message = db.execute("select name, quote from seen_user where name"
|
|
||||||
" like ? and chan = ?", (nick.lower(), input.chan.lower())).fetchone()
|
|
||||||
|
|
||||||
if last_message:
|
find = split[1]
|
||||||
splitinput = input.msg.split("/")
|
replace = split[2]
|
||||||
find = splitinput[1]
|
|
||||||
replace = splitinput[2]
|
for item in bot.history[input.chan].__reversed__():
|
||||||
if find in last_message[1]:
|
name, timestamp, msg = item
|
||||||
if "\x01ACTION" in last_message[1]:
|
if "/" in msg:
|
||||||
msg = last_message[1].replace("\x01ACTION ", "/me ").replace("\x01", "")
|
if re.match(CORRECTION_RE, msg):
|
||||||
else:
|
# don't correct corrections, it gets really confusing
|
||||||
msg = last_message[1]
|
continue
|
||||||
message(u"Correction, <{}> {}".format(nick, msg.replace(find, "\x02" + replace + "\x02")))
|
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:
|
else:
|
||||||
notice(u"{} can't be found in your last message".format(find))
|
continue
|
||||||
else:
|
|
||||||
if nick == input.nick:
|
return "Did not find {} in any recent messages.".format(find)
|
||||||
notice(u"I haven't seen you say anything here yet")
|
|
||||||
else:
|
|
||||||
notice(u"I haven't seen {} say anything here yet".format(nick))
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ def track_history(input, message_time, bot):
|
||||||
bot.history[input.chan] = deque(maxlen=1000)
|
bot.history[input.chan] = deque(maxlen=1000)
|
||||||
history = bot.history[input.chan]
|
history = bot.history[input.chan]
|
||||||
|
|
||||||
data = (input.nick.lower(), message_time, input.msg)
|
data = (input.nick, message_time, input.msg)
|
||||||
history.append(data)
|
history.append(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue