@discordanalytics/oceanic 2.8.0 → 2.8.2
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.
- package/dist/index.d.ts +56 -0
- package/dist/index.js +19 -16
- package/package.json +8 -6
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AnalyticsBase, AnalyticsOptions } from '@discordanalytics/core';
|
|
2
|
+
/**
|
|
3
|
+
* @class DiscordAnalytics
|
|
4
|
+
* @description The Oceanic.js class for the DiscordAnalytics library.
|
|
5
|
+
* @param {AnalyticsOptions} options - Configuration options.
|
|
6
|
+
* @property {any} options.client The Oceanic.js client to track events for.
|
|
7
|
+
* @property {string} options.api_key The API token for DiscordAnalytics.
|
|
8
|
+
* @property {boolean} options.debug Enable or not the debug mode /!\ MUST BE USED ONLY FOR DEVELOPMENT PURPOSES /!\
|
|
9
|
+
* @example
|
|
10
|
+
* const { default: DiscordAnalytics } = require('discord-analytics/oceanic');
|
|
11
|
+
* const { Client } = require('oceanic.js');
|
|
12
|
+
* const client = new Client({
|
|
13
|
+
* auth: 'Bot <YOUR_BOT_TOKEN>',
|
|
14
|
+
* gateway: {
|
|
15
|
+
* intents: ['GUILDS']
|
|
16
|
+
* }
|
|
17
|
+
* })
|
|
18
|
+
* client.on('ready', () => {
|
|
19
|
+
* const analytics = new DiscordAnalytics({
|
|
20
|
+
* client: client,
|
|
21
|
+
* api_key: 'YOUR_API_TOKEN'
|
|
22
|
+
* });
|
|
23
|
+
* analytics.init();
|
|
24
|
+
* analytics.trackEvents();
|
|
25
|
+
* });
|
|
26
|
+
* client.connect();
|
|
27
|
+
* @link https://discordanalytics.xyz/docs/main/get-started/installation/oceanic.js Check docs for more informations about advanced usages
|
|
28
|
+
*/
|
|
29
|
+
export default class DiscordAnalytics extends AnalyticsBase {
|
|
30
|
+
private readonly _client;
|
|
31
|
+
private _isReady;
|
|
32
|
+
constructor(options: Omit<AnalyticsOptions, 'sharded'>);
|
|
33
|
+
/**
|
|
34
|
+
* Initialize DiscordAnalytics on your bot
|
|
35
|
+
* /!\ Advanced users only
|
|
36
|
+
* /!\ Required to use DiscordAnalytics
|
|
37
|
+
* /!\ Must be used when the client is ready (recommended to use in ready event to prevent problems)
|
|
38
|
+
*/
|
|
39
|
+
init(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Track interactions
|
|
42
|
+
* /!\ Advanced users only
|
|
43
|
+
* /!\ You need to initialize the class first
|
|
44
|
+
* @param interaction BaseInteraction class and its extensions only
|
|
45
|
+
* @param interactionNameResolver A function that will resolve the name of the interaction
|
|
46
|
+
*/
|
|
47
|
+
trackInteractions(interaction: any, interactionNameResolver?: (interaction: any) => string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Let DiscordAnalytics declare the events necessary for its operation.
|
|
50
|
+
* /!\ Not recommended for big bots
|
|
51
|
+
* /!\ Not compatible with other functions
|
|
52
|
+
* @param interactionNameResolver A function that will resolve the name of the interaction
|
|
53
|
+
*/
|
|
54
|
+
trackEvents(interactionNameResolver?: (interaction: any) => string): void;
|
|
55
|
+
private is_guild_install;
|
|
56
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -92,7 +92,7 @@ class DiscordAnalytics extends core_1.AnalyticsBase {
|
|
|
92
92
|
this.debug('[DISCORDANALYTICS] trackInteractions() triggered');
|
|
93
93
|
if (!this._isReady)
|
|
94
94
|
return this.error(core_1.ErrorCodes.INSTANCE_NOT_INITIALIZED);
|
|
95
|
-
this.updateOrInsert(this.stats_data.guildsLocales, (x) => x.locale === interaction.
|
|
95
|
+
this.updateOrInsert(this.stats_data.guildsLocales, (x) => x.locale === interaction.guildLocale, (x) => x.number++, () => ({ locale: interaction.guildLocale, number: 1 }));
|
|
96
96
|
this.updateOrInsert(this.stats_data.locales, (x) => x.locale === interaction.locale, (x) => x.number++, () => ({ locale: interaction.locale, number: 1 }));
|
|
97
97
|
if (interaction.type === core_1.InteractionType.ApplicationCommand) {
|
|
98
98
|
const commandType = interaction.data.type;
|
|
@@ -119,29 +119,29 @@ class DiscordAnalytics extends core_1.AnalyticsBase {
|
|
|
119
119
|
}));
|
|
120
120
|
}
|
|
121
121
|
this.updateOrInsert(this.stats_data.guildsStats, (x) => x.guildId === (interaction.guild ? interaction.guildID : 'dm'), (x) => x.interactions++, () => ({
|
|
122
|
-
guildId: interaction.
|
|
123
|
-
name: interaction
|
|
124
|
-
icon: interaction
|
|
122
|
+
guildId: interaction.guildID ? interaction.guildID : 'dm',
|
|
123
|
+
name: this.is_guild_install(interaction) ? interaction.guild.name : 'DM',
|
|
124
|
+
icon: this.is_guild_install(interaction) && interaction.guild.icon ? interaction.guild.icon : undefined,
|
|
125
125
|
interactions: 1,
|
|
126
|
-
members: interaction
|
|
126
|
+
members: this.is_guild_install(interaction) ? interaction.guild.memberCount : 0,
|
|
127
127
|
}));
|
|
128
128
|
const oneWeekAgo = new Date();
|
|
129
129
|
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
|
|
130
|
-
if (!interaction.
|
|
130
|
+
if (!interaction.guildID)
|
|
131
131
|
++this.stats_data.users_type.private_message;
|
|
132
132
|
else if (interaction.member
|
|
133
|
-
&& interaction.
|
|
134
|
-
&& interaction.
|
|
135
|
-
|| interaction.
|
|
133
|
+
&& interaction.memberPermissions
|
|
134
|
+
&& interaction.memberPermissions.has(8n)
|
|
135
|
+
|| interaction.memberPermissions.has(32n))
|
|
136
136
|
++this.stats_data.users_type.admin;
|
|
137
137
|
else if (interaction.member
|
|
138
|
-
&& interaction.
|
|
139
|
-
&& interaction.
|
|
140
|
-
|| interaction.
|
|
141
|
-
|| interaction.
|
|
142
|
-
|| interaction.
|
|
143
|
-
|| interaction.
|
|
144
|
-
|| interaction.
|
|
138
|
+
&& interaction.memberPermissions
|
|
139
|
+
&& interaction.memberPermissions.has(8192n)
|
|
140
|
+
|| interaction.memberPermissions.has(2n)
|
|
141
|
+
|| interaction.memberPermissions.has(4194304n)
|
|
142
|
+
|| interaction.memberPermissions.has(8388608n)
|
|
143
|
+
|| interaction.memberPermissions.has(16777216n)
|
|
144
|
+
|| interaction.memberPermissions.has(1099511627776n))
|
|
145
145
|
++this.stats_data.users_type.moderator;
|
|
146
146
|
else if (interaction.member
|
|
147
147
|
&& interaction.member.joinedAt
|
|
@@ -162,5 +162,8 @@ class DiscordAnalytics extends core_1.AnalyticsBase {
|
|
|
162
162
|
this._client.on('guildCreate', async (guild) => this.trackGuilds('create'));
|
|
163
163
|
this._client.on('guildDelete', async (guild) => this.trackGuilds('delete'));
|
|
164
164
|
}
|
|
165
|
+
is_guild_install(interaction) {
|
|
166
|
+
return interaction.authorizingIntegrationOwners["0"] === interaction.guildID;
|
|
167
|
+
}
|
|
165
168
|
}
|
|
166
169
|
exports.default = DiscordAnalytics;
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discordanalytics/oceanic",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.2",
|
|
4
4
|
"description": "Oceanic package for working with Discord Analytics",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
5
8
|
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
6
10
|
"author": "Discord Analytics",
|
|
7
11
|
"homepage": "https://discordanalytics.xyz",
|
|
8
12
|
"readme": "README.md",
|
|
@@ -14,16 +18,14 @@
|
|
|
14
18
|
"url": "https://github.com/DiscordAnalytics/node-package/issues"
|
|
15
19
|
},
|
|
16
20
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"node-fetch": "^2.7.0",
|
|
19
|
-
"@discordanalytics/core": "2.8.0"
|
|
21
|
+
"@discordanalytics/core": "2.8.2"
|
|
20
22
|
},
|
|
21
23
|
"devDependencies": {
|
|
22
|
-
"oceanic.js": "^1.
|
|
24
|
+
"oceanic.js": "^1.13.0",
|
|
23
25
|
"typescript": "*"
|
|
24
26
|
},
|
|
25
27
|
"peerDependencies": {
|
|
26
|
-
"oceanic.js": ">=1.
|
|
28
|
+
"oceanic.js": ">=1.13.x"
|
|
27
29
|
},
|
|
28
30
|
"scripts": {
|
|
29
31
|
"prebuild": "pnpm --filter @discordanalytics/core build",
|