mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
grunt default does weird things to lib
This commit is contained in:
@@ -509,6 +509,49 @@ var Client = (function (_EventEmitter) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//def setStatus
|
||||||
|
|
||||||
|
Client.prototype.setStatus = function setStatus(idleStatus, gameID) {
|
||||||
|
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2];
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
if (typeof gameID === "function") {
|
||||||
|
// gameID is the callback
|
||||||
|
callback = gameID;
|
||||||
|
} else if (typeof idleStatus === "function") {
|
||||||
|
// idleStatus is the callback
|
||||||
|
callback = idleStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.internal.setStatus(idleStatus, gameID).then(function () {
|
||||||
|
callback();
|
||||||
|
resolve();
|
||||||
|
})["catch"](function (e) {
|
||||||
|
callback(e);
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
//def sendTyping
|
||||||
|
|
||||||
|
Client.prototype.sendTyping = function sendTyping(channel) {
|
||||||
|
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
self.internal.sendTyping(channel).then(function () {
|
||||||
|
callback();
|
||||||
|
resolve();
|
||||||
|
})["catch"](function (e) {
|
||||||
|
callback(e);
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// def setTopic
|
// def setTopic
|
||||||
|
|
||||||
Client.prototype.setTopic = function setTopic(channel, topic) {
|
Client.prototype.setTopic = function setTopic(channel, topic) {
|
||||||
@@ -624,6 +667,16 @@ var Client = (function (_EventEmitter) {
|
|||||||
get: function get() {
|
get: function get() {
|
||||||
return this.internal.voiceConnection;
|
return this.internal.voiceConnection;
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
key: "readyTime",
|
||||||
|
get: function get() {
|
||||||
|
return this.internal.readyTime;
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: "uptime",
|
||||||
|
get: function get() {
|
||||||
|
return this.internal.uptime;
|
||||||
|
}
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
return Client;
|
return Client;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var EventEmitter = require("events");
|
var EventEmitter = require("events");
|
||||||
@@ -46,6 +48,7 @@ var InternalClient = (function () {
|
|||||||
this.private_channels = new Cache();
|
this.private_channels = new Cache();
|
||||||
this.voiceConnection = null;
|
this.voiceConnection = null;
|
||||||
this.resolver = new Resolver(this);
|
this.resolver = new Resolver(this);
|
||||||
|
this.readyTime = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//def leaveVoiceChannel
|
//def leaveVoiceChannel
|
||||||
@@ -856,6 +859,54 @@ var InternalClient = (function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//def setStatus
|
||||||
|
|
||||||
|
InternalClient.prototype.setStatus = function setStatus(idleStatus, gameID) {
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
var packet = {
|
||||||
|
op: 3,
|
||||||
|
d: {
|
||||||
|
idle_since: null,
|
||||||
|
game_id: null
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (idleStatus) {
|
||||||
|
packet.d.idle_since = Date.now();
|
||||||
|
}
|
||||||
|
if (typeof gameID === "number") {
|
||||||
|
packet.d.game_id = gameID;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.sendWS(packet);
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
//def sendTyping
|
||||||
|
|
||||||
|
InternalClient.prototype.sendTyping = function sendTyping(channel) {
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
self.resolver.resolveChannel(channel).then(next)["catch"](reject);
|
||||||
|
|
||||||
|
function next(channel) {
|
||||||
|
|
||||||
|
request.post(Endpoints.CHANNEL(channel.id) + "/typing").set("authorization", self.token).end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
//def setTopic
|
//def setTopic
|
||||||
|
|
||||||
InternalClient.prototype.setTopic = function setTopic(chann) {
|
InternalClient.prototype.setTopic = function setTopic(chann) {
|
||||||
@@ -870,7 +921,7 @@ var InternalClient = (function () {
|
|||||||
|
|
||||||
request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({
|
request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({
|
||||||
name: channel.name,
|
name: channel.name,
|
||||||
position: 0,
|
position: channel.position,
|
||||||
topic: topic
|
topic: topic
|
||||||
}).end(function (err, res) {
|
}).end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -898,7 +949,7 @@ var InternalClient = (function () {
|
|||||||
|
|
||||||
request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({
|
request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({
|
||||||
name: name,
|
name: name,
|
||||||
position: 0,
|
position: channel.position,
|
||||||
topic: channel.topic
|
topic: channel.topic
|
||||||
}).end(function (err, res) {
|
}).end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -927,7 +978,7 @@ var InternalClient = (function () {
|
|||||||
|
|
||||||
request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({
|
request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({
|
||||||
name: name,
|
name: name,
|
||||||
position: 0,
|
position: channel.position,
|
||||||
topic: topic
|
topic: topic
|
||||||
}).end(function (err, res) {
|
}).end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -985,6 +1036,10 @@ var InternalClient = (function () {
|
|||||||
client.emit("disconnected");
|
client.emit("disconnected");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.websocket.onerror = function (e) {
|
||||||
|
console.log(e);
|
||||||
|
};
|
||||||
|
|
||||||
this.websocket.onmessage = function (e) {
|
this.websocket.onmessage = function (e) {
|
||||||
|
|
||||||
if (e.type === "Binary") {
|
if (e.type === "Binary") {
|
||||||
@@ -1023,6 +1078,8 @@ var InternalClient = (function () {
|
|||||||
client.emit("ready");
|
client.emit("ready");
|
||||||
client.emit("debug", "ready packet took " + (Date.now() - startTime) + "ms to process");
|
client.emit("debug", "ready packet took " + (Date.now() - startTime) + "ms to process");
|
||||||
client.emit("debug", "ready with " + self.servers.length + " servers, " + self.channels.length + " channels and " + self.users.length + " users cached.");
|
client.emit("debug", "ready with " + self.servers.length + " servers, " + self.channels.length + " channels and " + self.users.length + " users cached.");
|
||||||
|
|
||||||
|
self.readyTime = Date.now();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PacketType.MESSAGE_CREATE:
|
case PacketType.MESSAGE_CREATE:
|
||||||
@@ -1368,6 +1425,13 @@ var InternalClient = (function () {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_createClass(InternalClient, [{
|
||||||
|
key: "uptime",
|
||||||
|
get: function get() {
|
||||||
|
return this.readyTime ? Date.now() - this.readyTime : null;
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
|
||||||
return InternalClient;
|
return InternalClient;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ var ServerChannel = (function (_Channel) {
|
|||||||
_Channel.call(this, data, client);
|
_Channel.call(this, data, client);
|
||||||
this.name = data.name;
|
this.name = data.name;
|
||||||
this.type = data.type;
|
this.type = data.type;
|
||||||
|
this.position = data.position;
|
||||||
this.permissionOverwrites = new Cache();
|
this.permissionOverwrites = new Cache();
|
||||||
this.server = server;
|
this.server = server;
|
||||||
data.permission_overwrites.forEach(function (permission) {
|
data.permission_overwrites.forEach(function (permission) {
|
||||||
|
|||||||
@@ -3,24 +3,24 @@
|
|||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var VoicePacket = function VoicePacket(data, sequence, time, ssrc) {
|
var VoicePacket = function VoicePacket(data, sequence, time, ssrc) {
|
||||||
_classCallCheck(this, VoicePacket);
|
_classCallCheck(this, VoicePacket);
|
||||||
|
|
||||||
var audioBuffer = data,
|
var audioBuffer = data,
|
||||||
returnBuffer = new Buffer(audioBuffer.length + 12);
|
returnBuffer = new Buffer(audioBuffer.length + 12);
|
||||||
|
|
||||||
returnBuffer.fill(0);
|
returnBuffer.fill(0);
|
||||||
returnBuffer[0] = 0x80;
|
returnBuffer[0] = 0x80;
|
||||||
returnBuffer[1] = 0x78;
|
returnBuffer[1] = 0x78;
|
||||||
|
|
||||||
returnBuffer.writeUIntBE(sequence, 2, 2);
|
returnBuffer.writeUIntBE(sequence, 2, 2);
|
||||||
returnBuffer.writeUIntBE(time, 4, 4);
|
returnBuffer.writeUIntBE(time, 4, 4);
|
||||||
returnBuffer.writeUIntBE(ssrc, 8, 4);
|
returnBuffer.writeUIntBE(ssrc, 8, 4);
|
||||||
|
|
||||||
for (var i = 0; i < audioBuffer.length; i++) {
|
for (var i = 0; i < audioBuffer.length; i++) {
|
||||||
returnBuffer[i + 12] = audioBuffer[i];
|
returnBuffer[i + 12] = audioBuffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnBuffer;
|
return returnBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = VoicePacket;
|
module.exports = VoicePacket;
|
||||||
Reference in New Issue
Block a user