discord-voice-tracker 1.0.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.
- package/License +21 -0
- package/dist/core/VoiceManager.d.ts +98 -0
- package/dist/core/VoiceManager.d.ts.map +1 -0
- package/dist/core/VoiceManager.js +399 -0
- package/dist/core/VoiceManager.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/storage/JSONStorage.d.ts +30 -0
- package/dist/storage/JSONStorage.d.ts.map +1 -0
- package/dist/storage/JSONStorage.js +202 -0
- package/dist/storage/JSONStorage.js.map +1 -0
- package/dist/storage/MongoStorage.d.ts +27 -0
- package/dist/storage/MongoStorage.d.ts.map +1 -0
- package/dist/storage/MongoStorage.js +220 -0
- package/dist/storage/MongoStorage.js.map +1 -0
- package/dist/types/index.d.ts +266 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/Calculator.d.ts +31 -0
- package/dist/utils/Calculator.d.ts.map +1 -0
- package/dist/utils/Calculator.js +70 -0
- package/dist/utils/Calculator.js.map +1 -0
- package/dist/utils/Logger.d.ts +9 -0
- package/dist/utils/Logger.d.ts.map +1 -0
- package/dist/utils/Logger.js +25 -0
- package/dist/utils/Logger.js.map +1 -0
- package/dist/utils/Validator.d.ts +19 -0
- package/dist/utils/Validator.d.ts.map +1 -0
- package/dist/utils/Validator.js +63 -0
- package/dist/utils/Validator.js.map +1 -0
- package/package.json +76 -0
- package/readme.md +662 -0
package/License
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Async
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Client } from 'discord.js';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { VoiceManagerOptions, UserData, GuildConfig, LeaderboardEntry, UserUpdateOptions, LeaderboardOptions } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Main Voice Tracking Manager
|
|
6
|
+
*/
|
|
7
|
+
export declare class VoiceManager extends EventEmitter {
|
|
8
|
+
private client;
|
|
9
|
+
private storage;
|
|
10
|
+
private checkInterval;
|
|
11
|
+
private intervalId?;
|
|
12
|
+
private logger;
|
|
13
|
+
private calculator;
|
|
14
|
+
private activeSessions;
|
|
15
|
+
private defaultConfig;
|
|
16
|
+
constructor(client: Client, options: VoiceManagerOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Initialize the manager
|
|
19
|
+
*/
|
|
20
|
+
init(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Get default guild configuration
|
|
23
|
+
*/
|
|
24
|
+
private getDefaultConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Set up Discord event listeners
|
|
27
|
+
*/
|
|
28
|
+
private setupEventListeners;
|
|
29
|
+
/**
|
|
30
|
+
* Handle voice state updates
|
|
31
|
+
*/
|
|
32
|
+
private handleVoiceStateUpdate;
|
|
33
|
+
/**
|
|
34
|
+
* Start a voice session
|
|
35
|
+
*/
|
|
36
|
+
private startSession;
|
|
37
|
+
/**
|
|
38
|
+
* End a voice session
|
|
39
|
+
*/
|
|
40
|
+
private endSession;
|
|
41
|
+
/**
|
|
42
|
+
* Start tracking voice activity
|
|
43
|
+
*/
|
|
44
|
+
private startTracking;
|
|
45
|
+
/**
|
|
46
|
+
* Track voice activity for all guilds
|
|
47
|
+
*/
|
|
48
|
+
private trackVoiceActivity;
|
|
49
|
+
/**
|
|
50
|
+
* Process a single member's voice activity
|
|
51
|
+
*/
|
|
52
|
+
private processMember;
|
|
53
|
+
/**
|
|
54
|
+
* Check if member should be tracked
|
|
55
|
+
*/
|
|
56
|
+
private shouldTrackMember;
|
|
57
|
+
/**
|
|
58
|
+
* Check if channel should be tracked
|
|
59
|
+
*/
|
|
60
|
+
private shouldTrackChannel;
|
|
61
|
+
/**
|
|
62
|
+
* Get guild configuration
|
|
63
|
+
*/
|
|
64
|
+
getGuildConfig(guildId: string): Promise<GuildConfig>;
|
|
65
|
+
/**
|
|
66
|
+
* Save guild configuration
|
|
67
|
+
*/
|
|
68
|
+
saveGuildConfig(guildId: string, config: GuildConfig): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Create a new user
|
|
71
|
+
*/
|
|
72
|
+
private createUser;
|
|
73
|
+
/**
|
|
74
|
+
* Get user data
|
|
75
|
+
*/
|
|
76
|
+
getUser(guildId: string, userId: string): Promise<UserData | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Update user data
|
|
79
|
+
*/
|
|
80
|
+
updateUser(guildId: string, userId: string, options: UserUpdateOptions): Promise<UserData>;
|
|
81
|
+
/**
|
|
82
|
+
* Get leaderboard
|
|
83
|
+
*/
|
|
84
|
+
getLeaderboard(guildId: string, options?: LeaderboardOptions): Promise<LeaderboardEntry[]>;
|
|
85
|
+
/**
|
|
86
|
+
* Delete guild data
|
|
87
|
+
*/
|
|
88
|
+
deleteGuild(guildId: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Delete user data
|
|
91
|
+
*/
|
|
92
|
+
deleteUser(guildId: string, userId: string): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Destroy the manager
|
|
95
|
+
*/
|
|
96
|
+
destroy(): Promise<void>;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=VoiceManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VoiceManager.d.ts","sourceRoot":"","sources":["../../src/core/VoiceManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAA2B,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EACL,mBAAmB,EAEnB,QAAQ,EACR,WAAW,EAEX,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAIlB;;GAEG;AACH,qBAAa,YAAa,SAAQ,YAAY;IAC5C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,UAAU,CAAC,CAAiB;IACpC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAe;IACjC,OAAO,CAAC,cAAc,CAA2B;IACjD,OAAO,CAAC,aAAa,CAAuB;gBAEhC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB;IAYxD;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IA8B3B;;OAEG;IACH,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|
4
|
+
exports.VoiceManager = void 0;
|
|
5
|
+
const events_1 = require("events");
|
|
6
|
+
const Logger_1 = require("../utils/Logger");
|
|
7
|
+
const Calculator_1 = require("../utils/Calculator");
|
|
8
|
+
/**
|
|
9
|
+
* Main Voice Tracking Manager
|
|
10
|
+
*/
|
|
11
|
+
class VoiceManager extends events_1.EventEmitter {
|
|
12
|
+
client;
|
|
13
|
+
storage;
|
|
14
|
+
checkInterval;
|
|
15
|
+
intervalId;
|
|
16
|
+
logger;
|
|
17
|
+
calculator;
|
|
18
|
+
activeSessions;
|
|
19
|
+
defaultConfig;
|
|
20
|
+
constructor(client, options) {
|
|
21
|
+
super();
|
|
22
|
+
this.client = client;
|
|
23
|
+
this.storage = options.storage;
|
|
24
|
+
this.checkInterval = options.checkInterval || 5000;
|
|
25
|
+
this.logger = new Logger_1.Logger(options.debug || false);
|
|
26
|
+
this.calculator = new Calculator_1.XPCalculator();
|
|
27
|
+
this.activeSessions = new Map();
|
|
28
|
+
this.defaultConfig = options.defaultConfig || this.getDefaultConfig();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the manager
|
|
32
|
+
*/
|
|
33
|
+
async init() {
|
|
34
|
+
try {
|
|
35
|
+
this.logger.debug('Initializing VoiceManager...');
|
|
36
|
+
// Initialize storage
|
|
37
|
+
await this.storage.init();
|
|
38
|
+
this.logger.debug('Storage initialized');
|
|
39
|
+
// Wait for client to be ready
|
|
40
|
+
if (!this.client.isReady()) {
|
|
41
|
+
await new Promise((resolve) => {
|
|
42
|
+
this.client.once('ready', () => resolve());
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Set up event listeners
|
|
46
|
+
this.setupEventListeners();
|
|
47
|
+
// Start tracking interval
|
|
48
|
+
this.startTracking();
|
|
49
|
+
this.logger.debug('VoiceManager initialized successfully');
|
|
50
|
+
this.emit('debug', 'VoiceManager ready');
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
this.logger.error('Failed to initialize VoiceManager', error);
|
|
54
|
+
this.emit('error', error);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get default guild configuration
|
|
60
|
+
*/
|
|
61
|
+
getDefaultConfig() {
|
|
62
|
+
return {
|
|
63
|
+
guildId: '',
|
|
64
|
+
trackBots: false,
|
|
65
|
+
trackAllChannels: true,
|
|
66
|
+
channelIds: [],
|
|
67
|
+
trackMuted: true,
|
|
68
|
+
trackDeafened: true,
|
|
69
|
+
minUsersToTrack: 0,
|
|
70
|
+
maxUsersToTrack: 0,
|
|
71
|
+
exemptPermissions: [],
|
|
72
|
+
xpPerCheck: Math.floor(Math.random() * 10) + 1,
|
|
73
|
+
voiceTimePerCheck: 5000,
|
|
74
|
+
levelMultiplier: 0.1,
|
|
75
|
+
enableLeveling: true,
|
|
76
|
+
enableVoiceTime: true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set up Discord event listeners
|
|
81
|
+
*/
|
|
82
|
+
setupEventListeners() {
|
|
83
|
+
this.client.on('voiceStateUpdate', (oldState, newState) => {
|
|
84
|
+
this.handleVoiceStateUpdate(oldState, newState).catch((error) => {
|
|
85
|
+
this.logger.error('Error handling voice state update', error);
|
|
86
|
+
this.emit('error', error);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
this.logger.debug('Event listeners registered');
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Handle voice state updates
|
|
93
|
+
*/
|
|
94
|
+
async handleVoiceStateUpdate(oldState, newState) {
|
|
95
|
+
const member = newState.member;
|
|
96
|
+
if (!member)
|
|
97
|
+
return;
|
|
98
|
+
const guildId = newState.guild.id;
|
|
99
|
+
const userId = member.id;
|
|
100
|
+
// User joined a voice channel
|
|
101
|
+
if (!oldState.channel && newState.channel) {
|
|
102
|
+
await this.startSession(member, newState.channel.id);
|
|
103
|
+
}
|
|
104
|
+
// User left a voice channel
|
|
105
|
+
else if (oldState.channel && !newState.channel) {
|
|
106
|
+
await this.endSession(guildId, userId);
|
|
107
|
+
}
|
|
108
|
+
// User switched channels
|
|
109
|
+
else if (oldState.channel && newState.channel && oldState.channel.id !== newState.channel.id) {
|
|
110
|
+
await this.endSession(guildId, userId);
|
|
111
|
+
await this.startSession(member, newState.channel.id);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Start a voice session
|
|
116
|
+
*/
|
|
117
|
+
async startSession(member, channelId) {
|
|
118
|
+
const sessionKey = `${member.guild.id}-${member.id}`;
|
|
119
|
+
const session = {
|
|
120
|
+
sessionId: `${Date.now()}-${member.id}`,
|
|
121
|
+
userId: member.id,
|
|
122
|
+
guildId: member.guild.id,
|
|
123
|
+
channelId,
|
|
124
|
+
startTime: new Date(),
|
|
125
|
+
xpEarned: 0,
|
|
126
|
+
wasMuted: member.voice.mute || false,
|
|
127
|
+
wasDeafened: member.voice.deaf || false,
|
|
128
|
+
};
|
|
129
|
+
this.activeSessions.set(sessionKey, session);
|
|
130
|
+
this.emit('sessionStart', session);
|
|
131
|
+
this.logger.debug(`Session started: ${member.user.tag} in ${channelId}`);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* End a voice session
|
|
135
|
+
*/
|
|
136
|
+
async endSession(guildId, userId) {
|
|
137
|
+
const sessionKey = `${guildId}-${userId}`;
|
|
138
|
+
const session = this.activeSessions.get(sessionKey);
|
|
139
|
+
if (session) {
|
|
140
|
+
session.endTime = new Date();
|
|
141
|
+
session.duration = session.endTime.getTime() - session.startTime.getTime();
|
|
142
|
+
await this.storage.saveSession(session);
|
|
143
|
+
this.activeSessions.delete(sessionKey);
|
|
144
|
+
this.emit('sessionEnd', session);
|
|
145
|
+
this.logger.debug(`Session ended: ${userId}, duration: ${session.duration}ms`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Start tracking voice activity
|
|
150
|
+
*/
|
|
151
|
+
startTracking() {
|
|
152
|
+
this.intervalId = setInterval(() => {
|
|
153
|
+
this.trackVoiceActivity().catch((error) => {
|
|
154
|
+
this.logger.error('Error tracking voice activity', error);
|
|
155
|
+
this.emit('error', error);
|
|
156
|
+
});
|
|
157
|
+
}, this.checkInterval);
|
|
158
|
+
this.logger.debug(`Tracking started with ${this.checkInterval}ms interval`);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Track voice activity for all guilds
|
|
162
|
+
*/
|
|
163
|
+
async trackVoiceActivity() {
|
|
164
|
+
for (const [guildId, guild] of this.client.guilds.cache) {
|
|
165
|
+
try {
|
|
166
|
+
const config = await this.getGuildConfig(guildId);
|
|
167
|
+
// Get all members in voice channels
|
|
168
|
+
const membersInVoice = guild.members.cache.filter((member) => member.voice.channel !== null);
|
|
169
|
+
for (const [_, member] of membersInVoice) {
|
|
170
|
+
await this.processMember(member, config);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
this.logger.error(`Error tracking guild ${guildId}`, error);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Process a single member's voice activity
|
|
180
|
+
*/
|
|
181
|
+
async processMember(member, config) {
|
|
182
|
+
const channel = member.voice.channel;
|
|
183
|
+
if (!channel)
|
|
184
|
+
return;
|
|
185
|
+
// Check if member should be tracked
|
|
186
|
+
if (!(await this.shouldTrackMember(member, config)))
|
|
187
|
+
return;
|
|
188
|
+
if (!(await this.shouldTrackChannel(channel, config)))
|
|
189
|
+
return;
|
|
190
|
+
// Get or create user data
|
|
191
|
+
let userData = await this.storage.getUser(member.guild.id, member.id);
|
|
192
|
+
if (!userData) {
|
|
193
|
+
userData = await this.createUser(member.guild.id, member.id);
|
|
194
|
+
}
|
|
195
|
+
const oldUserData = { ...userData };
|
|
196
|
+
// Add voice time
|
|
197
|
+
if (config.enableVoiceTime) {
|
|
198
|
+
userData.totalVoiceTime += config.voiceTimePerCheck;
|
|
199
|
+
// Update channel-specific time
|
|
200
|
+
const channelData = userData.channels.find((c) => c.channelId === channel.id);
|
|
201
|
+
if (channelData) {
|
|
202
|
+
channelData.voiceTime += config.voiceTimePerCheck;
|
|
203
|
+
channelData.lastActivity = new Date();
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
userData.channels.push({
|
|
207
|
+
channelId: channel.id,
|
|
208
|
+
voiceTime: config.voiceTimePerCheck,
|
|
209
|
+
sessions: 1,
|
|
210
|
+
lastActivity: new Date(),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
this.emit('voiceTimeGained', userData, config.voiceTimePerCheck);
|
|
214
|
+
}
|
|
215
|
+
// Add XP and calculate level
|
|
216
|
+
if (config.enableLeveling) {
|
|
217
|
+
const xpGained = config.xpPerCheck;
|
|
218
|
+
userData.xp += xpGained;
|
|
219
|
+
const newLevel = this.calculator.calculateLevel(userData.xp, config.levelMultiplier);
|
|
220
|
+
const oldLevel = oldUserData.level;
|
|
221
|
+
if (newLevel > oldLevel) {
|
|
222
|
+
userData.level = newLevel;
|
|
223
|
+
this.emit('levelUp', userData, oldLevel, newLevel);
|
|
224
|
+
}
|
|
225
|
+
this.emit('xpGained', userData, xpGained);
|
|
226
|
+
// Update session XP
|
|
227
|
+
const sessionKey = `${member.guild.id}-${member.id}`;
|
|
228
|
+
const session = this.activeSessions.get(sessionKey);
|
|
229
|
+
if (session) {
|
|
230
|
+
session.xpEarned += xpGained;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// Update metadata
|
|
234
|
+
userData.lastSeen = new Date();
|
|
235
|
+
// Save user data
|
|
236
|
+
await this.storage.saveUser(member.guild.id, userData);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Check if member should be tracked
|
|
240
|
+
*/
|
|
241
|
+
async shouldTrackMember(member, config) {
|
|
242
|
+
// Don't track bots if disabled
|
|
243
|
+
if (!config.trackBots && member.user.bot)
|
|
244
|
+
return false;
|
|
245
|
+
// Check exempt permissions
|
|
246
|
+
if (config.exemptPermissions.length > 0) {
|
|
247
|
+
const hasExemptPermission = config.exemptPermissions.some((perm) => member.permissions.has(perm));
|
|
248
|
+
if (hasExemptPermission)
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
// Check mute/deafen
|
|
252
|
+
if (!config.trackMuted && member.voice.mute)
|
|
253
|
+
return false;
|
|
254
|
+
if (!config.trackDeafened && member.voice.deaf)
|
|
255
|
+
return false;
|
|
256
|
+
// Custom filter
|
|
257
|
+
if (config.memberFilter) {
|
|
258
|
+
return await config.memberFilter(member);
|
|
259
|
+
}
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Check if channel should be tracked
|
|
264
|
+
*/
|
|
265
|
+
async shouldTrackChannel(channel, config) {
|
|
266
|
+
// Check if all channels tracked or specific channel
|
|
267
|
+
if (!config.trackAllChannels && !config.channelIds.includes(channel.id)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
// Check user count
|
|
271
|
+
const memberCount = channel.members.size;
|
|
272
|
+
if (config.minUsersToTrack > 0 && memberCount < config.minUsersToTrack) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
if (config.maxUsersToTrack > 0 && memberCount > config.maxUsersToTrack) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
// Custom filter
|
|
279
|
+
if (config.channelFilter) {
|
|
280
|
+
return await config.channelFilter(channel);
|
|
281
|
+
}
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Get guild configuration
|
|
286
|
+
*/
|
|
287
|
+
async getGuildConfig(guildId) {
|
|
288
|
+
const guildData = await this.storage.getGuild(guildId);
|
|
289
|
+
if (guildData) {
|
|
290
|
+
return guildData.config;
|
|
291
|
+
}
|
|
292
|
+
// Create default config
|
|
293
|
+
const config = {
|
|
294
|
+
...this.getDefaultConfig(),
|
|
295
|
+
...this.defaultConfig,
|
|
296
|
+
guildId,
|
|
297
|
+
};
|
|
298
|
+
await this.saveGuildConfig(guildId, config);
|
|
299
|
+
return config;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Save guild configuration
|
|
303
|
+
*/
|
|
304
|
+
async saveGuildConfig(guildId, config) {
|
|
305
|
+
const existingGuild = await this.storage.getGuild(guildId);
|
|
306
|
+
const guildData = {
|
|
307
|
+
guildId,
|
|
308
|
+
config,
|
|
309
|
+
users: existingGuild?.users || new Map(), // Preserve existing users!
|
|
310
|
+
lastUpdated: new Date(),
|
|
311
|
+
};
|
|
312
|
+
await this.storage.saveGuild(guildData);
|
|
313
|
+
this.emit('configUpdated', guildId, config);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Create a new user
|
|
317
|
+
*/
|
|
318
|
+
async createUser(guildId, userId) {
|
|
319
|
+
const userData = {
|
|
320
|
+
userId,
|
|
321
|
+
guildId,
|
|
322
|
+
totalVoiceTime: 0,
|
|
323
|
+
xp: 0,
|
|
324
|
+
level: 0,
|
|
325
|
+
channels: [],
|
|
326
|
+
lastSeen: new Date(),
|
|
327
|
+
streak: 0,
|
|
328
|
+
totalSessions: 0,
|
|
329
|
+
};
|
|
330
|
+
await this.storage.saveUser(guildId, userData);
|
|
331
|
+
return userData;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Get user data
|
|
335
|
+
*/
|
|
336
|
+
async getUser(guildId, userId) {
|
|
337
|
+
return await this.storage.getUser(guildId, userId);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Update user data
|
|
341
|
+
*/
|
|
342
|
+
async updateUser(guildId, userId, options) {
|
|
343
|
+
let userData = await this.storage.getUser(guildId, userId);
|
|
344
|
+
if (!userData) {
|
|
345
|
+
userData = await this.createUser(guildId, userId);
|
|
346
|
+
}
|
|
347
|
+
if (options.addVoiceTime) {
|
|
348
|
+
userData.totalVoiceTime += options.addVoiceTime;
|
|
349
|
+
}
|
|
350
|
+
if (options.addXp) {
|
|
351
|
+
userData.xp += options.addXp;
|
|
352
|
+
const config = await this.getGuildConfig(guildId);
|
|
353
|
+
const newLevel = this.calculator.calculateLevel(userData.xp, config.levelMultiplier);
|
|
354
|
+
if (newLevel > userData.level) {
|
|
355
|
+
const oldLevel = userData.level;
|
|
356
|
+
userData.level = newLevel;
|
|
357
|
+
this.emit('levelUp', userData, oldLevel, newLevel);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (options.setLevel !== undefined) {
|
|
361
|
+
userData.level = options.setLevel;
|
|
362
|
+
}
|
|
363
|
+
if (options.metadata) {
|
|
364
|
+
userData.metadata = { ...userData.metadata, ...options.metadata };
|
|
365
|
+
}
|
|
366
|
+
await this.storage.saveUser(guildId, userData);
|
|
367
|
+
return userData;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Get leaderboard
|
|
371
|
+
*/
|
|
372
|
+
async getLeaderboard(guildId, options = {}) {
|
|
373
|
+
return await this.storage.getLeaderboard(guildId, options.sortBy || 'xp', options.limit || 10, options.offset || 0);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Delete guild data
|
|
377
|
+
*/
|
|
378
|
+
async deleteGuild(guildId) {
|
|
379
|
+
await this.storage.deleteGuild(guildId);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Delete user data
|
|
383
|
+
*/
|
|
384
|
+
async deleteUser(guildId, userId) {
|
|
385
|
+
await this.storage.deleteUser(guildId, userId);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Destroy the manager
|
|
389
|
+
*/
|
|
390
|
+
async destroy() {
|
|
391
|
+
if (this.intervalId) {
|
|
392
|
+
clearInterval(this.intervalId);
|
|
393
|
+
}
|
|
394
|
+
await this.storage.close();
|
|
395
|
+
this.logger.debug('VoiceManager destroyed');
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
exports.VoiceManager = VoiceManager;
|
|
399
|
+
//# sourceMappingURL=VoiceManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VoiceManager.js","sourceRoot":"","sources":["../../src/core/VoiceManager.ts"],"names":[],"mappings":";AAAA,2BAA2B;;;AAG3B,mCAAsC;AAWtC,4CAAyC;AACzC,oDAAmD;AAEnD;;GAEG;AACH,MAAa,YAAa,SAAQ,qBAAY;IACpC,MAAM,CAAS;IACf,OAAO,CAAiC;IACxC,aAAa,CAAS;IACtB,UAAU,CAAkB;IAC5B,MAAM,CAAS;IACf,UAAU,CAAe;IACzB,cAAc,CAA2B;IACzC,aAAa,CAAuB;IAE5C,YAAY,MAAc,EAAE,OAA4B;QACtD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC;QACnD,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC;QACjD,IAAI,CAAC,UAAU,GAAG,IAAI,yBAAY,EAAE,CAAC;QACrC,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;QAChC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACxE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAElD,qBAAqB;YACrB,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;YAEzC,8BAA8B;YAC9B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAA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KAAK,CAAC,cAAc,CAClB,OAAe,EACf,UAA8B,EAAE;QAEhC,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CACtC,OAAO,EACP,OAAO,CAAC,MAAM,IAAI,IAAI,EACtB,OAAO,CAAC,KAAK,IAAI,EAAE,EACnB,OAAO,CAAC,MAAM,IAAI,CAAC,CACpB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,OAAe;QAC/B,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,OAAe,EAAE,MAAc;QAC9C,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjC,CAAC;QAED,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;CACF;AA5dD,oCA4dC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { VoiceManager } from './core/VoiceManager';
|
|
2
|
+
export { JSONStorage } from './storage/JSONStorage';
|
|
3
|
+
export { MongoStorage } from './storage/MongoStorage';
|
|
4
|
+
export { XPCalculator } from './utils/Calculator';
|
|
5
|
+
export { Logger } from './utils/Logger';
|
|
6
|
+
export { Validator } from './utils/Validator';
|
|
7
|
+
export * from './types';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Validator = exports.Logger = exports.XPCalculator = exports.MongoStorage = exports.JSONStorage = exports.VoiceManager = void 0;
|
|
18
|
+
// Export main classes
|
|
19
|
+
var VoiceManager_1 = require("./core/VoiceManager");
|
|
20
|
+
Object.defineProperty(exports, "VoiceManager", { enumerable: true, get: function () { return VoiceManager_1.VoiceManager; } });
|
|
21
|
+
// Export storage adapters
|
|
22
|
+
var JSONStorage_1 = require("./storage/JSONStorage");
|
|
23
|
+
Object.defineProperty(exports, "JSONStorage", { enumerable: true, get: function () { return JSONStorage_1.JSONStorage; } });
|
|
24
|
+
var MongoStorage_1 = require("./storage/MongoStorage");
|
|
25
|
+
Object.defineProperty(exports, "MongoStorage", { enumerable: true, get: function () { return MongoStorage_1.MongoStorage; } });
|
|
26
|
+
// Export utilities
|
|
27
|
+
var Calculator_1 = require("./utils/Calculator");
|
|
28
|
+
Object.defineProperty(exports, "XPCalculator", { enumerable: true, get: function () { return Calculator_1.XPCalculator; } });
|
|
29
|
+
var Logger_1 = require("./utils/Logger");
|
|
30
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return Logger_1.Logger; } });
|
|
31
|
+
var Validator_1 = require("./utils/Validator");
|
|
32
|
+
Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return Validator_1.Validator; } });
|
|
33
|
+
// Export types
|
|
34
|
+
__exportStar(require("./types"), exports);
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sBAAsB;AACtB,oDAAmD;AAA1C,4GAAA,YAAY,OAAA;AAErB,0BAA0B;AAC1B,qDAAoD;AAA3C,0GAAA,WAAW,OAAA;AACpB,uDAAsD;AAA7C,4GAAA,YAAY,OAAA;AAErB,mBAAmB;AACnB,iDAAkD;AAAzC,0GAAA,YAAY,OAAA;AACrB,yCAAwC;AAA/B,gGAAA,MAAM,OAAA;AACf,+CAA8C;AAArC,sGAAA,SAAS,OAAA;AAElB,eAAe;AACf,0CAAwB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { StorageAdapter, GuildData, UserData, SessionData, LeaderboardEntry } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* JSON file-based storage adapter
|
|
4
|
+
*/
|
|
5
|
+
export declare class JSONStorage implements StorageAdapter {
|
|
6
|
+
private dataDir;
|
|
7
|
+
private guildsFile;
|
|
8
|
+
private sessionsFile;
|
|
9
|
+
private cache;
|
|
10
|
+
constructor(dataDir?: string);
|
|
11
|
+
init(): Promise<void>;
|
|
12
|
+
private ensureFile;
|
|
13
|
+
private loadCache;
|
|
14
|
+
private saveCache;
|
|
15
|
+
private dateReviver;
|
|
16
|
+
private serializeGuild;
|
|
17
|
+
private deserializeGuild;
|
|
18
|
+
getGuild(guildId: string): Promise<GuildData | null>;
|
|
19
|
+
saveGuild(guildData: GuildData): Promise<void>;
|
|
20
|
+
deleteGuild(guildId: string): Promise<void>;
|
|
21
|
+
getUser(guildId: string, userId: string): Promise<UserData | null>;
|
|
22
|
+
saveUser(guildId: string, userData: UserData): Promise<void>;
|
|
23
|
+
deleteUser(guildId: string, userId: string): Promise<void>;
|
|
24
|
+
getAllGuilds(): Promise<GuildData[]>;
|
|
25
|
+
getLeaderboard(guildId: string, sortBy: 'voiceTime' | 'xp' | 'level', limit: number, offset: number): Promise<LeaderboardEntry[]>;
|
|
26
|
+
saveSession(session: SessionData): Promise<void>;
|
|
27
|
+
getSessions(guildId: string, userId: string, limit?: number): Promise<SessionData[]>;
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=JSONStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONStorage.d.ts","sourceRoot":"","sources":["../../src/storage/JSONStorage.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,cAAc,EACd,SAAS,EACT,QAAQ,EACR,WAAW,EACX,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,qBAAa,WAAY,YAAW,cAAc;IAChD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,KAAK,CAAyB;gBAE1B,OAAO,GAAE,MAAiB;IAOhC,IAAI,IAAI,OAA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