magmastream 2.9.0-dev.2 → 2.9.0-dev.20

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/README.md CHANGED
@@ -95,12 +95,12 @@
95
95
  | [Stal](https://discord.com/oauth2/authorize?client_id=923938180263182356&scope=bot%20applications.commands&permissions=27648861246) | memte |
96
96
  | [Lunio](https://discord.com/api/oauth2/authorize?client_id=945030475779551415&permissions=61991952&scope=bot+applications.commands) | vexi |
97
97
  | [JukeDisc](https://discord.com/oauth2/authorize?client_id=1109751797549105176&permissions=968552214080&scope=bot+applications.commands) | Theo |
98
- | [Cool Music](https://discord.com/oauth2/authorize?client_id=923529398425096193&permissions=12888394808&redirect_uri=https%3A%2F%2Fdiscord.gg%2Fcool-music-support-925619107460698202&response_type=code&scope=bot%20identify%20applications.commands) | Itz Random |
98
+ | [Leo](https://discord.com/oauth2/authorize?client_id=923529398425096193&permissions=12888394808&scope=bot%20identify%20applications.commands) | Itz Random |
99
99
  | [Soundy](https://dsc.gg/sndy) | iaMJ |
100
100
  | [HamBot](https://discord.com/oauth2/authorize?client_id=1049314312776335390) | yanishamburger|
101
101
  | [Miyu](https://discord.com/oauth2/authorize?client_id=1277180179273482280&permissions=572851999731703&response_type=code&redirect_uri=https%3A%2F%2Fdiscord.gg%2Ftn3nbFB8nX&integration_type=0&scope=identify+applications.commands+bot) | Kenver |
102
102
  | [Savage Bot](https://discord.com/oauth2/authorize?client_id=823703707522433054&permissions=8&scope=bot%20applications.commands) | Savage
103
- | [rive](https://discord.com/oauth2/authorize?client_id=1350601402325405806) | pomice
103
+ | [lost](https://discord.com/oauth2/authorize?client_id=1280681209604739204) | pomice
104
104
 
105
105
 
106
106
  Want to showcase your bot? Feel free to create a pull request and add it to our growing list of amazing bots powered by Magmastream!
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 {
@@ -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,35 @@ 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
+ setPrevious(tracks: Track[]): Promise<void>;
597
+ clearPrevious(): Promise<void>;
598
+ /**
599
+ * The total duration of the queue in milliseconds.
600
+ * This includes the duration of the currently playing track.
601
+ */
602
+ duration(): Promise<number>;
603
+ /**
604
+ * The total size of tracks in the queue including the current track.
605
+ * This includes the current track if it is not null.
606
+ * @returns The total size of tracks in the queue including the current track.
607
+ */
608
+ totalSize(): Promise<number>;
609
+ /**
610
+ * The size of tracks in the queue.
611
+ * This does not include the currently playing track.
612
+ * @returns The size of tracks in the queue.
613
+ */
614
+ size(): Promise<number>;
608
615
  /**
609
616
  * Adds a track to the queue.
610
617
  * @param track The track or tracks to add. Can be a single `Track` or an array of `Track`s.
611
618
  * @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
619
  */
613
- add(track: Track | Track[], offset?: number): void;
620
+ add(track: Track | Track[], offset?: number): Promise<void>;
614
621
  /**
615
622
  * Removes track(s) from the queue.
616
623
  * @param startOrPosition If a single number is provided, it will be treated as the position of the track to remove.
@@ -618,26 +625,36 @@ declare class Queue extends Array<Track> {
618
625
  * @param end Optional, end of the range of tracks to remove.
619
626
  * @returns The removed track(s).
620
627
  */
621
- remove(position?: number): Track[];
622
- remove(start: number, end: number): Track[];
628
+ remove(position?: number): Promise<Track[]>;
629
+ remove(start: number, end: number): Promise<Track[]>;
623
630
  /**
624
631
  * Clears the queue.
625
632
  * This will remove all tracks from the queue and emit a state update event.
626
633
  */
627
- clear(): void;
634
+ clear(): Promise<void>;
628
635
  /**
629
636
  * Shuffles the queue.
630
637
  * This will randomize the order of the tracks in the queue and emit a state update event.
631
638
  */
632
- shuffle(): void;
639
+ shuffle(): Promise<void>;
633
640
  /**
634
641
  * Shuffles the queue to play tracks requested by each user one block at a time.
635
642
  */
636
- userBlockShuffle(): void;
643
+ userBlockShuffle(): Promise<void>;
637
644
  /**
638
645
  * Shuffles the queue to play tracks requested by each user one by one.
639
646
  */
640
- roundRobinShuffle(): void;
647
+ roundRobinShuffle(): Promise<void>;
648
+ dequeue(): Promise<Track | undefined>;
649
+ enqueueFront(track: Track | Track[]): Promise<void>;
650
+ getTracks(): Promise<Track[]>;
651
+ getSlice(start?: number, end?: number): Promise<Track[]>;
652
+ modifyAt(start: number, deleteCount?: number, ...items: Track[]): Promise<Track[]>;
653
+ mapAsync<T>(callback: (track: Track, index: number, array: Track[]) => T): Promise<T[]>;
654
+ filterAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track[]>;
655
+ findAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track | undefined>;
656
+ someAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
657
+ everyAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
641
658
  }
642
659
 
643
660
  declare abstract class TrackUtils {
@@ -678,11 +695,26 @@ declare abstract class AutoPlayUtils {
678
695
  * @hidden
679
696
  */
680
697
  static init(manager: Manager): void;
681
- static getRecommendedTracks(player: Player, track: Track, attempt?: number): Promise<Track[]>;
698
+ /**
699
+ * Gets recommended tracks for the given track.
700
+ * @param track The track to get recommended tracks for.
701
+ * @returns An array of recommended tracks.
702
+ */
703
+ static getRecommendedTracks(track: Track): Promise<Track[]>;
704
+ /**
705
+ * Gets recommended tracks from Last.fm for the given track.
706
+ * @param track The track to get recommended tracks for.
707
+ * @param apiKey The API key for Last.fm.
708
+ * @returns An array of recommended tracks.
709
+ */
682
710
  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;
711
+ /**
712
+ * Gets recommended tracks from the given source.
713
+ * @param track The track to get recommended tracks for.
714
+ * @param platform The source to get recommended tracks from.
715
+ * @returns An array of recommended tracks.
716
+ */
717
+ static getRecommendedTracksFromSource(track: Track, platform: string): Promise<Track[]>;
686
718
  }
687
719
  /** Gets or extends structures to extend the built in, or already extended, classes to add more functionality. */
688
720
  declare abstract class Structure {
@@ -883,6 +915,33 @@ interface PlayerUpdate {
883
915
  ping: number;
884
916
  };
885
917
  }
918
+ interface IQueue {
919
+ getCurrent(): Promise<Track | null>;
920
+ setCurrent(track: Track | null): Promise<void>;
921
+ getPrevious(): Promise<Track[]>;
922
+ addPrevious(track: Track | Track[]): Promise<void>;
923
+ setPrevious(track: Track | Track[]): Promise<void>;
924
+ clearPrevious(): Promise<void>;
925
+ size(): Promise<number>;
926
+ totalSize(): Promise<number>;
927
+ duration(): Promise<number>;
928
+ add(track: Track | Track[], offset?: number): Promise<void>;
929
+ remove(start?: number, end?: number): Promise<Track[]>;
930
+ clear(): Promise<void>;
931
+ dequeue(): Promise<Track | undefined>;
932
+ enqueueFront(track: Track | Track[]): Promise<void>;
933
+ getTracks(): Promise<Track[]>;
934
+ getSlice(start?: number, end?: number): Promise<Track[]>;
935
+ modifyAt(start: number, deleteCount?: number, ...items: Track[]): Promise<Track[]>;
936
+ shuffle(): Promise<void>;
937
+ userBlockShuffle(): Promise<void>;
938
+ roundRobinShuffle(): Promise<void>;
939
+ mapAsync<T>(callback: (track: Track, index: number, array: Track[]) => T): Promise<T[]>;
940
+ filterAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track[]>;
941
+ findAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<Track | undefined>;
942
+ someAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
943
+ everyAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Promise<boolean>;
944
+ }
886
945
 
887
946
  /**
888
947
  * The main hub for interacting with Lavalink and using Magmastream,
@@ -895,13 +954,14 @@ declare class Manager extends EventEmitter {
895
954
  /** The options that were set. */
896
955
  readonly options: ManagerOptions;
897
956
  initiated: boolean;
957
+ redis?: Redis;
898
958
  /**
899
959
  * Initiates the Manager class.
900
960
  * @param options
901
961
  * @param options.enabledPlugins - An array of enabledPlugins to load.
902
962
  * @param options.nodes - An array of node options to create nodes from.
903
963
  * @param options.playNextOnEnd - 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.
964
+ * @param options.autoPlaySearchPlatforms - The search platform autoplay will use. Fallback to Youtube if not found.
905
965
  * @param options.enablePriorityMode - Whether to use the priority when selecting a node to play on.
906
966
  * @param options.clientName - The name of the client to send to Lavalink.
907
967
  * @param options.defaultSearchPlatform - The default search platform to use when searching for tracks.
@@ -926,17 +986,24 @@ declare class Manager extends EventEmitter {
926
986
  */
927
987
  search<T = unknown>(query: string | SearchQuery, requester?: T): Promise<SearchResult>;
928
988
  /**
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.
989
+ * Returns a player or undefined if it does not exist.
990
+ * @param guildId The guild ID of the player to retrieve.
991
+ * @returns The player if it exists, undefined otherwise.
932
992
  */
933
- create(options: PlayerOptions): Player;
993
+ getPlayer(guildId: string): Player | undefined;
934
994
  /**
995
+ * @deprecated - Will be removed with v2.10.0 use {@link getPlayer} instead
935
996
  * Returns a player or undefined if it does not exist.
936
997
  * @param guildId The guild ID of the player to retrieve.
937
998
  * @returns The player if it exists, undefined otherwise.
938
999
  */
939
- get(guildId: string): Player | undefined;
1000
+ get(guildId: string): Promise<Player | undefined>;
1001
+ /**
1002
+ * Creates a player or returns one if it already exists.
1003
+ * @param options The options to create the player with.
1004
+ * @returns The created player.
1005
+ */
1006
+ create(options: PlayerOptions): Player;
940
1007
  /**
941
1008
  * Destroys a player.
942
1009
  * @param guildId The guild ID of the player to destroy.
@@ -990,6 +1057,12 @@ declare class Manager extends EventEmitter {
990
1057
  * @param {string} guildId - The guild ID of the player to save
991
1058
  */
992
1059
  savePlayerState(guildId: string): Promise<void>;
1060
+ /**
1061
+ * Sleeps for a specified amount of time.
1062
+ * @param ms The amount of time to sleep in milliseconds.
1063
+ * @returns A promise that resolves after the specified amount of time.
1064
+ */
1065
+ private sleep;
993
1066
  /**
994
1067
  * Loads player states from the JSON file.
995
1068
  * @param nodeId The ID of the node to load player states from.
@@ -1072,7 +1145,7 @@ declare class Manager extends EventEmitter {
1072
1145
  * @param player The Player instance to serialize
1073
1146
  * @returns The serialized Player instance
1074
1147
  */
1075
- private serializePlayer;
1148
+ serializePlayer(player: Player): Record<string, unknown>;
1076
1149
  /**
1077
1150
  * Checks for players that are no longer active and deletes their saved state files.
1078
1151
  * This is done to prevent stale state files from accumulating on the file system.
@@ -1114,13 +1187,19 @@ interface Payload {
1114
1187
  };
1115
1188
  }
1116
1189
  interface ManagerOptions {
1190
+ /** The state storage options.
1191
+ *
1192
+ * @default { type: StateStorageType.Collection }
1193
+ */
1194
+ stateStorage?: StateStorageOptions;
1117
1195
  /** Enable priority mode over least player count or load balancing? */
1118
1196
  enablePriorityMode?: boolean;
1119
1197
  /** Automatically play the next track when the current one ends. */
1120
1198
  playNextOnEnd?: boolean;
1121
- /** The search platform autoplay should use
1122
- * Use enum `SearchPlatform`. */
1123
- autoPlaySearchPlatform?: SearchPlatform;
1199
+ /** An array of search platforms to use for autoplay. First to last matters
1200
+ * Use enum `AutoPlayPlatform`.
1201
+ */
1202
+ autoPlaySearchPlatforms?: AutoPlayPlatform[];
1124
1203
  /** The client ID to use. */
1125
1204
  clientId?: string;
1126
1205
  /** Value to use for the `Client-Name` header. */
@@ -1135,7 +1214,7 @@ interface ManagerOptions {
1135
1214
  /** The last.fm API key.
1136
1215
  * If you need to create one go here: https://www.last.fm/api/account/create.
1137
1216
  * If you already have one, get it from here: https://www.last.fm/api/accounts. */
1138
- lastFmApiKey: string;
1217
+ lastFmApiKey?: string;
1139
1218
  /** The maximum number of previous tracks to store. */
1140
1219
  maxPreviousTracks?: number;
1141
1220
  /** The array of nodes to connect to. */
@@ -1153,6 +1232,21 @@ interface ManagerOptions {
1153
1232
  */
1154
1233
  send(id: string, payload: Payload): void;
1155
1234
  }
1235
+ interface RedisConfig {
1236
+ host: string;
1237
+ port: string;
1238
+ password?: string;
1239
+ db?: number;
1240
+ prefix?: string;
1241
+ }
1242
+ declare enum StateStorageType {
1243
+ Collection = "collection",
1244
+ Redis = "redis"
1245
+ }
1246
+ interface StateStorageOptions {
1247
+ type: StateStorageType;
1248
+ redisConfig?: RedisConfig;
1249
+ }
1156
1250
  declare enum TrackPartial {
1157
1251
  /** The base64 encoded string of the track */
1158
1252
  Track = "track",
@@ -1195,6 +1289,7 @@ declare enum SearchPlatform {
1195
1289
  Bandcamp = "bcsearch",
1196
1290
  Deezer = "dzsearch",
1197
1291
  Jiosaavn = "jssearch",
1292
+ Qobuz = "qbsearch",
1198
1293
  SoundCloud = "scsearch",
1199
1294
  Spotify = "spsearch",
1200
1295
  Tidal = "tdsearch",
@@ -1202,6 +1297,15 @@ declare enum SearchPlatform {
1202
1297
  YouTube = "ytsearch",
1203
1298
  YouTubeMusic = "ytmsearch"
1204
1299
  }
1300
+ declare enum AutoPlayPlatform {
1301
+ Spotify = "spotify",
1302
+ Deezer = "deezer",
1303
+ SoundCloud = "soundcloud",
1304
+ Tidal = "tidal",
1305
+ VKMusic = "vkmusic",
1306
+ Qobuz = "qobuz",
1307
+ YouTube = "youtube"
1308
+ }
1205
1309
  declare enum PlayerStateEventTypes {
1206
1310
  AutoPlayChange = "playerAutoplay",
1207
1311
  ConnectionChange = "playerConnection",
@@ -1360,11 +1464,27 @@ interface ManagerEvents {
1360
1464
  [ManagerEventTypes.ChapterStarted]: [player: Player, track: Track, payload: SponsorBlockChapterStarted];
1361
1465
  [ManagerEventTypes.ChaptersLoaded]: [player: Player, track: Track, payload: SponsorBlockChaptersLoaded];
1362
1466
  }
1467
+ interface PlayerStore {
1468
+ get(guildId: string): Promise<Player | undefined>;
1469
+ set(guildId: string, player: Player): Promise<void>;
1470
+ delete(guildId: string): Promise<void>;
1471
+ keys(): Promise<string[]>;
1472
+ has(guildId: string): Promise<boolean>;
1473
+ filter(predicate: (player: Player, guildId: string) => boolean | Promise<boolean>): Promise<Map<string, Player>>;
1474
+ find(predicate: (player: Player, guildId: string) => boolean | Promise<boolean>): Promise<Player | undefined>;
1475
+ map<T>(callback: (player: Player, guildId: string) => T | Promise<T>): Promise<T[]>;
1476
+ forEach(callback: (player: Player, guildId: string) => void | Promise<void>): Promise<void>;
1477
+ some(predicate: (player: Player, guildId: string) => boolean | Promise<boolean>): Promise<boolean>;
1478
+ every(predicate: (player: Player, guildId: string) => boolean | Promise<boolean>): Promise<boolean>;
1479
+ size(): Promise<number>;
1480
+ clear(): Promise<void>;
1481
+ entries(): AsyncIterableIterator<[string, Player]>;
1482
+ }
1363
1483
 
1364
1484
  declare class Player {
1365
1485
  options: PlayerOptions;
1366
1486
  /** The Queue for the Player. */
1367
- readonly queue: Queue;
1487
+ queue: IQueue;
1368
1488
  /** The filters applied to the audio. */
1369
1489
  filters: Filters;
1370
1490
  /** Whether the queue repeats the track. */
@@ -1402,11 +1522,11 @@ declare class Player {
1402
1522
  /** The autoplay state of the player. */
1403
1523
  isAutoplay: boolean;
1404
1524
  /** The number of times to try autoplay before emitting queueEnd. */
1405
- autoplayTries: number | null;
1525
+ autoplayTries: number;
1406
1526
  private static _manager;
1407
1527
  private readonly data;
1408
1528
  private dynamicLoopInterval;
1409
- private dynamicRepeatIntervalMs;
1529
+ dynamicRepeatIntervalMs: number | null;
1410
1530
  /**
1411
1531
  * Creates a new player, returns one if it already exists.
1412
1532
  * @param options The player options.
@@ -1569,7 +1689,7 @@ declare class Player {
1569
1689
  * @throws {TypeError} If the repeat parameter is not a boolean.
1570
1690
  * @throws {RangeError} If the queue size is less than or equal to 1.
1571
1691
  */
1572
- setDynamicRepeat(repeat: boolean, ms: number): this;
1692
+ setDynamicRepeat(repeat: boolean, ms: number): Promise<this>;
1573
1693
  /**
1574
1694
  * Restarts the currently playing track from the beginning.
1575
1695
  * If there is no track playing, it will play the next track in the queue.
@@ -2136,5 +2256,5 @@ declare class Plugin {
2136
2256
  load(manager: Manager): void;
2137
2257
  }
2138
2258
 
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 };
2259
+ 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 };
2260
+ 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,77 @@
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
+ class CollectionPlayerStore {
7
+ store = new collection_1.Collection();
8
+ async get(guildId) {
9
+ return this.store.get(guildId);
10
+ }
11
+ async set(guildId, player) {
12
+ this.store.set(guildId, player);
13
+ }
14
+ async delete(guildId) {
15
+ this.store.delete(guildId);
16
+ }
17
+ async keys() {
18
+ return [...this.store.keys()];
19
+ }
20
+ async has(guildId) {
21
+ return this.store.has(guildId);
22
+ }
23
+ async filter(predicate) {
24
+ const result = new Map();
25
+ for (const [guildId, player] of this.store.entries()) {
26
+ if (await predicate(player, guildId)) {
27
+ result.set(guildId, player);
28
+ }
29
+ }
30
+ return result;
31
+ }
32
+ async find(predicate) {
33
+ for (const [guildId, player] of this.store.entries()) {
34
+ if (await predicate(player, guildId))
35
+ return player;
36
+ }
37
+ return undefined;
38
+ }
39
+ async map(callback) {
40
+ const results = [];
41
+ for (const [guildId, player] of this.store.entries()) {
42
+ results.push(await callback(player, guildId));
43
+ }
44
+ return results;
45
+ }
46
+ async forEach(callback) {
47
+ for (const [guildId, player] of this.store.entries()) {
48
+ await callback(player, guildId);
49
+ }
50
+ }
51
+ async some(predicate) {
52
+ for (const [guildId, player] of this.store.entries()) {
53
+ if (await predicate(player, guildId))
54
+ return true;
55
+ }
56
+ return false;
57
+ }
58
+ async every(predicate) {
59
+ for (const [guildId, player] of this.store.entries()) {
60
+ if (!(await predicate(player, guildId)))
61
+ return false;
62
+ }
63
+ return true;
64
+ }
65
+ async size() {
66
+ return this.store.size;
67
+ }
68
+ async clear() {
69
+ this.store.clear();
70
+ }
71
+ async *entries() {
72
+ for (const entry of this.store.entries()) {
73
+ yield entry;
74
+ }
75
+ }
76
+ }
77
+ exports.CollectionPlayerStore = CollectionPlayerStore;
@@ -0,0 +1,156 @@
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
+ class RedisPlayerStore {
6
+ redis;
7
+ manager;
8
+ prefix;
9
+ constructor(redis, manager, prefix = "magmastream:") {
10
+ this.redis = redis;
11
+ this.manager = manager;
12
+ this.prefix = prefix;
13
+ }
14
+ getKey(guildId) {
15
+ return `${this.prefix}player:${guildId}`;
16
+ }
17
+ async get(guildId) {
18
+ const raw = await this.redis.get(this.getKey(guildId));
19
+ if (!raw)
20
+ return undefined;
21
+ return JSON.parse(raw);
22
+ }
23
+ async set(guildId, player) {
24
+ const serialized = this.manager.serializePlayer(player);
25
+ await this.redis.set(this.getKey(guildId), JSON.stringify(serialized));
26
+ }
27
+ async delete(guildId) {
28
+ await this.redis.del(this.getKey(guildId));
29
+ }
30
+ async keys() {
31
+ const keys = await this.redis.keys(`${this.prefix}player:*`);
32
+ return keys.map((key) => key.replace(`${this.prefix}player:`, ""));
33
+ }
34
+ async has(guildId) {
35
+ return (await this.redis.exists(this.getKey(guildId))) === 1;
36
+ }
37
+ async filter(predicate) {
38
+ const keys = await this.keys();
39
+ const pipeline = this.redis.pipeline();
40
+ for (const guildId of keys) {
41
+ pipeline.get(this.getKey(guildId));
42
+ }
43
+ const results = await pipeline.exec();
44
+ const result = new Map();
45
+ for (let i = 0; i < results.length; i++) {
46
+ const [err, raw] = results[i];
47
+ if (err || typeof raw !== "string")
48
+ continue;
49
+ const guildId = keys[i];
50
+ const player = JSON.parse(raw);
51
+ if (await predicate(player, guildId)) {
52
+ result.set(guildId, player);
53
+ }
54
+ }
55
+ return result;
56
+ }
57
+ async find(predicate) {
58
+ for (const guildId of await this.keys()) {
59
+ const raw = await this.redis.get(this.getKey(guildId));
60
+ if (!raw)
61
+ continue;
62
+ const parsed = JSON.parse(raw);
63
+ if (await predicate(parsed, guildId))
64
+ return parsed;
65
+ }
66
+ return undefined;
67
+ }
68
+ async map(callback) {
69
+ const keys = await this.keys();
70
+ if (!keys.length)
71
+ return [];
72
+ const pipeline = this.redis.pipeline();
73
+ for (const guildId of keys) {
74
+ pipeline.get(this.getKey(guildId));
75
+ }
76
+ const results = await pipeline.exec();
77
+ const output = [];
78
+ for (let i = 0; i < results.length; i++) {
79
+ const [err, raw] = results[i];
80
+ if (err || typeof raw !== "string")
81
+ continue;
82
+ const guildId = keys[i];
83
+ const player = JSON.parse(raw);
84
+ output.push(await callback(player, guildId));
85
+ }
86
+ return output;
87
+ }
88
+ async forEach(callback) {
89
+ for (const guildId of await this.keys()) {
90
+ const raw = await this.redis.get(this.getKey(guildId));
91
+ if (!raw)
92
+ continue;
93
+ const parsed = JSON.parse(raw);
94
+ await callback(parsed, guildId);
95
+ }
96
+ }
97
+ async some(predicate) {
98
+ const keys = await this.keys();
99
+ if (!keys.length)
100
+ return false;
101
+ const pipeline = this.redis.pipeline();
102
+ for (const guildId of keys) {
103
+ pipeline.get(this.getKey(guildId));
104
+ }
105
+ const results = await pipeline.exec();
106
+ for (let i = 0; i < results.length; i++) {
107
+ const [err, raw] = results[i];
108
+ if (err || typeof raw !== "string")
109
+ continue;
110
+ const guildId = keys[i];
111
+ const player = JSON.parse(raw);
112
+ if (await predicate(player, guildId))
113
+ return true;
114
+ }
115
+ return false;
116
+ }
117
+ async every(predicate) {
118
+ const keys = await this.keys();
119
+ if (!keys.length)
120
+ return true;
121
+ const pipeline = this.redis.pipeline();
122
+ for (const guildId of keys) {
123
+ pipeline.get(this.getKey(guildId));
124
+ }
125
+ const results = await pipeline.exec();
126
+ for (let i = 0; i < results.length; i++) {
127
+ const [err, raw] = results[i];
128
+ if (err || typeof raw !== "string")
129
+ continue;
130
+ const guildId = keys[i];
131
+ const player = JSON.parse(raw);
132
+ if (!(await predicate(player, guildId)))
133
+ return false;
134
+ }
135
+ return true;
136
+ }
137
+ async size() {
138
+ const keys = await this.keys();
139
+ return keys.length;
140
+ }
141
+ async clear() {
142
+ const keys = await this.redis.keys(`${this.prefix}player:*`);
143
+ if (keys.length) {
144
+ await this.redis.del(...keys);
145
+ }
146
+ }
147
+ async *entries() {
148
+ for (const guildId of await this.keys()) {
149
+ const raw = await this.redis.get(this.getKey(guildId));
150
+ if (!raw)
151
+ continue;
152
+ yield [guildId, JSON.parse(raw)];
153
+ }
154
+ }
155
+ }
156
+ exports.RedisPlayerStore = RedisPlayerStore;