Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.41 KB | None | 0 0
  1. # bdc - bloated discord client
  2. # written by null over a grueling long weekend and 1 tuesday study hall
  3.  
  4. import curses, discord, asyncio
  5.  
  6. stdscr = curses.initscr()
  7. height, width = curses.LINES, curses.COLS
  8.  
  9. class bdc_client(discord.Client):
  10.     # TODO: store current channel DONE
  11.     # TODO: non-blocking message input, research curses textbox DONE
  12.  
  13.     line = 0
  14.  
  15.     def __init__(self, *args, **kwargs):
  16.         super().__init__(*args, **kwargs)
  17.  
  18.         self.text_win = curses.newwin(height - 2, width, 0, 0)
  19.         self.text_win.refresh()
  20.  
  21.         self.input_win = curses.newwin(1, width, height - 1, 0)
  22.         self.input_win.echo()
  23.         self.input_win.refresh()
  24.  
  25.         self.messaging_daemon = self.loop.create_task(self.send_message())
  26.  
  27.     async def on_ready(self):
  28.         # on_ready not running, see: https://github.com/Rapptz/discord.py/issues/2567
  29.         # throwing error because its executing before client is ready
  30.         self.current_channel = discord.utils.get(self.get_all_channels(), name="<defualt channel>") # default channel and ~~default server~~
  31.         self.text_win.addstr(self.line, 0, "logged in as" + self.user.name)
  32.  
  33.     async def on_message(self, message):
  34.         if(message.channel != self.current_channel):
  35.             return
  36.  
  37.         if(self.line >= height-2):
  38.             self.text_win.clear()
  39.             self.line = 0
  40.  
  41.         self.text_win.addstr(self.line, 0, message.author.name + ": " + message.content)
  42.         self.text_win.refresh()
  43.         self.line += 1
  44.  
  45.     async def send_message(self):
  46.         await self.wait_until_ready()
  47.  
  48.         while not self.is_closed():
  49.             # block but only the while loop should be blocked, not on_message
  50.             # no way to test this until the bug gets patched :|
  51.             input_text = self.input_win.getstr().decode("utf-8")
  52.  
  53.             if(len(input_text) > 0 and input_text[0] == "/"):
  54.                 command = input_text[1:]
  55.                 if(command == "exit"):
  56.                     curses.endwin()
  57.                     await self.close()
  58.                 elif(command == "join"):
  59.                     ch = discord.utils.get(self.get_all_channels(), name=input_text.split(" ")[1]) # arg
  60.                     if(ch != None):
  61.                         self.current_channel = ch
  62.             else:
  63.                 await self.current_channel.send(input_text)
  64.  
  65. client = bdc_client()
  66. client.run("<token>", bot=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement