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
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)