Socket active, added api functions for setting game and status

This commit is contained in:
Jiiks 2016-01-07 08:35:40 +02:00
parent 1b23fd15f8
commit 98bb5a3c79
1 changed files with 24 additions and 9 deletions

View File

@ -1442,6 +1442,10 @@ PluginModule.prototype.channelSwitch = function() {
}); });
}; };
PluginModule.prototype.socketEvent = function(e, data) {
};
/* BetterDiscordApp ThemeModule JavaScript /* BetterDiscordApp ThemeModule JavaScript
* Version: 1.0 * Version: 1.0
@ -1528,7 +1532,6 @@ BdWSocket.prototype.start = function() {
}; };
BdWSocket.prototype.open = function(host) { BdWSocket.prototype.open = function(host) {
return;
utils.log("Socket Host: " + host); utils.log("Socket Host: " + host);
try { try {
bdSocket = new WebSocket(host); bdSocket = new WebSocket(host);
@ -1567,21 +1570,20 @@ BdWSocket.prototype.onMessage = function(e) {
switch(type) { switch(type) {
case "READY": case "READY":
// bdSocket.interval = setInterval(() => bdws.send({ op: 1, d: Date.now() }), data.heartbeat_interval); bdSocket.interval = setInterval(() => bdws.send({ op: 1, d: Date.now() }), data.heartbeat_interval);
// utils.log("Socket Ready"); utils.log("Socket Ready");
// console.log(data.heartbeat_interval);
break; break;
case "PRESENCE_UPDATE": case "PRESENCE_UPDATE":
pluginModule.socketEvent("PRESENCE_UPDATE", data);
break; break;
case "TYPING_START": case "TYPING_START":
pluginModule.socketEvent("TYPING_START", data);
break; break;
case "MESSAGE_CREATE": case "MESSAGE_CREATE":
// console.log("MESSAGE CREATE"); pluginModule.socketEvent("MESSAGE_CREATE", data);
// console.log(data);
break; break;
case "MESSAGE_UPDATE": case "MESSAGE_UPDATE":
// console.log("MESSAGE UPDATE"); pluginModule.socketEvent("MESSAGE_UPDATE", data);
// console.log(data);
break; break;
default: default:
break; break;
@ -1590,11 +1592,12 @@ BdWSocket.prototype.onMessage = function(e) {
}; };
BdWSocket.prototype.onError = function(e) { BdWSocket.prototype.onError = function(e) {
utils.log("onError: "); utils.log("Socket Error - " + e.message);
}; };
BdWSocket.prototype.onClose = function(e) { BdWSocket.prototype.onClose = function(e) {
utils.log("Socket Closed - " + e.code + " : " + e.reason); utils.log("Socket Closed - " + e.code + " : " + e.reason);
bdws.start();
}; };
BdWSocket.prototype.send = function(data) { BdWSocket.prototype.send = function(data) {
@ -1602,6 +1605,10 @@ BdWSocket.prototype.send = function(data) {
bdSocket.send(JSON.stringify(data)); bdSocket.send(JSON.stringify(data));
}; };
BdWSocket.prototype.getSocket = function() {
return bdSocket;
};
/* BetterDiscordApp API for Plugins /* BetterDiscordApp API for Plugins
* Version: 1.0 * Version: 1.0
* Author: Jiiks | http://jiiks.net * Author: Jiiks | http://jiiks.net
@ -1685,3 +1692,11 @@ BdApi.getUserNameById = function(id) {
} }
return null; return null;
}; };
BdApi.setPlaying = function(game) {
bdws.send({"op":3,"d":{"idle_since":null,"game":{"name": game}}});
};
BdApi.setStatus = function(idle_since, status) {
bdws.send({"op":3,"d":{"idle_since":idle_since,"game":{"name": status}}});
};