magmastream 2.9.3-dev.21 → 2.9.3-dev.22

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 CHANGED
@@ -859,7 +859,7 @@ declare abstract class Plugin {
859
859
  interface ManagerOptions {
860
860
  /** The state storage options.
861
861
  *
862
- * @default { type: StateStorageType.Collection, deleteInactivePlayers: true }
862
+ * @default { type: StateStorageType.Collection, deleteDestroyedPlayers: true }
863
863
  */
864
864
  stateStorage?: StateStorageOptions;
865
865
  /** Enable priority mode over least player count or load balancing?
@@ -945,7 +945,7 @@ interface StateStorageOptions {
945
945
  type: StateStorageType;
946
946
  redisConfig?: RedisConfig;
947
947
  jsonConfig?: JsonConfig;
948
- deleteInactivePlayers?: boolean;
948
+ deleteDestroyedPlayers?: boolean;
949
949
  }
950
950
  /**
951
951
  * Node Options
@@ -3101,11 +3101,6 @@ declare class Manager extends EventEmitter {
3101
3101
  * @emits {playerDisconnect} - Emits a player disconnect event if the channel ID is null.
3102
3102
  */
3103
3103
  private handleVoiceStateUpdate;
3104
- /**
3105
- * Cleans up inactive players by removing their state files from the file system.
3106
- * This is done to prevent stale state files from accumulating on the file system.
3107
- */
3108
- cleanupInactivePlayers(): Promise<void>;
3109
3104
  /**
3110
3105
  * Cleans up an inactive player by removing its state data.
3111
3106
  * This is done to prevent stale state data from accumulating.
@@ -92,7 +92,7 @@ class Manager extends events_1.EventEmitter {
92
92
  stateStorage: {
93
93
  ...options.stateStorage,
94
94
  type: options.stateStorage?.type ?? Enums_1.StateStorageType.Memory,
95
- deleteInactivePlayers: options.stateStorage?.deleteInactivePlayers ?? true,
95
+ deleteDestroyedPlayers: options.stateStorage?.deleteDestroyedPlayers ?? true,
96
96
  },
97
97
  autoPlaySearchPlatforms: options.autoPlaySearchPlatforms ?? [Enums_1.AutoPlayPlatform.YouTube],
98
98
  send: this._send,
@@ -949,8 +949,6 @@ class Manager extends events_1.EventEmitter {
949
949
  }
950
950
  });
951
951
  await Promise.allSettled(savePromises);
952
- if (this.options.stateStorage.deleteInactivePlayers)
953
- await this.cleanupInactivePlayers();
954
952
  setTimeout(() => {
955
953
  console.warn("\x1b[32m%s\x1b[0m", "MAGMASTREAM INFO: Shutting down complete, exiting...");
956
954
  process.exit(0);
@@ -1124,86 +1122,6 @@ class Manager extends events_1.EventEmitter {
1124
1122
  data: { voice: { token, endpoint, sessionId: update.session_id, channelId: update.channel_id } },
1125
1123
  });
1126
1124
  }
1127
- /**
1128
- * Cleans up inactive players by removing their state files from the file system.
1129
- * This is done to prevent stale state files from accumulating on the file system.
1130
- */
1131
- async cleanupInactivePlayers() {
1132
- switch (this.options.stateStorage.type) {
1133
- case Enums_1.StateStorageType.JSON:
1134
- {
1135
- const playersBaseDir = Utils_1.PlayerUtils.getPlayersBaseDir();
1136
- try {
1137
- await promises_1.default.mkdir(playersBaseDir, { recursive: true });
1138
- const activeGuildIds = new Set(this.players.keys());
1139
- // Cleanup inactive guild directories inside playersBaseDir
1140
- const guildDirs = await promises_1.default.readdir(playersBaseDir, { withFileTypes: true });
1141
- for (const dirent of guildDirs) {
1142
- if (!dirent.isDirectory())
1143
- continue;
1144
- const guildId = dirent.name;
1145
- if (!activeGuildIds.has(guildId)) {
1146
- const guildPath = Utils_1.PlayerUtils.getGuildDir(guildId);
1147
- await promises_1.default.rm(guildPath, { recursive: true, force: true });
1148
- this.emit(Enums_1.ManagerEventTypes.Debug, `[MANAGER] Deleted inactive player data folder: ${guildId}`);
1149
- }
1150
- }
1151
- }
1152
- catch (err) {
1153
- this.emit(Enums_1.ManagerEventTypes.Debug, `[MANAGER] Error cleaning up inactive JSON players: ${err}`);
1154
- const error = err instanceof MagmastreamError_1.MagmaStreamError
1155
- ? err
1156
- : new MagmastreamError_1.MagmaStreamError({
1157
- code: Enums_1.MagmaStreamErrorCode.MANAGER_CLEANUP_INACTIVE_PLAYERS_FAILED,
1158
- message: "Error cleaning up inactive players.",
1159
- cause: err,
1160
- context: { stage: "CLEANUP_INACTIVE_PLAYERS" },
1161
- });
1162
- console.error(error);
1163
- }
1164
- }
1165
- break;
1166
- case Enums_1.StateStorageType.Redis:
1167
- {
1168
- const prefix = Utils_1.PlayerUtils.getRedisKey();
1169
- const pattern = `${prefix}queue:*:current`;
1170
- try {
1171
- const stream = this.redis.scanStream({
1172
- match: pattern,
1173
- count: 100,
1174
- });
1175
- for await (const keys of stream) {
1176
- for (const key of keys) {
1177
- // Extract guildId from queue key
1178
- const match = key.match(new RegExp(`^${prefix}queue:(.+):current$`));
1179
- if (!match)
1180
- continue;
1181
- const guildId = match[1];
1182
- // If player is not active in memory, clean up all keys
1183
- if (!this.players.has(guildId)) {
1184
- await this.redis.del(`${prefix}playerstore:${guildId}`, `${prefix}queue:${guildId}:current`, `${prefix}queue:${guildId}:tracks`, `${prefix}queue:${guildId}:previous`);
1185
- this.emit(Enums_1.ManagerEventTypes.Debug, `[MANAGER] Cleaned inactive Redis player data: ${guildId}`);
1186
- }
1187
- }
1188
- }
1189
- }
1190
- catch (err) {
1191
- const error = err instanceof MagmastreamError_1.MagmaStreamError
1192
- ? err
1193
- : new MagmastreamError_1.MagmaStreamError({
1194
- code: Enums_1.MagmaStreamErrorCode.MANAGER_SHUTDOWN_FAILED,
1195
- message: "Error saving player state.",
1196
- cause: err,
1197
- context: { stage: "CLEANUP_INACTIVE_PLAYERS" },
1198
- });
1199
- console.error(error);
1200
- }
1201
- }
1202
- break;
1203
- default:
1204
- break;
1205
- }
1206
- }
1207
1125
  /**
1208
1126
  * Cleans up an inactive player by removing its state data.
1209
1127
  * This is done to prevent stale state data from accumulating.
@@ -99,9 +99,7 @@ class Node {
99
99
  this.createReadmeFile();
100
100
  break;
101
101
  case Enums_1.StateStorageType.Redis:
102
- this.redisPrefix = this.manager.options.stateStorage.redisConfig.prefix?.endsWith(":")
103
- ? this.manager.options.stateStorage.redisConfig.prefix
104
- : (this.manager.options.stateStorage.redisConfig.prefix ?? "magmastream:");
102
+ this.redisPrefix = Utils_1.PlayerUtils.getRedisKey();
105
103
  break;
106
104
  }
107
105
  }
@@ -125,7 +123,7 @@ class Node {
125
123
  return `${this.redisPrefix}node:sessionIds`;
126
124
  }
127
125
  getNodeSessionsDir() {
128
- return path_1.default.join(process.cwd(), "magmastream", "sessionData", "cluster", String(this.manager.options.clusterId), "nodeSessions");
126
+ return path_1.default.join(process.cwd(), "magmastream", "sessionData", "nodeSessions");
129
127
  }
130
128
  getNodeSessionPath() {
131
129
  const safeId = String(this.options.identifier).replace(/[^a-zA-Z0-9._-]/g, "_");
@@ -281,7 +281,7 @@ class Player {
281
281
  this.nowPlayingMessage = undefined;
282
282
  this.manager.emit(Enums_1.ManagerEventTypes.PlayerDestroy, this);
283
283
  const deleted = this.manager.players.delete(this.guildId);
284
- if (this.manager.options.stateStorage.deleteInactivePlayers) {
284
+ if (this.manager.options.stateStorage.deleteDestroyedPlayers) {
285
285
  await this.manager.cleanupInactivePlayer(this.guildId);
286
286
  }
287
287
  return deleted;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magmastream",
3
- "version": "2.9.3-dev.21",
3
+ "version": "2.9.3-dev.22",
4
4
  "description": "A user-friendly Lavalink client designed for NodeJS.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",