@discordanalytics/core 2.7.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +29 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -55,6 +55,7 @@ class AnalyticsBase {
55
55
  private_message: 0,
56
56
  },
57
57
  custom_events: {},
58
+ user_install_count: 0,
58
59
  };
59
60
  client_id = '';
60
61
  constructor(api_key, debug = false) {
@@ -138,21 +139,31 @@ class AnalyticsBase {
138
139
  let retries = 0;
139
140
  let response;
140
141
  while (retries < max_retries) {
141
- response = await fetch(url, {
142
- method,
143
- headers: this._headers,
144
- body,
145
- });
146
- if (response.ok)
147
- return response;
148
- else if (response.status === 401)
149
- return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_API_TOKEN}`);
150
- else if (response.status === 423)
151
- return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.SUSPENDED_BOT}`);
152
- else if (response.status === 404 && url.includes('events'))
153
- return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_EVENT_KEY}`, true);
154
- else if (response.status !== 200)
155
- return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_RESPONSE}`);
142
+ try {
143
+ response = await fetch(url, {
144
+ method,
145
+ headers: this._headers,
146
+ body,
147
+ });
148
+ if (response.ok)
149
+ return response;
150
+ else if (response.status === 401)
151
+ return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_API_TOKEN}`);
152
+ else if (response.status === 423)
153
+ return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.SUSPENDED_BOT}`);
154
+ else if (response.status === 404 && url.includes('events'))
155
+ return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_EVENT_KEY}`, true);
156
+ else if (response.status !== 200)
157
+ return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.INVALID_RESPONSE}`);
158
+ }
159
+ catch (error) {
160
+ retries++;
161
+ const retry_after = Math.pow(2, retries) * backoff_factor;
162
+ this.error(`[DISCORDANALYTICS] Error: ${error}. Retrying in ${retry_after} seconds...`);
163
+ if (retries >= max_retries)
164
+ return this.error(`[DISCORDANALYTICS] ${types_1.ErrorCodes.MAX_RETRIES_EXCEEDED}`);
165
+ await new Promise((resolve) => setTimeout(resolve, retry_after * 1000));
166
+ }
156
167
  }
157
168
  }
158
169
  /**
@@ -160,10 +171,11 @@ class AnalyticsBase {
160
171
  * @param client_id The client ID of the bot
161
172
  * @param guild_count The number of guilds the bot is in (default: 0)
162
173
  * @param user_count The number of users the bot is in (default: 0)
174
+ * @param user_install_count The number of user installs (default: 0)
163
175
  * @param guild_members The number of members in each guild (optional)
164
176
  * @returns {Promise<void>} A promise that resolves when the stats are sent
165
177
  */
166
- async sendStats(client_id, guild_count = 0, user_count = 0, guild_members = []) {
178
+ async sendStats(client_id, guild_count = 0, user_count = 0, user_install_count = 0, guild_members = []) {
167
179
  this.debug('[DISCORDANALYTICS] Sending stats...');
168
180
  const url = types_1.ApiEndpoints.EDIT_STATS_URL.replace(':id', client_id);
169
181
  const body = JSON.stringify(this.stats_data);
@@ -188,6 +200,7 @@ class AnalyticsBase {
188
200
  private_message: 0,
189
201
  },
190
202
  custom_events: this.stats_data.custom_events,
203
+ user_install_count,
191
204
  };
192
205
  }
193
206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discordanalytics/core",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "description": "Core package to work with Discord Analytics",
5
5
  "main": "dist/index.js",
6
6
  "author": "Discord Analytics",