import websocket
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 = []
########## ##########
########## DEFS ##########
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"])
print(result)
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(msg):
_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()
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}