minor fixes

slightly more stable, removed redundant functions and added one or two
features ;)
This commit is contained in:
hydrabolt
2015-08-11 21:23:52 +01:00
parent 0c1c3446ff
commit 62d0581c90
2 changed files with 25 additions and 23 deletions

View File

@@ -101,13 +101,12 @@ exports.Client.prototype.connectWebsocket = function(cb) {
var client = this;
this.websocket = new WebSocket(Endpoints.WEBSOCKET_HUB);
this.websocket.onclose = function() {
client.triggerEvent("disconnected");
this.websocket.onclose = function(e) {
client.triggerEvent("disconnected", [e]);
};
this.websocket.onmessage = function(e) {
var dat = JSON.parse(e.data);
switch (dat.op) {
case 0:
@@ -137,14 +136,20 @@ exports.Client.prototype.connectWebsocket = function(cb) {
client.user = new User(data.user.username, data.user.id, data.user.discriminator, data.user.avatar);
} else if (dat.t === "MESSAGE_CREATE") {
var data = dat.d;
var channel = client.channelFromId(data.channel_id);
var message = new Message(data, channel);
client.triggerEvent("message", [message]);
} else if (dat.t === "PRESENCE_UPDATE"){
var data = dat.d;
client.triggerEvent("presence", [new User(data.user), data.status, client.serverList.filter("id", data.guild_id, true)]);
}
break;
@@ -173,8 +178,8 @@ exports.Client.prototype.connectWebsocket = function(cb) {
};
connDat.d.properties = {
"$os": "Windows",
"$browser": "Chrome",
"$os": "DiscordJS",
"$browser": "Dischromecord", // ;)
"$device": "discord.js",
"$referrer": "",
"$referring_domain": ""
@@ -239,6 +244,9 @@ exports.Client.prototype.sendMessage = function(channel, message, cb, _mentions)
exports.Client.prototype.deleteMessage = function(message) {
if(!message)
return false;
var client = this;
request
@@ -249,23 +257,6 @@ exports.Client.prototype.deleteMessage = function(message) {
});
}
exports.Client.prototype.logFile = function(name, url){
var fs = require("fs");
request
.get(url)
.set("authorization", this.token)
.end(function(err, res){
fs.writeFile("./log/"+name+".json", JSON.stringify(res.body, null, "\t"), function(err) {
if (err) {
return console.log(err);
}
});
});
}
exports.Client.prototype.channelFromId = function(id){
var channelList = this.serverList.concatSublists("channels", "id");
var channel = channelList.filter("id", id, true);
@@ -283,6 +274,11 @@ exports.Client.prototype.getChannelLogs = function(channel, amount, cb){
.set("authorization", client.token)
.end(function(err, res){
if(err){
cb(new List("id"));
return;
}
var datList = new List("id");
for(item of res.body){

View File

@@ -16,3 +16,9 @@ exports.Server = function(region, ownerID, name, id, members){
}
}
exports.Server.prototype.getDefaultChannel = function(){
return this.channels.filter("name", "general", true);
}