forked from discordjs/discord.js
/
OAuth2Application.js
157 lines (134 loc) · 3.21 KB
/
OAuth2Application.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const Snowflake = require('../util/Snowflake');
const Team = require('./Team');
const util = require('util');
/**
* Represents an OAuth2 Application.
*/
class OAuth2Application {
constructor(client, data) {
/**
* The client that instantiated the application
* @name OAuth2Application#client
* @type {Client}
* @readonly
*/
Object.defineProperty(this, 'client', { value: client });
this.setup(data);
}
setup(data) {
/**
* The ID of the app
* @type {Snowflake}
*/
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 {?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;
/**
* The flags for the app
* @type {number}
*/
this.flags = data.flags;
/**
* OAuth2 secret for the application
* @type {boolean}
*/
this.secret = data.secret;
if (data.owner) {
/**
* The owner of this OAuth application
* @type {?User}
*/
this.owner = this.client.dataManager.newUser(data.owner);
}
if (data.team) {
/**
* The owning team of this OAuth application
* @type {?Team}
*/
this.team = new Team(this.client, data.team);
}
}
/**
* The timestamp the app was created at
* @type {number}
* @readonly
*/
get createdTimestamp() {
return Snowflake.deconstruct(this.id).timestamp;
}
/**
* The time the app was created
* @type {Date}
* @readonly
*/
get createdAt() {
return new Date(this.createdTimestamp);
}
/**
* Reset the app's secret and bot token.
* <warn>This is only available when using a user account.</warn>
* @returns {OAuth2Application}
* @deprecated
*/
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}
*/
toString() {
return this.name;
}
}
OAuth2Application.prototype.reset =
util.deprecate(OAuth2Application.prototype.reset, 'OAuth2Application#reset: userbot methods will be removed');
module.exports = OAuth2Application;