Skip to content

Instantly share code, notes, and snippets.

@Julien00859
Created July 7, 2016 11:13
Show Gist options
  • Save Julien00859/5bcce0d8f1ce3142e0e4af8e8717eca3 to your computer and use it in GitHub Desktop.
Save Julien00859/5bcce0d8f1ce3142e0e4af8e8717eca3 to your computer and use it in GitHub Desktop.
Cookie Clicker with Conky
var Julien = function Julien() {
var ws, init, send, plugin_indice;
init = function init() {
ws = new WebSocket("ws://Julien00859.be:9000");
ws.onopen = function onopen(){
console.log("Connection established");
if (plugin_indice === void 0) plugin_indice = Game.customTickers.push(send) - 1;
else Game.customTickets[plugin_indice] = send;
}
ws.onmessage = function onmessage(data){console.log("From WebSocket:", data)}
ws.onclose = function onclose(){
console.log("Connection closed")
Game.customTickets[plugin_indice] = init
}
}
send = function send() {
if (ws !== void 0 && ws.readyState === 1) ws.send(Game.cookies);
}
return init
}()()
#!/usr/bin/python
# ${execpi <time> path/to/conkywrapper.py}
import socket
try:
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect("/home/julien/Scripts/cookies")
s.sendall(b"get")
data = s.recv(64)
cookies = int.from_bytes(data, "big", signed=True)
print("$hr")
print("${color grey}${alignc}Cookie Clicker")
print()
print("${color grey}Cookies in bank:${color}", cookies)
except:
pass
from websocket_server import WebsocketServer
from threading import Thread
import socket
from os import unlink
from os.path import exists
cookies = 0
def handle_new_cookies(client, server, cookiestring):
if "." in cookiestring:
cookiestring = cookiestring[:cookiestring.find(".")]
if cookiestring.isdigit():
global cookies
cookies = int(float(cookiestring))
else:
print("recv:", cookiestring)
websocket = WebsocketServer(9000)
websocket.set_fn_message_received(handle_new_cookies)
Thread(target=websocket.run_forever, daemon=True).start()
unixsocketpath = "./cookies"
try:
unlink(unixsocketpath)
except OSError:
if exists(unixsocketpath):
raise
unixsocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
unixsocket.bind(unixsocketpath)
unixsocket.listen(1)
while True:
client, client_infos = unixsocket.accept()
data = client.recv(16)
if not data:
client.close()
break
else:
msg = data.decode()
if msg == "get":
global cookies
print(cookies)
client.sendall(cookies.to_bytes(64, "big", signed=False))
elif msg == "stop":
break
else:
print(msg)
client.close()
print("Stop")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment