Gateway v6 support

This commit is contained in:
abalabahaha
2016-09-18 09:26:29 +09:00
parent d96f5d1e30
commit 34323c869e
10 changed files with 113 additions and 44 deletions

View File

@@ -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];

View File

@@ -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);

View File

@@ -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)));