Dernière activité 1692435909

I mean title is kinda self explanatory

TheRealToxicDev's Avatar TheRealToxicDev a révisé ce gist 1692435909. Aller à la révision

1 file changed, 77 insertions

post.js(fichier créé)

@@ -0,0 +1,77 @@
1 + /**
2 + * POST YOUR BOTS STATS
3 + * @param apiKey Your bots infinity api token found in your bot settings
4 + * @param botID Your bots discord id. Can be found on the discord dev portal
5 + * @requires servers The user count of your bot/client.
6 + * @requires shards
7 + * @requires users
8 + */
9 + public async postBotStats(servers?: Bot, shards?: Bot, users?: Bot) {
10 +
11 + if (!this.apiKey) return log('Please provide a valid bot api token', {
12 + header: '@INFINITYBOTS/NODE-SDK: REFERENCE_ERROR',
13 + type: 'error'
14 + });
15 +
16 + else if (!this.botID) return log('Please provide a valid bot id', {
17 + header: '@INFINITYBOTS/NODE-SDK: REFERENCE_ERROR',
18 + type: 'error'
19 + });
20 +
21 + else if (!servers) return log('Please provide a valid server count, should be a integer of 1 or greater!', {
22 + header: '@INFINITYBOTS/NODE-SDK: REFERENCE_ERROR',
23 + type: 'error'
24 + });
25 +
26 + else if (typeof servers !== 'number') return log('Please provide a valid server count, should be a integer of 1 or greater!', {
27 + header: '@INFINITYBOTS/NODE-SDK: REFERENCE_ERROR',
28 + type: 'error'
29 + });
30 +
31 + else if (!shards) return log('Please provide a valid shard count, should be a integer of 1 or greater!', {
32 + header: '@INFINITYBOTS/NODE-SDK: REFERENCE_ERROR',
33 + type: 'error'
34 + });
35 +
36 + else if (typeof shards !== 'number') return log('Please provide a valid shard count, should be a integer of 1 or greater!', {
37 + header: '@INFINITYBOTS/NODE-SDK: REFERENCE_ERROR',
38 + type: 'error'
39 + });
40 +
41 + else if (!users) return log('Please provide a valid user count, should be a integer of 1 or greater!', {
42 + header: '@INFINITYBOTS/NODE-SDK: REFERENCE_ERROR',
43 + type: 'error'
44 + });
45 +
46 + else if (typeof users !== 'number') return log('Please provide a valid user count, should be a integer of 1 or greater!', {
47 + header: '@INFINITYBOTS/NODE-SDK: REFERENCE_ERROR',
48 + type: 'error'
49 + });
50 +
51 + else {
52 +
53 + await fetch(`${this.url}/bots/stats`, {
54 + method: 'POST',
55 + headers: {
56 + 'Authorization': `${this.apiKey}`,
57 + 'Content-Type': 'application/json'
58 + },
59 + body: JSON.stringify({
60 + servers: servers,
61 + shards: shards,
62 + users: users
63 + })
64 + })
65 + .then(() => log('Hooray, your bot stats were successfully posted.', {
66 + header: '@INFINITYBOTS/NODE-SDK: STATS_POST_SUCCESS',
67 + type: 'success'
68 + }))
69 + .catch((e) => {
70 +
71 + return log(`Whoops, your bot stats post failed: ${e.stack}`, {
72 + header: '@INFINITYBOTS/NODE-SDK: STATS_POST_FAILURE',
73 + type: 'error'
74 + })
75 + })
76 + }
77 + }
Plus récent Plus ancien