diff --git a/src/client/Client.js b/src/client/Client.js index 4751333ee..d7ec95dfb 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -361,12 +361,11 @@ class Client extends EventEmitter { /** * Obtains the OAuth Application of the bot from Discord. - * This is only available when using a bot account. + * @param {Snowflake} [id='@me'] ID of application to fetch * @returns {Promise} */ - fetchApplication() { - if (!this.user.bot) throw new Error(Constants.Errors.NO_BOT_ACCOUNT); - return this.rest.methods.getMyApplication(); + fetchApplication(id = '@me') { + return this.rest.methods.getApplication(id); } /** diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js index 37556069f..cd1987f3e 100644 --- a/src/client/rest/RESTMethods.js +++ b/src/client/rest/RESTMethods.js @@ -12,7 +12,7 @@ const Role = require('../../structures/Role'); const Invite = require('../../structures/Invite'); const Webhook = require('../../structures/Webhook'); const UserProfile = require('../../structures/UserProfile'); -const ClientOAuth2Application = require('../../structures/ClientOAuth2Application'); +const OAuth2Application = require('../../structures/OAuth2Application'); const Channel = require('../../structures/Channel'); const Guild = require('../../structures/Guild'); const VoiceRegion = require('../../structures/VoiceRegion'); @@ -799,12 +799,20 @@ class RESTMethods { ); } - getMyApplication() { - return this.rest.makeRequest('get', Constants.Endpoints.myApplication, true).then(app => - new ClientOAuth2Application(this.client, app) + getApplication(id) { + return this.rest.makeRequest('get', Constants.Endpoints.oauth2Application(id), true).then(app => + new OAuth2Application(this.client, app) ); } + resetApplication(id) { + return this.rest.makeRequest( + 'post', + `${Constants.Endpoints.oauth2Application(id)}/reset`, + true + ).then(app => new OAuth2Application(this.client, app)); + } + setNote(user, note) { return this.rest.makeRequest('put', Constants.Endpoints.note(user.id), true, { note }).then(() => user); } diff --git a/src/index.js b/src/index.js index 6808c9815..2b1345e34 100644 --- a/src/index.js +++ b/src/index.js @@ -24,7 +24,6 @@ module.exports = { // Structures Channel: require('./structures/Channel'), - ClientOAuth2Application: require('./structures/ClientOAuth2Application'), ClientUser: require('./structures/ClientUser'), DMChannel: require('./structures/DMChannel'), Emoji: require('./structures/Emoji'), diff --git a/src/structures/ClientOAuth2Application.js b/src/structures/ClientOAuth2Application.js deleted file mode 100644 index 46e125040..000000000 --- a/src/structures/ClientOAuth2Application.js +++ /dev/null @@ -1,26 +0,0 @@ -const User = require('./User'); -const OAuth2Application = require('./OAuth2Application'); - -/** - * Represents the client's OAuth2 Application - * @extends {OAuth2Application} - */ -class ClientOAuth2Application extends OAuth2Application { - setup(data) { - super.setup(data); - - /** - * The app's flags - * @type {number} - */ - this.flags = data.flags; - - /** - * The app's owner - * @type {User} - */ - this.owner = new User(this.client, data.owner); - } -} - -module.exports = ClientOAuth2Application; diff --git a/src/structures/OAuth2Application.js b/src/structures/OAuth2Application.js index cbe162466..30e9b3f34 100644 --- a/src/structures/OAuth2Application.js +++ b/src/structures/OAuth2Application.js @@ -47,9 +47,51 @@ class OAuth2Application { /** * The app's RPC origins - * @type {Array} + * @type {?string[]} */ this.rpcOrigins = data.rpc_origins; + + /** + * The app's redirect URIs + * @type {string[]} + */ + this.redirectURIs = data.redirect_uris; + + /** + * If this app's bot requires a code grant when using the oauth2 flow + * @type {boolean} + */ + this.botRequireCodeGrant = data.bot_require_code_grant; + + /** + * If this app's bot is public + * @type {boolean} + */ + this.botPublic = data.bot_public; + + /** + * If this app can use rpc + * @type {boolean} + */ + this.rpcApplicationState = data.rpc_application_state; + + /** + * Object containing basic info about this app's bot + * @type {Object} + */ + this.bot = data.bot; + + /** + * Flags for the app + * @type {number} + */ + this.flags = data.flags; + + /** + * oauth2 secret for the app + * @type {boolean} + */ + this.secret = data.secret; } /** @@ -70,6 +112,14 @@ class OAuth2Application { return new Date(this.createdTimestamp); } + /** + * Reset the app's secret and bot token + * @returns {OAuth2Application} + */ + reset() { + return this.client.rest.methods.resetApplication(this.id); + } + /** * When concatenated with a string, this automatically concatenates the app name rather than the app object. * @returns {string} diff --git a/src/util/Constants.js b/src/util/Constants.js index 76bb705df..873b881b8 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -158,7 +158,7 @@ const Endpoints = exports.Endpoints = { webhook: (webhookID, token) => `${API}/webhooks/${webhookID}${token ? `/${token}` : ''}`, // oauth - myApplication: `${API}/oauth2/applications/@me`, + oauth2Application: (appID) => `${API}/oauth2/applications/${appID}`, getApp: (id) => `${API}/oauth2/authorize?client_id=${id}`, // emoji