From 586d14bc69a0e5be10148b634d50988057ac4449 Mon Sep 17 00:00:00 2001 From: d_m Date: Fri, 26 Jan 2024 00:42:05 -0500 Subject: [PATCH] fix default channel, make ping less noisy --- uxnrepl.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/uxnrepl.py b/uxnrepl.py index 67ae96b..3b36526 100644 --- a/uxnrepl.py +++ b/uxnrepl.py @@ -8,8 +8,8 @@ from sys import argv, stdin, stdout from tempfile import mkdtemp, mkstemp server = "irc.libera.chat" -nick = b"uxnbot7" -channel = b"#uxnbot" +nick = b"uxnbot" +channel = b"#uxn" sandbox = None irc = None @@ -83,13 +83,19 @@ def repl(): stdout.write(execute(s).decode('utf-8')) stdout.flush() -def send(msg): - print('>>> %r' % msg) +ping_re = re.compile(br'PING (.+)$') +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') def recv(): msg = irc.recv(2040) - print('<<< %r' % msg) + if not ping_re.match(msg): + print('<<< %r' % msg) return msg def evaluate(msg): @@ -111,16 +117,12 @@ def ircbot(): #send("PRIVMSG nickserv :iNOOPE\r\n") 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: text = recv() m = ping_re.match(text) if m: - send(b'PONG %s' % m.group(1).strip()) + send(b'PONG %s' % m.group(1).strip(), quiet=True) continue m = chan_msg_re.match(text)