Merge branch 'indev' into indev-prism

This commit is contained in:
Amish Shah
2016-12-29 14:04:05 +00:00
16 changed files with 298 additions and 1066 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "typings"]
path = typings
url = https://github.com/zajrik/discord.js-typings

View File

@@ -48,7 +48,7 @@
"eslint": "^3.12.0",
"parallel-webpack": "^1.6.0",
"uglify-js": "mishoo/UglifyJS2#harmony",
"webpack": "2.2.0-rc.2"
"webpack": "2.2.0-rc.3"
},
"engines": {
"node": ">=6.0.0"

View File

@@ -345,19 +345,17 @@ class Client extends EventEmitter {
/**
* Generate an invite link for your bot
* @param {Array|number} [permissions] An array of permissions to request
* @param {PermissionResolvable[]|number} [permissions] An array of permissions to request
* @returns {Promise<string>} The invite link
* @example
* client.generateInvite(['SEND_MESSAGES', 'MANAGE_GUILD', 'MENTION_EVERYONE'])
* .then(link => {
* console.log(link);
* console.log(`Generated bot invite link: ${link}`);
* });
*/
generateInvite(permissions) {
if (permissions) {
if (permissions instanceof Array) {
permissions = this.resolver.resolvePermissions(permissions);
}
if (permissions instanceof Array) permissions = this.resolver.resolvePermissions(permissions);
} else {
permissions = 0;
}

View File

@@ -65,7 +65,8 @@ class ClientDataResolver {
/**
* Data that resolves to give a Guild object. This can be:
* * A Guild object
* @typedef {Guild} GuildResolvable
* * A Guild ID
* @typedef {Guild|string} GuildResolvable
*/
/**
@@ -173,7 +174,9 @@ class ClientDataResolver {
* "USE_VAD", // use voice activity detection
* "CHANGE_NICKNAME",
* "MANAGE_NICKNAMES", // change nicknames of others
* "MANAGE_ROLES_OR_PERMISSIONS"
* "MANAGE_ROLES_OR_PERMISSIONS",
* "MANAGE_WEBHOOKS",
* "MANAGE_EMOJIS"
* ]
* ```
* @typedef {string|number} PermissionResolvable
@@ -191,15 +194,13 @@ class ClientDataResolver {
}
/**
* Turn an array of permissions into a valid discord permission bitfield
* @param {Array} permissions An array of permissions as strings or permissions numbers (see resolvePermission)
* Turn an array of permissions into a valid Discord permission bitfield
* @param {PermissionResolvable[]} permissions Permissions to resolve together
* @returns {number}
*/
resolvePermissions(permissions) {
let bitfield = 0;
for (const permission of permissions) {
bitfield |= this.resolvePermission(permission);
}
for (const permission of permissions) bitfield |= this.resolvePermission(permission);
return bitfield;
}

View File

@@ -2,6 +2,7 @@ const Constants = require('../../util/Constants');
const Collection = require('../../util/Collection');
const splitMessage = require('../../util/SplitMessage');
const parseEmoji = require('../../util/ParseEmoji');
const escapeMarkdown = require('../../util/EscapeMarkdown');
const User = require('../../structures/User');
const GuildMember = require('../../structures/GuildMember');
@@ -15,13 +16,14 @@ const ClientOAuth2Application = require('../../structures/ClientOAuth2Applicatio
class RESTMethods {
constructor(restManager) {
this.rest = restManager;
this.client = restManager.client;
}
login(token = this.rest.client.token) {
login(token = this.client.token) {
return new Promise((resolve, reject) => {
if (typeof token !== 'string') throw new Error(Constants.Errors.INVALID_TOKEN);
token = token.replace(/^Bot\s*/i, '');
this.rest.client.manager.connectToWebSocket(token, resolve, reject);
this.client.manager.connectToWebSocket(token, resolve, reject);
});
}
@@ -31,8 +33,8 @@ class RESTMethods {
getGateway() {
return this.rest.makeRequest('get', Constants.Endpoints.gateway, true).then(res => {
this.rest.client.ws.gateway = `${res.url}/?v=${Constants.PROTOCOL_VERSION}`;
return this.rest.client.ws.gateway;
this.client.ws.gateway = `${res.url}/?v=${Constants.PROTOCOL_VERSION}`;
return this.client.ws.gateway;
});
}
@@ -40,63 +42,64 @@ class RESTMethods {
return this.rest.makeRequest('get', Constants.Endpoints.botGateway, true);
}
sendMessage(channel, content, { tts, nonce, embed, disableEveryone, split } = {}, file = null) {
sendMessage(channel, content, { tts, nonce, embed, disableEveryone, split, code } = {}, file = null) {
return new Promise((resolve, reject) => {
if (typeof content !== 'undefined') content = this.rest.client.resolver.resolveString(content);
if (typeof content !== 'undefined') content = this.client.resolver.resolveString(content);
if (content) {
if (disableEveryone || (typeof disableEveryone === 'undefined' && this.rest.client.options.disableEveryone)) {
if (code) {
content = escapeMarkdown(this.client.resolver.resolveString(content), true);
content = `\`\`\`${typeof code !== 'undefined' && code !== null ? code : ''}\n${content}\n\`\`\``;
}
if (disableEveryone || (typeof disableEveryone === 'undefined' && this.client.options.disableEveryone)) {
content = content.replace(/@(everyone|here)/g, '@\u200b$1');
}
if (split) content = splitMessage(content, typeof split === 'object' ? split : {});
}
const send = (chan) => {
if (content instanceof Array) {
const messages = [];
(function sendChunk(list, index) {
const options = index === list.length ? { tts, embed } : { tts };
chan.send(list[index], options, index === list.length ? file : null).then((message) => {
messages.push(message);
if (index >= list.length) return resolve(messages);
return sendChunk(list, ++index);
});
}(content, 0));
} else {
this.rest.makeRequest('post', Constants.Endpoints.channelMessages(chan.id), true, {
content, tts, nonce, embed,
}, file).then(data => resolve(this.client.actions.MessageCreate.handle(data).message), reject);
}
};
if (channel instanceof User || channel instanceof GuildMember) {
this.createDM(channel).then(chan => {
this._sendMessageRequest(chan, content, file, tts, nonce, embed, resolve, reject);
}, reject);
this.createDM(channel).then(send, reject);
} else {
this._sendMessageRequest(channel, content, file, tts, nonce, embed, resolve, reject);
send(channel);
}
});
}
_sendMessageRequest(channel, content, file, tts, nonce, embed, resolve, reject) {
if (content instanceof Array) {
const datas = [];
let promise = this.rest.makeRequest('post', Constants.Endpoints.channelMessages(channel.id), true, {
content: content[0], tts, nonce,
}, file).catch(reject);
for (let i = 1; i <= content.length; i++) {
if (i < content.length) {
const i2 = i;
promise = promise.then(data => {
datas.push(data);
return this.rest.makeRequest('post', Constants.Endpoints.channelMessages(channel.id), true, {
content: content[i2], tts, nonce, embed,
}, file);
}, reject);
} else {
promise.then(data => {
datas.push(data);
resolve(this.rest.client.actions.MessageCreate.handle(datas).messages);
}, reject);
}
}
} else {
this.rest.makeRequest('post', Constants.Endpoints.channelMessages(channel.id), true, {
content, tts, nonce, embed,
}, file)
.then(data => resolve(this.rest.client.actions.MessageCreate.handle(data).message), reject);
updateMessage(message, content, { embed, code } = {}) {
content = this.client.resolver.resolveString(content);
if (code) {
content = escapeMarkdown(this.client.resolver.resolveString(content), true);
content = `\`\`\`${typeof code !== 'undefined' && code !== null ? code : ''}\n${content}\n\`\`\``;
}
return this.rest.makeRequest('patch', Constants.Endpoints.channelMessage(message.channel.id, message.id), true, {
content, embed,
}).then(data => this.client.actions.MessageUpdate.handle(data).updated);
}
deleteMessage(message) {
return this.rest.makeRequest('del', Constants.Endpoints.channelMessage(message.channel.id, message.id), true)
.then(() =>
this.rest.client.actions.MessageDelete.handle({
this.client.actions.MessageDelete.handle({
id: message.id,
channel_id: message.channel.id,
}).message
@@ -107,39 +110,32 @@ class RESTMethods {
return this.rest.makeRequest('post', `${Constants.Endpoints.channelMessages(channel.id)}/bulk_delete`, true, {
messages,
}).then(() =>
this.rest.client.actions.MessageDeleteBulk.handle({
this.client.actions.MessageDeleteBulk.handle({
channel_id: channel.id,
ids: messages,
}).messages
);
}
updateMessage(message, content, { embed } = {}) {
content = this.rest.client.resolver.resolveString(content);
return this.rest.makeRequest('patch', Constants.Endpoints.channelMessage(message.channel.id, message.id), true, {
content, embed,
}).then(data => this.rest.client.actions.MessageUpdate.handle(data).updated);
}
createChannel(guild, channelName, channelType, overwrites) {
if (overwrites instanceof Collection) overwrites = overwrites.array();
return this.rest.makeRequest('post', Constants.Endpoints.guildChannels(guild.id), true, {
name: channelName,
type: channelType,
permission_overwrites: overwrites,
}).then(data => this.rest.client.actions.ChannelCreate.handle(data).channel);
}).then(data => this.client.actions.ChannelCreate.handle(data).channel);
}
createDM(recipient) {
const dmChannel = this.getExistingDM(recipient);
if (dmChannel) return Promise.resolve(dmChannel);
return this.rest.makeRequest('post', Constants.Endpoints.userChannels(this.rest.client.user.id), true, {
return this.rest.makeRequest('post', Constants.Endpoints.userChannels(this.client.user.id), true, {
recipient_id: recipient.id,
}).then(data => this.rest.client.actions.ChannelCreate.handle(data).channel);
}).then(data => this.client.actions.ChannelCreate.handle(data).channel);
}
getExistingDM(recipient) {
return this.rest.client.channels.find(channel =>
return this.client.channels.find(channel =>
channel.recipient && channel.recipient.id === recipient.id
);
}
@@ -149,7 +145,7 @@ class RESTMethods {
if (!channel) return Promise.reject(new Error('No channel to delete.'));
return this.rest.makeRequest('del', Constants.Endpoints.channel(channel.id), true).then(data => {
data.id = channel.id;
return this.rest.client.actions.ChannelDelete.handle(data).channel;
return this.client.actions.ChannelDelete.handle(data).channel;
});
}
@@ -161,38 +157,38 @@ class RESTMethods {
data.bitrate = _data.bitrate || channel.bitrate;
data.user_limit = _data.userLimit || channel.userLimit;
return this.rest.makeRequest('patch', Constants.Endpoints.channel(channel.id), true, data).then(newData =>
this.rest.client.actions.ChannelUpdate.handle(newData).updated
this.client.actions.ChannelUpdate.handle(newData).updated
);
}
leaveGuild(guild) {
if (guild.ownerID === this.rest.client.user.id) return Promise.reject(new Error('Guild is owned by the client.'));
if (guild.ownerID === this.client.user.id) return Promise.reject(new Error('Guild is owned by the client.'));
return this.rest.makeRequest('del', Constants.Endpoints.meGuild(guild.id), true).then(() =>
this.rest.client.actions.GuildDelete.handle({ id: guild.id }).guild
this.client.actions.GuildDelete.handle({ id: guild.id }).guild
);
}
createGuild(options) {
options.icon = this.rest.client.resolver.resolveBase64(options.icon) || null;
options.icon = this.client.resolver.resolveBase64(options.icon) || null;
options.region = options.region || 'us-central';
return new Promise((resolve, reject) => {
this.rest.makeRequest('post', Constants.Endpoints.guilds, true, options).then(data => {
if (this.rest.client.guilds.has(data.id)) {
resolve(this.rest.client.guilds.get(data.id));
if (this.client.guilds.has(data.id)) {
resolve(this.client.guilds.get(data.id));
return;
}
const handleGuild = guild => {
if (guild.id === data.id) {
this.rest.client.removeListener('guildCreate', handleGuild);
this.rest.client.clearTimeout(timeout);
this.client.removeListener('guildCreate', handleGuild);
this.client.clearTimeout(timeout);
resolve(guild);
}
};
this.rest.client.on('guildCreate', handleGuild);
this.client.on('guildCreate', handleGuild);
const timeout = this.rest.client.setTimeout(() => {
this.rest.client.removeListener('guildCreate', handleGuild);
const timeout = this.client.setTimeout(() => {
this.client.removeListener('guildCreate', handleGuild);
reject(new Error('Took too long to receive guild data.'));
}, 10000);
}, reject);
@@ -202,28 +198,28 @@ class RESTMethods {
// untested but probably will work
deleteGuild(guild) {
return this.rest.makeRequest('del', Constants.Endpoints.guild(guild.id), true).then(() =>
this.rest.client.actions.GuildDelete.handle({ id: guild.id }).guild
this.client.actions.GuildDelete.handle({ id: guild.id }).guild
);
}
getUser(userID) {
return this.rest.makeRequest('get', Constants.Endpoints.user(userID), true).then(data =>
this.rest.client.actions.UserGet.handle(data).user
this.client.actions.UserGet.handle(data).user
);
}
updateCurrentUser(_data, password) {
const user = this.rest.client.user;
const user = this.client.user;
const data = {};
data.username = _data.username || user.username;
data.avatar = this.rest.client.resolver.resolveBase64(_data.avatar) || user.avatar;
data.avatar = this.client.resolver.resolveBase64(_data.avatar) || user.avatar;
if (!user.bot) {
data.email = _data.email || user.email;
data.password = password;
if (_data.new_password) data.new_password = _data.newPassword;
}
return this.rest.makeRequest('patch', Constants.Endpoints.me, true, data).then(newData =>
this.rest.client.actions.UserUpdate.handle(newData).updated
this.client.actions.UserUpdate.handle(newData).updated
);
}
@@ -232,19 +228,19 @@ class RESTMethods {
if (_data.name) data.name = _data.name;
if (_data.region) data.region = _data.region;
if (_data.verificationLevel) data.verification_level = Number(_data.verificationLevel);
if (_data.afkChannel) data.afk_channel_id = this.rest.client.resolver.resolveChannel(_data.afkChannel).id;
if (_data.afkChannel) data.afk_channel_id = this.client.resolver.resolveChannel(_data.afkChannel).id;
if (_data.afkTimeout) data.afk_timeout = Number(_data.afkTimeout);
if (_data.icon) data.icon = this.rest.client.resolver.resolveBase64(_data.icon);
if (_data.owner) data.owner_id = this.rest.client.resolver.resolveUser(_data.owner).id;
if (_data.splash) data.splash = this.rest.client.resolver.resolveBase64(_data.splash);
if (_data.icon) data.icon = this.client.resolver.resolveBase64(_data.icon);
if (_data.owner) data.owner_id = this.client.resolver.resolveUser(_data.owner).id;
if (_data.splash) data.splash = this.client.resolver.resolveBase64(_data.splash);
return this.rest.makeRequest('patch', Constants.Endpoints.guild(guild.id), true, data).then(newData =>
this.rest.client.actions.GuildUpdate.handle(newData).updated
this.client.actions.GuildUpdate.handle(newData).updated
);
}
kickGuildMember(guild, member) {
return this.rest.makeRequest('del', Constants.Endpoints.guildMember(guild.id, member.id), true).then(() =>
this.rest.client.actions.GuildMemberRemove.handle({
this.client.actions.GuildMemberRemove.handle({
guild_id: guild.id,
user: member.user,
}).member
@@ -253,7 +249,7 @@ class RESTMethods {
createGuildRole(guild) {
return this.rest.makeRequest('post', Constants.Endpoints.guildRoles(guild.id), true).then(role =>
this.rest.client.actions.GuildRoleCreate.handle({
this.client.actions.GuildRoleCreate.handle({
guild_id: guild.id,
role,
}).role
@@ -262,7 +258,7 @@ class RESTMethods {
deleteGuildRole(role) {
return this.rest.makeRequest('del', Constants.Endpoints.guildRole(role.guild.id, role.id), true).then(() =>
this.rest.client.actions.GuildRoleDelete.handle({
this.client.actions.GuildRoleDelete.handle({
guild_id: role.guild.id,
role_id: role.id,
}).role
@@ -301,17 +297,17 @@ class RESTMethods {
getGuildMember(guild, user) {
return this.rest.makeRequest('get', Constants.Endpoints.guildMember(guild.id, user.id), true).then(data =>
this.rest.client.actions.GuildMemberGet.handle(guild, data).member
this.client.actions.GuildMemberGet.handle(guild, data).member
);
}
updateGuildMember(member, data) {
if (data.channel) data.channel_id = this.rest.client.resolver.resolveChannel(data.channel).id;
if (data.channel) data.channel_id = this.client.resolver.resolveChannel(data.channel).id;
if (data.roles) data.roles = data.roles.map(role => role instanceof Role ? role.id : role);
let endpoint = Constants.Endpoints.guildMember(member.guild.id, member.id);
// fix your endpoints, discord ;-;
if (member.id === this.rest.client.user.id) {
if (member.id === this.client.user.id) {
const keys = Object.keys(data);
if (keys.length === 1 && keys[0] === 'nick') {
endpoint = Constants.Endpoints.guildMemberNickname(member.guild.id);
@@ -348,7 +344,7 @@ class RESTMethods {
}
banGuildMember(guild, member, deleteDays = 0) {
const id = this.rest.client.resolver.resolveUserID(member);
const id = this.client.resolver.resolveUserID(member);
if (!id) return Promise.reject(new Error('Couldn\'t resolve the user ID to ban.'));
return this.rest.makeRequest(
'put', `${Constants.Endpoints.guildBans(guild.id)}/${id}?delete-message-days=${deleteDays}`, true, {
@@ -356,9 +352,9 @@ class RESTMethods {
}
).then(() => {
if (member instanceof GuildMember) return member;
const user = this.rest.client.resolver.resolveUser(id);
const user = this.client.resolver.resolveUser(id);
if (user) {
member = this.rest.client.resolver.resolveGuildMember(guild, user);
member = this.client.resolver.resolveGuildMember(guild, user);
return member || user;
}
return id;
@@ -367,26 +363,26 @@ class RESTMethods {
unbanGuildMember(guild, member) {
return new Promise((resolve, reject) => {
const id = this.rest.client.resolver.resolveUserID(member);
const id = this.client.resolver.resolveUserID(member);
if (!id) throw new Error('Couldn\'t resolve the user ID to unban.');
const listener = (eGuild, eUser) => {
if (eGuild.id === guild.id && eUser.id === id) {
this.rest.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener);
this.rest.client.clearTimeout(timeout);
this.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener);
this.client.clearTimeout(timeout);
resolve(eUser);
}
};
this.rest.client.on(Constants.Events.GUILD_BAN_REMOVE, listener);
this.client.on(Constants.Events.GUILD_BAN_REMOVE, listener);
const timeout = this.rest.client.setTimeout(() => {
this.rest.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener);
const timeout = this.client.setTimeout(() => {
this.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener);
reject(new Error('Took too long to receive the ban remove event.'));
}, 10000);
this.rest.makeRequest('del', `${Constants.Endpoints.guildBans(guild.id)}/${id}`, true).catch(err => {
this.rest.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener);
this.rest.client.clearTimeout(timeout);
this.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener);
this.client.clearTimeout(timeout);
reject(err);
});
});
@@ -396,7 +392,7 @@ class RESTMethods {
return this.rest.makeRequest('get', Constants.Endpoints.guildBans(guild.id), true).then(banItems => {
const bannedUsers = new Collection();
for (const banItem of banItems) {
const user = this.rest.client.dataManager.newUser(banItem.user);
const user = this.client.dataManager.newUser(banItem.user);
bannedUsers.set(user.id, user);
}
return bannedUsers;
@@ -428,7 +424,7 @@ class RESTMethods {
return this.rest.makeRequest(
'patch', Constants.Endpoints.guildRole(role.guild.id, role.id), true, data
).then(_role =>
this.rest.client.actions.GuildRoleUpdate.handle({
this.client.actions.GuildRoleUpdate.handle({
role: _role,
guild_id: role.guild.id,
}).updated
@@ -455,7 +451,7 @@ class RESTMethods {
payload.max_age = options.maxAge;
payload.max_uses = options.maxUses;
return this.rest.makeRequest('post', `${Constants.Endpoints.channelInvites(channel.id)}`, true, payload)
.then(invite => new Invite(this.rest.client, invite));
.then(invite => new Invite(this.client, invite));
}
deleteInvite(invite) {
@@ -464,7 +460,7 @@ class RESTMethods {
getInvite(code) {
return this.rest.makeRequest('get', Constants.Endpoints.invite(code), true).then(invite =>
new Invite(this.rest.client, invite)
new Invite(this.client, invite)
);
}
@@ -472,7 +468,7 @@ class RESTMethods {
return this.rest.makeRequest('get', Constants.Endpoints.guildInvites(guild.id), true).then(inviteItems => {
const invites = new Collection();
for (const inviteItem of inviteItems) {
const invite = new Invite(this.rest.client, inviteItem);
const invite = new Invite(this.client, inviteItem);
invites.set(invite.code, invite);
}
return invites;
@@ -486,24 +482,24 @@ class RESTMethods {
createEmoji(guild, image, name) {
return this.rest.makeRequest('post', `${Constants.Endpoints.guildEmojis(guild.id)}`, true, { name, image })
.then(data => this.rest.client.actions.EmojiCreate.handle(data, guild).emoji);
.then(data => this.client.actions.EmojiCreate.handle(data, guild).emoji);
}
deleteEmoji(emoji) {
return this.rest.makeRequest('delete', `${Constants.Endpoints.guildEmojis(emoji.guild.id)}/${emoji.id}`, true)
.then(() => this.rest.client.actions.EmojiDelete.handle(emoji).data);
.then(() => this.client.actions.EmojiDelete.handle(emoji).data);
}
getWebhook(id, token) {
return this.rest.makeRequest('get', Constants.Endpoints.webhook(id, token), !token).then(data =>
new Webhook(this.rest.client, data)
new Webhook(this.client, data)
);
}
getGuildWebhooks(guild) {
return this.rest.makeRequest('get', Constants.Endpoints.guildWebhooks(guild.id), true).then(data => {
const hooks = new Collection();
for (const hook of data) hooks.set(hook.id, new Webhook(this.rest.client, hook));
for (const hook of data) hooks.set(hook.id, new Webhook(this.client, hook));
return hooks;
});
}
@@ -511,14 +507,14 @@ class RESTMethods {
getChannelWebhooks(channel) {
return this.rest.makeRequest('get', Constants.Endpoints.channelWebhooks(channel.id), true).then(data => {
const hooks = new Collection();
for (const hook of data) hooks.set(hook.id, new Webhook(this.rest.client, hook));
for (const hook of data) hooks.set(hook.id, new Webhook(this.client, hook));
return hooks;
});
}
createWebhook(channel, name, avatar) {
return this.rest.makeRequest('post', Constants.Endpoints.channelWebhooks(channel.id), true, { name, avatar })
.then(data => new Webhook(this.rest.client, data));
.then(data => new Webhook(this.client, data));
}
editWebhook(webhook, name, avatar) {
@@ -537,9 +533,9 @@ class RESTMethods {
}
sendWebhookMessage(webhook, content, { avatarURL, tts, disableEveryone, embeds } = {}, file = null) {
if (typeof content !== 'undefined') content = this.rest.client.resolver.resolveString(content);
if (typeof content !== 'undefined') content = this.client.resolver.resolveString(content);
if (content) {
if (disableEveryone || (typeof disableEveryone === 'undefined' && this.rest.client.options.disableEveryone)) {
if (disableEveryone || (typeof disableEveryone === 'undefined' && this.client.options.disableEveryone)) {
content = content.replace(/@(everyone|here)/g, '@\u200b$1');
}
}
@@ -570,7 +566,7 @@ class RESTMethods {
return this.rest.makeRequest(
'get',
Constants.Endpoints.meMentions(options.limit, options.roles, options.everyone, options.guild)
).then(res => res.body.map(m => new Message(this.rest.client.channels.get(m.channel_id), m, this.rest.client)));
).then(res => res.body.map(m => new Message(this.client.channels.get(m.channel_id), m, this.client)));
}
addFriend(user) {
@@ -597,7 +593,7 @@ class RESTMethods {
setRolePositions(guildID, roles) {
return this.rest.makeRequest('patch', Constants.Endpoints.guildRoles(guildID), true, roles).then(() =>
this.rest.client.actions.GuildRolesPositionUpdate.handle({
this.client.actions.GuildRolesPositionUpdate.handle({
guild_id: guildID,
roles,
}).guild
@@ -608,8 +604,8 @@ class RESTMethods {
return this.rest.makeRequest(
'put', Constants.Endpoints.selfMessageReaction(message.channel.id, message.id, emoji), true
).then(() =>
this.rest.client.actions.MessageReactionAdd.handle({
user_id: this.rest.client.user.id,
this.client.actions.MessageReactionAdd.handle({
user_id: this.client.user.id,
message_id: message.id,
emoji: parseEmoji(emoji),
channel_id: message.channel.id,
@@ -619,11 +615,11 @@ class RESTMethods {
removeMessageReaction(message, emoji, user) {
let endpoint = Constants.Endpoints.selfMessageReaction(message.channel.id, message.id, emoji);
if (user.id !== this.rest.client.user.id) {
if (user.id !== this.client.user.id) {
endpoint = Constants.Endpoints.userMessageReaction(message.channel.id, message.id, emoji, null, user.id);
}
return this.rest.makeRequest('delete', endpoint, true).then(() =>
this.rest.client.actions.MessageReactionRemove.handle({
this.client.actions.MessageReactionRemove.handle({
user_id: user.id,
message_id: message.id,
emoji: parseEmoji(emoji),
@@ -645,7 +641,7 @@ class RESTMethods {
getMyApplication() {
return this.rest.makeRequest('get', Constants.Endpoints.myApplication, true).then(app =>
new ClientOAuth2Application(this.rest.client, app)
new ClientOAuth2Application(this.client, app)
);
}

View File

@@ -229,6 +229,11 @@ class WebSocketManager extends EventEmitter {
this.sequence = -1;
}
/**
* @external CloseEvent
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent}
*/
/**
* Run whenever the connection to the gateway is closed, it will try to reconnect the client.
* @param {CloseEvent} event The WebSocket close event

View File

@@ -119,8 +119,75 @@ class ClientUser extends User {
}
/**
* Set the status of the logged in user.
* @param {string} status can be `online`, `idle`, `invisible` or `dnd` (do not disturb)
* Data resembling a raw Discord presence
* @typedef {Object} PresenceData
* @property {PresenceStatus} [status] Status of the user
* @property {boolean} [afk] Whether the user is AFK
* @property {Object} [game] Game the user is playing
* @property {string} [game.name] Name of the game
* @property {string} [game.url] Twitch stream URL
*/
/**
* Sets the full presence of the client user.
* @param {PresenceData} data Data for the presence
* @returns {Promise<ClientUser>}
*/
setPresence(data) {
// {"op":3,"d":{"status":"dnd","since":0,"game":null,"afk":false}}
return new Promise(resolve => {
let status = this.localPresence.status || this.presence.status;
let game = this.localPresence.game;
let afk = this.localPresence.afk || this.presence.afk;
if (!game && this.presence.game) {
game = {
name: this.presence.game.name,
type: this.presence.game.type,
url: this.presence.game.url,
};
}
if (data.status) {
if (typeof data.status !== 'string') throw new TypeError('Status must be a string');
status = data.status;
}
if (data.game) {
game = data.game;
if (game.url) game.type = 1;
}
if (typeof data.afk !== 'undefined') afk = data.afk;
afk = Boolean(afk);
this.localPresence = { status, game, afk };
this.localPresence.since = 0;
this.localPresence.game = this.localPresence.game || null;
this.client.ws.send({
op: 3,
d: this.localPresence,
});
this.client._setPresence(this.id, this.localPresence);
resolve(this);
});
}
/**
* A user's status. Must be one of:
* - `online`
* - `idle`
* - `invisible`
* - `dnd` (do not disturb)
* @typedef {string} PresenceStatus
*/
/**
* Sets the status of the client user.
* @param {PresenceStatus} status Status to change to
* @returns {Promise<ClientUser>}
*/
setStatus(status) {
@@ -128,9 +195,9 @@ class ClientUser extends User {
}
/**
* Set the current game of the logged in user.
* @param {string} game the game being played
* @param {string} [streamingURL] an optional URL to a twitch stream, if one is available.
* Sets the game the client user is playing.
* @param {string} game Game being played
* @param {string} [streamingURL] Twitch stream URL
* @returns {Promise<ClientUser>}
*/
setGame(game, streamingURL) {
@@ -141,8 +208,8 @@ class ClientUser extends User {
}
/**
* Set/remove the AFK flag for the current user.
* @param {boolean} afk whether or not the user is AFK.
* Sets/removes the AFK flag for the client user.
* @param {boolean} afk Whether or not the user is AFK
* @returns {Promise<ClientUser>}
*/
setAFK(afk) {
@@ -202,54 +269,6 @@ class ClientUser extends User {
);
}
}
/**
* Set the full presence of the current user.
* @param {Object} data the data to provide
* @returns {Promise<ClientUser>}
*/
setPresence(data) {
// {"op":3,"d":{"status":"dnd","since":0,"game":null,"afk":false}}
return new Promise(resolve => {
let status = this.localPresence.status || this.presence.status;
let game = this.localPresence.game;
let afk = this.localPresence.afk || this.presence.afk;
if (!game && this.presence.game) {
game = {
name: this.presence.game.name,
type: this.presence.game.type,
url: this.presence.game.url,
};
}
if (data.status) {
if (typeof data.status !== 'string') throw new TypeError('Status must be a string');
status = data.status;
}
if (data.game) {
game = data.game;
if (game.url) game.type = 1;
}
if (typeof data.afk !== 'undefined') afk = data.afk;
afk = Boolean(afk);
this.localPresence = { status, game, afk };
this.localPresence.since = 0;
this.localPresence.game = this.localPresence.game || null;
this.client.ws.send({
op: 3,
d: this.localPresence,
});
this.client._setPresence(this.id, this.localPresence);
resolve(this);
});
}
}
module.exports = ClientUser;

View File

@@ -430,8 +430,8 @@ class GuildMember {
}
// These are here only for documentation purposes - they are implemented by TextBasedChannel
send() { return; }
sendMessage() { return; }
sendTTSMessage() { return; }
sendEmbed() { return; }
sendFile() { return; }
sendCode() { return; }

View File

@@ -369,12 +369,13 @@ class Message {
* Options that can be passed into editMessage
* @typedef {Object} MessageEditOptions
* @property {Object} [embed] An embed to be added/edited
* @property {string} [code] Language for optional codeblock formatting to apply
*/
/**
* Edit the content of the message
* @param {StringResolvable} content The new content for the message
* @param {MessageEditOptions} [options={}] The options to provide
* @param {StringResolvable} [content] The new content for the message
* @param {MessageEditOptions} [options] The options to provide
* @returns {Promise<Message>}
* @example
* // update the content of a message
@@ -382,7 +383,13 @@ class Message {
* .then(msg => console.log(`Updated the content of a message from ${msg.author}`))
* .catch(console.error);
*/
edit(content, options = {}) {
edit(content, options) {
if (!options && typeof content === 'object') {
options = content;
content = '';
} else if (!options) {
options = {};
}
return this.client.rest.methods.updateMessage(this, content, options);
}
@@ -467,16 +474,8 @@ class Message {
* .catch(console.error);
*/
reply(content, options = {}) {
content = this.client.resolver.resolveString(content);
const prepend = this.guild ? `${this.author}, ` : '';
content = `${prepend}${content}`;
if (options.split) {
if (typeof options.split !== 'object') options.split = {};
if (!options.split.prepend) options.split.prepend = prepend;
}
return this.client.rest.methods.sendMessage(this.channel, content, options);
content = `${this.guild || this.channel.type === 'group' ? `${this.author}, ` : ''}${content}`;
return this.channel.send(content, options);
}
/**

View File

@@ -321,6 +321,7 @@ class Role {
* @returns {string}
*/
toString() {
if (this.id === this.guild.id) return '@everyone';
return `<@&${this.id}>`;
}

View File

@@ -73,8 +73,8 @@ class TextChannel extends GuildChannel {
}
// These are here only for documentation purposes - they are implemented by TextBasedChannel
send() { return; }
sendMessage() { return; }
sendTTSMessage() { return; }
sendEmbed() { return; }
sendFile() { return; }
sendCode() { return; }

View File

@@ -237,7 +237,7 @@ class User {
}
/**
* Checks if the user is equal to another. It compares username, ID, discriminator, status and the game being played.
* Checks if the user is equal to another. It compares ID, username, discriminator, avatar, and bot flags.
* It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.
* @param {User} user User to compare with
* @returns {boolean}
@@ -265,8 +265,8 @@ class User {
}
// These are here only for documentation purposes - they are implemented by TextBasedChannel
send() { return; }
sendMessage() { return; }
sendTTSMessage() { return; }
sendEmbed() { return; }
sendFile() { return; }
sendCode() { return; }

View File

@@ -2,8 +2,7 @@ const path = require('path');
const Message = require('../Message');
const MessageCollector = require('../MessageCollector');
const Collection = require('../../util/Collection');
const RichEmbed = require('../RichEmbed');
const escapeMarkdown = require('../../util/EscapeMarkdown');
/**
* Interface for classes that have text-channel-like features
@@ -25,7 +24,7 @@ class TextBasedChannel {
}
/**
* Options that can be passed into sendMessage, sendTTSMessage, sendFile, sendCode, or Message.reply
* Options that can be passed into send, sendMessage, sendFile, sendEmbed, sendCode, and Message#reply
* @typedef {Object} MessageOptions
* @property {boolean} [tts=false] Whether or not the message should be spoken aloud
* @property {string} [nonce=''] The nonce for the message
@@ -33,10 +32,18 @@ class TextBasedChannel {
* (see [here](https://discordapp.com/developers/docs/resources/channel#embed-object) for more details)
* @property {boolean} [disableEveryone=this.client.options.disableEveryone] Whether or not @everyone and @here
* should be replaced with plain-text
* @property {FileOptions|string} [file] A file to send with the message
* @property {string} [code] Language for optional codeblock formatting to apply
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if
* it exceeds the character limit. If an object is provided, these are the options for splitting the message.
*/
/**
* @typedef {Object} FileOptions
* @property {BufferResolvable} attachment
* @property {string} [name='file.jpg']
*/
/**
* Options for splitting a message
* @typedef {Object} SplitOptions
@@ -46,6 +53,45 @@ class TextBasedChannel {
* @property {string} [append=''] Text to append to every piece except the last
*/
/**
* Send a message to this channel
* @param {StringResolvable} [content] The content to send
* @param {MessageOptions} [options={}] The options to provide
* @returns {Promise<Message|Message[]>}
* @example
* // send a message
* channel.send('hello!')
* .then(message => console.log(`Sent message: ${message.content}`))
* .catch(console.error);
*/
send(content, options) {
if (!options && typeof content === 'object' && !(content instanceof Array)) {
options = content;
content = '';
} else if (!options) {
options = {};
}
if (options.file) {
if (typeof options.file === 'string') options.file = { attachment: options.file };
if (!options.file.name) {
if (typeof options.file.attachment === 'string') {
options.file.name = path.basename(options.file.attachment);
} else if (options.file.attachment && options.file.attachment.path) {
options.file.name = path.basename(options.file.attachment.path);
} else {
options.file.name = 'file.jpg';
}
}
return this.client.resolver.resolveBuffer(options.file.attachment).then(file =>
this.client.rest.methods.sendMessage(this, content, options, {
file,
name: options.file.name,
})
);
}
return this.client.rest.methods.sendMessage(this, content, options);
}
/**
* Send a message to this channel
* @param {StringResolvable} content The content to send
@@ -57,88 +103,48 @@ class TextBasedChannel {
* .then(message => console.log(`Sent message: ${message.content}`))
* .catch(console.error);
*/
sendMessage(content, options = {}) {
return this.client.rest.methods.sendMessage(this, content, options);
}
/**
* Send a text-to-speech message to this channel
* @param {StringResolvable} content The content to send
* @param {MessageOptions} [options={}] The options to provide
* @returns {Promise<Message|Message[]>}
* @example
* // send a TTS message
* channel.sendTTSMessage('hello!')
* .then(message => console.log(`Sent tts message: ${message.content}`))
* .catch(console.error);
*/
sendTTSMessage(content, options = {}) {
Object.assign(options, { tts: true });
return this.client.rest.methods.sendMessage(this, content, options);
sendMessage(content, options) {
return this.send(content, options);
}
/**
* Send an embed to this channel
* @param {RichEmbed|Object} embed The embed to send
* @param {string|MessageOptions} contentOrOptions Content to send or message options
* @param {MessageOptions} options If contentOrOptions is content, this will be options
* @param {string} [content] Content to send
* @param {MessageOptions} [options] The options to provide
* @returns {Promise<Message>}
*/
sendEmbed(embed, contentOrOptions, options = {}) {
if (!(embed instanceof RichEmbed)) embed = new RichEmbed(embed);
let content;
if (contentOrOptions) {
if (typeof contentOrOptions === 'string') {
content = contentOrOptions;
} else {
options = contentOrOptions;
}
sendEmbed(embed, content, options) {
if (!options && typeof content === 'object') {
options = content;
content = '';
} else if (!options) {
options = {};
}
options.embed = embed;
return this.sendMessage(content, options);
return this.send(content, Object.assign(options, { embed }));
}
/**
* Send a file to this channel
* @param {BufferResolvable} attachment The file to send
* @param {string} [fileName="file.jpg"] The name and extension of the file
* @param {string} [name='file.jpg'] The name and extension of the file
* @param {StringResolvable} [content] Text message to send with the attachment
* @param {MessageOptions} [options] The options to provide
* @returns {Promise<Message>}
*/
sendFile(attachment, fileName, content, options = {}) {
if (!fileName) {
if (typeof attachment === 'string') {
fileName = path.basename(attachment);
} else if (attachment && attachment.path) {
fileName = path.basename(attachment.path);
} else {
fileName = 'file.jpg';
}
}
return this.client.resolver.resolveBuffer(attachment).then(file =>
this.client.rest.methods.sendMessage(this, content, options, {
file,
name: fileName,
})
);
sendFile(attachment, name, content, options = {}) {
return this.send(content, Object.assign(options, { file: { attachment, name } }));
}
/**
* Send a code block to this channel
* @param {string} lang Language for the code block
* @param {StringResolvable} content Content of the code block
* @param {MessageOptions} options The options to provide
* @param {MessageOptions} [options] The options to provide
* @returns {Promise<Message|Message[]>}
*/
sendCode(lang, content, options = {}) {
if (options.split) {
if (typeof options.split !== 'object') options.split = {};
if (!options.split.prepend) options.split.prepend = `\`\`\`${lang || ''}\n`;
if (!options.split.append) options.split.append = '\n```';
}
content = escapeMarkdown(this.client.resolver.resolveString(content), true);
return this.sendMessage(`\`\`\`${lang || ''}\n${content}\n\`\`\``, options);
return this.send(content, Object.assign(options, { code: lang }));
}
/**
@@ -349,19 +355,21 @@ class TextBasedChannel {
}
exports.applyToClass = (structure, full = false) => {
const props = ['sendMessage', 'sendTTSMessage', 'sendEmbed', 'sendFile', 'sendCode'];
const props = ['send', 'sendMessage', 'sendEmbed', 'sendFile', 'sendCode'];
if (full) {
props.push('_cacheMessage');
props.push('fetchMessages');
props.push('fetchMessage');
props.push('bulkDelete');
props.push('startTyping');
props.push('stopTyping');
props.push('typing');
props.push('typingCount');
props.push('fetchPinnedMessages');
props.push('createCollector');
props.push('awaitMessages');
props.push(
'_cacheMessage',
'fetchMessages',
'fetchMessage',
'bulkDelete',
'startTyping',
'stopTyping',
'typing',
'typingCount',
'fetchPinnedMessages',
'createCollector',
'awaitMessages'
);
}
for (const prop of props) {
Object.defineProperty(structure.prototype, prop, Object.getOwnPropertyDescriptor(TextBasedChannel.prototype, prop));

1
typings Submodule

Submodule typings added at 9b503a119c

786
typings/index.d.ts vendored
View File

@@ -1,786 +0,0 @@
// Type definitions for discord.js 10.0.1
// Project: https://github.com/hydrabolt/discord.js
// Definitions by: acdenisSK <acdenissk69@gmail.com> (https://github.com/acdenisSK)
// License: MIT
declare module "discord.js" {
import { EventEmitter } from "events";
import { Readable as ReadableStream } from "stream";
import { ChildProcess } from "child_process";
export const version: string;
export class Client extends EventEmitter {
constructor(options?: ClientOptions);
email: string;
emojis: Collection<string, Emoji>;
guilds: Collection<string, Guild>;
channels: Collection<string, Channel>;
options: ClientOptions;
password: string;
readyAt: Date;
readyTimestamp: number;
status: number;
token: string;
uptime: number;
user: ClientUser;
users: Collection<string, User>;
voiceConnections: Collection<string, VoiceConnection>;
clearInterval(timeout: NodeJS.Timer): void;
clearTimeout(timeout: NodeJS.Timer): void;
destroy(): Promise<void>;
fetchInvite(code: string): Promise<Invite>;
fetchUser(id: string): Promise<User>;
login(tokenOrEmail: string, password?: string): Promise<string>;
setInterval(fn: Function, delay: number, ...args: any[]): NodeJS.Timer;
setTimeout(fn: Function, delay: number, ...args: any[]): NodeJS.Timer;
sweepMessages(lifetime?: number): number;
syncGuilds(guilds?: Guild[]): void;
on(event: string, listener: Function): this;
on(event: "debug", listener: (the: string) => void): this;
on(event: "disconnect", listener: () => void): this;
on(event: "error", listener: (error: Error) => void): this;
on(event: "guildBanAdd", listener: (user: User) => void): this;
on(event: "guildBanRemove", listener: (user: User) => void): this;
on(event: "guildCreate", listener: (guild: Guild) => void): this;
on(event: "guildDelete", listener: (guild: Guild) => void): this;
on(event: "guildEmojiCreate", listener: (emoji: Emoji) => void): this;
on(event: "guildEmojiDelete", listener: (emoji: Emoji) => void): this;
on(event: "guildEmojiUpdate", listener: (oldEmoji: Emoji, newEmoji: Emoji) => void): this;
on(event: "guildMemberAdd", listener: (member: GuildMember) => void): this;
on(event: "guildMemberAvailable", listener: (member: GuildMember) => void): this;
on(event: "guildMemberRemove", listener: (member: GuildMember) => void): this;
on(event: "guildMembersChunk", listener: (members: GuildMember[]) => void): this;
on(event: "guildMemberSpeaking", listener: (member: GuildMember, speaking: boolean) => void): this;
on(event: "guildMemberUpdate", listener: (oldMember: GuildMember, newMember: GuildMember) => void): this;
on(event: "roleCreate", listener: (role: Role) => void): this;
on(event: "roleDelete", listener: (role: Role) => void): this;
on(event: "roleUpdate", listener: (oldRole: Role, newRole: Role) => void): this;
on(event: "guildUnavailable", listener: (guild: Guild) => void): this;
on(event: "guildUpdate", listener: (oldGuild: Guild, newGuild: Guild) => void): this;
on(event: "channelCreate", listener: (channel: Channel) => void): this;
on(event: "channelDelete", listener: (channel: Channel) => void): this;
on(event: "channelPinsUpdate", listener: (channel: Channel, time: Date) => void): this;
on(event: "channelUpdate", listener: (oldChannel: Channel, newChannel: Channel) => void): this;
on(event: "message", listener: (message: Message) => void): this;
on(event: "messageDelete", listener: (message: Message) => void): this;
on(event: "messageDeleteBulk", listener: (messages: Collection<string, Message>) => void): this;
on(event: "messageUpdate", listener: (oldMessage: Message, newMessage: Message) => void): this;
on(event: "presenceUpdate", listener: (oldUser: User, newUser: User) => void): this;
on(event: "ready", listener: () => void): this;
on(event: "reconnecting", listener: () => void): this;
on(event: "typingStart", listener: (channel: Channel, user: User) => void): this;
on(event: "typingStop", listener: (channel: Channel, user: User) => void): this;
on(event: "userUpdate", listener: (oldClientUser: ClientUser, newClientUser: ClientUser) => void): this;
on(event: "voiceStateUpdate", listener: (oldMember: GuildMember, newMember: GuildMember) => void): this;
on(event: "warn", listener: (the: string) => void): this;
}
export class Webhook {
avatar: string;
client: Client;
guildID: string;
channelID: string;
id: string;
name: string;
token: string;
delete(): Promise<void>;
edit(name: string, avatar: FileResolvable): Promise<Webhook>;
sendCode(lang: string, content: StringResolvable, options?: WebhookMessageOptions): Promise<Message | Message[]>;
sendFile(attachment: FileResolvable, fileName?: string, content?: StringResolvable, options?: WebhookMessageOptions): Promise<Message>;
sendMessage(content: StringResolvable, options?: WebhookMessageOptions): Promise<Message | Message[]>;
sendSlackMessage(body: Object): Promise<void>;
sendTTSMessage(content: StringResolvable, options?: WebhookMessageOptions): Promise<Message | Message[]>;
}
class SecretKey {
key: Uint8Array;
}
class RequestHandler { // docs going nowhere again, yay
constructor(restManager: {});
globalLimit: boolean;
queue: {}[];
restManager: {};
handle();
push(request: {});
}
export class WebhookClient extends Webhook {
constructor(id: string, token: string, options?: ClientOptions);
options: ClientOptions;
}
export class Emoji {
client: Client;
createdAt: Date;
createdTimestamp: number;
guild: Guild;
id: string;
managed: boolean;
name: string;
requiresColons: boolean;
roles: Collection<string, Role>;
url: string;
toString(): string;
}
export class ReactionEmoji {
id: string;
identifier: string;
name: string;
reaction: MessageReaction;
toString(): string;
}
export class ClientUser extends User {
email: string;
verified: boolean;
blocked: Collection<string, User>;
friends: Collection<string, User>;
addFriend(user: UserResolvable): Promise<User>;
removeFriend(user: UserResolvable): Promise<User>;
setAvatar(avatar: Base64Resolvable): Promise<ClientUser>;
setEmail(email: string): Promise<ClientUser>;
setPassword(password: string): Promise<ClientUser>;
setStatus(status?: string): Promise<ClientUser>;
setGame(game: string, streamingURL?: string): Promise<ClientUser>;
setPresence(data: Object): Promise<ClientUser>;
setUsername(username: string): Promise<ClientUser>;
createGuild(name: string, region: string, icon?: FileResolvable): Promise<Guild>;
}
export class Presence {
game: Game;
status: string;
equals(other: Presence): boolean;
}
export class Channel {
client: Client;
createdAt: Date;
createdTimestamp: number;
id: string;
type: string;
delete(): Promise<Channel>;
}
export class DMChannel extends Channel {
lastMessageID: string;
messages: Collection<string, Message>;
recipient: User;
typing: boolean;
typingCount: number;
awaitMessages(filter: CollectorFilterFunction, options?: AwaitMessagesOptions): Promise<Collection<string, Message>>;
bulkDelete(messages: Collection<string, Message> | Message[] | number): Collection<string, Message>;
createCollector(filter: CollectorFilterFunction, options?: CollectorOptions): MessageCollector;
fetchMessage(messageID: string): Promise<Message>;
fetchMessages(options?: ChannelLogsQueryOptions): Promise<Collection<string, Message>>;
fetchPinnedMessages(): Promise<Collection<string, Message>>;
sendCode(lang: string, content: StringResolvable, options?: MessageOptions): Promise<Message | Message[]>;
sendFile(attachment: FileResolvable, fileName?: string, content?: StringResolvable, options?: MessageOptions): Promise<Message>;
sendMessage(content: string, options?: MessageOptions): Promise<Message | Message[]>;
sendTTSMessage(content: string, options?: MessageOptions): Promise<Message | Message[]>;
startTyping(count?: number): void;
stopTyping(force?: boolean): void;
toString(): string;
}
export class GroupDMChannel extends Channel {
lastMessageID: string;
messages: Collection<string, Message>;
recipients: Collection<string, User>;
owner: User;
typing: boolean;
typingCount: number;
awaitMessages(filter: CollectorFilterFunction, options?: AwaitMessagesOptions): Promise<Collection<string, Message>>;
bulkDelete(messages: Collection<string, Message> | Message[] | number): Collection<string, Message>;
createCollector(filter: CollectorFilterFunction, options?: CollectorOptions): MessageCollector;
fetchMessage(messageID: string): Promise<Message>;
fetchMessages(options?: ChannelLogsQueryOptions): Promise<Collection<string, Message>>;
fetchPinnedMessages(): Promise<Collection<string, Message>>;
sendCode(lang: string, content: StringResolvable, options?: MessageOptions): Promise<Message | Message[]>;
sendFile(attachment: FileResolvable, fileName?: string, content?: StringResolvable, options?: MessageOptions): Promise<Message>;
sendMessage(content: string, options?: MessageOptions): Promise<Message | Message[]>;
sendTTSMessage(content: string, options?: MessageOptions): Promise<Message | Message[]>;
startTyping(count?: number): void;
stopTyping(force?: boolean): void;
toString(): string;
}
export class GuildChannel extends Channel {
guild: Guild;
name: string;
permissionOverwrites: Collection<string, PermissionOverwrites>;
position: number;
createInvite(options?: InviteOptions): Promise<Invite>;
equals(channel: GuildChannel): boolean;
overwritePermissions(userOrRole: Role | User, options: PermissionOverwriteOptions): Promise<void>;
permissionsFor(member: GuildMemberResolvable): EvaluatedPermissions;
setName(name: string): Promise<GuildChannel>;
setPosition(position: number): Promise<GuildChannel>;
setTopic(topic: string): Promise<GuildChannel>;
toString(): string;
}
export class TextChannel extends GuildChannel {
lastMessageID: string;
members: Collection<string, GuildMember>;
messages: Collection<string, Message>;
topic: string;
typing: boolean;
typingCount: number;
awaitMessages(filter: CollectorFilterFunction, options?: AwaitMessagesOptions): Promise<Collection<string, Message>>;
bulkDelete(messages: Collection<string, Message> | Message[] | number): Collection<string, Message>;
createCollector(filter: CollectorFilterFunction, options?: CollectorOptions): MessageCollector;
fetchMessage(messageID: string): Promise<Message>;
fetchMessages(options?: ChannelLogsQueryOptions): Promise<Collection<string, Message>>;
fetchPinnedMessages(): Promise<Collection<string, Message>>;
sendCode(lang: string, content: StringResolvable, options?: MessageOptions): Promise<Message | Message[]>;
sendFile(attachment: FileResolvable, fileName?: string, content?: StringResolvable, options?: MessageOptions): Promise<Message>;
sendMessage(content: string, options?: MessageOptions): Promise<Message | Message[]>;
sendTTSMessage(content: string, options?: MessageOptions): Promise<Message | Message[]>;
startTyping(count?: number): void;
stopTyping(force?: boolean): void;
}
export class MessageCollector extends EventEmitter {
constructor(channel: Channel, filter: CollectorFilterFunction, options?: CollectorOptions);
collected: Collection<string, Message>;
filter: CollectorFilterFunction;
channel: Channel;
options: CollectorOptions;
stop(reason?: string): void;
on(event: "end", listener: (collection: Collection<string, Message>, reason: string) => void): this;
on(event: "message", listener: (message: Message, collector: MessageCollector) => void): this;
}
export class Game {
name: string;
streaming: boolean;
url: string;
type: number;
equals(other: Game): boolean;
}
export class PermissionOverwrites {
channel: GuildChannel;
id: string;
type: string;
delete(): Promise<PermissionOverwrites>;
}
export class Guild {
afkChannelID: string;
afkTimeout: number;
available: boolean;
client: Client;
createdAt: Date;
createdTimestamp: number;
defaultChannel: GuildChannel;
embedEnabled: boolean;
emojis: Collection<string, Emoji>;
features: Object[];
channels: Collection<string, GuildChannel>;
icon: string;
iconURL: string;
id: string;
joinDate: Date;
large: boolean;
memberCount: number;
members: Collection<string, GuildMember>;
name: string;
owner: GuildMember;
ownerID: string;
region: string;
roles: Collection<string, Role>;
splash: string;
verificationLevel: number;
voiceConnection: VoiceConnection;
ban(user: GuildMember, deleteDays?: number): Promise<GuildMember | User | string>;
createChannel(name: string, type: "text" | "voice"): Promise<TextChannel | VoiceChannel>;
createRole(data?: RoleData): Promise<Role>;
delete(): Promise<Guild>;
edit(data: {}): Promise<Guild>;
equals(guild: Guild): boolean;
fetchBans(): Promise<Collection<string, User>>;
fetchInvites(): Promise<Collection<string, Invite>>;
fetchMember(user: UserResolvable): Promise<GuildMember>;
fetchMembers(query?: string): Promise<Guild>;
leave(): Promise<Guild>;
member(user: UserResolvable): GuildMember;
pruneMembers(days: number, dry?: boolean): Promise<number>;
setAFKChannel(afkChannel: ChannelResovalble): Promise<Guild>;
setAFKTimeout(afkTimeout: number): Promise<Guild>;
setIcon(icon: Base64Resolvable): Promise<Guild>;
setName(name: string): Promise<Guild>;
setOwner(owner: GuildMemberResolvable): Promise<Guild>;
setRegion(region: string): Promise<Guild>;
setSplash(splash: Base64Resolvable): Promise<Guild>;
setVerificationLevel(level: number): Promise<Guild>;
sync(): void;
toString(): string;
unban(user: UserResolvable): Promise<User>;
}
export class GuildMember {
bannable: boolean;
client: Client;
deaf: boolean;
guild: Guild;
highestRole: Role;
id: string;
joinDate: Date;
kickable: boolean;
mute: boolean;
nickname: string;
permissions: EvaluatedPermissions;
roles: Collection<string, Role>;
selfDeaf: boolean;
selfMute: boolean;
serverDeaf: boolean;
serverMute: boolean;
speaking: boolean;
user: User;
voiceChannel: VoiceChannel;
voiceChannelID: string;
voiceSessionID: string;
addRole(role: Role | string): Promise<GuildMember>;
addRoles(roles: Collection<string, Role> | Role[] | string[]): Promise<GuildMember>;
ban(deleteDays?: number): Promise<GuildMember>;
deleteDM(): Promise<DMChannel>;
edit(data: {}): Promise<GuildMember>;
hasPermission(permission: PermissionResolvable, explicit?: boolean): boolean;
hasPermissions(permission: Permissions[], explicit?: boolean): boolean;
kick(): Promise<GuildMember>;
permissionsIn(channel: ChannelResovalble): EvaluatedPermissions;
removeRole(role: Role | string): Promise<GuildMember>;
removeRoles(roles: Collection<string, Role> | Role[] | string[]): Promise<GuildMember>;
sendCode(lang: string, content: StringResolvable, options?: MessageOptions): Promise<Message | Message[]>;
sendFile(attachment: FileResolvable, fileName?: string, content?: StringResolvable, options?: MessageOptions): Promise<Message>;
sendMessage(content: string, options?: MessageOptions): Promise<Message | Message[]>;
sendTTSMessage(content: string, options?: MessageOptions): Promise<Message | Message[]>;
setDeaf(deaf: boolean): Promise<GuildMember>;
setMute(mute: boolean): Promise<GuildMember>;
setNickname(nickname: string): Promise<GuildMember>;
setRoles(roles: Collection<string, Role> | Role[] | string[]): Promise<GuildMember>;
setVoiceChannel(voiceChannel: ChannelResovalble): Promise<GuildMember>;
toString(): string;
}
export class User {
avatar: string;
avatarURL: string;
bot: boolean;
client: Client;
createdAt: Date;
createdTimestamp: number;
discriminator: string;
presence: Presence;
id: string;
status: string;
username: string;
block(): Promise<User>;
unblock(): Promise<User>;
fetchProfile(): Promise<UserProfile>;
deleteDM(): Promise<DMChannel>;
equals(user: User): boolean;
sendCode(lang: string, content: StringResolvable, options?: MessageOptions): Promise<Message | Message[]>;
sendFile(attachment: FileResolvable, fileName?: string, content?: StringResolvable, options?: MessageOptions): Promise<Message>;
sendMessage(content: string, options?: MessageOptions): Promise<Message | Message[]>;
sendTTSMessage(content: string, options?: MessageOptions): Promise<Message | Message[]>;
toString(): string;
}
export class PartialGuildChannel {
client: Client;
id: string;
name: string;
type: string;
}
export class PartialGuild {
client: Client;
icon: string;
id: string;
name: string;
splash: string;
}
class PendingVoiceConnection {
data: Object;
deathTimer: NodeJS.Timer;
channel: VoiceChannel;
voiceManager: ClientVoiceManager;
setSessionID(sessionID: string);
setTokenAndEndpoint(token: string, endpoint: string);
upgrade(): VoiceConnection;
}
export class OAuth2Application {
client: Client;
createdAt: Date;
createdTimestamp: number;
description: string;
icon: string;
iconURL: string;
id: string;
name: string;
rpcOrigins: string[];
toString(): string;
}
export class ClientOAuth2Application extends OAuth2Application {
flags: number;
owner: User;
}
export class Message {
attachments: Collection<string, MessageAttachment>;
author: User;
channel: TextChannel | DMChannel | GroupDMChannel;
cleanContent: string;
client: Client;
content: string;
createdAt: Date;
createdTimestamp: number;
deletable: boolean;
editable: boolean;
editedAt: Date;
editedTimestamp: number;
edits: Message[];
embeds: MessageEmbed[];
guild: Guild;
id: string;
member: GuildMember;
mentions: {
users: Collection<string, User>;
roles: Collection<string, Role>;
channels: Collection<string, GuildChannel>;
everyone: boolean;
};
nonce: string;
pinnable: boolean;
pinned: boolean;
reactions: Collection<string, MessageReaction>;
system: boolean;
tts: boolean;
type: string;
addReaction(emoji: string): MessageReaction; // Not really documented but still worth using/making typings for it.
delete(timeout?: number): Promise<Message>;
edit(content: StringResolvable): Promise<Message>;
editCode(lang: string, content: StringResolvable): Promise<Message>;
equals(message: Message, rawData: Object): boolean;
isMentioned(data: GuildChannel | User | Role | string): boolean;
pin(): Promise<Message>;
reply(content: StringResolvable, options?: MessageOptions): Promise<Message | Message[]>;
toString(): string;
unpin(): Promise<Message>;
}
export class MessageEmbed {
author: MessageEmbedAuthor;
client: Client;
description: string;
message: Message;
provider: MessageEmbedProvider;
thumbnail: MessageEmbedThumbnail;
title: string;
type: string;
url: string;
}
export class MessageEmbedThumbnail {
embed: MessageEmbed;
height: number;
proxyURL: string;
url: string;
width: number;
}
export class MessageEmbedProvider {
embed: MessageEmbed;
name: string;
url: string;
}
export class MessageEmbedAuthor {
embed: MessageEmbed;
name: string;
url: string;
}
export class RichEmbed {
title?: string;
description?: string;
url?: string;
timestamp?: Date;
color?: number | string;
fields?: { name: string; value: string; inline?: boolean; }[];
author?: { name: string; url?: string; icon_url?: string; };
thumbnail?: { url: string; height?: number; width?: number; };
image?: { url: string; proxy_url?: string; height?: number; width?: number; };
video?: { url: string; height: number; width: number; };
footer?: { text?: string; icon_url?: string; };
addField(name: string, value: StringResolvable, inline?: boolean): this;
setAuthor(name: string, icon?: string, url?: string): this;
setColor(color: string | number | number[]): this;
setDescription(description: string): this;
setFooter(text: string, icon: string): this;
setImage(url: string): this;
setThumbnail(url: string): this;
setTimestamp(timestamp?: Date): this;
setTitle(title: string): this;
setURL(url: string): this;
}
export class MessageAttachment {
client: Client;
filename: string;
filesize: number;
height: number;
id: string;
message: Message;
proxyURL: string;
url: string;
width: number;
}
export class MessageReaction {
count: number;
emoji: Emoji | ReactionEmoji;
me: boolean;
message: Message;
users: Collection<string, User>;
fetchUsers(limit?: number): Promise<Collection<string, User>>;
remove(user?: UserResolvable): Promise<MessageReaction>;
}
export class Invite {
client: Client;
code: string;
createdAt: Date;
createdTimestamp: number;
guild: Guild | PartialGuild;
channel: GuildChannel | PartialGuildChannel;
inviter: User;
maxUses: number;
temporary: boolean;
url: string;
uses: number;
delete(): Promise<Invite>;
toString(): string;
}
export class VoiceChannel extends GuildChannel {
bitrate: number;
connection: VoiceConnection;
members: Collection<string, GuildMember>;
userLimit: number;
join(): Promise<VoiceConnection>;
leave(): null;
setBitrate(bitrate: number): Promise<VoiceChannel>;
}
export class Shard {
id: string;
manager: ShardingManager;
process: ChildProcess;
eval(script: string): Promise<any>;
fetchClientValue(prop: string): Promise<any>;
send(message: any): Promise<Shard>;
}
export class ShardingManager extends EventEmitter {
constructor(file: string, options?: {
totalShards?: number;
respawn?: boolean;
shardArgs?: string[];
token?: string;
});
file: string;
respawn: boolean;
shardArgs: string[];
shards: Collection<number, Shard>;
totalShards: number;
broadcast(message: any): Promise<Shard[]>;
broadcastEval(script: string): Promise<any[]>;
createShard(id: number): Promise<Shard>;
fetchClientValues(prop: string): Promise<any[]>;
spawn(amount?: number, delay?: number): Promise<Collection<number, Shard>>;
on(event: "launch", listener: (shard: Shard) => void): this;
}
export class ShardClientUtil {
constructor(client: Client);
id: number;
count: number;
broadcastEval(script: string): Promise<any[]>;
fetchClientValues(prop: string): Promise<any[]>;
send(message: any): Promise<void>;
singleton(client: Client): ShardClientUtil;
}
export class UserConnection {
id: string;
integrations: Object[];
name: string;
revoked: boolean;
type: string;
user: User;
}
export class UserProfile {
client: Client;
connections: Collection<string, UserConnection>;
mutualGuilds: Collection<string, Guild>;
user: User;
}
export class StreamDispatcher extends EventEmitter {
passes: number;
time: number;
totalStreamTime: number;
volume: number;
end(): void;
pause(): void;
resume(): void;
setVolume(volume: number): void;
setVolumeDecibels(db: number): void;
setVolumeLogarithmic(value: number): void;
on(event: "debug", listener: (information: string) => void): this;
on(event: "end", listener: () => void): this;
on(event: "error", listener: (err: Error) => void): this;
on(event: "speaking", listener: (value: boolean) => void): this;
on(event: "start", listener: () => void): this;
}
interface Permissions {
CREATE_INSTANT_INVITE: boolean;
KICK_MEMBERS: boolean;
BAN_MEMBERS: boolean;
ADMINISTRATOR: boolean;
MANAGE_CHANNELS: boolean;
MANAGE_GUILD: boolean;
READ_MESSAGES: boolean;
SEND_MESSAGES: boolean;
SEND_TTS_MESSAGES: boolean;
MANAGE_MESSAGES: boolean;
EMBED_LINKS: boolean;
ATTACH_FILES: boolean;
READ_MESSAGE_HISTORY: boolean;
MENTION_EVERYONE: boolean;
USE_EXTERNAL_EMOJIS: boolean;
CONNECT: boolean;
SPEAK: boolean;
MUTE_MEMBERS: boolean;
DEAFEN_MEMBERS: boolean;
MOVE_MEMBERS: boolean;
USE_VAD: boolean;
CHANGE_NICKNAME: boolean;
MANAGE_NICKNAMES: boolean;
MANAGE_ROLES: boolean;
MANAGE_WEBHOOKS: boolean;
}
export class EvaluatedPermissions {
member: GuildMember;
raw: number;
hasPermission(permission: PermissionResolvable, explicit?: boolean): boolean;
hasPermissions(permission: PermissionResolvable[], explicit?: boolean): boolean;
serialize(): Permissions;
}
export class Role {
client: Client;
color: number;
createdAt: Date; createdTimestamp: number;
guild: Guild;
hexColor: string;
hoist: boolean;
id: string;
managed: boolean;
members: Collection<string, GuildMember>;
mentionable: boolean;
name: string;
permissions: number;
position: number;
delete(): Promise<Role>;
edit(data: RoleData): Promise<Role>;
equals(role: Role): boolean;
hasPermission(permission: PermissionResolvable, explicit?: boolean): boolean;
hasPermissions(permissions: PermissionResolvable[], explicit?: boolean): boolean;
serialize(): Permissions;
setColor(color: string | number): Promise<Role>;
setHoist(hoist: boolean): Promise<Role>;
setName(name: string): Promise<Role>;
setPermissions(permissions: string[]): Promise<Role>;
setPosition(position: number): Promise<Role>;
toString(): string;
}
export class ClientVoiceManager {
client: Client;
connections: Collection<string, VoiceConnection>;
pending: Collection<string, VoiceConnection>;
joinChannel(channel: VoiceChannel): Promise<VoiceConnection>;
sendVoiceStateUpdate(channel: VoiceChannel, options?: Object);
}
class AudioPlayer extends EventEmitter {
dispatcher: StreamDispatcher;
voiceConnection: VoiceConnection;
}
export class VoiceConnection extends EventEmitter {
authentication: Object;
channel: VoiceChannel;
player: AudioPlayer;
receivers: VoiceReceiver[];
sockets: Object;
ssrcMap: Map<number, boolean>;
voiceManager: ClientVoiceManager;
createReceiver(): VoiceReceiver;
disconnect();
playConvertedStream(stream: ReadableStream, options?: StreamOptions): StreamDispatcher;
playFile(file: string, options?: StreamOptions): StreamDispatcher;
playStream(stream: ReadableStream, options?: StreamOptions): StreamDispatcher;
on(event: "disconnect", listener: (error: Error) => void): this;
on(event: "error", listener: (error: Error) => void): this;
on(event: "ready", listener: () => void): this;
on(event: "speaking", listener: (user: User, speaking: boolean) => void): this;
}
export class VoiceReceiver extends EventEmitter {
connection: VoiceConnection;
destroyed: boolean;
createOpusStream(user: User): ReadableStream;
createPCMStream(user: User): ReadableStream;
destroy(): void;
recreate(): void;
on(event: "opus", listener: (user: User, buffer: Buffer) => void): this;
on(event: "pcm", listener: (user: User, buffer: Buffer) => void): this;
on(event: "warn", listener: (message: string) => void): this;
}
export class Collection<key, value> extends Map<key, value> {
array(): value[];
concat(...collections: Collection<any, any>[]): Collection<any, any>;
deleteAll(): Promise<void[]>;
every(fn: Function, thisArg?: Object): boolean;
exists(prop: string, value: any): boolean;
filter(fn: Function, thisArg?: Object): Collection<key, value>;
filterArray(fn: Function, thisArg?: Object): value[];
find(propOrFn: string | Function, value?: any): value;
findAll(prop: string, value: any): value[];
findKey(propOrFn: string | Function, value?: any): key;
first(): value;
firstKey(): key;
keyArray(): key[];
last(): value;
lastKey(): key;
map(fn: Function, thisArg?: Object): any[];
random(): value;
randomKey(): key;
reduce(fn: Function, startVal?: any): any;
some(fn: Function, thisArg?: Object): boolean;
}
type CollectorOptions = { time?: number; max?: number };
type AwaitMessagesOptions = { time?: number; max?: number; errors?: string[]; };
type Base64Resolvable = Buffer | string;
type CollectorFilterFunction = (message: Message, collector: MessageCollector) => boolean;
type FileResolvable = Buffer | string;
type GuildMemberResolvable = GuildMember | User;
type GuildResolvable = Guild;
type ChannelLogsQueryOptions = { limit?: number; before?: string; after?: string; around?: string };
type ChannelResovalble = Channel | Guild | Message | string;
type InviteOptions = { temporary?: boolean; maxAge?: number; maxUses?: number; };
type MessageOptions = { tts?: boolean; nonce?: string; disableEveryone?: boolean; split?: boolean | SplitOptions; };
type PermissionOverwriteOptions = Permissions;
type PermissionResolvable = string | string[] | number[];
type SplitOptions = { maxLength?: number; char?: string; prepend?: string; append?: string; };
type StreamOptions = { seek?: number; volume?: number; passes?: number; };
type StringResolvable = any[] | string | any;
type UserResolvable = User | string | Message | Guild | GuildMember;
type WebSocketOptions = { large_threshold?: number; compress?: boolean; };
type ClientOptions = {
apiRequestMethod?: string;
shardId?: number;
shardCount?: number;
maxMessageCache?: number;
messageCacheLifetime?: number;
messageSweepInterval?: number;
fetchAllMembers?: boolean;
disableEveryone?: boolean;
restWsBridgeTimeout?: number;
ws?: WebSocketOptions;
};
type WebhookMessageOptions = {
tts?: boolean;
disableEveryone?: boolean;
};
type WebhookOptions = {
large_threshold?: number;
compress?: boolean;
};
type RoleData = {
name?: string;
color?: number | string;
hoist?: boolean;
position?: number;
permissions?: string[];
mentionable?: boolean;
};
}

View File

@@ -1,13 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"strictNullChecks": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts"
]
}