fix default channel, make ping less noisy

This commit is contained in:
~d6 2024-01-26 00:42:05 -05:00
parent 7e624d550b
commit 586d14bc69
1 changed files with 12 additions and 10 deletions

View File

@ -8,8 +8,8 @@ from sys import argv, stdin, stdout
from tempfile import mkdtemp, mkstemp from tempfile import mkdtemp, mkstemp
server = "irc.libera.chat" server = "irc.libera.chat"
nick = b"uxnbot7" nick = b"uxnbot"
channel = b"#uxnbot" channel = b"#uxn"
sandbox = None sandbox = None
irc = None irc = None
@ -83,13 +83,19 @@ def repl():
stdout.write(execute(s).decode('utf-8')) stdout.write(execute(s).decode('utf-8'))
stdout.flush() stdout.flush()
def send(msg): ping_re = re.compile(br'PING (.+)$')
print('>>> %r' % msg) chan_msg_re = re.compile(br':([^!]+)![^ ]+ PRIVMSG ([^ ]+) :' + nick + br': (.*)$')
priv_msg_re = re.compile(br':([^!]+)![^ ]+ PRIVMSG ' + nick + br' :(.*)$')
def send(msg, quiet=False):
if not quiet:
print('>>> %r' % msg)
irc.send(msg + b'\r\n') irc.send(msg + b'\r\n')
def recv(): def recv():
msg = irc.recv(2040) msg = irc.recv(2040)
print('<<< %r' % msg) if not ping_re.match(msg):
print('<<< %r' % msg)
return msg return msg
def evaluate(msg): def evaluate(msg):
@ -111,16 +117,12 @@ def ircbot():
#send("PRIVMSG nickserv :iNOOPE\r\n") #send("PRIVMSG nickserv :iNOOPE\r\n")
send(b"JOIN %s" % channel) send(b"JOIN %s" % channel)
ping_re = re.compile(br'PING (.+)$')
chan_msg_re = re.compile(br':([^!]+)![^ ]+ PRIVMSG ([^ ]+) :' + nick + br': (.*)$')
priv_msg_re = re.compile(br':([^!]+)![^ ]+ PRIVMSG ' + nick + br' :(.*)$')
while True: while True:
text = recv() text = recv()
m = ping_re.match(text) m = ping_re.match(text)
if m: if m:
send(b'PONG %s' % m.group(1).strip()) send(b'PONG %s' % m.group(1).strip(), quiet=True)
continue continue
m = chan_msg_re.match(text) m = chan_msg_re.match(text)