Facebook
From anti_gay_programmer, 4 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 148
  1. import websocket
  2. import json
  3. import threading
  4. import time
  5.  
  6. ##########    infos    ##########
  7. channel = input('channel:\n>>')
  8. trip = input('passwd:\n>>')
  9. nick = input('nick:\n>>')
  10.  
  11. if trip == '':
  12.     pass
  13. else:
  14.     nick = nick + '#' + trip
  15.  
  16. on_message = []  # msgs from ur join to now
  17. online_users = []  # online since u joined
  18. on_join = []
  19. on_leave = []
  20. on_whisper = []
  21.  
  22.  
  23. ##########        ##########
  24.  
  25. ##########    DEFS    ##########
  26. def _send_msg(msg):
  27.     _send({"cmd": "chat", "text": msg})
  28.  
  29. def _info():
  30.     while True:
  31.         result = json.loads(ws.recv())  # get stuff
  32.         if result["cmd"] == "chat" and not result["nick"] == nick:  # if otheres send shit
  33.             for handler in list(on_message):
  34.                 handler(result["text"], result["nick"])
  35.             if result['text']=='#yelp':
  36.                 send_msg('yelp me im not done yet\nrn only lol can use me so fuck you')
  37.             if result['text']=='#game':
  38.                 _send_msg('we dont have any... yet')
  39.                     #if result['text']=='#game -l':
  40.                         #print(list_game())
  41.             print(result)
  42. #def _game_r_p_s():
  43.         elif result["cmd"] == "onlineAdd":
  44.             online_users.append(result["nick"])
  45.             for handler in list(on_join):
  46.                 handler(result["nick"])
  47.             print(result)
  48.  
  49.         elif result["cmd"] == "onlineRemove":
  50.             online_users.remove(result["nick"])
  51.             for handler in list(on_leave):
  52.                 handler(result["nick"])
  53.             print(result)
  54.  
  55.         elif result["cmd"] == "onlineSet":
  56.             for nick in result["nicks"]:
  57.                 online_users.append(nick)
  58.             print(result)
  59.  
  60.         elif result["cmd"] == "info" and result["type"] == "whisper":
  61.             for handler in list(on_whisper):
  62.                 handler(result["text"], result["from"], result)
  63.             print(result)
  64.  
  65.  
  66. # def send_to(target, msg):
  67. #        _send({"cmd": "whisper", "nick": target, "text": msg})
  68.  
  69.  
  70. def _send(pkg):
  71.     encoded = json.dumps(pkg)
  72.     ws.send(encoded)
  73.  
  74.  
  75. def _stay_in_chat():
  76.     while ws.connected:
  77.         _send({"cmd": "ping"})
  78.         time.sleep(60)
  79.  
  80.  
  81. def _send_msg_in_chat():
  82.     while True:
  83.         msg=input()
  84.         _send({"cmd": "chat", "text": msg})
  85.  
  86.  
  87. ##########        ##########
  88.  
  89. ##########     CONNECT    ##########
  90. ws = websocket.create_connection('wss://hack.chat/chat-ws')
  91.  
  92. _send({"cmd": "join", "channel": channel, "nick": nick})
  93. threading.Thread(target=_stay_in_chat).start()
  94.  
  95.  
  96. # def _daemon():
  97. #    daemon_thread=threading.Thread(target=info)
  98. #    daemon_thread.start()
  99.  
  100. daemon_thread = threading.Thread(target=_info)
  101. daemon_thread.start()
  102. msg=threading.Thread(target=_send_msg_in_chat).start()