- Notifications
You must be signed in to change notification settings - Fork0
Distribution mirror forhttps://github.com/joseph-gerald/jklm-py-client
License
joseph-gerald-os/jklm
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Flexible JKLM.fun client built for Python 3
- Versatile implementation allowing you to build anything
- Integrated JKLM client functions (chat, join, etc)
- Proxy support allows safe and anonymous connection
- Simple to use api
Install via pip
pip install -U jklm
- Make A Room
- Simple Usage
- Proxy Usage
- Set A Profile Picture
- Connections (Twitch, Discord)
- Chat Client
- PopSauce
- Bomb Party
- Someone make a PR
Note
As of18/02/25 only9775/9806(~99.7%) ofPopSauce are indexed due to the nature of scraping themx log(x)
heavy zipped folder of *all the questions, answers and data (image, etc)
light weight txt file of all the
challenge_hash:answer
pairings
simple script to extract pairs from the unzipped popsauce folder to popsauce_pairs.txt
Here is an example of how to create a room
fromjklmimportJKLMjklm=JKLM("BOT")res=jklm.start_room("selector",True,"test")print(res)# {'url': 'https://falcon.jklm.fun', 'room_code': 'RNGG'}
Here is a simple example of how to connect to a room and join a round(gamemode agnostic)
fromjklmimportJKLMdefmain(room_id):username="EXAMPLE_BOT"# Initialize JKLM sessionsession=JKLM(username)try:# Attempt to connect to specified roomsession.connect(room_id)print("[.] Successfully joined",room_id)exceptExceptionase:# Handle connection failures gracefullyprint("[X] Failed to join room:",e)return# Join active game round after successful connectionsession.join_round()if__name__=='__main__':# Launch bot and join room "ABUM"main("ABUM")
Here is an example of how to connect to a room using a proxy
fromjklmimportJKLMdefmain(room_id):username="EXAMPLE_BOT"proxy= {"host":"...","port":8080,"type":"http",# http, https, socks4, socks5"auth": ("username","password") }# Initialize JKLM sessionsession=JKLM(username,proxy=proxy)try:# Attempt to connect to specified roomsession.connect(room_id)print("[.] Successfully joined",room_id)exceptExceptionase:# Handle connection failures gracefullyprint("[X] Failed to join room:",e)return# Join active game round after successful connectionsession.join_round()if__name__=='__main__':# Launch bot and join room "ABUM"main("ABUM")
Here is an example of how to set a profile picture
fromjklmimportJKLMimporttimeimportpsutilimportosdefmain(room_id):image=open("logo.png","rb").read()# Try to keep image 128x128username="BOT_"+str(time.time())[-5:]session=JKLM(username,pfp=image)try:session.connect(room_id)print("[.] Successfully joined",room_id)exceptExceptionase:print("[X] Failed to join room:",e)returninput("")current_system_pid=os.getpid()ThisSystem=psutil.Process(current_system_pid)ThisSystem.terminate()if__name__=='__main__':main("KMPW")
Here is an example of how to connect to a room using a twitch or discord account
fromjklmimportJKLMimporttimeimportpsutilimportosdefmain(room_id):image=open("logo.png","rb").read()# Try to keep image 128x128username="BOT_"+str(time.time())[-5:]session=JKLM(username,pfp=image,connection={"service":"twitch",# twitch, discord"username":"jklm_bot",# Isn't validated"token":"YOUR_TOKEN",# Validated"expiration":0# Isn't validated })try:session.connect(room_id)print("[.] Successfully joined",room_id)exceptExceptionase:print("[X] Failed to join room:",e)returninput("")current_system_pid=os.getpid()ThisSystem=psutil.Process(current_system_pid)ThisSystem.terminate()if__name__=='__main__':main("KMPW")
Here is an example of how to connect to a room and chat back and forth with other users
fromjklmimportJKLMimporttimeimportpsutilimportosdefmain(room_id):username="BOT_"+str(time.time())[-5:]session=JKLM(username)defchat_handler(code,raw_data):event=raw_data[0]data=raw_data[1]# 0 CODE = Kicked from room (event = TYPE ["KICKED" | "BAN"], data = INFO)if (code==0):print("[X] Kicked from room:",data)returnmatchevent:case"chat":message=raw_data[2]print(f"[CHAT]{data['nickname']}:{message}")passcase"chatterAdded":print(f"[+]{data} joined the room")case"chatterRemoved":print(f"[-]{data} left the room")case"setPlayerCount":print(f"[!]{data} players in the room")case _:print(f"[UNHANDLED CHAT EVENT]{event}:",data)try:session.connect(room_id,chat_handler=chat_handler)print("[.] Successfully joined",room_id)exceptExceptionase:print("[X] Failed to join room:",e)returntry:whileTrue:message=input("")ifmessage=="":raiseKeyboardInterruptsession.send_chat_message(message)time.sleep(1)ifsession.reconnect_attempts>5:print("Reconnect attempts exceeded")current_system_pid=os.getpid()ThisSystem=psutil.Process(current_system_pid)ThisSystem.terminate()breakexceptKeyboardInterrupt:current_system_pid=os.getpid()ThisSystem=psutil.Process(current_system_pid)ThisSystem.terminate()if__name__=='__main__':main("ABUM")
Here is an example of how to hash a challenge
fromjklmimportJKLMimporttimeimporthashlibimportpsutilimportosexpecting_image=Falsechallenge= {"end_time":0,"image":None,"prompt":None,"text":None,"hash":None}defsha1(input):ifisinstance(input,str):input=input.encode()returnhashlib.sha1(input).hexdigest()defmain(room_id):globalexpecting_image,challengeusername="BOT_"+str(time.time())[-5:]session=JKLM(username)defgame_handler(code,raw_data):globalexpecting_image,challengeevent=raw_data[0]data=raw_data[1]# -1 CODE = Image data# 0 CODE = Kicked from room (event = TYPE ["KICKED" | "BAN"], data = INFO)if (code==0):print("[X] Kicked from room:",data)returnif (code==-1):asset_type=challenge["image"]["type"]extension=""matchasset_type:case"image/svg+xml":extension="svg"case"image/png":extension="png"case"image/jpeg":extension="jpeg"challenge["hash"]=sha1(challenge["prompt"].encode()+raw_data)challenge["image"]["extension"]=extensionprint("[?] Challenge Hash:",challenge["hash"])print("[?] Image has been saved to image."+extension)withopen("image."+extension,"wb")asf:f.write(raw_data)returnmatchevent:case"startChallenge":print("\n[!] New Challenge Started")challenge["end_time"]=data["endTime"]challenge["image"]=data["image"]challenge["prompt"]=data["prompt"]challenge["text"]=data["text"]ifchallenge["image"]:expecting_image=Trueprint("[?] Image Challenge",challenge["prompt"])else:expecting_image=Falsechallenge["hash"]=sha1(challenge["prompt"]+challenge["text"])print("[?] Text Challenge:",challenge["prompt"])print("[?] Challenge Hash:",challenge["hash"])print("[?]",challenge["text"])case"endChallenge":print("\n[!] Challenge Ended")print("[X] Correct Answer:",data["source"])case"setPlayerState":event,peer_id,data=raw_dataguess=data["guess"]found_answer=data["hasFoundSource"]points=data["points"]elapsed_time=data["elapsedTime"]player=list(filter(lambdax:x["profile"]["peerId"]==peer_id,session.game["players"]))[0]iffound_answer:print(f"[!]{player['profile']['nickname']} with{points} points guessed it in{elapsed_time} seconds")else:print(f"[!]{player['profile']['nickname']} with{points} points guessed{guess}")case"updatePlayer":event,peer_id,data,online=raw_dataplayer=list(filter(lambdax:x["profile"]["peerId"]==peer_id,session.game["players"]))[0]ifonline:print(f"[+]{player['profile']['nickname']} reconnected to the game")else:print(f"[-]{player['profile']['nickname']} disconnected from the game")case"addPlayer":print(f"[+]{data['profile']['nickname']} joined the game")case _:print(f"[UNHANDLED GAME EVENT]{event}:",raw_data)try:session.connect(room_id,game_handler=game_handler)print("[.] Successfully joined",room_id)exceptExceptionase:print("[X] Failed to join room:",e)returnsession.join_round()# Checks if a challenge is already startedif ("challenge"insession.game["milestone"]):print("\n[!] Challenge already started")current_challenge=session.game["milestone"]["challenge"]# If the challenge has ended but the next one hasn't started yet endTime will be nullchallenge["end_time"]=current_challenge["endTime"]if"endTime"incurrent_challengeelse0challenge["image"]=current_challenge["image"]challenge["prompt"]=current_challenge["prompt"]challenge["text"]=current_challenge["text"]ifchallenge["image"]:expecting_image=Trueprint("[?] Image Challenge",challenge["prompt"])else:expecting_image=Falsechallenge["hash"]=sha1(challenge["prompt"]+challenge["text"])print("[?] Text Challenge:",challenge["prompt"])print("[?]",challenge["text"])print("[?] Challenge Hash:",challenge["hash"])input("")current_system_pid=os.getpid()ThisSystem=psutil.Process(current_system_pid)ThisSystem.terminate()if__name__=='__main__':main("ABUM")
Here is an example of how to auto-answer and send the answer to the chat
fromjklmimportJKLMimportrequestsimporttimeimporthashlibimportpsutilimportosexpecting_image=Falsechallenge= {"end_time":0,"image":None,"prompt":None,"text":None,"hash":None}res=requests.get("https://cdn.jsdelivr.net/gh/joseph-gerald/jklm-py-client@main/answers/popsauce_pairs.txt")answers= {x.split(":",1)[0]:x.split(":",1)[1].strip()forxinres.text.split("\n")ifx}defsha1(input):ifisinstance(input,str):input=input.encode()returnhashlib.sha1(input).hexdigest()defmain(room_id):globalexpecting_image,challengeusername="BOT_"+str(time.time())[-5:]session=JKLM(username)defgame_handler(code,raw_data):globalexpecting_image,challengeevent=raw_data[0]data=raw_data[1]# -1 CODE = Image data# 0 CODE = Kicked from room (event = TYPE ["KICKED" | "BAN"], data = INFO)if (code==0):print("[X] Kicked from room:",data)returnif (code==-1):asset_type=challenge["image"]["type"]extension=""matchasset_type:case"image/svg+xml":extension="svg"case"image/png":extension="png"case"image/jpeg":extension="jpeg"challenge["hash"]=sha1(challenge["prompt"].encode()+raw_data)challenge["image"]["extension"]=extensionprint("[?] Challenge Hash:",challenge["hash"])answer=answers.get(challenge["hash"])ifanswer:print("[!] Answer is indexed:",answer)session.submit_guess(answer)session.send_chat_message(answer)else:print("[!] Answer was not indexed")returnmatchevent:case"startChallenge":print("\n[!] New Challenge Started")challenge["end_time"]=data["endTime"]challenge["image"]=data["image"]challenge["prompt"]=data["prompt"]challenge["text"]=data["text"]ifchallenge["image"]:expecting_image=Trueprint("[?] Image Challenge",challenge["prompt"])else:expecting_image=Falsechallenge["hash"]=sha1(challenge["prompt"]+challenge["text"])print("[?] Text Challenge:",challenge["prompt"])print("[?] Challenge Hash:",challenge["hash"])print("[?]",challenge["text"])answer=answers.get(challenge["hash"])ifanswer:print("[!] Answer is indexed:",answer)session.submit_guess(answer)session.send_chat_message(answer)else:print("[!] Answer was not indexed")case"endChallenge":print("\n[!] Challenge Ended")print("[X] Correct Answer:",data["source"])case"setPlayerState":event,peer_id,data=raw_dataguess=data["guess"]found_answer=data["hasFoundSource"]points=data["points"]elapsed_time=data["elapsedTime"]print(f"[!]{peer_id}{data}")ifpeer_id==session.peer_id:returnplayer=list(filter(lambdax:x["profile"]["peerId"]==peer_id,session.game["players"]))[0]iffound_answer:print(f"[!]{player['profile']['nickname']} with{points} points guessed it in{elapsed_time} seconds")else:print(f"[!]{player['profile']['nickname']} with{points} points guessed{guess}")case"updatePlayer":event,peer_id,data,online=raw_dataplayer=list(filter(lambdax:x["profile"]["peerId"]==peer_id,session.game["players"]))[0]ifonline:print(f"[+]{player['profile']['nickname']} reconnected to the game")else:print(f"[-]{player['profile']['nickname']} disconnected from the game")case"addPlayer":print(f"[+]{data['profile']['nickname']} joined the game")case _:print(f"[UNHANDLED GAME EVENT]{event}:",raw_data)try:session.connect(room_id,game_handler=game_handler)print("[.] Successfully joined",room_id)exceptExceptionase:print("[X] Failed to join room:",e)returnsession.join_round()# Checks if a challenge is already startedif ("challenge"insession.game["milestone"]):print("\n[!] Challenge already started")current_challenge=session.game["milestone"]["challenge"]# If the challenge has ended but the next one hasn't started yet endTime will be nullchallenge["end_time"]=current_challenge["endTime"]if"endTime"incurrent_challengeelse0challenge["image"]=current_challenge["image"]challenge["prompt"]=current_challenge["prompt"]challenge["text"]=current_challenge["text"]ifchallenge["image"]:expecting_image=Trueprint("[?] Image Challenge",challenge["prompt"])else:expecting_image=Falsechallenge["hash"]=sha1(challenge["prompt"]+challenge["text"])print("[?] Text Challenge:",challenge["prompt"])print("[?]",challenge["text"])print("[?] Challenge Hash:",challenge["hash"])input("")current_system_pid=os.getpid()ThisSystem=psutil.Process(current_system_pid)ThisSystem.terminate()if__name__=='__main__':main("ABUM")
soon™️
About
Distribution mirror forhttps://github.com/joseph-gerald/jklm-py-client
Topics
Resources
License
Stars
Watchers
Forks
Languages
- Python100.0%