PianoRhythm Bridge

This commit is contained in:
Bop It Freak 2019-06-27 16:14:59 -07:00 committed by Lamp
parent 1133e9aff4
commit 915efb7803
2 changed files with 121 additions and 0 deletions

50
src/prbridge/PRClient.js Normal file
View File

@ -0,0 +1,50 @@
const socketCluster = require("socketcluster-client")
const EventEmitter = require("events").EventEmitter;
const HttpsProxyAgent = require("https-proxy-agent");
const SocksProxyAgent = require("socks-proxy-agent");
class PRClient extends EventEmitter {
constructor(credentials, options) {
super()
EventEmitter.call(this);
this.options = options;
this.socket;
this.channels = {};
this.credentials = credentials
}
connect() {
if (!this.options) {
this.options = {
path: "/socketcluster/",
hostname: "www.pianorhythm.me",
port: 443,
secure: true,
autoReconnect: true,
}
}
// Initiate the connection to the server
this.socket = socketCluster.connect(this.options);
this.socket.connect();
this.socket.on("error", (msg) => {
console.error(msg);
})
this.socket.on("connect", () => {
console.log("Connected!")
this.socket.emit("enableAuthLogin", {
enable: true,
roomName: this.credentials.roomName
});
this.socket.emit("enableCursor", {
enable: true
});
this.socket.emit("login", {
password: this.credentials.password,
roomName: this.credentials.roomName,
username: this.credentials.username
});
this.socket.emit("getPlayerStats", {
"username": this.credentials.username
})
})
}
}
module.exports = PRClient;

71
src/prbridge/index.js Normal file
View File

@ -0,0 +1,71 @@
const PRClient = require("./PRClient.js");
evalcmd();
const Discord = require("discord.js");
const dclient = new Discord.Client();
dclient.login("no u");
dclient.on('ready', () => {
let client = new PRClient({// account stuff
username: "Discord",
password: "vWmnsEkgAPcU3VR",
roomName: 'lobby'
});
client.connect();
client.socket.on("setRoom", function (data, callback) {
client.roomID = data.roomID;
try {
if (client.channels.chatChannel && client.roomID) {
client.socket.destroyChannel(client.roomID);
}
} catch (err) {}
client.channels.chatChannel = client.socket.subscribe(data.roomID);
client.channels.chatChannel.watch(messagehandle);
})
})
function messagehandle(data) {
if (data && data.type) {
switch (data.type) {
case "chat":
if (data && data.message) {
let name = data.name || "";
let effect = data.effect || "";
let roomName = data.roomName;
let color = data.color;
let id = data.id;
if (data.notify)
console.log("NOTIFY: " + data.message);
console.log(`${name}: ${data.message}`);
dclient.channels.get("380431177812803584").send(`${name}: ${data.message}`);
}
break;
}
}
}
function evalcmd() {
//with all optional parameters set to opposite of default
const {
EntoliPrompt
} = require('entoli');
let EP = new EntoliPrompt('', {
enterMessage: false,
exitMessage: false,
preventExit: false
});
EP().then((a) => {
client.socket.publish("fcf6e7e5-1d9a-48ee-808f-a9b626ce090b", {
"type": "chat",
"message": a.toString(),
"value": false,
"socketID": "󠀀[discord.gg/k44Eqha]",
"uuid": "󠀀[discord.gg/k44Eqha]",
"color": "#8012ed",
"name": "󠀀[discord.gg/k44Eqha]"
})
evalcmd();
}).catch((e) => {
console.error(e);
evalcmd();
});
}