mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
minor fixes
slightly more stable, removed redundant functions and added one or two features ;)
This commit is contained in:
42
index.js
42
index.js
@@ -101,13 +101,12 @@ exports.Client.prototype.connectWebsocket = function(cb) {
|
|||||||
var client = this;
|
var client = this;
|
||||||
|
|
||||||
this.websocket = new WebSocket(Endpoints.WEBSOCKET_HUB);
|
this.websocket = new WebSocket(Endpoints.WEBSOCKET_HUB);
|
||||||
this.websocket.onclose = function() {
|
this.websocket.onclose = function(e) {
|
||||||
client.triggerEvent("disconnected");
|
client.triggerEvent("disconnected", [e]);
|
||||||
};
|
};
|
||||||
this.websocket.onmessage = function(e) {
|
this.websocket.onmessage = function(e) {
|
||||||
|
|
||||||
var dat = JSON.parse(e.data);
|
var dat = JSON.parse(e.data);
|
||||||
|
|
||||||
switch (dat.op) {
|
switch (dat.op) {
|
||||||
|
|
||||||
case 0:
|
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);
|
client.user = new User(data.user.username, data.user.id, data.user.discriminator, data.user.avatar);
|
||||||
} else if (dat.t === "MESSAGE_CREATE") {
|
} else if (dat.t === "MESSAGE_CREATE") {
|
||||||
|
|
||||||
var data = dat.d;
|
var data = dat.d;
|
||||||
|
|
||||||
var channel = client.channelFromId(data.channel_id);
|
var channel = client.channelFromId(data.channel_id);
|
||||||
|
|
||||||
var message = new Message(data, channel);
|
var message = new Message(data, channel);
|
||||||
|
|
||||||
client.triggerEvent("message", [message]);
|
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;
|
break;
|
||||||
|
|
||||||
@@ -173,8 +178,8 @@ exports.Client.prototype.connectWebsocket = function(cb) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
connDat.d.properties = {
|
connDat.d.properties = {
|
||||||
"$os": "Windows",
|
"$os": "DiscordJS",
|
||||||
"$browser": "Chrome",
|
"$browser": "Dischromecord", // ;)
|
||||||
"$device": "discord.js",
|
"$device": "discord.js",
|
||||||
"$referrer": "",
|
"$referrer": "",
|
||||||
"$referring_domain": ""
|
"$referring_domain": ""
|
||||||
@@ -239,6 +244,9 @@ exports.Client.prototype.sendMessage = function(channel, message, cb, _mentions)
|
|||||||
|
|
||||||
exports.Client.prototype.deleteMessage = function(message) {
|
exports.Client.prototype.deleteMessage = function(message) {
|
||||||
|
|
||||||
|
if(!message)
|
||||||
|
return false;
|
||||||
|
|
||||||
var client = this;
|
var client = this;
|
||||||
|
|
||||||
request
|
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){
|
exports.Client.prototype.channelFromId = function(id){
|
||||||
var channelList = this.serverList.concatSublists("channels", "id");
|
var channelList = this.serverList.concatSublists("channels", "id");
|
||||||
var channel = channelList.filter("id", id, true);
|
var channel = channelList.filter("id", id, true);
|
||||||
@@ -283,6 +274,11 @@ exports.Client.prototype.getChannelLogs = function(channel, amount, cb){
|
|||||||
.set("authorization", client.token)
|
.set("authorization", client.token)
|
||||||
.end(function(err, res){
|
.end(function(err, res){
|
||||||
|
|
||||||
|
if(err){
|
||||||
|
cb(new List("id"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var datList = new List("id");
|
var datList = new List("id");
|
||||||
|
|
||||||
for(item of res.body){
|
for(item of res.body){
|
||||||
|
|||||||
@@ -16,3 +16,9 @@ exports.Server = function(region, ownerID, name, id, members){
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.Server.prototype.getDefaultChannel = function(){
|
||||||
|
|
||||||
|
return this.channels.filter("name", "general", true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user