From 98bb5a3c7999822ce6d98cdc4bf13230d582dcc3 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Thu, 7 Jan 2016 08:35:40 +0200 Subject: [PATCH] Socket active, added api functions for setting game and status --- js/main.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/js/main.js b/js/main.js index e424483..faebf3f 100644 --- a/js/main.js +++ b/js/main.js @@ -1442,6 +1442,10 @@ PluginModule.prototype.channelSwitch = function() { }); }; +PluginModule.prototype.socketEvent = function(e, data) { + +}; + /* BetterDiscordApp ThemeModule JavaScript * Version: 1.0 @@ -1528,7 +1532,6 @@ BdWSocket.prototype.start = function() { }; BdWSocket.prototype.open = function(host) { - return; utils.log("Socket Host: " + host); try { bdSocket = new WebSocket(host); @@ -1567,21 +1570,20 @@ BdWSocket.prototype.onMessage = function(e) { switch(type) { case "READY": - // bdSocket.interval = setInterval(() => bdws.send({ op: 1, d: Date.now() }), data.heartbeat_interval); - // utils.log("Socket Ready"); - // console.log(data.heartbeat_interval); + bdSocket.interval = setInterval(() => bdws.send({ op: 1, d: Date.now() }), data.heartbeat_interval); + utils.log("Socket Ready"); break; case "PRESENCE_UPDATE": + pluginModule.socketEvent("PRESENCE_UPDATE", data); break; case "TYPING_START": + pluginModule.socketEvent("TYPING_START", data); break; case "MESSAGE_CREATE": - // console.log("MESSAGE CREATE"); - // console.log(data); + pluginModule.socketEvent("MESSAGE_CREATE", data); break; case "MESSAGE_UPDATE": - // console.log("MESSAGE UPDATE"); - // console.log(data); + pluginModule.socketEvent("MESSAGE_UPDATE", data); break; default: break; @@ -1590,11 +1592,12 @@ BdWSocket.prototype.onMessage = function(e) { }; BdWSocket.prototype.onError = function(e) { - utils.log("onError: "); + utils.log("Socket Error - " + e.message); }; BdWSocket.prototype.onClose = function(e) { utils.log("Socket Closed - " + e.code + " : " + e.reason); + bdws.start(); }; BdWSocket.prototype.send = function(data) { @@ -1602,6 +1605,10 @@ BdWSocket.prototype.send = function(data) { bdSocket.send(JSON.stringify(data)); }; +BdWSocket.prototype.getSocket = function() { + return bdSocket; +}; + /* BetterDiscordApp API for Plugins * Version: 1.0 * Author: Jiiks | http://jiiks.net @@ -1684,4 +1691,12 @@ BdApi.getUserNameById = function(id) { } } 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}}}); }; \ No newline at end of file