import websocket from collections import OrderedDict import json import threading import time ########## infos ########## channel = input('channel:\n>>') trip = input('passwd:\n>>') nick = input('nick:\n>>') if trip == '': pass else: nick = nick + '#' + trip on_message = [] # msgs from ur join to now online_users = [] # online since u joined on_join = [] on_leave = [] on_whisper = [] players = [] ########## ########## ########## DEFS ########## def _send_msg(msg): _send({"cmd": "chat", "text": msg}) # def _game_r_p_s(): def _info(): while True: result = json.loads(ws.recv()) # get stuff if result["cmd"] == "chat" and not result["nick"] == nick:# if otheres send shit for handler in list(on_message): handler(result["text"], result["nick"]) if result['text'] == '#yelp': _send_msg( 'yelp me im not done yet\nrn only lol can use me so fuck you') if result['text'] == '#game': _send_msg('we dont have any... yet') if result['cmd']=='info' or result['type']=='whisper' and result['from']=='lol': print('if this works i will fuck my self') if result['text'] == '#game -rps': players.append(result["nick"]) _players = list(OrderedDict.fromkeys(players)) print(_players) if len(_players) == 2: _send_msg('and its on...') print('ass') player1 = _players[0] player2 = players[1] _send_to( player1, 'you have 3 option.\nthey are "Rock" , "Paper" , "Scissor". to simplify. just whisper "R" or "P" or "S"') _send_to( player2, 'you have 3 option.\nthey are "Rock" , "Paper" , "Scissor". to simplify. just whisper "R" or "P" or "S"') print('ass1') print(players[0]) if result['cmd'] == 'info' and 'from' in result and result['type'] == 'whisper' and result['from'] == player1 or player2: _send_msg('rut,wtf') elif len(_players) <= 1: _send_msg('one more player to go...') print(result) # def _game_r_p_s(): elif result["cmd"] == "onlineAdd": online_users.append(result["nick"]) for handler in list(on_join): handler(result["nick"]) print(result) elif result["cmd"] == "onlineRemove": online_users.remove(result["nick"]) for handler in list(on_leave): handler(result["nick"]) print(result) elif result["cmd"] == "onlineSet": for nick in result["nicks"]: online_users.append(nick) print(result) elif result["cmd"] == "info" and result["type"] == "whisper": for handler in list(on_whisper): handler(result["text"], result["from"], result) print(result) def _send_to(target, msg): _send({"cmd": "whisper", "nick": target, "text": msg}) def _send(pkg): encoded = json.dumps(pkg) ws.send(encoded) def _stay_in_chat(): while ws.connected: _send({"cmd": "ping"}) time.sleep(60) def _send_msg_in_chat(): while True: msg = input() _send({"cmd": "chat", "text": msg}) ########## ########## ########## CONNECT ########## ws = websocket.create_connection('wss://hack.chat/chat-ws') _send({"cmd": "join", "channel": channel, "nick": nick}) threading.Thread(target=_stay_in_chat).start() # def _daemon(): # daemon_thread=threading.Thread(target=info) # daemon_thread.start() daemon_thread = threading.Thread(target=_info) daemon_thread.start() msg = threading.Thread(target=_send_msg_in_chat).start()