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