magmastream 2.9.0-dev.0 → 2.9.0-dev.10

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
@@ -2,6 +2,7 @@ import { User, ClientUser, Message } from 'discord.js';
2
2
  import WebSocket from 'ws';
3
3
  import { Collection } from '@discordjs/collection';
4
4
  import { EventEmitter } from 'events';
5
+ import { Redis } from 'ioredis';
5
6
 
6
7
  /** Represents an equalizer band. */
7
8
  interface Band {
@@ -200,7 +201,7 @@ declare class Node {
200
201
  * @remarks
201
202
  * If the node is already connected, this method will do nothing.
202
203
  * If the node has a session ID, it will be sent in the headers of the WebSocket connection.
203
- * If the node has no session ID but the `resumeStatus` option is true, it will use the session ID
204
+ * If the node has no session ID but the `enableSessionResumeOption` option is true, it will use the session ID
204
205
  * stored in the sessionIds.json file if it exists.
205
206
  */
206
207
  connect(): void;
@@ -477,21 +478,21 @@ interface NodeOptions {
477
478
  /** The password for the node. */
478
479
  password?: string;
479
480
  /** Whether the host uses SSL. */
480
- secure?: boolean;
481
+ useSSL?: boolean;
481
482
  /** The identifier for the node. */
482
483
  identifier?: string;
483
- /** The retryAmount for the node. */
484
- retryAmount?: number;
485
- /** The retryDelay for the node. */
486
- retryDelay?: number;
484
+ /** The maxRetryAttempts for the node. */
485
+ maxRetryAttempts?: number;
486
+ /** The retryDelayMs for the node. */
487
+ retryDelayMs?: number;
487
488
  /** Whether to resume the previous session. */
488
- resumeStatus?: boolean;
489
+ enableSessionResumeOption?: boolean;
489
490
  /** The time the lavalink server will wait before it removes the player. */
490
- resumeTimeout?: number;
491
+ sessionTimeoutMs?: number;
491
492
  /** The timeout used for api calls. */
492
- requestTimeout?: number;
493
+ apiRequestTimeoutMs?: number;
493
494
  /** Priority of the node. */
494
- priority?: number;
495
+ nodePriority?: number;
495
496
  }
496
497
  interface NodeStats {
497
498
  /** The amount of players on the node. */
@@ -573,24 +574,7 @@ interface Lyrics {
573
574
  /**
574
575
  * The player's queue, the `current` property is the currently playing track, think of the rest as the up-coming tracks.
575
576
  */
576
- declare class Queue extends Array<Track> {
577
- /**
578
- * The total duration of the queue in milliseconds.
579
- * This includes the duration of the currently playing track.
580
- */
581
- get duration(): number;
582
- /**
583
- * The total size of tracks in the queue including the current track.
584
- * This includes the current track if it is not null.
585
- * @returns The total size of tracks in the queue including the current track.
586
- */
587
- get totalSize(): number;
588
- /**
589
- * The size of tracks in the queue.
590
- * This does not include the currently playing track.
591
- * @returns The size of tracks in the queue.
592
- */
593
- get size(): number;
577
+ declare class Queue extends Array<Track> implements IQueue {
594
578
  /** The current track */
595
579
  current: Track | null;
596
580
  /** The previous tracks */
@@ -605,12 +589,34 @@ declare class Queue extends Array<Track> {
605
589
  * @param manager The Manager instance.
606
590
  */
607
591
  constructor(guildId: string, manager: Manager);
592
+ getCurrent(): Promise<Track | null>;
593
+ setCurrent(track: Track | null): Promise<void>;
594
+ getPrevious(): Promise<Track[]>;
595
+ addPrevious(track: Track | Track[]): Promise<void>;
596
+ clearPrevious(): Promise<void>;
597
+ /**
598
+ * The total duration of the queue in milliseconds.
599
+ * This includes the duration of the currently playing track.
600
+ */
601
+ duration(): Promise<number>;
602
+ /**
603
+ * The total size of tracks in the queue including the current track.
604
+ * This includes the current track if it is not null.
605
+ * @returns The total size of tracks in the queue including the current track.
606
+ */
607
+ totalSize(): Promise<number>;
608
+ /**
609
+ * The size of tracks in the queue.
610
+ * This does not include the currently playing track.
611
+ * @returns The size of tracks in the queue.
612
+ */
613
+ size(): Promise<number>;
608
614
  /**
609
615
  * Adds a track to the queue.
610
616
  * @param track The track or tracks to add. Can be a single `Track` or an array of `Track`s.
611
617
  * @param [offset=null] The position to add the track(s) at. If not provided, the track(s) will be added at the end of the queue.
612
618
  */
613
- add(track: Track | Track[], offset?: number): void;
619
+ add(track: Track | Track[], offset?: number): Promise<void>;
614
620
  /**
615
621
  * Removes track(s) from the queue.
616
622
  * @param startOrPosition If a single number is provided, it will be treated as the position of the track to remove.
@@ -618,26 +624,36 @@ declare class Queue extends Array<Track> {
618
624
  * @param end Optional, end of the range of tracks to remove.
619
625
  * @returns The removed track(s).
620
626
  */
621
- remove(position?: number): Track[];
622
- remove(start: number, end: number): Track[];
627
+ remove(position?: number): Promise<Track[]>;
628
+ remove(start: number, end: number): Promise<Track[]>;
623
629
  /**
624
630
  * Clears the queue.
625
631
  * This will remove all tracks from the queue and emit a state update event.
626
632
  */
627
- clear(): void;
633
+ clear(): Promise<void>;
628
634
  /**
629
635
  * Shuffles the queue.
630
636
  * This will randomize the order of the tracks in the queue and emit a state update event.
631
637
  */
632
- shuffle(): void;
638
+ shuffle(): Promise<void>;
633
639
  /**
634
640
  * Shuffles the queue to play tracks requested by each user one block at a time.
635
641
  */
636
- userBlockShuffle(): void;
642
+ userBlockShuffle(): Promise<void>;
637
643
  /**
638
644
  * Shuffles the queue to play tracks requested by each user one by one.
639
645
  */
640
- roundRobinShuffle(): void;
646
+ roundRobinShuffle(): Promise<void>;
647
+ dequeue(): Promise<Track | undefined>;
648
+ enqueueFront(track: Track | Track[]): Promise<void>;
649
+ getTracks(): Promise<Track[]>;
650
+ getSlice(start?: number, end?: number): Promise<Track[]>;
651
+ modifyAt(start: number, deleteCount?: number, ...items: Track[]): Promise<Track[]>;
652
+ mapAsync<T>(callback: (track: Track, index: number, array: Track[]) => T): Promise<T[]>;
653
+ filterAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track[]>;
654
+ findAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track | undefined>;
655
+ someAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
656
+ everyAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
641
657
  }
642
658
 
643
659
  declare abstract class TrackUtils {
@@ -678,11 +694,26 @@ declare abstract class AutoPlayUtils {
678
694
  * @hidden
679
695
  */
680
696
  static init(manager: Manager): void;
681
- static getRecommendedTracks(player: Player, track: Track, attempt?: number): Promise<Track[]>;
697
+ /**
698
+ * Gets recommended tracks for the given track.
699
+ * @param track The track to get recommended tracks for.
700
+ * @returns An array of recommended tracks.
701
+ */
702
+ static getRecommendedTracks(track: Track): Promise<Track[]>;
703
+ /**
704
+ * Gets recommended tracks from Last.fm for the given track.
705
+ * @param track The track to get recommended tracks for.
706
+ * @param apiKey The API key for Last.fm.
707
+ * @returns An array of recommended tracks.
708
+ */
682
709
  static getRecommendedTracksFromLastFm(track: Track, apiKey: string): Promise<Track[]>;
683
- static getRecommendedTracksFromSource(track: Track, mappedPlatform: string): Promise<Track[]>;
684
- static getRecommendedTracksFromYouTube(track: Track): Promise<Track[]>;
685
- static selectPlatform(enabledSources: string[]): SearchPlatform | null;
710
+ /**
711
+ * Gets recommended tracks from the given source.
712
+ * @param track The track to get recommended tracks for.
713
+ * @param platform The source to get recommended tracks from.
714
+ * @returns An array of recommended tracks.
715
+ */
716
+ static getRecommendedTracksFromSource(track: Track, platform: string): Promise<Track[]>;
686
717
  }
687
718
  /** Gets or extends structures to extend the built in, or already extended, classes to add more functionality. */
688
719
  declare abstract class Structure {
@@ -883,6 +914,32 @@ interface PlayerUpdate {
883
914
  ping: number;
884
915
  };
885
916
  }
917
+ interface IQueue {
918
+ getCurrent(): Promise<Track | null>;
919
+ setCurrent(track: Track | null): Promise<void>;
920
+ getPrevious(): Promise<Track[]>;
921
+ addPrevious(track: Track | Track[]): Promise<void>;
922
+ clearPrevious(): Promise<void>;
923
+ size(): Promise<number>;
924
+ totalSize(): Promise<number>;
925
+ duration(): Promise<number>;
926
+ add(track: Track | Track[], offset?: number): Promise<void>;
927
+ remove(start?: number, end?: number): Promise<Track[]>;
928
+ clear(): Promise<void>;
929
+ dequeue(): Promise<Track | undefined>;
930
+ enqueueFront(track: Track | Track[]): Promise<void>;
931
+ getTracks(): Promise<Track[]>;
932
+ getSlice(start?: number, end?: number): Promise<Track[]>;
933
+ modifyAt(start: number, deleteCount?: number, ...items: Track[]): Promise<Track[]>;
934
+ shuffle(): Promise<void>;
935
+ userBlockShuffle(): Promise<void>;
936
+ roundRobinShuffle(): Promise<void>;
937
+ mapAsync<T>(callback: (track: Track, index: number, array: Track[]) => T): Promise<T[]>;
938
+ filterAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track[]>;
939
+ findAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track | undefined>;
940
+ someAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
941
+ everyAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
942
+ }
886
943
 
887
944
  /**
888
945
  * The main hub for interacting with Lavalink and using Magmastream,
@@ -895,14 +952,15 @@ declare class Manager extends EventEmitter {
895
952
  /** The options that were set. */
896
953
  readonly options: ManagerOptions;
897
954
  initiated: boolean;
955
+ redis?: Redis;
898
956
  /**
899
957
  * Initiates the Manager class.
900
958
  * @param options
901
- * @param options.plugins - An array of plugins to load.
959
+ * @param options.enabledPlugins - An array of enabledPlugins to load.
902
960
  * @param options.nodes - An array of node options to create nodes from.
903
- * @param options.autoPlay - Whether to automatically play the first track in the queue when the player is created.
904
- * @param options.autoPlaySearchPlatform - The search platform autoplay will use. Fallback to Youtube if not found.
905
- * @param options.usePriority - Whether to use the priority when selecting a node to play on.
961
+ * @param options.playNextOnEnd - Whether to automatically play the first track in the queue when the player is created.
962
+ * @param options.autoPlaySearchPlatforms - The search platform autoplay will use. Fallback to Youtube if not found.
963
+ * @param options.enablePriorityMode - Whether to use the priority when selecting a node to play on.
906
964
  * @param options.clientName - The name of the client to send to Lavalink.
907
965
  * @param options.defaultSearchPlatform - The default search platform to use when searching for tracks.
908
966
  * @param options.useNode - The strategy to use when selecting a node to play on.
@@ -926,17 +984,24 @@ declare class Manager extends EventEmitter {
926
984
  */
927
985
  search<T = unknown>(query: string | SearchQuery, requester?: T): Promise<SearchResult>;
928
986
  /**
929
- * Creates a player or returns one if it already exists.
930
- * @param options The options to create the player with.
931
- * @returns The created player.
987
+ * Returns a player or undefined if it does not exist.
988
+ * @param guildId The guild ID of the player to retrieve.
989
+ * @returns The player if it exists, undefined otherwise.
932
990
  */
933
- create(options: PlayerOptions): Player;
991
+ getPlayer(guildId: string): Player | undefined;
934
992
  /**
993
+ * @deprecated - Will be removed with v2.10.0 use {@link getPlayer} instead
935
994
  * Returns a player or undefined if it does not exist.
936
995
  * @param guildId The guild ID of the player to retrieve.
937
996
  * @returns The player if it exists, undefined otherwise.
938
997
  */
939
- get(guildId: string): Player | undefined;
998
+ get(guildId: string): Promise<Player | undefined>;
999
+ /**
1000
+ * Creates a player or returns one if it already exists.
1001
+ * @param options The options to create the player with.
1002
+ * @returns The created player.
1003
+ */
1004
+ create(options: PlayerOptions): Player;
940
1005
  /**
941
1006
  * Destroys a player.
942
1007
  * @param guildId The guild ID of the player to destroy.
@@ -997,10 +1062,10 @@ declare class Manager extends EventEmitter {
997
1062
  */
998
1063
  loadPlayerStates(nodeId: string): Promise<void>;
999
1064
  /**
1000
- * Returns the node to use based on the configured `useNode` and `usePriority` options.
1001
- * If `usePriority` is true, the node is chosen based on priority, otherwise it is chosen based on the `useNode` option.
1065
+ * Returns the node to use based on the configured `useNode` and `enablePriorityMode` options.
1066
+ * If `enablePriorityMode` is true, the node is chosen based on priority, otherwise it is chosen based on the `useNode` option.
1002
1067
  * If `useNode` is "leastLoad", the node with the lowest load is chosen, if it is "leastPlayers", the node with the fewest players is chosen.
1003
- * If `usePriority` is false and `useNode` is not set, the node with the lowest load is chosen.
1068
+ * If `enablePriorityMode` is false and `useNode` is not set, the node with the lowest load is chosen.
1004
1069
  * @returns {Node} The node to use.
1005
1070
  */
1006
1071
  get useableNode(): Node;
@@ -1072,7 +1137,7 @@ declare class Manager extends EventEmitter {
1072
1137
  * @param player The Player instance to serialize
1073
1138
  * @returns The serialized Player instance
1074
1139
  */
1075
- private serializePlayer;
1140
+ serializePlayer(player: Player): Record<string, unknown>;
1076
1141
  /**
1077
1142
  * Checks for players that are no longer active and deletes their saved state files.
1078
1143
  * This is done to prevent stale state files from accumulating on the file system.
@@ -1114,17 +1179,27 @@ interface Payload {
1114
1179
  };
1115
1180
  }
1116
1181
  interface ManagerOptions {
1117
- /** Whether players should automatically play the next song. */
1118
- autoPlay?: boolean;
1119
- /** The search platform autoplay should use. Fallback to YouTube if not found.
1120
- * Use enum `SearchPlatform`. */
1121
- autoPlaySearchPlatform?: SearchPlatform;
1182
+ /** The state storage options.
1183
+ *
1184
+ * @default { type: StateStorageType.Collection }
1185
+ */
1186
+ stateStorage?: StateStorageOptions;
1187
+ /** Enable priority mode over least player count or load balancing? */
1188
+ enablePriorityMode?: boolean;
1189
+ /** Automatically play the next track when the current one ends. */
1190
+ playNextOnEnd?: boolean;
1191
+ /** An array of search platforms to use for autoplay. First to last matters
1192
+ * Use enum `AutoPlayPlatform`.
1193
+ */
1194
+ autoPlaySearchPlatforms?: AutoPlayPlatform[];
1122
1195
  /** The client ID to use. */
1123
1196
  clientId?: string;
1124
1197
  /** Value to use for the `Client-Name` header. */
1125
1198
  clientName?: string;
1126
1199
  /** The array of shard IDs connected to this manager instance. */
1127
1200
  clusterId?: number;
1201
+ /** List of plugins to load. */
1202
+ enabledPlugins?: Plugin[];
1128
1203
  /** The default search platform to use.
1129
1204
  * Use enum `SearchPlatform`. */
1130
1205
  defaultSearchPlatform?: SearchPlatform;
@@ -1136,16 +1211,12 @@ interface ManagerOptions {
1136
1211
  maxPreviousTracks?: number;
1137
1212
  /** The array of nodes to connect to. */
1138
1213
  nodes?: NodeOptions[];
1139
- /** A array of plugins to use. */
1140
- plugins?: Plugin[];
1141
1214
  /** Whether the YouTube video titles should be replaced if the Author does not exactly match. */
1142
- replaceYouTubeCredentials?: boolean;
1215
+ normalizeYouTubeTitles?: boolean;
1143
1216
  /** An array of track properties to keep. `track` will always be present. */
1144
1217
  trackPartial?: TrackPartial[];
1145
1218
  /** Use the least amount of players or least load? */
1146
1219
  useNode?: UseNodeOptions.LeastLoad | UseNodeOptions.LeastPlayers;
1147
- /** Use priority mode over least amount of player or load? */
1148
- usePriority?: boolean;
1149
1220
  /**
1150
1221
  * Function to send data to the websocket.
1151
1222
  * @param id The ID of the node to send the data to.
@@ -1153,6 +1224,21 @@ interface ManagerOptions {
1153
1224
  */
1154
1225
  send(id: string, payload: Payload): void;
1155
1226
  }
1227
+ interface RedisConfig {
1228
+ host: string;
1229
+ port: string;
1230
+ password?: string;
1231
+ db?: number;
1232
+ prefix?: string;
1233
+ }
1234
+ declare enum StateStorageType {
1235
+ Collection = "collection",
1236
+ Redis = "redis"
1237
+ }
1238
+ interface StateStorageOptions {
1239
+ type: StateStorageType;
1240
+ redisConfig?: RedisConfig;
1241
+ }
1156
1242
  declare enum TrackPartial {
1157
1243
  /** The base64 encoded string of the track */
1158
1244
  Track = "track",
@@ -1202,6 +1288,14 @@ declare enum SearchPlatform {
1202
1288
  YouTube = "ytsearch",
1203
1289
  YouTubeMusic = "ytmsearch"
1204
1290
  }
1291
+ declare enum AutoPlayPlatform {
1292
+ Spotify = "spotify",
1293
+ Deezer = "deezer",
1294
+ SoundCloud = "soundcloud",
1295
+ Tidal = "tidal",
1296
+ VKMusic = "vkmusic",
1297
+ YouTube = "youtube"
1298
+ }
1205
1299
  declare enum PlayerStateEventTypes {
1206
1300
  AutoPlayChange = "playerAutoplay",
1207
1301
  ConnectionChange = "playerConnection",
@@ -1360,11 +1454,27 @@ interface ManagerEvents {
1360
1454
  [ManagerEventTypes.ChapterStarted]: [player: Player, track: Track, payload: SponsorBlockChapterStarted];
1361
1455
  [ManagerEventTypes.ChaptersLoaded]: [player: Player, track: Track, payload: SponsorBlockChaptersLoaded];
1362
1456
  }
1457
+ interface PlayerStore {
1458
+ get(guildId: string): Promise<Player | undefined>;
1459
+ set(guildId: string, player: Player): Promise<void>;
1460
+ delete(guildId: string): Promise<void>;
1461
+ keys(): Promise<string[]>;
1462
+ has(guildId: string): Promise<boolean>;
1463
+ filter(predicate: (player: Player, guildId: string) => boolean | Promise<boolean>): Promise<Map<string, Player>>;
1464
+ find(predicate: (player: Player, guildId: string) => boolean | Promise<boolean>): Promise<Player | undefined>;
1465
+ map<T>(callback: (player: Player, guildId: string) => T | Promise<T>): Promise<T[]>;
1466
+ forEach(callback: (player: Player, guildId: string) => void | Promise<void>): Promise<void>;
1467
+ some(predicate: (player: Player, guildId: string) => boolean | Promise<boolean>): Promise<boolean>;
1468
+ every(predicate: (player: Player, guildId: string) => boolean | Promise<boolean>): Promise<boolean>;
1469
+ size(): Promise<number>;
1470
+ clear(): Promise<void>;
1471
+ entries(): AsyncIterableIterator<[string, Player]>;
1472
+ }
1363
1473
 
1364
1474
  declare class Player {
1365
1475
  options: PlayerOptions;
1366
1476
  /** The Queue for the Player. */
1367
- readonly queue: Queue;
1477
+ queue: IQueue;
1368
1478
  /** The filters applied to the audio. */
1369
1479
  filters: Filters;
1370
1480
  /** Whether the queue repeats the track. */
@@ -1402,11 +1512,11 @@ declare class Player {
1402
1512
  /** The autoplay state of the player. */
1403
1513
  isAutoplay: boolean;
1404
1514
  /** The number of times to try autoplay before emitting queueEnd. */
1405
- autoplayTries: number | null;
1515
+ autoplayTries: number;
1406
1516
  private static _manager;
1407
1517
  private readonly data;
1408
1518
  private dynamicLoopInterval;
1409
- private dynamicRepeatIntervalMs;
1519
+ dynamicRepeatIntervalMs: number | null;
1410
1520
  /**
1411
1521
  * Creates a new player, returns one if it already exists.
1412
1522
  * @param options The player options.
@@ -1569,7 +1679,7 @@ declare class Player {
1569
1679
  * @throws {TypeError} If the repeat parameter is not a boolean.
1570
1680
  * @throws {RangeError} If the queue size is less than or equal to 1.
1571
1681
  */
1572
- setDynamicRepeat(repeat: boolean, ms: number): this;
1682
+ setDynamicRepeat(repeat: boolean, ms: number): Promise<this>;
1573
1683
  /**
1574
1684
  * Restarts the currently playing track from the beginning.
1575
1685
  * If there is no track playing, it will play the next track in the queue.
@@ -2136,5 +2246,5 @@ declare class Plugin {
2136
2246
  load(manager: Manager): void;
2137
2247
  }
2138
2248
 
2139
- export { AutoPlayUtils, AvailableFilters, Filters, LoadTypes, Manager, ManagerEventTypes, Node, Player, PlayerStateEventTypes, Plugin, Queue, Rest, SearchPlatform, SeverityTypes, SponsorBlockSegment, StateTypes, Structure, TrackEndReasonTypes, TrackPartial, TrackSourceTypes, TrackUtils, UseNodeOptions };
2140
- export type { CPUStats, EqualizerBand, Exception, Extendable, FrameStats, LavalinkInfo, LavalinkResponse, LoadType, Lyrics, LyricsLine, ManagerEvents, ManagerOptions, MemoryStats, NodeMessage, NodeOptions, NodeStats, Payload, PlayOptions, PlayerEvent, PlayerEventType, PlayerEvents, PlayerOptions, PlayerUpdate, PlaylistData, PlaylistInfoData, PlaylistRawData, SearchQuery, SearchResult, Severity, Sizes, SponsorBlockChapterStarted, SponsorBlockChaptersLoaded, SponsorBlockSegmentEventType, SponsorBlockSegmentEvents, SponsorBlockSegmentSkipped, SponsorBlockSegmentsLoaded, State, Track, TrackData, TrackDataInfo, TrackEndEvent, TrackEndReason, TrackExceptionEvent, TrackPluginInfo, TrackSourceName, TrackStartEvent, TrackStuckEvent, UseNodeOption, VoicePacket, VoiceServer, VoiceState, WebSocketClosedEvent };
2249
+ export { AutoPlayPlatform, AutoPlayUtils, AvailableFilters, Filters, LoadTypes, Manager, ManagerEventTypes, Node, Player, PlayerStateEventTypes, Plugin, Queue, Rest, SearchPlatform, SeverityTypes, SponsorBlockSegment, StateStorageType, StateTypes, Structure, TrackEndReasonTypes, TrackPartial, TrackSourceTypes, TrackUtils, UseNodeOptions };
2250
+ export type { CPUStats, EqualizerBand, Exception, Extendable, FrameStats, IQueue, LavalinkInfo, LavalinkResponse, LoadType, Lyrics, LyricsLine, ManagerEvents, ManagerOptions, MemoryStats, NodeMessage, NodeOptions, NodeStats, Payload, PlayOptions, PlayerEvent, PlayerEventType, PlayerEvents, PlayerOptions, PlayerStore, PlayerUpdate, PlaylistData, PlaylistInfoData, PlaylistRawData, RedisConfig, SearchQuery, SearchResult, Severity, Sizes, SponsorBlockChapterStarted, SponsorBlockChaptersLoaded, SponsorBlockSegmentEventType, SponsorBlockSegmentEvents, SponsorBlockSegmentSkipped, SponsorBlockSegmentsLoaded, State, StateStorageOptions, Track, TrackData, TrackDataInfo, TrackEndEvent, TrackEndReason, TrackExceptionEvent, TrackPluginInfo, TrackSourceName, TrackStartEvent, TrackStuckEvent, UseNodeOption, VoicePacket, VoiceServer, VoiceState, WebSocketClosedEvent };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ // THIS WILL BE REMOVED IF YOU DONT FIND A USE FOR IT.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.CollectionPlayerStore = void 0;
5
+ const collection_1 = require("@discordjs/collection");
6
+ const logExecutionTime_1 = require("../utils/logExecutionTime");
7
+ class CollectionPlayerStore {
8
+ store = new collection_1.Collection();
9
+ async get(guildId) {
10
+ return (0, logExecutionTime_1.logExecutionTime)("CollectionStore.get", async () => {
11
+ return this.store.get(guildId);
12
+ });
13
+ }
14
+ async set(guildId, player) {
15
+ this.store.set(guildId, player);
16
+ }
17
+ async delete(guildId) {
18
+ this.store.delete(guildId);
19
+ }
20
+ async keys() {
21
+ return [...this.store.keys()];
22
+ }
23
+ async has(guildId) {
24
+ return this.store.has(guildId);
25
+ }
26
+ async filter(predicate) {
27
+ const result = new Map();
28
+ for (const [guildId, player] of this.store.entries()) {
29
+ if (await predicate(player, guildId)) {
30
+ result.set(guildId, player);
31
+ }
32
+ }
33
+ return result;
34
+ }
35
+ async find(predicate) {
36
+ for (const [guildId, player] of this.store.entries()) {
37
+ if (await predicate(player, guildId))
38
+ return player;
39
+ }
40
+ return undefined;
41
+ }
42
+ async map(callback) {
43
+ const results = [];
44
+ for (const [guildId, player] of this.store.entries()) {
45
+ results.push(await callback(player, guildId));
46
+ }
47
+ return results;
48
+ }
49
+ async forEach(callback) {
50
+ for (const [guildId, player] of this.store.entries()) {
51
+ await callback(player, guildId);
52
+ }
53
+ }
54
+ async some(predicate) {
55
+ for (const [guildId, player] of this.store.entries()) {
56
+ if (await predicate(player, guildId))
57
+ return true;
58
+ }
59
+ return false;
60
+ }
61
+ async every(predicate) {
62
+ for (const [guildId, player] of this.store.entries()) {
63
+ if (!(await predicate(player, guildId)))
64
+ return false;
65
+ }
66
+ return true;
67
+ }
68
+ async size() {
69
+ return this.store.size;
70
+ }
71
+ async clear() {
72
+ this.store.clear();
73
+ }
74
+ async *entries() {
75
+ for (const entry of this.store.entries()) {
76
+ yield entry;
77
+ }
78
+ }
79
+ }
80
+ exports.CollectionPlayerStore = CollectionPlayerStore;
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ // THIS WILL BE REMOVED IF YOU DONT FIND A USE FOR IT.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RedisPlayerStore = void 0;
5
+ const logExecutionTime_1 = require("../utils/logExecutionTime");
6
+ class RedisPlayerStore {
7
+ redis;
8
+ manager;
9
+ prefix;
10
+ constructor(redis, manager, prefix = "magmastream:") {
11
+ this.redis = redis;
12
+ this.manager = manager;
13
+ this.prefix = prefix;
14
+ }
15
+ getKey(guildId) {
16
+ return `${this.prefix}player:${guildId}`;
17
+ }
18
+ async get(guildId) {
19
+ return (0, logExecutionTime_1.logExecutionTime)("RedisStore.get", async () => {
20
+ const raw = await this.redis.get(this.getKey(guildId));
21
+ if (!raw)
22
+ return undefined;
23
+ return JSON.parse(raw);
24
+ });
25
+ }
26
+ async set(guildId, player) {
27
+ const serialized = this.manager.serializePlayer(player);
28
+ await this.redis.set(this.getKey(guildId), JSON.stringify(serialized));
29
+ }
30
+ async delete(guildId) {
31
+ await this.redis.del(this.getKey(guildId));
32
+ }
33
+ async keys() {
34
+ const keys = await this.redis.keys(`${this.prefix}player:*`);
35
+ return keys.map((key) => key.replace(`${this.prefix}player:`, ""));
36
+ }
37
+ async has(guildId) {
38
+ return (await this.redis.exists(this.getKey(guildId))) === 1;
39
+ }
40
+ async filter(predicate) {
41
+ const keys = await this.keys();
42
+ const pipeline = this.redis.pipeline();
43
+ for (const guildId of keys) {
44
+ pipeline.get(this.getKey(guildId));
45
+ }
46
+ const results = await pipeline.exec();
47
+ const result = new Map();
48
+ for (let i = 0; i < results.length; i++) {
49
+ const [err, raw] = results[i];
50
+ if (err || typeof raw !== "string")
51
+ continue;
52
+ const guildId = keys[i];
53
+ const player = JSON.parse(raw);
54
+ if (await predicate(player, guildId)) {
55
+ result.set(guildId, player);
56
+ }
57
+ }
58
+ return result;
59
+ }
60
+ async find(predicate) {
61
+ for (const guildId of await this.keys()) {
62
+ const raw = await this.redis.get(this.getKey(guildId));
63
+ if (!raw)
64
+ continue;
65
+ const parsed = JSON.parse(raw);
66
+ if (await predicate(parsed, guildId))
67
+ return parsed;
68
+ }
69
+ return undefined;
70
+ }
71
+ async map(callback) {
72
+ const keys = await this.keys();
73
+ if (!keys.length)
74
+ return [];
75
+ const pipeline = this.redis.pipeline();
76
+ for (const guildId of keys) {
77
+ pipeline.get(this.getKey(guildId));
78
+ }
79
+ const results = await pipeline.exec();
80
+ const output = [];
81
+ for (let i = 0; i < results.length; i++) {
82
+ const [err, raw] = results[i];
83
+ if (err || typeof raw !== "string")
84
+ continue;
85
+ const guildId = keys[i];
86
+ const player = JSON.parse(raw);
87
+ output.push(await callback(player, guildId));
88
+ }
89
+ return output;
90
+ }
91
+ async forEach(callback) {
92
+ for (const guildId of await this.keys()) {
93
+ const raw = await this.redis.get(this.getKey(guildId));
94
+ if (!raw)
95
+ continue;
96
+ const parsed = JSON.parse(raw);
97
+ await callback(parsed, guildId);
98
+ }
99
+ }
100
+ async some(predicate) {
101
+ const keys = await this.keys();
102
+ if (!keys.length)
103
+ return false;
104
+ const pipeline = this.redis.pipeline();
105
+ for (const guildId of keys) {
106
+ pipeline.get(this.getKey(guildId));
107
+ }
108
+ const results = await pipeline.exec();
109
+ for (let i = 0; i < results.length; i++) {
110
+ const [err, raw] = results[i];
111
+ if (err || typeof raw !== "string")
112
+ continue;
113
+ const guildId = keys[i];
114
+ const player = JSON.parse(raw);
115
+ if (await predicate(player, guildId))
116
+ return true;
117
+ }
118
+ return false;
119
+ }
120
+ async every(predicate) {
121
+ const keys = await this.keys();
122
+ if (!keys.length)
123
+ return true;
124
+ const pipeline = this.redis.pipeline();
125
+ for (const guildId of keys) {
126
+ pipeline.get(this.getKey(guildId));
127
+ }
128
+ const results = await pipeline.exec();
129
+ for (let i = 0; i < results.length; i++) {
130
+ const [err, raw] = results[i];
131
+ if (err || typeof raw !== "string")
132
+ continue;
133
+ const guildId = keys[i];
134
+ const player = JSON.parse(raw);
135
+ if (!(await predicate(player, guildId)))
136
+ return false;
137
+ }
138
+ return true;
139
+ }
140
+ async size() {
141
+ const keys = await this.keys();
142
+ return keys.length;
143
+ }
144
+ async clear() {
145
+ const keys = await this.redis.keys(`${this.prefix}player:*`);
146
+ if (keys.length) {
147
+ await this.redis.del(...keys);
148
+ }
149
+ }
150
+ async *entries() {
151
+ for (const guildId of await this.keys()) {
152
+ const raw = await this.redis.get(this.getKey(guildId));
153
+ if (!raw)
154
+ continue;
155
+ yield [guildId, JSON.parse(raw)];
156
+ }
157
+ }
158
+ }
159
+ exports.RedisPlayerStore = RedisPlayerStore;