We can fork and exec certain commands.
authorCMDR furrycat <elite@furrycat.net>
Thu, 15 Sep 2016 14:23:47 +0000 (15:23 +0100)
committerCMDR furrycat <elite@furrycat.net>
Thu, 15 Sep 2016 14:26:19 +0000 (15:26 +0100)
bot.py

diff --git a/bot.py b/bot.py
index 3b1032f..dc1b773 100755 (executable)
--- a/bot.py
+++ b/bot.py
@@ -37,6 +37,14 @@ def say(channel, text):
   yield from maybe_say(channel, text, 1.0)
 
 @asyncio.coroutine
+def say_expect(message, stdout):
+  if stdout:
+    log.debug(stdout)
+    yield from client.send_message(message.channel, '{}```{}```'.format('{} '.format(message.author.mention) if not message.channel.is_private else '', stdout))
+  else:
+    yield from say(message.channel, 'Sorry!')
+
+@asyncio.coroutine
 def not_admin(message):
   log.warning('Not admin: {} id {}'.format(message.author, message.author.id))
   yield from maybe_say(message.channel, 'hiss!')
@@ -92,12 +100,17 @@ def do_edi(message, command, raw, p):
   yield from client.send_typing(message.channel)
   p.sendline(raw)
   wait_for_prompt(p)
-  stdout = p.before
-  if stdout:
-    log.info(stdout)
-    yield from client.send_message(message.channel, '{}```{}```'.format('{} '.format(message.author.mention) if not message.channel.is_private else '', stdout))
-  else:
-    yield from say(message.channel, 'Sorry!')
+  yield from say_expect(message, p.before)
+
+@asyncio.coroutine
+def do_fork(message, command, raw):
+  yield from client.send_typing(message.channel)
+  if re.search(r'[^A-Za-z0-9-_."\'"]', raw):
+    yield from say(message.channel, 'hiss')
+    return
+  p = pexpect.spawnu('./{}'.format(raw))
+  p.expect(pexpect.EOF)
+  yield from say_expect(message, p.before)
 
 p = pexpect.spawnu('./edi.py')
 wait_for_prompt(p)
@@ -112,6 +125,11 @@ modules = {
     'fn': do_edi,
     'args': [p],
     'commands': ['coords', 'close_to', 'distance', 'edts', 'fuel_usage', 'galmath', 'help', 'raikogram']
+  },
+  'fork': {
+    'fn': do_fork,
+    'args': [],
+    'commands': ['gravity', 'material', 'range']
   }
 }