mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Gateway v6 support
This commit is contained in:
@@ -802,13 +802,13 @@ var Client = (function (_EventEmitter) {
|
||||
// def createChannel
|
||||
|
||||
Client.prototype.createChannel = function createChannel(server, name) {
|
||||
var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2];
|
||||
var type = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
|
||||
var callback = arguments.length <= 3 || arguments[3] === undefined ? function () /*err, channel*/{} : arguments[3];
|
||||
|
||||
if (typeof type === "function") {
|
||||
// options is the callback
|
||||
callback = type;
|
||||
type = "text";
|
||||
type = 0;
|
||||
}
|
||||
|
||||
return this.internal.createChannel(server, name, type).then(dataCallback(callback), errorCallback(callback));
|
||||
|
||||
@@ -86,7 +86,7 @@ var _UtilTokenCacher = require("../Util/TokenCacher");
|
||||
|
||||
var _UtilTokenCacher2 = _interopRequireDefault(_UtilTokenCacher);
|
||||
|
||||
var GATEWAY_VERSION = 5;
|
||||
var GATEWAY_VERSION = 6;
|
||||
var zlib;
|
||||
var libVersion = require('../../package.json').version;
|
||||
|
||||
@@ -1082,7 +1082,7 @@ var InternalClient = (function () {
|
||||
InternalClient.prototype.createChannel = function createChannel(server, name) {
|
||||
var _this21 = this;
|
||||
|
||||
var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2];
|
||||
var type = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
|
||||
|
||||
server = this.resolver.resolveServer(server);
|
||||
|
||||
@@ -1091,7 +1091,7 @@ var InternalClient = (function () {
|
||||
type: type
|
||||
}).then(function (res) {
|
||||
var channel;
|
||||
if (res.type === "text") {
|
||||
if (res.type === 0) {
|
||||
channel = new _StructuresTextChannel2["default"](res, _this21.client, server);
|
||||
} else {
|
||||
channel = new _StructuresVoiceChannel2["default"](res, _this21.client, server);
|
||||
@@ -1908,7 +1908,6 @@ var InternalClient = (function () {
|
||||
_this36.identify();
|
||||
break;
|
||||
case 10:
|
||||
console.log(packet);
|
||||
if (_this36.sessionID) {
|
||||
_this36.resume();
|
||||
} else {
|
||||
@@ -2080,15 +2079,15 @@ var InternalClient = (function () {
|
||||
|
||||
if (msg) {
|
||||
// old message exists
|
||||
data.nonce = data.nonce || msg.nonce;
|
||||
data.attachments = data.attachments || msg.attachments;
|
||||
data.tts = data.tts || msg.tts;
|
||||
data.embeds = data.embeds || msg.embeds;
|
||||
data.timestamp = data.timestamp || msg.timestamp;
|
||||
data.mention_everyone = data.mention_everyone || msg.everyoneMentioned;
|
||||
data.content = data.content || msg.content;
|
||||
data.mentions = data.mentions || msg.mentions;
|
||||
data.author = data.author || msg.author;
|
||||
data.nonce = data.nonce !== undefined ? data.nonce : msg.nonce;
|
||||
data.attachments = data.attachments !== undefined ? data.attachments : msg.attachments;
|
||||
data.tts = data.tts !== undefined ? data.tts : msg.tts;
|
||||
data.embeds = data.embeds !== undefined ? data.embeds : msg.embeds;
|
||||
data.timestamp = data.timestamp !== undefined ? data.timestamp : msg.timestamp;
|
||||
data.mention_everyone = data.mention_everyone !== undefined ? data.mention_everyone : msg.everyoneMentioned;
|
||||
data.content = data.content !== undefined ? data.content : msg.content;
|
||||
data.mentions = data.mentions !== undefined ? data.mentions : msg.mentions;
|
||||
data.author = data.author !== undefined ? data.author : msg.author;
|
||||
msg = new _StructuresMessage2["default"](msg, channel, client);
|
||||
} else if (!data.author || !data.content) {
|
||||
break;
|
||||
@@ -2230,7 +2229,7 @@ var InternalClient = (function () {
|
||||
var server = this.servers.get("id", data.guild_id);
|
||||
if (server) {
|
||||
var chan = null;
|
||||
if (data.type === "text") {
|
||||
if (data.type === 0) {
|
||||
chan = this.channels.add(new _StructuresTextChannel2["default"](data, client, server));
|
||||
} else {
|
||||
chan = this.channels.add(new _StructuresVoiceChannel2["default"](data, client, server));
|
||||
@@ -2272,7 +2271,7 @@ var InternalClient = (function () {
|
||||
client.emit("channelUpdated", new _StructuresPMChannel2["default"](channel, client), this.private_channels.update(channel, new _StructuresPMChannel2["default"](data, client)));
|
||||
} else {
|
||||
if (channel.server) {
|
||||
if (channel.type === "text") {
|
||||
if (channel.type === 0) {
|
||||
//TEXT CHANNEL
|
||||
var chan = new _StructuresTextChannel2["default"](data, client, channel.server);
|
||||
chan.messages = channel.messages;
|
||||
|
||||
@@ -39,12 +39,14 @@ var Message = (function (_Equality) {
|
||||
_classCallCheck(this, Message);
|
||||
|
||||
_Equality.call(this);
|
||||
this.type = data.type;
|
||||
this.channel = channel;
|
||||
this.server = channel.server;
|
||||
this.client = client;
|
||||
this.nonce = data.nonce;
|
||||
this.attachments = data.attachments;
|
||||
this.tts = data.tts;
|
||||
this.pinned = data.pinned;
|
||||
this.embeds = data.embeds;
|
||||
this.timestamp = Date.parse(data.timestamp);
|
||||
this.everyoneMentioned = data.mention_everyone !== undefined ? data.mention_everyone : data.everyoneMentioned;
|
||||
@@ -61,7 +63,25 @@ var Message = (function (_Equality) {
|
||||
this.author = client.internal.users.add(new _User2["default"](data.author, client));
|
||||
}
|
||||
|
||||
this.content = data.content;
|
||||
if (this.type === 0) {
|
||||
this.content = data.content;
|
||||
} else if (this.type === 1) {
|
||||
this.content = this.author.mention() + " added <@" + data.mentions[0].id + ">.";
|
||||
} else if (this.type === 2) {
|
||||
if (this.author.id === data.mentions[0].id) {
|
||||
this.content = this.author.mention() + " left the group.";
|
||||
} else {
|
||||
this.content = this.author.mention() + " removed <@" + data.mentions[0].id + ">.";
|
||||
}
|
||||
} else if (this.type === 3) {
|
||||
this.content = this.author.mention() + " started a call.";
|
||||
} else if (this.type === 4) {
|
||||
this.content = this.author.mention() + " changed the channel name: " + data.content;
|
||||
} else if (this.type === 5) {
|
||||
this.content = this.author.mention() + " changed the channel icon.";
|
||||
} else if (this.type === 6) {
|
||||
this.content = this.author.mention() + " pinned a message to this channel. See all the pins.";
|
||||
}
|
||||
|
||||
var mentionData = client.internal.resolver.resolveMentions(data.content, channel);
|
||||
this.cleanContent = mentionData[1];
|
||||
|
||||
@@ -28,18 +28,28 @@ var PMChannel = (function (_Channel) {
|
||||
_inherits(PMChannel, _Channel);
|
||||
|
||||
function PMChannel(data, client) {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, PMChannel);
|
||||
|
||||
_Channel.call(this, data, client);
|
||||
|
||||
this.type = data.type || "text";
|
||||
this.type = data.type;
|
||||
this.lastMessageID = data.last_message_id || data.lastMessageID;
|
||||
this.messages = new _UtilCache2["default"]("id", client.options.maxCachedMessages);
|
||||
this.recipient = this.client.internal.users.add(new _User2["default"](data.recipient, this.client));
|
||||
if (data.recipients instanceof _UtilCache2["default"]) {
|
||||
this.recipients = data.recipients;
|
||||
} else {
|
||||
this.recipients = new _UtilCache2["default"]();
|
||||
data.recipients.forEach(function (recipient) {
|
||||
_this.recipients.add(_this.client.internal.users.add(new _User2["default"](recipient, _this.client)));
|
||||
});
|
||||
}
|
||||
this.name = data.name !== undefined ? data.name : this.name;
|
||||
this.owner = data.owner || this.client.internal.users.get("id", data.owner_id);
|
||||
this.icon = data.icon !== undefined ? data.icon : this.icon;
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
|
||||
PMChannel.prototype.toString = function toString() {
|
||||
return this.recipient.toString();
|
||||
};
|
||||
@@ -105,6 +115,13 @@ var PMChannel = (function (_Channel) {
|
||||
};
|
||||
|
||||
_createClass(PMChannel, [{
|
||||
key: "recipient",
|
||||
get: function get() {
|
||||
return this.recipients[0];
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
}, {
|
||||
key: "lastMessage",
|
||||
get: function get() {
|
||||
return this.messages.get("id", this.lastMessageID);
|
||||
|
||||
@@ -134,7 +134,7 @@ var Server = (function (_Equality) {
|
||||
});
|
||||
} else {
|
||||
data.channels.forEach(function (dataChannel) {
|
||||
if (dataChannel.type === "text") {
|
||||
if (dataChannel.type === 0) {
|
||||
_this.channels.add(client.internal.channels.add(new _TextChannel2["default"](dataChannel, client, _this)));
|
||||
} else {
|
||||
_this.channels.add(client.internal.channels.add(new _VoiceChannel2["default"](dataChannel, client, _this)));
|
||||
|
||||
@@ -877,11 +877,11 @@ export default class Client extends EventEmitter {
|
||||
}
|
||||
|
||||
// def createChannel
|
||||
createChannel(server, name, type = "text", callback = (/*err, channel*/) => { }) {
|
||||
createChannel(server, name, type = 0, callback = (/*err, channel*/) => { }) {
|
||||
if (typeof type === "function") {
|
||||
// options is the callback
|
||||
callback = type;
|
||||
type = "text";
|
||||
type = 0;
|
||||
}
|
||||
|
||||
return this.internal.createChannel(server, name, type)
|
||||
|
||||
@@ -24,7 +24,7 @@ import Invite from "../Structures/Invite";
|
||||
import VoiceConnection from "../Voice/VoiceConnection";
|
||||
import TokenCacher from "../Util/TokenCacher";
|
||||
|
||||
var GATEWAY_VERSION = 5;
|
||||
var GATEWAY_VERSION = 6;
|
||||
var zlib;
|
||||
var libVersion = require('../../package.json').version;
|
||||
|
||||
@@ -935,7 +935,7 @@ export default class InternalClient {
|
||||
}
|
||||
|
||||
// def createChannel
|
||||
createChannel(server, name, type = "text") {
|
||||
createChannel(server, name, type = 0) {
|
||||
|
||||
server = this.resolver.resolveServer(server);
|
||||
|
||||
@@ -945,7 +945,7 @@ export default class InternalClient {
|
||||
})
|
||||
.then(res => {
|
||||
var channel;
|
||||
if (res.type === "text") {
|
||||
if (res.type === 0) {
|
||||
channel = new TextChannel(res, this.client, server);
|
||||
} else {
|
||||
channel = new VoiceChannel(res, this.client, server);
|
||||
@@ -1679,7 +1679,6 @@ export default class InternalClient {
|
||||
this.identify();
|
||||
break;
|
||||
case 10:
|
||||
console.log(packet);
|
||||
if(this.sessionID) {
|
||||
this.resume();
|
||||
} else {
|
||||
@@ -1840,15 +1839,15 @@ export default class InternalClient {
|
||||
|
||||
if (msg) {
|
||||
// old message exists
|
||||
data.nonce = data.nonce || msg.nonce;
|
||||
data.attachments = data.attachments || msg.attachments;
|
||||
data.tts = data.tts || msg.tts;
|
||||
data.embeds = data.embeds || msg.embeds;
|
||||
data.timestamp = data.timestamp || msg.timestamp;
|
||||
data.mention_everyone = data.mention_everyone || msg.everyoneMentioned;
|
||||
data.content = data.content || msg.content;
|
||||
data.mentions = data.mentions || msg.mentions;
|
||||
data.author = data.author || msg.author;
|
||||
data.nonce = data.nonce !== undefined ? data.nonce : msg.nonce;
|
||||
data.attachments = data.attachments !== undefined ? data.attachments : msg.attachments;
|
||||
data.tts = data.tts !== undefined ? data.tts : msg.tts;
|
||||
data.embeds = data.embeds !== undefined ? data.embeds : msg.embeds;
|
||||
data.timestamp = data.timestamp !== undefined ? data.timestamp : msg.timestamp;
|
||||
data.mention_everyone = data.mention_everyone !== undefined ? data.mention_everyone : msg.everyoneMentioned;
|
||||
data.content = data.content !== undefined ? data.content : msg.content;
|
||||
data.mentions = data.mentions !== undefined ? data.mentions : msg.mentions;
|
||||
data.author = data.author !== undefined ? data.author : msg.author;
|
||||
msg = new Message(msg, channel, client);
|
||||
} else if (!data.author || !data.content) {
|
||||
break;
|
||||
@@ -1955,7 +1954,7 @@ export default class InternalClient {
|
||||
var server = this.servers.get("id", data.guild_id);
|
||||
if (server) {
|
||||
var chan = null;
|
||||
if (data.type === "text") {
|
||||
if (data.type === 0) {
|
||||
chan = this.channels.add(new TextChannel(data, client, server));
|
||||
} else {
|
||||
chan = this.channels.add(new VoiceChannel(data, client, server));
|
||||
@@ -1999,7 +1998,7 @@ export default class InternalClient {
|
||||
this.private_channels.update(channel, new PMChannel(data, client)));
|
||||
} else {
|
||||
if (channel.server) {
|
||||
if (channel.type === "text") {
|
||||
if (channel.type === 0) {
|
||||
//TEXT CHANNEL
|
||||
var chan = new TextChannel(data, client, channel.server);
|
||||
chan.messages = channel.messages;
|
||||
|
||||
@@ -14,12 +14,14 @@ import Equality from "../Util/Equality";
|
||||
export default class Message extends Equality{
|
||||
constructor(data, channel, client) {
|
||||
super();
|
||||
this.type = data.type;
|
||||
this.channel = channel;
|
||||
this.server = channel.server;
|
||||
this.client = client;
|
||||
this.nonce = data.nonce;
|
||||
this.attachments = data.attachments;
|
||||
this.tts = data.tts;
|
||||
this.pinned = data.pinned;
|
||||
this.embeds = data.embeds;
|
||||
this.timestamp = Date.parse(data.timestamp);
|
||||
this.everyoneMentioned = data.mention_everyone !== undefined ? data.mention_everyone : data.everyoneMentioned;
|
||||
@@ -36,7 +38,25 @@ export default class Message extends Equality{
|
||||
this.author = client.internal.users.add(new User(data.author, client));
|
||||
}
|
||||
|
||||
this.content = data.content;
|
||||
if(this.type === 0) {
|
||||
this.content = data.content;
|
||||
} else if(this.type === 1) {
|
||||
this.content = this.author.mention() + " added <@" + data.mentions[0].id + ">.";
|
||||
} else if(this.type === 2) {
|
||||
if(this.author.id === data.mentions[0].id) {
|
||||
this.content = this.author.mention() + " left the group.";
|
||||
} else {
|
||||
this.content = this.author.mention() + " removed <@" + data.mentions[0].id + ">.";
|
||||
}
|
||||
} else if(this.type === 3) {
|
||||
this.content = this.author.mention() + " started a call.";
|
||||
} else if(this.type === 4) {
|
||||
this.content = this.author.mention() + " changed the channel name: " + data.content;
|
||||
} else if(this.type === 5) {
|
||||
this.content = this.author.mention() + " changed the channel icon.";
|
||||
} else if(this.type === 6) {
|
||||
this.content = this.author.mention() + " pinned a message to this channel. See all the pins.";
|
||||
}
|
||||
|
||||
var mentionData = client.internal.resolver.resolveMentions(data.content, channel);
|
||||
this.cleanContent = mentionData[1];
|
||||
|
||||
@@ -9,10 +9,24 @@ export default class PMChannel extends Channel {
|
||||
constructor(data, client){
|
||||
super(data, client);
|
||||
|
||||
this.type = data.type || "text";
|
||||
this.type = data.type;
|
||||
this.lastMessageID = data.last_message_id || data.lastMessageID;
|
||||
this.messages = new Cache("id", client.options.maxCachedMessages);
|
||||
this.recipient = this.client.internal.users.add(new User(data.recipient, this.client));
|
||||
if(data.recipients instanceof Cache) {
|
||||
this.recipients = data.recipients;
|
||||
} else {
|
||||
this.recipients = new Cache();
|
||||
data.recipients.forEach((recipient) => {
|
||||
this.recipients.add(this.client.internal.users.add(new User(recipient, this.client)));
|
||||
});
|
||||
}
|
||||
this.name = data.name !== undefined ? data.name : this.name;
|
||||
this.owner = data.owner || this.client.internal.users.get("id", data.owner_id);
|
||||
this.icon = data.icon !== undefined ? data.icon : this.icon;
|
||||
}
|
||||
|
||||
get recipient() {
|
||||
return this.recipients[0];
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
|
||||
@@ -88,7 +88,7 @@ export default class Server extends Equality {
|
||||
data.channels.forEach((channel) => this.channels.add(channel));
|
||||
} else {
|
||||
data.channels.forEach((dataChannel) => {
|
||||
if (dataChannel.type === "text") {
|
||||
if (dataChannel.type === 0) {
|
||||
this.channels.add(client.internal.channels.add(new TextChannel(dataChannel, client, this)));
|
||||
} else {
|
||||
this.channels.add(client.internal.channels.add(new VoiceChannel(dataChannel, client, this)));
|
||||
|
||||
Reference in New Issue
Block a user