mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
Finished most of structure
This commit is contained in:
@@ -5,6 +5,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var Equality = require("../Util/Equality.js");
|
||||
var Cache = require("../Util/Cache.js");
|
||||
var PermissionOverwrite = require("./PermissionOverwrite.js");
|
||||
|
||||
var Channel = (function (_Equality) {
|
||||
_inherits(Channel, _Equality);
|
||||
@@ -13,7 +15,6 @@ var Channel = (function (_Equality) {
|
||||
_classCallCheck(this, Channel);
|
||||
|
||||
_Equality.call(this);
|
||||
this.type = data.type || "text";
|
||||
this.id = data.id;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
38
lib/Structures/Message.js
Normal file
38
lib/Structures/Message.js
Normal file
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var Cache = require("../Util/Cache.js");
|
||||
var User = require("./User.js");
|
||||
|
||||
var Message = function Message(data, channel, client) {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, Message);
|
||||
|
||||
this.channel = channel;
|
||||
this.client = client;
|
||||
|
||||
this.nonce = data.nonce;
|
||||
this.attachments = data.attachments;
|
||||
this.tts = data.tts;
|
||||
this.embeds = data.embeds;
|
||||
this.timestamp = Date.parse(data.timestamp);
|
||||
this.everyoneMentioned = data.mention_everyone;
|
||||
this.id = data.id;
|
||||
|
||||
if (data.edited_timestamp) this.editedTimestamp = Date.parse(data.edited_timestamp);
|
||||
this.author = client.internal.users.add(new User(data.author, client));
|
||||
this.content = data.content;
|
||||
this.mentions = new Cache();
|
||||
|
||||
data.mentions.forEach(function (mention) {
|
||||
// this is .add and not .get because it allows the bot to cache
|
||||
// users from messages from logs who may have left the server and were
|
||||
// not previously cached.
|
||||
console.log(mention);
|
||||
_this.mentions.add(client.internal.users.add(new User(mention, client)));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Message;
|
||||
@@ -1,5 +1,7 @@
|
||||
"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 _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
@@ -7,16 +9,31 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
||||
var Channel = require("./Channel.js");
|
||||
var Equality = require("../Util/Equality.js");
|
||||
|
||||
var PMChannel = (function (_Channel) {
|
||||
_inherits(PMChannel, _Channel);
|
||||
var PMChannel = (function (_Equality) {
|
||||
_inherits(PMChannel, _Equality);
|
||||
|
||||
function PMChannel(data, client) {
|
||||
_classCallCheck(this, PMChannel);
|
||||
|
||||
_Channel.call(this, data, client);
|
||||
_Equality.call(this);
|
||||
this.client = client;
|
||||
|
||||
this.type = data.type || "text";
|
||||
this.id = data.id;
|
||||
this.lastMessageId = data.last_message_id;
|
||||
this.recipient = this.client.internal.users.add(data.recipient);
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
|
||||
_createClass(PMChannel, [{
|
||||
key: "lastMessage",
|
||||
get: function get() {
|
||||
return this.messages.get("id", this.lastMessageID);
|
||||
}
|
||||
}]);
|
||||
|
||||
return PMChannel;
|
||||
})(Channel);
|
||||
})(Equality);
|
||||
|
||||
module.exports = PMChannel;
|
||||
@@ -10,7 +10,6 @@ var Equality = require("../Util/Equality.js");
|
||||
var Endpoints = require("../Constants.js").Endpoints;
|
||||
var Cache = require("../Util/Cache.js");
|
||||
var User = require("./User.js");
|
||||
var Member = require("./Member.js");
|
||||
var TextChannel = require("./TextChannel.js");
|
||||
var VoiceChannel = require("./VoiceChannel.js");
|
||||
var Role = require("./Role.js");
|
||||
@@ -38,10 +37,17 @@ var Server = (function (_Equality) {
|
||||
this.icon = data.icon;
|
||||
this.afkTimeout = data.afkTimeout;
|
||||
this.afkChannelID = data.afk_channel_id;
|
||||
this.memberMap = {};
|
||||
|
||||
data.members.forEach(function (dataUser) {
|
||||
var user = client.internal.users.add(new User(dataUser, client));
|
||||
_this.members.add(new Member(dataUser, client, self));
|
||||
_this.memberMap[dataUser.user.id] = {
|
||||
roles: dataUser.roles,
|
||||
mute: dataUser.mute,
|
||||
deaf: dataUser.deaf,
|
||||
joinedAt: Date.parse(dataUser.joined_at)
|
||||
};
|
||||
var user = client.internal.users.add(new User(dataUser.user, client));
|
||||
_this.members.add(user);
|
||||
});
|
||||
|
||||
data.channels.forEach(function (dataChannel) {
|
||||
|
||||
30
lib/Structures/ServerChannel.js
Normal file
30
lib/Structures/ServerChannel.js
Normal file
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var Channel = require("./Channel.js");
|
||||
var Cache = require("../Util/Cache.js");
|
||||
var PermissionOverwrite = require("./PermissionOverwrite.js");
|
||||
|
||||
var ServerChannel = (function (_Channel) {
|
||||
_inherits(ServerChannel, _Channel);
|
||||
|
||||
function ServerChannel(data, client) {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, ServerChannel);
|
||||
|
||||
_Channel.call(this, data, client);
|
||||
this.type = data.type;
|
||||
this.permissionOverwrites = new Cache();
|
||||
data.permission_overwrites.forEach(function (permission) {
|
||||
_this.permissionOverwrites.add(new PermissionOverwrite(permission));
|
||||
});
|
||||
}
|
||||
|
||||
return ServerChannel;
|
||||
})(Channel);
|
||||
|
||||
module.exports = ServerChannel;
|
||||
@@ -6,30 +6,22 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var Channel = require("./Channel.js");
|
||||
var ServerChannel = require("./ServerChannel.js");
|
||||
var Cache = require("../Util/Cache.js");
|
||||
var PermissionOverwrite = require("./PermissionOverwrite.js");
|
||||
|
||||
var TextChannel = (function (_Channel) {
|
||||
_inherits(TextChannel, _Channel);
|
||||
var TextChannel = (function (_ServerChannel) {
|
||||
_inherits(TextChannel, _ServerChannel);
|
||||
|
||||
function TextChannel(data, client) {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, TextChannel);
|
||||
|
||||
_Channel.call(this, data, client);
|
||||
_ServerChannel.call(this, data, client);
|
||||
|
||||
this.name = data.name;
|
||||
this.topic = data.topic;
|
||||
this.position = data.position;
|
||||
this.lastMessageID = data.last_message_id;
|
||||
this.messages = new Cache("id", client.options.maximumMessages);
|
||||
|
||||
this.permissionOverwrites = new Cache();
|
||||
data.permission_overwrites.forEach(function (permission) {
|
||||
_this.permissionOverwrites.add(new PermissionOverwrite(permission));
|
||||
});
|
||||
}
|
||||
|
||||
/* warning! may return null */
|
||||
@@ -42,6 +34,6 @@ var TextChannel = (function (_Channel) {
|
||||
}]);
|
||||
|
||||
return TextChannel;
|
||||
})(Channel);
|
||||
})(ServerChannel);
|
||||
|
||||
module.exports = TextChannel;
|
||||
@@ -4,18 +4,18 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var Channel = require("./Channel.js");
|
||||
var ServerChannel = require("./ServerChannel.js");
|
||||
|
||||
var VoiceChannel = (function (_Channel) {
|
||||
_inherits(VoiceChannel, _Channel);
|
||||
var VoiceChannel = (function (_ServerChannel) {
|
||||
_inherits(VoiceChannel, _ServerChannel);
|
||||
|
||||
function VoiceChannel(data, client) {
|
||||
_classCallCheck(this, VoiceChannel);
|
||||
|
||||
_Channel.call(this, data, client);
|
||||
_ServerChannel.call(this, data, client);
|
||||
}
|
||||
|
||||
return VoiceChannel;
|
||||
})(Channel);
|
||||
})(ServerChannel);
|
||||
|
||||
module.exports = VoiceChannel;
|
||||
Reference in New Issue
Block a user