Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
85d538a738
22
uxnrepl.py
22
uxnrepl.py
|
@ -7,17 +7,16 @@ from subprocess import run, TimeoutExpired
|
||||||
from sys import argv, stdin, stdout
|
from sys import argv, stdin, stdout
|
||||||
from tempfile import mkdtemp, mkstemp
|
from tempfile import mkdtemp, mkstemp
|
||||||
|
|
||||||
server = "irc.libera.chat"
|
|
||||||
nick = b"uxnbot"
|
|
||||||
channel = b"#uxn"
|
|
||||||
|
|
||||||
sandbox = None
|
sandbox = None
|
||||||
irc = None
|
irc = None
|
||||||
|
|
||||||
template = '''
|
template = '''
|
||||||
|0100
|
|0100
|
||||||
( start ) %s ( end )
|
;on-console #10 DEO2
|
||||||
|
|
||||||
|
( start ) %s ( end ) BRK
|
||||||
|
|
||||||
|
@on-console ( -> BRK )
|
||||||
#05 DEI ,emit-wst/n STR
|
#05 DEI ,emit-wst/n STR
|
||||||
;wst print
|
;wst print
|
||||||
|
|
||||||
|
@ -66,7 +65,7 @@ def execute(s, sandbox=None, timeout=2.0):
|
||||||
if res.returncode != 0:
|
if res.returncode != 0:
|
||||||
return res.stderr
|
return res.stderr
|
||||||
try:
|
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:
|
except TimeoutExpired:
|
||||||
return b'uxncli: timed out'
|
return b'uxncli: timed out'
|
||||||
return res.stdout
|
return res.stdout
|
||||||
|
@ -84,8 +83,6 @@ def repl():
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
ping_re = re.compile(br'PING (.+)$')
|
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):
|
def send(msg, quiet=False):
|
||||||
if not quiet:
|
if not quiet:
|
||||||
|
@ -106,7 +103,7 @@ def evaluate(msg):
|
||||||
print('*** executing %r gave %r -> %r -> %r' % (msg, output, interesting, result))
|
print('*** executing %r gave %r -> %r -> %r' % (msg, output, interesting, result))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def ircbot():
|
def ircbot(server, nick, channel):
|
||||||
global sandbox, irc
|
global sandbox, irc
|
||||||
sandbox = mkdtemp(prefix='uxnrepl')
|
sandbox = mkdtemp(prefix='uxnrepl')
|
||||||
irc = socket(AF_INET, SOCK_STREAM)
|
irc = socket(AF_INET, SOCK_STREAM)
|
||||||
|
@ -114,9 +111,11 @@ def ircbot():
|
||||||
irc.connect((server, 6667))
|
irc.connect((server, 6667))
|
||||||
send(b"USER %s %s %s :bot for testing uxntal code" % (nick, nick, nick))
|
send(b"USER %s %s %s :bot for testing uxntal code" % (nick, nick, nick))
|
||||||
send(b"NICK %s" % nick)
|
send(b"NICK %s" % nick)
|
||||||
#send("PRIVMSG nickserv :iNOOPE\r\n")
|
|
||||||
send(b"JOIN %s" % channel)
|
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:
|
while True:
|
||||||
text = recv()
|
text = recv()
|
||||||
|
|
||||||
|
@ -145,9 +144,8 @@ def main():
|
||||||
if argv[1:] == [] or argv[1:] == ["repl"]:
|
if argv[1:] == [] or argv[1:] == ["repl"]:
|
||||||
repl()
|
repl()
|
||||||
elif argv[1] == "bot" and len(argv) == 5:
|
elif argv[1] == "bot" and len(argv) == 5:
|
||||||
# TODO: plug in server, nick, channel
|
|
||||||
server, nick, channel = argv[2:]
|
server, nick, channel = argv[2:]
|
||||||
ircbot()
|
ircbot(server, nick.encode('utf-8'), channel.encode('utf-8'))
|
||||||
else:
|
else:
|
||||||
print("usage: %s [repl]" % argv[0])
|
print("usage: %s [repl]" % argv[0])
|
||||||
print(" %s bot <server> <nick> <channel>" % argv[0])
|
print(" %s bot <server> <nick> <channel>" % argv[0])
|
||||||
|
|
Loading…
Reference in New Issue