1
0
mirror of https://github.com/sys-fs/seddy synced 2024-11-22 03:44:17 -05:00

Fix bugs that tired eyes overlooked

This commit is contained in:
Thomas Mannay 2018-02-01 18:37:38 +00:00
parent b8f5234066
commit bebadf0bfb

27
seddy.py Normal file → Executable file
View File

@ -1,6 +1,8 @@
#!/usr/bin/python3 #!/usr/bin/python3
# See the LICENSE file for licensing information # See the LICENSE file for licensing information
import re import re
from time import sleep
from random import choice
nick = 'seddy' nick = 'seddy'
server = 'chat.freenode.net' server = 'chat.freenode.net'
@ -10,7 +12,7 @@ gecos = 'A text processing bot'
receive = '/tmp/{0}.in'.format(server) receive = '/tmp/{0}.in'.format(server)
send = '/tmp/{0}.out'.format(server) send = '/tmp/{0}.out'.format(server)
parse_msg = re.compile(channel + ' :(.*)') parse_msg = re.compile('.* PRIVMSG ' + channel + ' :(.*)')
parse_sed = re.compile('(?<!\\\\)/') parse_sed = re.compile('(?<!\\\\)/')
is_sed = re.compile('^s/.*/.*') is_sed = re.compile('^s/.*/.*')
ping = re.compile('PING :(.*)') ping = re.compile('PING :(.*)')
@ -45,12 +47,12 @@ class Queue:
def empty(self): def empty(self):
return self.head == self.count return self.head == self.count
def find(self, s, flags=0): def find(self, s, f=0):
i = self.tail-1 i = self.tail-1
while True: while True:
if i == -1: if i == -1:
i = self.size-1 i = self.size-1
if re.search(s, self.data[i], flags): if re.search(s, self.data[i], f):
return self.data[i] return self.data[i]
i -= 1 i -= 1
if i == self.tail-1 or self.data[i] is None: if i == self.tail-1 or self.data[i] is None:
@ -79,9 +81,9 @@ def seddy(sed, history, parser):
except: except:
return False return False
if "g" in regex[3]: if "g" in regex[3]:
res = msg_replace(regex[1], regex[2], msg, 0, f) res = msg_replace(regex[1], regex[2], msg, f, n=0)
else: else:
res = msg_replace(regex[1], regex[2], msg, 1, f) res = msg_replace(regex[1], regex[2], msg, f)
if res: if res:
res = res.replace('\0', re.search(regex[1], msg, f).group(0)) res = res.replace('\0', re.search(regex[1], msg, f).group(0))
return res return res
@ -118,8 +120,7 @@ if __name__ == "__main__":
m = parse_msg.match(line) m = parse_msg.match(line)
try: try:
channel = m.group(1) msg = m.group(1)
msg = m.group(2)
except: except:
continue continue
@ -129,10 +130,14 @@ if __name__ == "__main__":
history.enqueue(msg) history.enqueue(msg)
if '.bots' in msg[:5] or '.bot ' + nick in msg[:5 + len(nick)]: if '.bots' in msg[:5] or '.bot ' + nick in msg[:5 + len(nick)]:
notice("I was written to correct your mistakes.") notice("I was written to correct your mistakes.", channel)
if '.source ' + nick in msg[:8 + len(nick)]: if '.source ' + nick in msg[:8 + len(nick)]:
notice('[Python] https://github.com/sys-fs/seddy') notice('[Python] https://github.com/sys-fs/seddy', channel)
elif is_sed.match(msg): elif is_sed.match(msg):
res = seddy(msg, history) res = seddy(msg, history, parse_sed)
if res: if res:
privmsg(re.sub('\\\\/', '/', foo)) res = re.sub('\\\\/', '/', res)
if history.full():
history.dequeue()
history.enqueue(res)
privmsg(res, channel)