@discordanalytics/core 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 +136 -0
- package/dist/types.d.ts +56 -0
- package/package.json +5 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { GuildsStatsData, InteractionData, LocaleData, TrackGuildType } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* DiscordAnalytics Base Class
|
|
4
|
+
* @class AnalyticsBase
|
|
5
|
+
* @description Base class for DiscordAnalytics
|
|
6
|
+
* @param {string} api_key The API key for DiscordAnalytics
|
|
7
|
+
* @param {boolean} debug Optional flag to enable debug mode /!\ MUST BE USED ONLY FOR DEBUGGING PURPOSES
|
|
8
|
+
* @returns {AnalyticsBase} An instance of the AnalyticsBase class
|
|
9
|
+
* @example
|
|
10
|
+
* const analytics = new AnalyticsBase('YOUR_API_KEY');
|
|
11
|
+
* analytics.sendStats('YOUR_CLIENT_ID', 0, 0);
|
|
12
|
+
*/
|
|
13
|
+
export declare class AnalyticsBase {
|
|
14
|
+
private readonly _api_key;
|
|
15
|
+
private readonly _headers;
|
|
16
|
+
private readonly debug_mode;
|
|
17
|
+
stats_data: {
|
|
18
|
+
date: string;
|
|
19
|
+
guilds: number;
|
|
20
|
+
users: number;
|
|
21
|
+
interactions: InteractionData[];
|
|
22
|
+
locales: LocaleData[];
|
|
23
|
+
guildsLocales: LocaleData[];
|
|
24
|
+
guildMembers: {
|
|
25
|
+
little: number;
|
|
26
|
+
medium: number;
|
|
27
|
+
big: number;
|
|
28
|
+
huge: number;
|
|
29
|
+
};
|
|
30
|
+
guildsStats: GuildsStatsData[];
|
|
31
|
+
addedGuilds: number;
|
|
32
|
+
removedGuilds: number;
|
|
33
|
+
users_type: {
|
|
34
|
+
admin: number;
|
|
35
|
+
moderator: number;
|
|
36
|
+
new_member: number;
|
|
37
|
+
other: number;
|
|
38
|
+
private_message: number;
|
|
39
|
+
};
|
|
40
|
+
custom_events: Record<string, number>;
|
|
41
|
+
user_install_count: number;
|
|
42
|
+
};
|
|
43
|
+
client_id: string;
|
|
44
|
+
constructor(api_key: string, debug?: boolean);
|
|
45
|
+
debug(...args: any[]): void;
|
|
46
|
+
error(content: any, exit?: boolean): void;
|
|
47
|
+
/**
|
|
48
|
+
* Custom events
|
|
49
|
+
* /!\ Advanced users only
|
|
50
|
+
* /!\ You need to initialize the class first
|
|
51
|
+
* @param event_key The event key to track
|
|
52
|
+
* @returns {CustomEvent} The CustomEvent instance
|
|
53
|
+
* @example
|
|
54
|
+
* const event = analytics.events('my_custom_event');
|
|
55
|
+
* event.increment(1);
|
|
56
|
+
* event.decrement(1);
|
|
57
|
+
* event.set(10);
|
|
58
|
+
*/
|
|
59
|
+
events(event_key: string): CustomEvent;
|
|
60
|
+
updateOrInsert<T>(array: T[], match: (item: T) => boolean, update: (item: T) => void, insert: () => T): void;
|
|
61
|
+
calculateGuildMembers(guildMembers: number[]): {
|
|
62
|
+
little: number;
|
|
63
|
+
medium: number;
|
|
64
|
+
big: number;
|
|
65
|
+
huge: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Track guilds
|
|
69
|
+
* /!\ Advanced users only
|
|
70
|
+
* /!\ You need to initialize the class first
|
|
71
|
+
* @param {TrackGuildType} type 'create' if the event is guildCreate and 'delete' if is guildDelete
|
|
72
|
+
*/
|
|
73
|
+
trackGuilds(type: TrackGuildType): void;
|
|
74
|
+
/**
|
|
75
|
+
* API call with retries
|
|
76
|
+
* @param method The HTTP method to use (GET, POST, PUT, DELETE)
|
|
77
|
+
* @param url The URL to call
|
|
78
|
+
* @param body The body to send (optional)
|
|
79
|
+
* @param max_retries The maximum number of retries (default: 5)
|
|
80
|
+
* @param backoff_factor The backoff factor to use (default: 0.5)
|
|
81
|
+
* @returns {Promise<void | Response>} The response from the API
|
|
82
|
+
*/
|
|
83
|
+
api_call_with_retries(method: string, url: string, body?: string, max_retries?: number, backoff_factor?: number): Promise<void | Response>;
|
|
84
|
+
/**
|
|
85
|
+
* Send stats to the API
|
|
86
|
+
* @param client_id The client ID of the bot
|
|
87
|
+
* @param guild_count The number of guilds the bot is in (default: 0)
|
|
88
|
+
* @param user_count The number of users the bot is in (default: 0)
|
|
89
|
+
* @param user_install_count The number of user installs (default: 0)
|
|
90
|
+
* @param guild_members The number of members in each guild (optional)
|
|
91
|
+
* @returns {Promise<void>} A promise that resolves when the stats are sent
|
|
92
|
+
*/
|
|
93
|
+
sendStats(client_id: string, guild_count?: number, user_count?: number, user_install_count?: number, guild_members?: number[]): Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* CustomEvent class
|
|
97
|
+
* @class CustomEvent
|
|
98
|
+
* @description Class for custom events
|
|
99
|
+
* @param {AnalyticsBase} analytics The AnalyticsBase instance
|
|
100
|
+
* @param {string} event_key The event key to track
|
|
101
|
+
* @returns {CustomEvent} An instance of the CustomEvent class
|
|
102
|
+
* @example
|
|
103
|
+
* const event = analytics.events('my_custom_event');
|
|
104
|
+
* event.increment(1);
|
|
105
|
+
* event.decrement(1);
|
|
106
|
+
* event.set(10);
|
|
107
|
+
* event.get();
|
|
108
|
+
*/
|
|
109
|
+
export declare class CustomEvent {
|
|
110
|
+
private readonly _analytics;
|
|
111
|
+
private readonly _event_key;
|
|
112
|
+
private _last_action;
|
|
113
|
+
constructor(analytics: AnalyticsBase, event_key: string);
|
|
114
|
+
private ensure;
|
|
115
|
+
/**
|
|
116
|
+
* Increment the event by a value
|
|
117
|
+
* @param value The value to increment the event by (default: 1)
|
|
118
|
+
*/
|
|
119
|
+
increment(value?: number): void;
|
|
120
|
+
/**
|
|
121
|
+
* Decrement the event by a value
|
|
122
|
+
* @param value The value to decrement the event by (default: 1)
|
|
123
|
+
*/
|
|
124
|
+
decrement(value?: number): void;
|
|
125
|
+
/**
|
|
126
|
+
* Set the event to a value
|
|
127
|
+
* @param value The value to set the event to
|
|
128
|
+
*/
|
|
129
|
+
set(value: number): void;
|
|
130
|
+
/**
|
|
131
|
+
* Get the event value
|
|
132
|
+
* @returns {number} The event value
|
|
133
|
+
*/
|
|
134
|
+
get(): number;
|
|
135
|
+
}
|
|
136
|
+
export * from './types';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export declare const api_url = "https://discordanalytics.xyz/api";
|
|
2
|
+
export declare const ApiEndpoints: {
|
|
3
|
+
EDIT_SETTINGS_URL: string;
|
|
4
|
+
EDIT_STATS_URL: string;
|
|
5
|
+
EVENT_URL: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const ErrorCodes: {
|
|
8
|
+
INVALID_CLIENT_TYPE: string;
|
|
9
|
+
CLIENT_NOT_READY: string;
|
|
10
|
+
INVALID_RESPONSE: string;
|
|
11
|
+
INVALID_API_TOKEN: string;
|
|
12
|
+
DATA_NOT_SENT: string;
|
|
13
|
+
SUSPENDED_BOT: string;
|
|
14
|
+
INSTANCE_NOT_INITIALIZED: string;
|
|
15
|
+
INVALID_EVENTS_COUNT: string;
|
|
16
|
+
INVALID_VALUE_TYPE: string;
|
|
17
|
+
INVALID_EVENT_KEY: string;
|
|
18
|
+
MAX_RETRIES_EXCEEDED: string;
|
|
19
|
+
};
|
|
20
|
+
export type Locale = 'id' | 'en-US' | 'en-GB' | 'bg' | 'zh-CN' | 'zh-TW' | 'hr' | 'cs' | 'da' | 'nl' | 'fi' | 'fr' | 'de' | 'el' | 'hi' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'no' | 'pl' | 'pt-BR' | 'ro' | 'ru' | 'es-ES' | 'sv-SE' | 'th' | 'tr' | 'uk' | 'vi';
|
|
21
|
+
export declare enum InteractionType {
|
|
22
|
+
Ping = 1,
|
|
23
|
+
ApplicationCommand = 2,
|
|
24
|
+
MessageComponent = 3,
|
|
25
|
+
ApplicationCommandAutocomplete = 4,
|
|
26
|
+
ModalSubmit = 5
|
|
27
|
+
}
|
|
28
|
+
export declare enum ApplicationCommandType {
|
|
29
|
+
ChatInputCommand = 1,
|
|
30
|
+
UserCommand = 2,
|
|
31
|
+
MessageCommand = 3
|
|
32
|
+
}
|
|
33
|
+
export interface InteractionData {
|
|
34
|
+
name: string;
|
|
35
|
+
number: number;
|
|
36
|
+
type: InteractionType;
|
|
37
|
+
command_type?: ApplicationCommandType;
|
|
38
|
+
}
|
|
39
|
+
export interface LocaleData {
|
|
40
|
+
locale: Locale;
|
|
41
|
+
number: number;
|
|
42
|
+
}
|
|
43
|
+
export interface GuildsStatsData {
|
|
44
|
+
guildId: string;
|
|
45
|
+
name: string;
|
|
46
|
+
icon: string | null;
|
|
47
|
+
members: number;
|
|
48
|
+
interactions: number;
|
|
49
|
+
}
|
|
50
|
+
export interface AnalyticsOptions {
|
|
51
|
+
client: any;
|
|
52
|
+
api_key: string;
|
|
53
|
+
sharded?: boolean;
|
|
54
|
+
debug?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export type TrackGuildType = 'create' | 'delete';
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discordanalytics/core",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.2",
|
|
4
4
|
"description": "Core package to work 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",
|