mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
new application stuff very hype (#1764)
* application stuff, more to come * docstrings * Update Message.js
This commit is contained in:
@@ -16,7 +16,7 @@ const VoiceRegion = require('../structures/VoiceRegion');
|
|||||||
const Webhook = require('../structures/Webhook');
|
const Webhook = require('../structures/Webhook');
|
||||||
const User = require('../structures/User');
|
const User = require('../structures/User');
|
||||||
const Invite = require('../structures/Invite');
|
const Invite = require('../structures/Invite');
|
||||||
const OAuth2Application = require('../structures/OAuth2Application');
|
const ClientApplication = require('../structures/ClientApplication');
|
||||||
const ShardClientUtil = require('../sharding/ShardClientUtil');
|
const ShardClientUtil = require('../sharding/ShardClientUtil');
|
||||||
const VoiceBroadcast = require('./voice/VoiceBroadcast');
|
const VoiceBroadcast = require('./voice/VoiceBroadcast');
|
||||||
const { Error, TypeError, RangeError } = require('../errors');
|
const { Error, TypeError, RangeError } = require('../errors');
|
||||||
@@ -415,7 +415,7 @@ class Client extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
fetchApplication(id = '@me') {
|
fetchApplication(id = '@me') {
|
||||||
return this.api.oauth2.applications(id).get()
|
return this.api.oauth2.applications(id).get()
|
||||||
.then(app => new OAuth2Application(this, app));
|
.then(app => new ClientApplication(this, app));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ module.exports = {
|
|||||||
MessageEmbed: require('./structures/MessageEmbed'),
|
MessageEmbed: require('./structures/MessageEmbed'),
|
||||||
MessageMentions: require('./structures/MessageMentions'),
|
MessageMentions: require('./structures/MessageMentions'),
|
||||||
MessageReaction: require('./structures/MessageReaction'),
|
MessageReaction: require('./structures/MessageReaction'),
|
||||||
OAuth2Application: require('./structures/OAuth2Application'),
|
ClientApplication: require('./structures/ClientApplication'),
|
||||||
ClientOAuth2Application: require('./structures/OAuth2Application'),
|
|
||||||
PartialGuild: require('./structures/PartialGuild'),
|
PartialGuild: require('./structures/PartialGuild'),
|
||||||
PartialGuildChannel: require('./structures/PartialGuildChannel'),
|
PartialGuildChannel: require('./structures/PartialGuildChannel'),
|
||||||
PermissionOverwrites: require('./structures/PermissionOverwrites'),
|
PermissionOverwrites: require('./structures/PermissionOverwrites'),
|
||||||
|
|||||||
@@ -126,7 +126,36 @@ class OAuth2Application {
|
|||||||
*/
|
*/
|
||||||
iconURL({ format, size } = {}) {
|
iconURL({ format, size } = {}) {
|
||||||
if (!this.icon) return null;
|
if (!this.icon) return null;
|
||||||
return Constants.Endpoints.CDN(this.client.options.http.cdn).AppIcon(this.id, this.icon, format, size);
|
return Constants.Endpoints.CDN(this.client.options.http.cdn).AppIcon(this.id, this.icon, { format, size });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get rich presence assets
|
||||||
|
* @returns {Promise<Object>}
|
||||||
|
*/
|
||||||
|
fetchAssets() {
|
||||||
|
return this.client.api.applications(this.id).assets.get()
|
||||||
|
.then(assets => assets.map(a => ({
|
||||||
|
id: a.id,
|
||||||
|
name: a.name,
|
||||||
|
type: Object.keys(Constants.ClientApplicationAssetTypes)[a.type - 1],
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a rich presence asset
|
||||||
|
* @param {string} name Name of the asset
|
||||||
|
* @param {Base64Resolvable} data Data of the asset
|
||||||
|
* @param {string} type Type of the asset. `big`, or `small`
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
createAsset(name, data, type) {
|
||||||
|
return this.client.resolveBase64(data).then(b64 =>
|
||||||
|
this.client.api.applications(this.id).assets.post({ data: {
|
||||||
|
name,
|
||||||
|
data: b64,
|
||||||
|
type: Constants.ClientApplicationAssetTypes[type.toUpperCase()],
|
||||||
|
} }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3,6 +3,7 @@ const Attachment = require('./MessageAttachment');
|
|||||||
const Embed = require('./MessageEmbed');
|
const Embed = require('./MessageEmbed');
|
||||||
const MessageReaction = require('./MessageReaction');
|
const MessageReaction = require('./MessageReaction');
|
||||||
const ReactionCollector = require('./ReactionCollector');
|
const ReactionCollector = require('./ReactionCollector');
|
||||||
|
const ClientApplication = require('./ClientApplication');
|
||||||
const Util = require('../util/Util');
|
const Util = require('../util/Util');
|
||||||
const Collection = require('../util/Collection');
|
const Collection = require('../util/Collection');
|
||||||
const Constants = require('../util/Constants');
|
const Constants = require('../util/Constants');
|
||||||
@@ -137,6 +138,21 @@ class Message {
|
|||||||
*/
|
*/
|
||||||
this.webhookID = data.webhook_id || null;
|
this.webhookID = data.webhook_id || null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supplimental application information for group activities
|
||||||
|
* @type {?ClientApplication}
|
||||||
|
*/
|
||||||
|
this.application = data.application ? new ClientApplication(this.client, data.application) : null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Group activity
|
||||||
|
* @type {?Object}
|
||||||
|
*/
|
||||||
|
this.activiy = data.activity ? {
|
||||||
|
partyID: data.activity.party_id,
|
||||||
|
type: data.activity.type,
|
||||||
|
} : null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this message is a hit in a search
|
* Whether this message is a hit in a search
|
||||||
* @type {?boolean}
|
* @type {?boolean}
|
||||||
|
|||||||
@@ -103,9 +103,10 @@ const AllowedImageSizes = [
|
|||||||
2048,
|
2048,
|
||||||
];
|
];
|
||||||
|
|
||||||
function checkImage({ size, format }) {
|
function makeImageUrl(root, { format = 'webp', size } = {}) {
|
||||||
if (format && !AllowedImageFormats.includes(format)) throw new Error('IMAGE_FORMAT', format);
|
if (format && !AllowedImageFormats.includes(format)) throw new Error('IMAGE_FORMAT', format);
|
||||||
if (size && !AllowedImageSizes.includes(size)) throw new RangeError('IMAGE_SIZE', size);
|
if (size && !AllowedImageSizes.includes(size)) throw new RangeError('IMAGE_SIZE', size);
|
||||||
|
return `${root}.${format}${size ? `?size=${size}` : ''}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Endpoints = {
|
exports.Endpoints = {
|
||||||
@@ -116,25 +117,16 @@ exports.Endpoints = {
|
|||||||
DefaultAvatar: number => `${root}/embed/avatars/${number}.png`,
|
DefaultAvatar: number => `${root}/embed/avatars/${number}.png`,
|
||||||
Avatar: (userID, hash, format = 'default', size) => {
|
Avatar: (userID, hash, format = 'default', size) => {
|
||||||
if (format === 'default') format = hash.startsWith('a_') ? 'gif' : 'webp';
|
if (format === 'default') format = hash.startsWith('a_') ? 'gif' : 'webp';
|
||||||
checkImage({ size, format });
|
return makeImageUrl(`${root}/avatars/${userID}/${hash}`, { format, size });
|
||||||
return `${root}/avatars/${userID}/${hash}.${format}${size ? `?size=${size}` : ''}`;
|
|
||||||
},
|
|
||||||
Icon: (guildID, hash, format = 'webp', size) => {
|
|
||||||
checkImage({ size, format });
|
|
||||||
return `${root}/icons/${guildID}/${hash}.${format}${size ? `?size=${size}` : ''}`;
|
|
||||||
},
|
|
||||||
AppIcon: (clientID, hash, format = 'webp', size) => {
|
|
||||||
checkImage({ size, format });
|
|
||||||
return `${root}/app-icons/${clientID}/${hash}.${format}${size ? `?size=${size}` : ''}`;
|
|
||||||
},
|
|
||||||
GDMIcon: (channelID, hash, format = 'webp', size) => {
|
|
||||||
checkImage({ size, format });
|
|
||||||
return `${root}/channel-icons/${channelID}/${hash}.${format}${size ? `?size=${size}` : ''}`;
|
|
||||||
},
|
|
||||||
Splash: (guildID, hash, format = 'webp', size) => {
|
|
||||||
checkImage({ size, format });
|
|
||||||
return `${root}/splashes/${guildID}/${hash}.${format}${size ? `?size=${size}` : ''}`;
|
|
||||||
},
|
},
|
||||||
|
Icon: (guildID, hash, format = 'webp', size) =>
|
||||||
|
makeImageUrl(`${root}/icons/${guildID}/${hash}`, { format, size }),
|
||||||
|
AppIcon: (clientID, hash, { format = 'webp', size } = {}) =>
|
||||||
|
makeImageUrl(`${root}/app-icons/${clientID}/${hash}`, { size, format }),
|
||||||
|
GDMIcon: (channelID, hash, format = 'webp', size) =>
|
||||||
|
makeImageUrl(`${root}/channel-icons/${channelID}/${hash}`, { size, format }),
|
||||||
|
Splash: (guildID, hash, format = 'webp', size) =>
|
||||||
|
makeImageUrl(`${root}/splashes/${guildID}/${hash}`, { size, format }),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
invite: (root, code) => `${root}/${code}`,
|
invite: (root, code) => `${root}/${code}`,
|
||||||
@@ -570,6 +562,11 @@ exports.UserFlags = {
|
|||||||
HYPESQUAD: 1 << 2,
|
HYPESQUAD: 1 << 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.ClientApplicationAssetTypes = {
|
||||||
|
SMALL: 1,
|
||||||
|
BIG: 2,
|
||||||
|
};
|
||||||
|
|
||||||
exports.Colors = {
|
exports.Colors = {
|
||||||
DEFAULT: 0x000000,
|
DEFAULT: 0x000000,
|
||||||
AQUA: 0x1ABC9C,
|
AQUA: 0x1ABC9C,
|
||||||
|
|||||||
Reference in New Issue
Block a user