A Python bot that bridges a MUSH to a Discord channel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mushcord.py 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import discord
  2. import telnetlib as tn
  3. from time import sleep
  4. import sys, os
  5. client = discord.Client()
  6. class Mushcord:
  7. VERSION = '0.1.3'
  8. def __init__(self):
  9. self.TOKEN = 'NDc1NzIzMTg2NTUwNjAzNzkz.DkjMAw.ZH9FM4VxY4lieOp_Fl3JmHovx_o'
  10. self.server = 'saminga.oyving.org'
  11. self.port = 6250
  12. self.username = "mushcord"
  13. self.password = "g3licht3n!"
  14. @client.event
  15. async def on_message(message):
  16. if message.author == client.user:
  17. return
  18. if message.content.startswith('!hello'):
  19. msg = 'Hello {0.author.mention}'.format(message)
  20. await client.send_message(message.channel, msg)
  21. if message.content.startswith('!say'):
  22. author = message.author.nick or str(message.author).split('#')[0]
  23. content = " ".join(message.content.split(" ")[1:])
  24. msg = bytes(":| {0} says, \"{1}\".\n".format(author, content), "UTF-8")
  25. mc.t.write(msg)
  26. if message.content.startswith('!"'):
  27. author = message.author.nick or str(message.author).split('#')[0]
  28. content = message.content[2:]
  29. msg = bytes(":| {0} says, \"{1}\".\n".format(author, content), "UTF-8")
  30. mc.t.write(msg)
  31. if message.content.startswith('!emote'):
  32. author = message.author.nick or str(message.author).split('#')[0]
  33. content = " ".join(message.content.split(" ")[1:])
  34. msg = bytes(":| {0} {1}\n".format(author, content), "UTF-8")
  35. mc.t.write(msg)
  36. if message.content.startswith('!:'):
  37. author = message.author.nick or str(message.author).split('#')[0]
  38. content = message.content[2:]
  39. msg = bytes(":| {0} {1}\n".format(author, content), "UTF-8")
  40. mc.t.write(msg)
  41. if message.content.startswith('!>:'):
  42. author = message.author.nick or str(message.author).split('#')[0]
  43. content = message.content[3:]
  44. msg = bytes(">:| {0} {1}\n".format(author, content), "UTF-8")
  45. mc.t.write(msg)
  46. if message.content.startswith('!>') and not message.content.startswith('!>:'):
  47. author = message.author.nick or str(message.author).split('#')[0]
  48. content = message.content[2:]
  49. msg = bytes(">:| {0} says, \"{1}\".\n".format(author, content), "UTF-8")
  50. mc.t.write(msg)
  51. @client.event
  52. async def on_ready():
  53. print('Logged in as')
  54. print(client.user.name)
  55. print(client.user.id)
  56. print("--------")
  57. def start(self):
  58. self.t = tn.Telnet(self.server,self.port)
  59. self.t.read_until(b"\"news\"")
  60. self.t.write(bytes("connect {0} {1}\n".format(self.username, self.password),"UTF-8"))
  61. client.run(self.TOKEN)
  62. def listen(self):
  63. while True:
  64. try:
  65. g = b''
  66. g = self.t.read_until(b'\r\n', 1)
  67. if g != b'':
  68. try:
  69. g = g.decode(encoding='iso-8859-1').strip()
  70. except UnicodeDecodeError:
  71. try:
  72. g = g.decode(errors="replace").strip()
  73. except:
  74. g = g.decode(errors="ignore").strip()
  75. client.send_message(message.channel, g)
  76. g = b''
  77. except KeyboardInterrupt:
  78. break
  79. except EOFError:
  80. break
  81. except:
  82. continue
  83. if __name__ == "__main__":
  84. mc = Mushcord()
  85. mc.start()
  86. mc.listen()