-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathupdate_topgg_stats.ts
56 lines (42 loc) · 1.07 KB
/
update_topgg_stats.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
import { Mongo } from '~/db/mod.ts';
if (import.meta.main) {
const APP_ID = Deno.env.get('APP_ID');
const MONGO_URI = Deno.env.get('MONGO_URI');
const TOPGG_TOKEN = Deno.env.get('TOPGG_TOKEN');
if (!APP_ID) {
throw new Error('APP_ID is not defined');
}
if (!MONGO_URI) {
throw new Error('MONGO_URI is not defined');
}
if (!TOPGG_TOKEN) {
throw new Error('TOPGG_TOKEN is not defined');
}
const db = new Mongo(MONGO_URI);
await db.connect();
const serverCount = await db.guilds().estimatedDocumentCount();
console.log(`APP ID: ${APP_ID}`);
console.log(`Server Count: ${serverCount}`);
const response = await fetch(
`https://top.gg/api/bots/${APP_ID}/stats`,
{
method: 'POST',
headers: {
'Authorization': TOPGG_TOKEN,
'Content-Type': 'application/json',
},
body: JSON.stringify({
server_count: serverCount,
}),
},
);
console.log(
response.status,
response.statusText,
await response.text(),
);
await db.close();
if (!response.ok) {
Deno.exit(1);
}
}