Moontalk server and client (provided by many parties)
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

78 lignes
2.4KB

  1. # Copyright 2024 Anonymous
  2. # Licensed under the terms of MIT+NIGGER
  3. # Notable issues:
  4. # No word wrap in the result box. It's a listbox and should probably be a textbox of some kind.
  5. # When it is closed it shits into the console like no tomorrow, too bad.
  6. # Overall this is a disgusting hack of python garbage
  7. import asyncio
  8. from tkinter import *
  9. from tkinter.ttk import *
  10. running = True
  11. root = Tk()
  12. root.option_add("*Font", 'TkFixedFont')
  13. def tk_kill(): # no good, nasty way to stop everything
  14. global running
  15. running = False
  16. root.destroy()
  17. root.protocol("WM_DELETE_WINDOW", tk_kill)
  18. root.geometry("700x400")
  19. root.rowconfigure(tuple(range(11)), weight=3) # needed for css-like grid behavior
  20. root.columnconfigure(tuple(range(6)), weight=3)
  21. message_log = Listbox(root)
  22. message_log.grid(rowspan=9, row=0, column=0, columnspan=6, sticky='nsew')
  23. input_var = StringVar()
  24. input_box = Entry(root, textvariable=input_var)
  25. input_box.grid(row=10, column=0, columnspan=5, sticky='nsew')
  26. def tk_send_message():
  27. content = input_var.get()
  28. loop = asyncio.get_running_loop()
  29. asyncio.run_coroutine_threadsafe(outbound_queue.put(content), loop)
  30. input_var.set("")
  31. submit_button = Button(root, text = 'Submit', command = tk_send_message)
  32. submit_button.grid(row=10, column=5, columnspan=1, sticky='nsew')
  33. # potential improvement: bind enter on input_box to submit as well
  34. outbound_queue = asyncio.Queue()
  35. def add_message(content: str):
  36. message_log.insert(END, content.strip())
  37. async def consume_message(reader: asyncio.StreamReader):
  38. while not reader.at_eof():
  39. line = await reader.readline()
  40. add_message(line.decode('ascii'))
  41. async def submit_message(writer: asyncio.StreamWriter):
  42. while True:
  43. content: str = await outbound_queue.get()
  44. content = content + "\n" # all messages must newline
  45. writer.write(content.encode('ascii'))
  46. add_message(f"YOU: {content}") # echo it back
  47. outbound_queue.task_done()
  48. async def update_tk():
  49. while running:
  50. root.update()
  51. await asyncio.sleep(0.01)
  52. raise asyncio.CancelledError
  53. async def main():
  54. reader, writer = await asyncio.open_connection(
  55. "7ks473deh6ggtwqsvbqdurepv5i6iblpbkx33b6cydon3ajph73sssad.onion",
  56. 50000
  57. )
  58. await asyncio.gather(update_tk(), consume_message(reader), submit_message(writer))
  59. if __name__ == "__main__":
  60. asyncio.run(main())