class RcTogether: def __init__(self, callbacks=[]): self.connection = Connection( origin=f"https://{RC_APP_ENDPOINT}", url=f"wss://{RC_APP_ENDPOINT}/cable?app_id={RC_APP_ID}&app_secret={RC_APP_SECRET}", ) self.connection.connect() while not self.connection.connected: # TODO - use callbacks to detect connection! print("Waiting for connection.") time.sleep(0.1) print("Connected.") self.subscription = Subscription(self.connection, identifier={"channel": "ApiChannel"}) # Websocket library captures and hides tracebacks, so make sruer self.subscription.on_receive(with_tracebacks(self.handle_message)) self.subscription.create() self.callbacks = callbacks self.bots = {} def block_until_done(self): self.connection.ws_thread.join() def create_bot(self, name, emoji, x, y, handle_update, can_be_mentioned=False): bot = Bot.create(name, emoji, x, y, handle_update, can_be_mentioned) self.bots[bot.id] = bot return bot def handle_message(self, message): if message["type"] == "world": for entity in message["payload"]["entities"]: self.handle_entity(entity) else: self.handle_entity(message["payload"]) def handle_entity(self, entity): for callback in self.callbacks: callback(entity) if entity['id'] in self.bots: self.bots[entity['id']].handle_entity(entity) def add_callback(self, callback): self.callbacks.append(callback)
def __init__(self, callbacks=[]): self.connection = Connection( origin=f"https://{RC_APP_ENDPOINT}", url=f"wss://{RC_APP_ENDPOINT}/cable?app_id={RC_APP_ID}&app_secret={RC_APP_SECRET}", ) self.connection.connect() while not self.connection.connected: # TODO - use callbacks to detect connection! print("Waiting for connection.") time.sleep(0.1) print("Connected.") self.subscription = Subscription(self.connection, identifier={"channel": "ApiChannel"}) # Websocket library captures and hides tracebacks, so make sruer self.subscription.on_receive(with_tracebacks(self.handle_message)) self.subscription.create() self.callbacks = callbacks self.bots = {}
dif = (now - stamp).total_seconds() # print(dif) if dif < 2: lodge.ask_lodge(mess['text']) if __name__ == "__main__": import os ID = os.getenv('ID') SEC = os.getenv('SEC') # import keyring # ID = keyring.get_password('summon', 'VIRTUAL_APP_ID') # SEC = keyring.get_password('summon', 'VIRTUAL_APP_SEC') lodge = SkiLodge(app_id=ID, app_sec=SEC, name="RC Lodge") con = Connection( origin='https://recurse.rctogether.com', url=f'wss://recurse.rctogether.com/cable?app_id={ID}&app_secret={SEC}') con.connect() while not con.connected: time.sleep(0.5) sub = Subscription(con, identifier={"channel": "ApiChannel"}) sub.on_receive(callback=sub_on_receive) sub.create() time.sleep(5) while con.connected: if lodge.status == 'closed': con.disconnect() else: time.sleep(5)
import requests import time import copy import json config = None with open("config.json", "r") as config_file: config = json.loads(config_file.read()) cookie=config["cookie"] csrf=config["csrf"] connection = Connection( url="wss://recurse.rctogether.com/cable", origin="https://recurse.rctogether.com", cookie=cookie) connection.connect() gwc_subscription = Subscription(connection, identifier={"channel": "GridWorldChannel"}) all_people = {} world = None players = [] turn = 0 def gwc_on_receive(message): global world global players global all_people
from actioncable.connection import Connection from actioncable.subscription import Subscription from actioncable.message import Message from serial.tools import list_ports import serial import time import json import time.sleep connection = Connection(url='ws://localhost:28080') connection.connect() subscription = Subscription(connection, identifier={'channel': 'DeviceChannel'}) subscription.create() def on_receive(message): print('New message arrived!') print('Action: {} | Data: {}'.format(message.action, message.data)) subscription.on_receive(callback=on_receive) subscription.connection.send({ 'command': 'message', 'identifier': json.dumps({'channel': 'DeviceChannel'}), 'data': json.dumps({
def delete(j=None, id=None): if id == None: id = BOTID if j is None: return requests.delete(BOTURL + id, auth=(app_id, app_secret)) else: return requests.delete(BOTURL + id, json=j, auth=(app_id, app_secret)) # ==== ACTIONCABLE ============================================================= #logging.basicConfig(level=logging.DEBUG) connection = Connection( url= f"wss://recurse.rctogether.com/cable?app_id={app_id}&app_secret={app_secret}", origin='https://recurse.rctogether.com') connection.connect() subscription = Subscription(connection, identifier={'channel': 'ApiChannel'}) # WORLD STATE BOTID = None steps = 0 STARTX = 16 STARTY = 16 world = None
from model import who_is_it, create_encoding, sess, retrain from actioncable.connection import Connection from actioncable.subscription import Subscription from actioncable.message import Message import numpy as np import scipy.misc import re import base64 from imageio import imread import cv2 from skimage.transform import resize from os import rename connection = Connection(url='ws://localhost:3000/cable', origin='http://localhost:3000') connection.connect() subscription = Subscription(connection, identifier={'channel': 'FaceChannel'}) image_dir_path = "./data/images" database = retrain() def on_receive(message): global database database = retrain() print(database.keys()) message = message['message'] print("Message: ", message) if re.match("Recieved faceprint: ", message): img_data = message.split(": ")[1] image_path = image_dir_path + "/new.jpg" with open(image_path, "wb") as fh: fh.write(base64.b64decode(img_data))