mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
@@ -324,6 +324,15 @@ class Client extends EventEmitter {
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's the bot's OAuth2 app. Only usable by bot accounts
|
||||
* @returns {Promise<ClientOAuth2App>}
|
||||
*/
|
||||
getMyApp() {
|
||||
if (!this.user.bot) throw new Error(Constants.Errors.NO_BOT_ACCOUNT);
|
||||
return this.rest.methods.getMyApp();
|
||||
}
|
||||
|
||||
setTimeout(fn, ...params) {
|
||||
const timeout = setTimeout(() => {
|
||||
fn();
|
||||
|
||||
@@ -10,6 +10,7 @@ const Role = requireStructure('Role');
|
||||
const Invite = requireStructure('Invite');
|
||||
const Webhook = requireStructure('Webhook');
|
||||
const UserProfile = requireStructure('UserProfile');
|
||||
const ClientOAuth2App = requireStructure('ClientOAuth2App');
|
||||
|
||||
class RESTMethods {
|
||||
constructor(restManager) {
|
||||
@@ -762,6 +763,14 @@ class RESTMethods {
|
||||
.then(resolve, reject);
|
||||
});
|
||||
}
|
||||
|
||||
getMyApp() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.rest.makeRequest('get', Constants.Endpoints.myApp, true)
|
||||
.then(app => resolve(new ClientOAuth2App(this.rest.client, app)))
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RESTMethods;
|
||||
|
||||
@@ -11,6 +11,7 @@ module.exports = {
|
||||
fetchRecommendedShards: require('./util/FetchRecommendedShards'),
|
||||
|
||||
Channel: require('./structures/Channel'),
|
||||
ClientOAuth2App: require('./structures/ClientOAuth2App'),
|
||||
ClientUser: require('./structures/ClientUser'),
|
||||
DMChannel: require('./structures/DMChannel'),
|
||||
Emoji: require('./structures/Emoji'),
|
||||
@@ -25,6 +26,7 @@ module.exports = {
|
||||
MessageAttachment: require('./structures/MessageAttachment'),
|
||||
MessageCollector: require('./structures/MessageCollector'),
|
||||
MessageEmbed: require('./structures/MessageEmbed'),
|
||||
OAuth2App: require('./structures/OAuth2App'),
|
||||
PartialGuild: require('./structures/PartialGuild'),
|
||||
PartialGuildChannel: require('./structures/PartialGuildChannel'),
|
||||
PermissionOverwrites: require('./structures/PermissionOverwrites'),
|
||||
|
||||
25
src/structures/ClientOAuth2App.js
Normal file
25
src/structures/ClientOAuth2App.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const User = require('./User');
|
||||
const OAuth2App = require('./OAuth2App');
|
||||
|
||||
/**
|
||||
* Represents the client's OAuth2 Application
|
||||
*/
|
||||
class ClientOAuth2App extends OAuth2App {
|
||||
setup(data) {
|
||||
super.setup(data);
|
||||
|
||||
/**
|
||||
* The app's flags
|
||||
* @type {int}
|
||||
*/
|
||||
this.flags = data.flags;
|
||||
|
||||
/**
|
||||
* The app's owner
|
||||
* @type {User}
|
||||
*/
|
||||
this.owner = new User(this.client, data.owner);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClientOAuth2App;
|
||||
81
src/structures/OAuth2App.js
Normal file
81
src/structures/OAuth2App.js
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Represents a OAuth2 Application
|
||||
*/
|
||||
class OAuth2App {
|
||||
constructor(client, data) {
|
||||
/**
|
||||
* The client that instantiated the role
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = client;
|
||||
Object.defineProperty(this, 'client', { enumerable: false, configurable: false });
|
||||
|
||||
this.setup(data);
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
/**
|
||||
* The ID of the app
|
||||
* @type {string}
|
||||
*/
|
||||
this.id = data.id;
|
||||
|
||||
/**
|
||||
* The name of the app
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = data.name;
|
||||
|
||||
/**
|
||||
* The app's description
|
||||
* @type {string}
|
||||
*/
|
||||
this.description = data.description;
|
||||
|
||||
/**
|
||||
* The app's icon hash
|
||||
* @type {string}
|
||||
*/
|
||||
this.icon = data.icon;
|
||||
|
||||
/**
|
||||
* The app's icon URL
|
||||
* @type {string}
|
||||
*/
|
||||
this.iconURL = `https://cdn.discordapp.com/app-icons/${this.id}/${this.icon}.jpg`;
|
||||
|
||||
/**
|
||||
* The app's RPC origins
|
||||
* @type {Array<String>}
|
||||
*/
|
||||
this.rpcOrigins = data.rpc_origins;
|
||||
}
|
||||
|
||||
/**
|
||||
* The timestamp the app was created at
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get createdTimestamp() {
|
||||
return (this.id / 4194304) + 1420070400000;
|
||||
}
|
||||
|
||||
/**
|
||||
* The time the app was created
|
||||
* @type {Date}
|
||||
* @readonly
|
||||
*/
|
||||
get createdAt() {
|
||||
return new Date(this.createdTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* When concatenated with a string, this automatically concatenates the app name rather than the app object.
|
||||
* @returns {string}
|
||||
*/
|
||||
toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OAuth2App;
|
||||
@@ -128,6 +128,10 @@ const Endpoints = exports.Endpoints = {
|
||||
|
||||
// webhooks
|
||||
webhook: (webhookID, token) => `${API}/webhooks/${webhookID}${token ? `/${token}` : ''}`,
|
||||
|
||||
// oauth
|
||||
myApp: `${API}/oauth2/applications/@me`,
|
||||
getApp: (id) => `${API}/oauth2/authorize?client_id=${id}`,
|
||||
};
|
||||
|
||||
exports.Status = {
|
||||
|
||||
Reference in New Issue
Block a user