-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
del.ts
262 lines (240 loc) · 5.41 KB
/
del.ts
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import type { APIChannel, APIRole } from "discord-api-types/v10";
import { request } from "undici";
import type { HttpMethod } from "undici/types/dispatcher";
import { version } from "./package.json";
/**
* The client for interacting with DEL's API
* @param {string} token - Your DEL API token
* @param {string} id - Your Discord Application's ID
*/
export class Del {
public static baseUrl = "https://api.discordextremelist.xyz/v2";
constructor();
constructor(public token?: string, public id?: string) {}
private async _request(method: HttpMethod, route: string, body?: object) {
let headers: {
"User-Agent": string;
"Content-Type"?: string;
Authorization?: string;
} = {
"User-Agent": `DEL.js/${version}`,
};
if (body) {
if (!this.token) throw new Error("Del not constructed with a token");
headers["Content-Type"] = "application/json";
headers["Authorization"] = this.token;
}
const response = await request(Del.baseUrl + route, {
method,
body,
headers,
});
return response.body.json();
}
/**
* Get Website Statistics
*/
async getWebsiteStats(): Promise<WebsiteStatistics> {
return this._request("GET", "/stats");
}
/**
* Get Website Health
*/
async getWebsiteHealth(): Promise<WebsiteHealth> {
return this._request("GET", "/health");
}
/**
* Get Bot Information
* @param {string} id - The bot's ID
*/
async getBotInfo(id: string): Promise<BotInformation> {
return this._request("GET", `/bot/${id}`);
}
/**
* Update your bot's stats on DEL
* @param {number} guildCount - The amount of guilds your bot is in
* @param {number} shardCount - The amount of shards your bot is using
*/
async postStats(
guildCount: number,
shardCount?: number
): Promise<BotStatistics> {
if (!this.id) throw new Error("Del not constructed with an id");
const body = shardCount
? { guildCount, shardCount }
: { guildCount, shardCount: 0 };
return this._request("POST", `/bot/${this.id}/stats`, body);
}
/**
* Get Server Information
* @param {string} id - The server's ID
*/
async getServerInfo(id: string): Promise<ServerInformation> {
return this._request("GET", `/server/${id}`);
}
/**
* Get Template Information
* @param {string} id - The template's ID
*/
async getTemplateInfo(id: string): Promise<TemplateInformation> {
return this._request("GET", `/template/${id}`);
}
/**
* Get User Information
* @param {string} id - The user's ID
*/
async getUserInfo(id: string): Promise<UserInformation> {
return this._request("GET", `/user/${id}`);
}
}
export interface BaseResponse {
error: boolean;
status: number;
}
export interface WebsiteStatistics extends BaseResponse {
servers: {
total: number;
};
bots: {
total: number;
approved: number;
premium: number;
};
users: {
total: number;
premium: number;
staff: {
total: number;
mods: number;
assistants: number;
admins: number;
};
};
templates: number;
}
export interface WebsiteHealth extends BaseResponse {
redis_ok: boolean;
mongo_ok: boolean;
}
export interface BotInformation extends BaseResponse {
bot: {
id: string;
name: string;
prefix: string;
tags: string[];
vanityUrl: string;
serverCount: number;
shardCount: number;
shortDesc: string;
longDesc: string;
editors: string[];
owner: {
id: string;
};
avatar: {
hash: string;
url: string;
};
links: {
invite: string;
support: string;
website: string;
donation: string;
repo: string;
};
status: {
approved: boolean;
siteBot: boolean;
archived: boolean;
};
};
}
export interface BotStatistics extends BaseResponse {
guildCount: number;
shardCount?: number;
}
export interface ServerInformation extends BaseResponse {
server: {
id: string;
name: string;
shortDesc: string;
longDesc: string;
tags: string[];
owner: {
id: string;
};
icon: {
hash: string;
url: string;
};
links: {
website: string;
donation: string;
};
};
}
export interface TemplateInformation extends BaseResponse {
template: {
id: string;
name: string;
region: string;
locale: string;
afkTimeout: number;
verificationLevel: number;
defaultMessageNotifications: number;
explicitContent: number;
roles: APIRole[];
channels: APIChannel[];
usageCount: number;
shortDesc: string;
longDesc: string;
tags: string[];
fromGuild: string;
owner: {
id: string;
};
icon: {
hash: string;
url: string;
};
links: {
template: string;
};
};
}
export interface UserInformation extends BaseResponse {
user: {
id: string;
name: string;
discrim: string;
fullUsername: string;
avatar: {
hash: string;
url: string;
};
profile: {
bio: string;
links: {
website: string;
github: string;
gitlab: string;
twitter: string;
instagram: string;
snapchat: string;
};
};
game: {
snakes: {
maxScore: number;
};
};
rank: {
admin: boolean;
mod: boolean;
assistant: boolean;
tester: boolean;
translator: boolean;
covid: boolean;
};
};
}