Skip to content

Commit 7f6f9fc

Browse files
committed
Clean up correction logic
1 parent 8538c05 commit 7f6f9fc

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

plugins/correction.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ def correction(match, conn, nick, chan, message):
2323
if not find.strip(): # Replacing empty or entirely whitespace strings is spammy
2424
return "really dude? you want me to replace nothing with {}?".format(replace)
2525

26-
for item in conn.history[chan].__reversed__():
27-
name, timestamp, msg = item
26+
for name, timestamp, msg in reversed(conn.history[chan]):
2827
if correction_re.match(msg):
2928
# don't correct corrections, it gets really confusing
3029
continue
3130

3231
if find.lower() in msg.lower():
3332
find_esc = re.escape(find)
3433
replace_esc = re.escape(replace)
35-
if "\x01ACTION" in msg:
36-
msg = msg.replace("\x01ACTION", "").replace("\x01", "")
37-
mod_msg = ireplace(msg, find_esc, "\x02" + replace_esc + "\x02")
38-
message("Correction, * {} {}".format(name, mod_msg))
34+
if msg.startswith('\x01ACTION'):
35+
mod_msg = msg[7:].strip(' \x01')
36+
fmt = "* {} {}"
3937
else:
40-
mod_msg = ireplace(msg, find_esc, "\x02" + replace_esc + "\x02")
41-
message("Correction, <{}> {}".format(name, mod_msg))
38+
mod_msg = msg
39+
fmt = "<{}> {}"
40+
41+
mod_msg = ireplace(mod_msg, find_esc, "\x02" + replace_esc + "\x02")
42+
43+
message("Correction, {}".format(fmt.format(name, mod_msg)))
4244

4345
msg = ireplace(msg, find_esc, replace_esc)
4446
if nick.lower() == name.lower():
4547
conn.history[chan].append((name, timestamp, msg))
46-
return
47-
else:
48-
continue
49-
# return("No matches for \"\x02{}\x02\" in recent messages from \x02{}\x02. You can only correct your own messages.".format(find, nick))
48+
49+
break

0 commit comments

Comments
 (0)