import discord import telnetlib as tn from time import sleep import sys, os client = discord.Client() class Mushcord: VERSION = '0.1.3' def __init__(self): with open('config.txt', 'r+') as file: options = file.readlines() config = {} for option in options: o = option.strip("\n").split('=') config[o[0]] = config[o[1]] self.TOKEN = config['TOKEN'] self.server = config['SERVER'] self.port = int(config['PORT']) self.username = config['USERNAME'] self.password = config['PASSWORD'] @client.event async def on_message(self, message): if message.author == client.user: return if message.content.startswith('!hello'): msg = 'Hello {0.author.mention}'.format(message) await client.send_message(message.channel, msg) if message.content.startswith('!say'): author = message.author.nick or str(message.author).split('#')[0] content = " ".join(message.content.split(" ")[1:]) msg = bytes(":| {0} says, \"{1}\".\n".format(author, content), "UTF-8") mc.t.write(msg) if message.content.startswith('!"'): author = message.author.nick or str(message.author).split('#')[0] content = message.content[2:] msg = bytes(":| {0} says, \"{1}\".\n".format(author, content), "UTF-8") mc.t.write(msg) if message.content.startswith('!emote'): author = message.author.nick or str(message.author).split('#')[0] content = " ".join(message.content.split(" ")[1:]) msg = bytes(":| {0} {1}\n".format(author, content), "UTF-8") mc.t.write(msg) if message.content.startswith('!:'): author = message.author.nick or str(message.author).split('#')[0] content = message.content[2:] msg = bytes(":| {0} {1}\n".format(author, content), "UTF-8") mc.t.write(msg) if message.content.startswith('!>:'): author = message.author.nick or str(message.author).split('#')[0] content = message.content[3:] msg = bytes(">:| {0} {1}\n".format(author, content), "UTF-8") mc.t.write(msg) if message.content.startswith('!>') and not message.content.startswith('!>:'): author = message.author.nick or str(message.author).split('#')[0] content = message.content[2:] msg = bytes(">:| {0} says, \"{1}\".\n".format(author, content), "UTF-8") mc.t.write(msg) @client.event async def on_ready(self): print('Logged in as') print(client.user.name) print(client.user.id) print("--------") def start(self): self.t = tn.Telnet(self.server,self.port) self.t.read_until(b"\"news\"") self.t.write(bytes("connect {0} {1}\n".format(self.username, self.password),"UTF-8")) client.run(self.TOKEN) def listen(self): while True: try: g = b'' g = self.t.read_until(b'\r\n', 1) if g != b'': try: g = g.decode(encoding='iso-8859-1').strip() except UnicodeDecodeError: try: g = g.decode(errors="replace").strip() except: g = g.decode(errors="ignore").strip() client.send_message(message.channel, g) g = b'' except KeyboardInterrupt: break except EOFError: break except: continue if __name__ == "__main__": mc = Mushcord() mc.start() mc.listen()