From 4f6b71d6419e7e91b35eba5f69d800aebed3dad9 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Thu, 15 Feb 2024 21:15:05 -0500 Subject: [PATCH] improve bot handling of BRK --- uxnrepl.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/uxnrepl.py b/uxnrepl.py index 3b36526..848a46f 100644 --- a/uxnrepl.py +++ b/uxnrepl.py @@ -7,17 +7,16 @@ from subprocess import run, TimeoutExpired from sys import argv, stdin, stdout from tempfile import mkdtemp, mkstemp -server = "irc.libera.chat" -nick = b"uxnbot" -channel = b"#uxn" - sandbox = None irc = None template = ''' |0100 - ( start ) %s ( end ) + ;on-console #10 DEO2 + ( start ) %s ( end ) BRK + +@on-console ( -> BRK ) #05 DEI ,emit-wst/n STR ;wst print @@ -66,7 +65,7 @@ def execute(s, sandbox=None, timeout=2.0): if res.returncode != 0: return res.stderr try: - res = run(['uxncli', tmp_rom], cwd=sandbox, capture_output=True, timeout=timeout) + res = run(['uxncli', tmp_rom, 'trigger'], cwd=sandbox, capture_output=True, timeout=timeout) except TimeoutExpired: return b'uxncli: timed out' return res.stdout @@ -84,8 +83,6 @@ def repl(): stdout.flush() 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: @@ -106,7 +103,7 @@ def evaluate(msg): print('*** executing %r gave %r -> %r -> %r' % (msg, output, interesting, result)) return result -def ircbot(): +def ircbot(server, nick, channel): global sandbox, irc sandbox = mkdtemp(prefix='uxnrepl') irc = socket(AF_INET, SOCK_STREAM) @@ -114,9 +111,11 @@ def ircbot(): irc.connect((server, 6667)) send(b"USER %s %s %s :bot for testing uxntal code" % (nick, nick, nick)) send(b"NICK %s" % nick) - #send("PRIVMSG nickserv :iNOOPE\r\n") send(b"JOIN %s" % channel) + chan_msg_re = re.compile(br':([^!]+)![^ ]+ PRIVMSG ([^ ]+) :' + nick + br': (.*)$') + priv_msg_re = re.compile(br':([^!]+)![^ ]+ PRIVMSG ' + nick + br' :(.*)$') + while True: text = recv() @@ -145,9 +144,8 @@ def main(): if argv[1:] == [] or argv[1:] == ["repl"]: repl() elif argv[1] == "bot" and len(argv) == 5: - # TODO: plug in server, nick, channel server, nick, channel = argv[2:] - ircbot() + ircbot(server, nick.encode('utf-8'), channel.encode('utf-8')) else: print("usage: %s [repl]" % argv[0]) print(" %s bot " % argv[0])