Facebook
From LOLI BOI 69, 4 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 143
  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['cmd']=='info' or result['type']=='whisper' and result['from']=='lol':
  47.                 print('if this works i will fuck my self')
  48.             if result['text'] == '#game -rps':
  49.                 players.append(result["nick"])
  50.                 _players = list(OrderedDict.fromkeys(players))
  51.                 print(_players)
  52.                 if len(_players) == 2:
  53.                     _send_msg('and its on...')
  54.  
  55.                     print('ass')
  56.                     player1 = _players[0]
  57.                     player2 = players[1]
  58.                     _send_to(
  59.                         player1, 'you have 3 option.\nthey are "Rock" , "Paper" , "Scissor". to simplify. just whisper "R" or "P" or "S"')
  60.                     _send_to(
  61.                         player2, 'you have 3 option.\nthey are "Rock" , "Paper" , "Scissor". to simplify. just whisper "R" or "P" or "S"')
  62.                     print('ass1')
  63.                     print(players[0])
  64.                     if result['cmd'] == 'info' and 'from' in result and result['type'] == 'whisper' and result['from'] == player1 or player2:
  65.                         _send_msg('rut,wtf')
  66.                 elif len(_players) <= 1:
  67.                     _send_msg('one more player to go...')
  68.                 print(result)
  69. # def _game_r_p_s():
  70.         elif result["cmd"] == "onlineAdd":
  71.             online_users.append(result["nick"])
  72.             for handler in list(on_join):
  73.                 handler(result["nick"])
  74.             print(result)
  75.  
  76.         elif result["cmd"] == "onlineRemove":
  77.             online_users.remove(result["nick"])
  78.             for handler in list(on_leave):
  79.                 handler(result["nick"])
  80.             print(result)
  81.  
  82.         elif result["cmd"] == "onlineSet":
  83.             for nick in result["nicks"]:
  84.                 online_users.append(nick)
  85.             print(result)
  86.  
  87.         elif result["cmd"] == "info" and result["type"] == "whisper":
  88.             for handler in list(on_whisper):
  89.                 handler(result["text"], result["from"], result)
  90.             print(result)
  91.  
  92.  
  93. def _send_to(target, msg):
  94.     _send({"cmd": "whisper", "nick": target, "text": msg})
  95.  
  96.  
  97. def _send(pkg):
  98.     encoded = json.dumps(pkg)
  99.     ws.send(encoded)
  100.  
  101.  
  102. def _stay_in_chat():
  103.     while ws.connected:
  104.         _send({"cmd": "ping"})
  105.         time.sleep(60)
  106.  
  107.  
  108. def _send_msg_in_chat():
  109.     while True:
  110.         msg = input()
  111.         _send({"cmd": "chat", "text": msg})
  112.  
  113.  
  114. ##########        ##########
  115.  
  116. ##########     CONNECT    ##########
  117. ws = websocket.create_connection('wss://hack.chat/chat-ws')
  118.  
  119. _send({"cmd": "join", "channel": channel, "nick": nick})
  120. threading.Thread(target=_stay_in_chat).start()
  121.  
  122.  
  123. # def _daemon():
  124. #    daemon_thread=threading.Thread(target=info)
  125. #    daemon_thread.start()
  126.  
  127. daemon_thread = threading.Thread(target=_info)
  128. daemon_thread.start()
  129. msg = threading.Thread(target=_send_msg_in_chat).start()