Facebook
From NIGGA SHIT, 4 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 151
  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.  
  28.  
  29. def _send_msg(msg):
  30.     _send({"cmd": "chat", "text": msg})
  31.  
  32. # def _game_r_p_s():
  33.  
  34.  
  35. def _info():
  36.     while True:
  37.         result = json.loads(ws.recv())  # get stuff
  38.         if result["cmd"] == "chat" and not result["nick"] == nick:  # if otheres send shit
  39.             for handler in list(on_message):
  40.                 handler(result["text"], result["nick"])
  41.             if result['text'] == '#yelp':
  42.                 _send_msg(
  43.                     'yelp me im not done yet\nrn only lol can use me so fuck you')
  44.             if result['text'] == '#game':
  45.                 _send_msg('we dont have any... yet')
  46.             if result['text'] == '#game -rps':
  47.                 players.append(result["nick"])
  48.                 _players = list(OrderedDict.fromkeys(players))
  49.                 print(_players)
  50.                 if len(_players) == 2:
  51.                     _send_msg('and its on...')
  52.  
  53.                     print('ass')
  54.                     player1 = _players[0]
  55.                     player2 = players[1]
  56.                     _send_to(
  57.                         player1, 'you have 3 option.\nthey are "Rock" , "Paper" , "Scissor". to simplify. just whisper "R" or "P" or "S"')
  58.                     _send_to(
  59.                         player2, 'you have 3 option.\nthey are "Rock" , "Paper" , "Scissor". to simplify. just whisper "R" or "P" or "S"')
  60.                     print('ass1')
  61.                     print(str(players[0]))
  62.                     if result['type']=='whisper':
  63.                         _send_msg('rut,wtf')
  64. #                    if result['nick'] == str(player1):
  65. #                        print('aasss')
  66. #                        if result['cmd'] == 'info':
  67. #                            if any("S" or "P" or "R" in text for text in result['text']):
  68. #                                print('FUCK YEAH BITCH')
  69. #                                _send_msg('it worked')
  70.  
  71.                 elif len(_players) <= 1:
  72.                     _send_msg('one more player to go...')
  73.             print(result)
  74. # def _game_r_p_s():
  75.         elif result["cmd"] == "onlineAdd":
  76.             online_users.append(result["nick"])
  77.             for handler in list(on_join):
  78.                 handler(result["nick"])
  79.             print(result)
  80.  
  81.         elif result["cmd"] == "onlineRemove":
  82.             online_users.remove(result["nick"])
  83.             for handler in list(on_leave):
  84.                 handler(result["nick"])
  85.             print(result)
  86.  
  87.         elif result["cmd"] == "onlineSet":
  88.             for nick in result["nicks"]:
  89.                 online_users.append(nick)
  90.             print(result)
  91.  
  92.         elif result["cmd"] == "info" and result["type"] == "whisper":
  93.             for handler in list(on_whisper):
  94.                 handler(result["text"], result["from"], result)
  95.             print(result)
  96.  
  97.  
  98. def _send_to(target, msg):
  99.     _send({"cmd": "whisper", "nick": target, "text": msg})
  100.  
  101.  
  102. def _send(pkg):
  103.     encoded = json.dumps(pkg)
  104.     ws.send(encoded)
  105.  
  106.  
  107. def _stay_in_chat():
  108.     while ws.connected:
  109.         _send({"cmd": "ping"})
  110.         time.sleep(60)
  111.  
  112.  
  113. def _send_msg_in_chat():
  114.     while True:
  115.         msg = input()
  116.         _send({"cmd": "chat", "text": msg})
  117.  
  118.  
  119. ##########        ##########
  120.  
  121. ##########     CONNECT    ##########
  122. ws = websocket.create_connection('wss://hack.chat/chat-ws')
  123.  
  124. _send({"cmd": "join", "channel": channel, "nick": nick})
  125. threading.Thread(target=_stay_in_chat).start()
  126.  
  127.  
  128. # def _daemon():
  129. #    daemon_thread=threading.Thread(target=info)
  130. #    daemon_thread.start()
  131.  
  132. daemon_thread = threading.Thread(target=_info)
  133. daemon_thread.start()
  134. msg = threading.Thread(target=_send_msg_in_chat).start()
  135.