mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
Gateway v6 support
This commit is contained in:
@@ -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