--- /dev/null
+#!/usr/bin/env python
+
+import asyncio
+import discord
+import logging
+import pexpect
+import random
+import re
+
+fd = open('TOKEN', 'r')
+token = fd.readline().strip()
+fd.close()
+#logging.basicConfig(level = logging.DEBUG)
+log = logging.getLogger('discord')
+
+def wait_for_prompt(p):
+ p.expect('EDI> ')
+
+p = pexpect.spawnu('./edi.py')
+wait_for_prompt(p)
+stuff = { 'edi': p, 'commands': ['coords', 'close_to', 'distance', 'edts', 'fuel_usage', 'galmath', 'help', 'raikogram'] }
+
+client = discord.Client()
+
+@client.event
+@asyncio.coroutine
+def on_ready():
+ print('Logged in as {}#{}'.format(client.user.name, client.user.id))
+ #yield from client.edit_profile(avatar = open('DELTA-FURRYCAThires.png', 'rb').read())
+
+@client.event
+@asyncio.coroutine
+def on_message(message):
+ if message.author.id == client.user.id:
+ return
+ log.debug('Got message from {}: {}'.format(message.author, message.content))
+ if not client.user.mentioned_in(message) and not message.channel.is_private:
+ log.debug('Message is not for me!')
+ return
+ raw = re.sub('<@{}>'.format(client.user.id), '', message.content).strip()
+ m = re.match(r'^\s*(\S+)', raw)
+ if m is None:
+ return
+ command = m.group(1)
+ if command not in stuff['commands']:
+ log.debug('Unrecognised command!')
+ if random.random() > 0.8:
+ yield from client.send_message(message.channel, 'meow!')
+ return
+
+ if command == 'close_to' and not '-m' in raw:
+ raw = 'close_to'
+ p = stuff['edi']
+ log.info(raw)
+ 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 client.send_message(message.channel, 'Sorry!')
+
+client.run(token)