mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
More rewrites
This commit is contained in:
24
lib/Structures/Channel.js
Normal file
24
lib/Structures/Channel.js
Normal file
@@ -0,0 +1,24 @@
|
||||
"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 Equality = require("../Util/Equality.js");
|
||||
|
||||
var Channel = (function (_Equality) {
|
||||
_inherits(Channel, _Equality);
|
||||
|
||||
function Channel(data, client) {
|
||||
_classCallCheck(this, Channel);
|
||||
|
||||
_Equality.call(this);
|
||||
this.type = data.type || "text";
|
||||
this.id = data.id;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
return Channel;
|
||||
})(Equality);
|
||||
|
||||
module.exports = Channel;
|
||||
31
lib/Structures/Member.js
Normal file
31
lib/Structures/Member.js
Normal file
@@ -0,0 +1,31 @@
|
||||
"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; }
|
||||
|
||||
var User = require("./User.js");
|
||||
|
||||
var Member = (function (_User) {
|
||||
_inherits(Member, _User);
|
||||
|
||||
function Member(data, client, server) {
|
||||
_classCallCheck(this, Member);
|
||||
|
||||
_User.call(this, data, client);
|
||||
this.serverID = server;
|
||||
}
|
||||
|
||||
_createClass(Member, [{
|
||||
key: "server",
|
||||
get: function get() {
|
||||
return this.client.internal.servers.get("id", this.serverID);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Member;
|
||||
})(User);
|
||||
|
||||
module.exports = Member;
|
||||
22
lib/Structures/PMChannel.js
Normal file
22
lib/Structures/PMChannel.js
Normal file
@@ -0,0 +1,22 @@
|
||||
"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 Equality = require("../Util/Equality.js");
|
||||
|
||||
var PMChannel = (function (_Channel) {
|
||||
_inherits(PMChannel, _Channel);
|
||||
|
||||
function PMChannel(data, client) {
|
||||
_classCallCheck(this, PMChannel);
|
||||
|
||||
_Channel.call(this, data, client);
|
||||
}
|
||||
|
||||
return PMChannel;
|
||||
})(Channel);
|
||||
|
||||
module.exports = PMChannel;
|
||||
91
lib/Structures/Server.js
Normal file
91
lib/Structures/Server.js
Normal file
@@ -0,0 +1,91 @@
|
||||
"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; }
|
||||
|
||||
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 Server = (function (_Equality) {
|
||||
_inherits(Server, _Equality);
|
||||
|
||||
function Server(data, client) {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, Server);
|
||||
|
||||
_Equality.call(this);
|
||||
|
||||
var self = this;
|
||||
this.client = client;
|
||||
|
||||
this.region = data.region;
|
||||
this.ownerID = data.owner_id;
|
||||
this.name = data.name;
|
||||
this.id = data.id;
|
||||
this.members = new Cache();
|
||||
this.channels = new Cache();
|
||||
this.roles = new Cache();
|
||||
this.icon = data.icon;
|
||||
this.afkTimeout = data.afkTimeout;
|
||||
this.afkChannelID = data.afk_channel_id;
|
||||
|
||||
data.members.forEach(function (dataUser) {
|
||||
var user = client.internal.users.add(new User(dataUser, client));
|
||||
_this.members.add(new Member(dataUser, client, self));
|
||||
});
|
||||
|
||||
data.channels.forEach(function (dataChannel) {
|
||||
|
||||
if (dataChannel.type === "text") {
|
||||
var channel = client.internal.channels.add(new TextChannel(dataChannel, client));
|
||||
_this.channels.add(channel);
|
||||
} else {
|
||||
var channel = client.internal.channels.add(new VoiceChannel(dataChannel, client));
|
||||
_this.channels.add(channel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Server.prototype.toString = function toString() {
|
||||
return this.name;
|
||||
};
|
||||
|
||||
_createClass(Server, [{
|
||||
key: "iconURL",
|
||||
get: function get() {
|
||||
if (!this.icon) {
|
||||
return null;
|
||||
} else {
|
||||
return Endpoints.SERVER_ICON(this.id, this.icon);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "afkChannel",
|
||||
get: function get() {
|
||||
return this.channels.get("id", this.afkChannelID);
|
||||
}
|
||||
}, {
|
||||
key: "defaultChannel",
|
||||
get: function get() {
|
||||
return this.channels.get("id", this.id);
|
||||
}
|
||||
}, {
|
||||
key: "owner",
|
||||
get: function get() {
|
||||
return this.members.get("id", this.ownerID);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Server;
|
||||
})(Equality);
|
||||
|
||||
module.exports = Server;
|
||||
23
lib/Structures/TextChannel.js
Normal file
23
lib/Structures/TextChannel.js
Normal file
@@ -0,0 +1,23 @@
|
||||
"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 TextChannel = (function (_Channel) {
|
||||
_inherits(TextChannel, _Channel);
|
||||
|
||||
function TextChannel(data, client) {
|
||||
_classCallCheck(this, TextChannel);
|
||||
|
||||
_Channel.call(this, data, client);
|
||||
this.messages = new Cache("id", client.options.maximumMessages);
|
||||
}
|
||||
|
||||
return TextChannel;
|
||||
})(Channel);
|
||||
|
||||
module.exports = TextChannel;
|
||||
50
lib/Structures/User.js
Normal file
50
lib/Structures/User.js
Normal file
@@ -0,0 +1,50 @@
|
||||
"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; }
|
||||
|
||||
var Equality = require("../Util/Equality.js");
|
||||
var Endpoints = require("../Constants.js").Endpoints;
|
||||
|
||||
var User = (function (_Equality) {
|
||||
_inherits(User, _Equality);
|
||||
|
||||
function User(data, client) {
|
||||
_classCallCheck(this, User);
|
||||
|
||||
_Equality.call(this);
|
||||
this.client = client;
|
||||
this.username = data.username;
|
||||
this.discriminator = data.discriminator;
|
||||
this.id = data.id;
|
||||
this.avatar = data.avatar;
|
||||
this.status = data.status || "offline";
|
||||
this.gameID = data.game_id || null;
|
||||
}
|
||||
|
||||
User.prototype.mention = function mention() {
|
||||
return "<@" + this.id + ">";
|
||||
};
|
||||
|
||||
User.prototype.toString = function toString() {
|
||||
return this.mention();
|
||||
};
|
||||
|
||||
_createClass(User, [{
|
||||
key: "avatarURL",
|
||||
get: function get() {
|
||||
if (!this.avatar) {
|
||||
return null;
|
||||
} else {
|
||||
return Endpoints.AVATAR(this.id, this.avatar);
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
return User;
|
||||
})(Equality);
|
||||
|
||||
module.exports = User;
|
||||
21
lib/Structures/VoiceChannel.js
Normal file
21
lib/Structures/VoiceChannel.js
Normal file
@@ -0,0 +1,21 @@
|
||||
"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 VoiceChannel = (function (_Channel) {
|
||||
_inherits(VoiceChannel, _Channel);
|
||||
|
||||
function VoiceChannel(data, client) {
|
||||
_classCallCheck(this, VoiceChannel);
|
||||
|
||||
_Channel.call(this, data, client);
|
||||
}
|
||||
|
||||
return VoiceChannel;
|
||||
})(Channel);
|
||||
|
||||
module.exports = VoiceChannel;
|
||||
Reference in New Issue
Block a user