improve bot handling of BRK

This commit is contained in:
~d6 2024-02-15 21:15:05 -05:00
parent 586d14bc69
commit 4f6b71d641
1 changed files with 10 additions and 12 deletions

View File

@ -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 <server> <nick> <channel>" % argv[0])