mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
push files again
This commit is contained in:
1365
lib/Client.js
Normal file
1365
lib/Client.js
Normal file
File diff suppressed because it is too large
Load Diff
13
lib/Endpoints.js
Normal file
13
lib/Endpoints.js
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
exports.BASE_DOMAIN = "discordapp.com";
|
||||
exports.BASE = "https://" + exports.BASE_DOMAIN;
|
||||
exports.WEBSOCKET_HUB = "wss://" + exports.BASE_DOMAIN + "/hub";
|
||||
|
||||
exports.API = exports.BASE + "/api";
|
||||
exports.AUTH = exports.API + "/auth";
|
||||
exports.LOGIN = exports.AUTH + "/login";
|
||||
exports.LOGOUT = exports.AUTH + "/logout";
|
||||
exports.USERS = exports.API + "/users";
|
||||
exports.SERVERS = exports.API + "/guilds";
|
||||
exports.CHANNELS = exports.API + "/channels";
|
||||
61
lib/PMChannel.js
Normal file
61
lib/PMChannel.js
Normal file
@@ -0,0 +1,61 @@
|
||||
"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"); } }
|
||||
|
||||
var PMChannel = (function () {
|
||||
function PMChannel(data, client) {
|
||||
_classCallCheck(this, PMChannel);
|
||||
|
||||
this.user = client.getUser("id", data.recipient.id);
|
||||
this.id = data.id;
|
||||
this.messages = [];
|
||||
}
|
||||
|
||||
_createClass(PMChannel, [{
|
||||
key: "addMessage",
|
||||
value: function addMessage(data) {
|
||||
if (!this.getMessage("id", data.id)) {
|
||||
this.messages.push(data);
|
||||
}
|
||||
return this.getMessage("id", data.id);
|
||||
}
|
||||
}, {
|
||||
key: "getMessage",
|
||||
value: function getMessage(key, value) {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var message = _step.value;
|
||||
|
||||
if (message[key] === value) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator["return"]) {
|
||||
_iterator["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}]);
|
||||
|
||||
return PMChannel;
|
||||
})();
|
||||
|
||||
module.exports = PMChannel;
|
||||
74
lib/channel.js
Normal file
74
lib/channel.js
Normal file
@@ -0,0 +1,74 @@
|
||||
"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"); } }
|
||||
|
||||
var Channel = (function () {
|
||||
function Channel(data, server) {
|
||||
_classCallCheck(this, Channel);
|
||||
|
||||
this.server = server;
|
||||
this.name = data.name;
|
||||
this.type = data.type;
|
||||
this.id = data.id;
|
||||
this.messages = [];
|
||||
//this.isPrivate = isPrivate; //not sure about the implementation of this...
|
||||
}
|
||||
|
||||
_createClass(Channel, [{
|
||||
key: "equals",
|
||||
value: function equals(object) {
|
||||
return object.id === this.id;
|
||||
}
|
||||
}, {
|
||||
key: "addMessage",
|
||||
value: function addMessage(data) {
|
||||
if (!this.getMessage("id", data.id)) {
|
||||
this.messages.push(data);
|
||||
}
|
||||
return this.getMessage("id", data.id);
|
||||
}
|
||||
}, {
|
||||
key: "getMessage",
|
||||
value: function getMessage(key, value) {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var message = _step.value;
|
||||
|
||||
if (message[key] === value) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator["return"]) {
|
||||
_iterator["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}, {
|
||||
key: "client",
|
||||
get: function get() {
|
||||
return this.server.client;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Channel;
|
||||
})();
|
||||
|
||||
module.exports = Channel;
|
||||
8
lib/index.js
Normal file
8
lib/index.js
Normal file
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var request = require("superagent");
|
||||
var Endpoints = require("./endpoints.js");
|
||||
var Client = require("./client.js");
|
||||
|
||||
exports.Endpoints = Endpoints;
|
||||
exports.Client = Client;
|
||||
203
lib/internal.js
Normal file
203
lib/internal.js
Normal file
@@ -0,0 +1,203 @@
|
||||
"use strict";
|
||||
|
||||
var request = require("superagent");
|
||||
var Endpoints = require("./endpoints.js");
|
||||
|
||||
var Internal = {};
|
||||
|
||||
Internal.XHR = {};
|
||||
Internal.WebSocket = {};
|
||||
|
||||
Internal.WebSocket.properties = {
|
||||
"$os": "discord.js",
|
||||
"$browser": "discord.js",
|
||||
"$device": "discord.js",
|
||||
"$referrer": "",
|
||||
"$referring_domain": ""
|
||||
};
|
||||
|
||||
Internal.XHR.login = function (email, password, callback) {
|
||||
|
||||
request.post(Endpoints.LOGIN).send({
|
||||
email: email,
|
||||
password: password
|
||||
}).end(function (err, res) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, res.body.token);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.logout = function (token, callback) {
|
||||
|
||||
request.post(Endpoints.LOGOUT).end(function (err, res) {
|
||||
|
||||
err ? callback(err) : callback(null);
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.createServer = function (token, name, region, callback) {
|
||||
|
||||
request.post(Endpoints.SERVERS).set("authorization", token).send({
|
||||
name: name,
|
||||
region: region
|
||||
}).end(function (err, res) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, res.body);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.leaveServer = function (token, serverId, callback) {
|
||||
|
||||
request.del(Endpoints.SERVERS + "/" + serverId).set("authorization", token).end(function (err, res) {
|
||||
|
||||
err ? callback(err) : callback(null);
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.createInvite = function (token, channelId, options, callback) {
|
||||
request.post(Endpoints.CHANNELS + "/" + channelId + "/invites").set("authorization", token).send(options).end(function (err, res) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, res.body);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.startPM = function (token, selfID, userID, callback) {
|
||||
|
||||
request.post(Endpoints.USERS + "/" + selfID + "/channels").set("authorization", token).send({
|
||||
recipient_id: userID
|
||||
}).end(function (err, res) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, res.body);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.sendMessage = function (token, channelID, messageParameters, callback) {
|
||||
request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization", token).send(messageParameters).end(function (err, res) {
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, res.body);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.sendFile = function (token, channelID, file, fileName, callback) {
|
||||
request.post(Endpoints.CHANNELS + "/" + channelID + "/messages").set("authorization", token).attach("file", file, fileName).end(function (err, res) {
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, res.body);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.deleteMessage = function (token, channelID, messageID, callback) {
|
||||
request.del(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization", token).end(function (err) {
|
||||
err ? callback(err) : callback(null);
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.updateMessage = function (token, channelID, messageID, messageParameters, callback) {
|
||||
|
||||
request.patch(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID).set("authorization", token).send(messageParameters).end(function (err, res) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, res.body);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.getChannelLogs = function (token, channelID, amount, callback) {
|
||||
request.get(Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount).set("authorization", token).end(function (err, res) {
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, res.body);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.createChannel = function (token, serverID, name, type, callback) {
|
||||
request.post(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization", token).send({
|
||||
name: name,
|
||||
type: type
|
||||
}).end(function (err, res) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, res.body);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.deleteChannel = function (token, channelID, callback) {
|
||||
|
||||
request.del(Endpoints.CHANNELS + "/" + channelID).set("authorization", token).end(function (err) {
|
||||
err ? callback(err) : callback(null);
|
||||
});
|
||||
};
|
||||
Internal.XHR.deleteServer = function (token, serverID, callback) {
|
||||
request.del(Endpoints.SERVERS + "/" + serverID).set("authorization", token).end(function (err) {
|
||||
err ? callback(err) : callback(null);
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.getChannels = function (token, serverID, callback) {
|
||||
request.get(Endpoints.SERVERS + "/" + serverID + "/channels").set("authorization", token).end(function (err) {
|
||||
err ? callback(err) : callback(null);
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.getServer = function (token, serverID, callback) {
|
||||
|
||||
request.get(Endpoints.SERVERS + "/" + serverID).set("authorization", token).end(function (err, res) {
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, res.body);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.acceptInvite = function (token, inviteID, callback) {
|
||||
|
||||
request.post(Endpoints.API + "/invite/" + inviteID).set("authorization", token).end(function (err, res) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, res.body);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Internal.XHR.setUsername = function (token, avatar, email, newPassword, password, username, callback) {
|
||||
|
||||
request.patch(Endpoints.API + "/users/@me").set("authorization", token).send({
|
||||
avatar: avatar,
|
||||
email: email,
|
||||
new_password: newPassword,
|
||||
password: password,
|
||||
username: username
|
||||
}).end(function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
exports.Internal = Internal;
|
||||
35
lib/invite.js
Normal file
35
lib/invite.js
Normal file
@@ -0,0 +1,35 @@
|
||||
"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"); } }
|
||||
|
||||
var Invite = (function () {
|
||||
function Invite(data, client) {
|
||||
_classCallCheck(this, Invite);
|
||||
|
||||
this.max_age = data.max_age;
|
||||
this.code = data.code;
|
||||
this.server = client.getServer("id", data.guild.id);
|
||||
this.revoked = data.revoked;
|
||||
this.created_at = Date.parse(data.created_at);
|
||||
this.temporary = data.temporary;
|
||||
this.uses = data.uses;
|
||||
this.max_uses = data.uses;
|
||||
this.inviter = client.addUser(data.inviter);
|
||||
this.xkcd = data.xkcdpass;
|
||||
this.channel = client.getChannel("id", data.channel.id);
|
||||
}
|
||||
|
||||
_createClass(Invite, [{
|
||||
key: "URL",
|
||||
get: function get() {
|
||||
var code = this.xkcd ? this.xkcdpass : this.code;
|
||||
return "https://discord.gg/" + code;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Invite;
|
||||
})();
|
||||
|
||||
module.exports = Invite;
|
||||
72
lib/message.js
Normal file
72
lib/message.js
Normal file
@@ -0,0 +1,72 @@
|
||||
"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"); } }
|
||||
|
||||
var Message = (function () {
|
||||
function Message(data, channel, mentions, author) {
|
||||
_classCallCheck(this, Message);
|
||||
|
||||
this.tts = data.tts;
|
||||
this.timestamp = Date.parse(data.timestamp);
|
||||
this.nonce = data.nonce;
|
||||
this.mentions = mentions;
|
||||
this.everyoneMentioned = data.mention_everyone;
|
||||
this.id = data.id;
|
||||
this.embeds = data.embeds;
|
||||
this.editedTimestamp = data.edited_timestamp;
|
||||
this.content = data.content.trim();
|
||||
this.channel = channel;
|
||||
this.author = author;
|
||||
this.attachments = data.attachments;
|
||||
}
|
||||
|
||||
/*exports.Message.prototype.isPM = function() {
|
||||
return ( this.channel instanceof PMChannel );
|
||||
}*/
|
||||
|
||||
_createClass(Message, [{
|
||||
key: "isMentioned",
|
||||
value: function isMentioned(user) {
|
||||
var id = user.id ? user.id : user;
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = this.mentions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var mention = _step.value;
|
||||
|
||||
if (mention.id === id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator["return"]) {
|
||||
_iterator["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}, {
|
||||
key: "sender",
|
||||
get: function get() {
|
||||
return this.author;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Message;
|
||||
})();
|
||||
|
||||
module.exports = Message;
|
||||
168
lib/server.js
Normal file
168
lib/server.js
Normal file
@@ -0,0 +1,168 @@
|
||||
"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"); } }
|
||||
|
||||
var Server = (function () {
|
||||
function Server(data, client) {
|
||||
_classCallCheck(this, Server);
|
||||
|
||||
this.client = client;
|
||||
this.region = data.region;
|
||||
this.ownerID = data.owner_id;
|
||||
this.name = data.name;
|
||||
this.id = data.id;
|
||||
this.members = [];
|
||||
this.channels = [];
|
||||
this.icon = data.icon;
|
||||
this.afkTimeout = data.afk_timeout;
|
||||
this.afkChannelId = data.afk_channel_id;
|
||||
|
||||
if (!data.members) {
|
||||
data.members = [client.user];
|
||||
return;
|
||||
}
|
||||
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = data.members[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var member = _step.value;
|
||||
|
||||
// first we cache the user in our Discord Client,
|
||||
// then we add it to our list. This way when we
|
||||
// get a user from this server's member list,
|
||||
// it will be identical (unless an async change occurred)
|
||||
// to the client's cache.
|
||||
if (member.user) this.members.push(client.addUser(member.user));
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator["return"]) {
|
||||
_iterator["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_createClass(Server, [{
|
||||
key: "getChannel",
|
||||
|
||||
// get/set
|
||||
value: function getChannel(key, value) {
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = this.channels[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var channel = _step2.value;
|
||||
|
||||
if (channel[key] === value) {
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2["return"]) {
|
||||
_iterator2["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}, {
|
||||
key: "getMember",
|
||||
value: function getMember(key, value) {
|
||||
var _iteratorNormalCompletion3 = true;
|
||||
var _didIteratorError3 = false;
|
||||
var _iteratorError3 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator3 = this.members[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
||||
var member = _step3.value;
|
||||
|
||||
if (member[key] === value) {
|
||||
return member;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError3 = true;
|
||||
_iteratorError3 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion3 && _iterator3["return"]) {
|
||||
_iterator3["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError3) {
|
||||
throw _iteratorError3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}, {
|
||||
key: "addChannel",
|
||||
value: function addChannel(chann) {
|
||||
if (!this.getChannel("id", chann.id)) {
|
||||
this.channels.push(chann);
|
||||
}
|
||||
return chann;
|
||||
}
|
||||
}, {
|
||||
key: "addMember",
|
||||
value: function addMember(member) {
|
||||
if (!this.getMember("id", member.id)) {
|
||||
this.members.push(member);
|
||||
}
|
||||
return member;
|
||||
}
|
||||
}, {
|
||||
key: "iconURL",
|
||||
get: function get() {
|
||||
if (!this.icon) return null;
|
||||
return "https://discordapp.com/api/guilds/" + this.id + "/icons/" + this.icon + ".jpg";
|
||||
}
|
||||
}, {
|
||||
key: "afkChannel",
|
||||
get: function get() {
|
||||
if (!this.afkChannelId) return false;
|
||||
|
||||
return this.getChannel("id", this.afkChannelId);
|
||||
}
|
||||
}, {
|
||||
key: "defaultChannel",
|
||||
get: function get() {
|
||||
return this.getChannel("name", "general");
|
||||
}
|
||||
}, {
|
||||
key: "owner",
|
||||
get: function get() {
|
||||
return this.client.getUser("id", this.ownerID);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Server;
|
||||
})();
|
||||
|
||||
module.exports = Server;
|
||||
56
lib/user.js
Normal file
56
lib/user.js
Normal file
@@ -0,0 +1,56 @@
|
||||
"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"); } }
|
||||
|
||||
var User = (function () {
|
||||
function User(data) {
|
||||
_classCallCheck(this, User);
|
||||
|
||||
this.username = data.username;
|
||||
this.discriminator = data.discriminator;
|
||||
this.id = data.id;
|
||||
this.avatar = data.avatar;
|
||||
}
|
||||
|
||||
// access using user.avatarURL;
|
||||
|
||||
_createClass(User, [{
|
||||
key: "mention",
|
||||
value: function mention() {
|
||||
return "<@" + this.id + ">";
|
||||
}
|
||||
}, {
|
||||
key: "toString",
|
||||
value: function toString() {
|
||||
/*
|
||||
if we embed a user in a String - like so:
|
||||
"Yo " + user + " what's up?"
|
||||
It would generate something along the lines of:
|
||||
"Yo @hydrabolt what's up?"
|
||||
*/
|
||||
return this.mention();
|
||||
}
|
||||
}, {
|
||||
key: "equals",
|
||||
value: function equals(object) {
|
||||
return object.id === this.id;
|
||||
}
|
||||
}, {
|
||||
key: "equalsStrict",
|
||||
value: function equalsStrict(object) {
|
||||
return object.id === this.id && object.avatar === this.avatar && object.username === this.username && object.discriminator === this.discriminator;
|
||||
}
|
||||
}, {
|
||||
key: "avatarURL",
|
||||
get: function get() {
|
||||
if (!this.avatar) return null;
|
||||
return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg";
|
||||
}
|
||||
}]);
|
||||
|
||||
return User;
|
||||
})();
|
||||
|
||||
module.exports = User;
|
||||
Reference in New Issue
Block a user