magmastream 2.7.2 → 2.7.3
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 +1 -0
- package/dist/index.d.ts +45 -16
- package/dist/structures/Manager.js +15 -8
- package/dist/structures/Node.js +48 -13
- package/dist/structures/Player.js +8 -8
- package/dist/structures/Utils.js +30 -1
- package/dist/utils/managerCheck.js +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,6 +45,7 @@ Also you can join the [Discord Support Server](https://discord.com/invite/HV59Z3
|
|
|
45
45
|
| [JukeDisc](https://discord.com/oauth2/authorize?client_id=1109751797549105176&permissions=968552214080&scope=bot+applications.commands) | Theo |
|
|
46
46
|
| [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 |
|
|
47
47
|
| [Soundy](https://dsc.gg/sndy) | iaMJ |
|
|
48
|
+
| [HamBot](https://discord.com/oauth2/authorize?client_id=1049314312776335390) | yanishamburger|
|
|
48
49
|
|
|
49
50
|
If you want to add your own bot create a pull request with your bot added. Please add your full name.
|
|
50
51
|
|
package/dist/index.d.ts
CHANGED
|
@@ -371,7 +371,7 @@ declare class Player {
|
|
|
371
371
|
/**The now playing message. */
|
|
372
372
|
nowPlayingMessage?: Message;
|
|
373
373
|
/** The current state of the player. */
|
|
374
|
-
state:
|
|
374
|
+
state: StateTypes;
|
|
375
375
|
/** The equalizer bands array. */
|
|
376
376
|
bands: number[];
|
|
377
377
|
/** The voice state object from Discord. */
|
|
@@ -1269,13 +1269,32 @@ declare enum LoadTypes {
|
|
|
1269
1269
|
Error = "error"
|
|
1270
1270
|
}
|
|
1271
1271
|
type LoadType = keyof typeof LoadTypes;
|
|
1272
|
-
|
|
1272
|
+
declare enum StateTypes {
|
|
1273
|
+
Connected = "CONNECTED",
|
|
1274
|
+
Connecting = "CONNECTING",
|
|
1275
|
+
Disconnected = "DISCONNECTED",
|
|
1276
|
+
Disconnecting = "DISCONNECTING",
|
|
1277
|
+
Destroying = "DESTROYING"
|
|
1278
|
+
}
|
|
1279
|
+
type State = keyof typeof StateTypes;
|
|
1273
1280
|
type SponsorBlockSegmentEvents = SponsorBlockSegmentSkipped | SponsorBlockSegmentsLoaded | SponsorBlockChapterStarted | SponsorBlockChaptersLoaded;
|
|
1274
1281
|
type SponsorBlockSegmentEventType = "SegmentSkipped" | "SegmentsLoaded" | "ChapterStarted" | "ChaptersLoaded";
|
|
1275
1282
|
type PlayerEvents = TrackStartEvent | TrackEndEvent | TrackStuckEvent | TrackExceptionEvent | WebSocketClosedEvent | SponsorBlockSegmentEvents;
|
|
1276
1283
|
type PlayerEventType = "TrackStartEvent" | "TrackEndEvent" | "TrackExceptionEvent" | "TrackStuckEvent" | "WebSocketClosedEvent" | "SegmentSkipped" | "SegmentsLoaded" | "ChaptersLoaded" | "ChapterStarted";
|
|
1277
|
-
|
|
1278
|
-
|
|
1284
|
+
declare enum TrackEndReasonTypes {
|
|
1285
|
+
Finished = "finished",
|
|
1286
|
+
LoadFailed = "loadFailed",
|
|
1287
|
+
Stopped = "stopped",
|
|
1288
|
+
Replaced = "replaced",
|
|
1289
|
+
Cleanup = "cleanup"
|
|
1290
|
+
}
|
|
1291
|
+
type TrackEndReason = keyof typeof TrackEndReasonTypes;
|
|
1292
|
+
declare enum SeverityTypes {
|
|
1293
|
+
Common = "common",
|
|
1294
|
+
Suspicious = "suspicious",
|
|
1295
|
+
Fault = "fault"
|
|
1296
|
+
}
|
|
1297
|
+
type Severity = keyof typeof SeverityTypes;
|
|
1279
1298
|
interface TrackData {
|
|
1280
1299
|
/** The track information. */
|
|
1281
1300
|
encoded: string;
|
|
@@ -1296,7 +1315,13 @@ interface TrackDataInfo {
|
|
|
1296
1315
|
artworkUrl?: string;
|
|
1297
1316
|
sourceName?: TrackSourceName;
|
|
1298
1317
|
}
|
|
1299
|
-
|
|
1318
|
+
declare enum TrackSourceTypes {
|
|
1319
|
+
Spotify = "spotify",
|
|
1320
|
+
Deezer = "deezer",
|
|
1321
|
+
SoundCloud = "soundcloud",
|
|
1322
|
+
YouTube = "youtube"
|
|
1323
|
+
}
|
|
1324
|
+
type TrackSourceName = keyof typeof TrackSourceTypes;
|
|
1300
1325
|
interface Extendable {
|
|
1301
1326
|
Player: typeof Player;
|
|
1302
1327
|
Queue: typeof Queue;
|
|
@@ -1335,7 +1360,7 @@ interface PlayerEvent {
|
|
|
1335
1360
|
}
|
|
1336
1361
|
interface Exception {
|
|
1337
1362
|
message: string;
|
|
1338
|
-
severity:
|
|
1363
|
+
severity: SeverityTypes;
|
|
1339
1364
|
cause: string;
|
|
1340
1365
|
}
|
|
1341
1366
|
interface TrackStartEvent extends PlayerEvent {
|
|
@@ -1345,7 +1370,7 @@ interface TrackStartEvent extends PlayerEvent {
|
|
|
1345
1370
|
interface TrackEndEvent extends PlayerEvent {
|
|
1346
1371
|
type: "TrackEndEvent";
|
|
1347
1372
|
track: TrackData;
|
|
1348
|
-
reason:
|
|
1373
|
+
reason: TrackEndReasonTypes;
|
|
1349
1374
|
}
|
|
1350
1375
|
interface TrackExceptionEvent extends PlayerEvent {
|
|
1351
1376
|
exception?: Exception;
|
|
@@ -1525,6 +1550,7 @@ declare class Manager extends EventEmitter {
|
|
|
1525
1550
|
* @param options.plugins - An array of plugins to load.
|
|
1526
1551
|
* @param options.nodes - An array of node options to create nodes from.
|
|
1527
1552
|
* @param options.autoPlay - Whether to automatically play the first track in the queue when the player is created.
|
|
1553
|
+
* @param options.autoPlaySearchPlatform - The search platform autoplay will use. Failback to Youtube if not found.
|
|
1528
1554
|
* @param options.usePriority - Whether to use the priority when selecting a node to play on.
|
|
1529
1555
|
* @param options.clientName - The name of the client to send to Lavalink.
|
|
1530
1556
|
* @param options.defaultSearchPlatform - The default search platform to use when searching for tracks.
|
|
@@ -1633,7 +1659,7 @@ interface ManagerOptions {
|
|
|
1633
1659
|
/** Use priority mode over least amount of player or load? */
|
|
1634
1660
|
usePriority?: boolean;
|
|
1635
1661
|
/** Use the least amount of players or least load? */
|
|
1636
|
-
useNode?:
|
|
1662
|
+
useNode?: UseNodeOptions.LeastLoad | UseNodeOptions.LeastPlayers;
|
|
1637
1663
|
/** The array of nodes to connect to. */
|
|
1638
1664
|
nodes?: NodeOptions[];
|
|
1639
1665
|
/** The client ID to use. */
|
|
@@ -1644,16 +1670,19 @@ interface ManagerOptions {
|
|
|
1644
1670
|
plugins?: Plugin[];
|
|
1645
1671
|
/** Whether players should automatically play the next song. */
|
|
1646
1672
|
autoPlay?: boolean;
|
|
1673
|
+
/** The search platform autoplay should use. Failback to Youtube if not found.
|
|
1674
|
+
* Use enum `SearchPlatform`. */
|
|
1675
|
+
autoPlaySearchPlatform?: SearchPlatform;
|
|
1647
1676
|
/** An array of track properties to keep. `track` will always be present. */
|
|
1648
1677
|
trackPartial?: string[];
|
|
1649
|
-
/** The default search platform to use.
|
|
1678
|
+
/** The default search platform to use.
|
|
1679
|
+
* Use enum `SearchPlatform`. */
|
|
1650
1680
|
defaultSearchPlatform?: SearchPlatform;
|
|
1651
1681
|
/** Whether the YouTube video titles should be replaced if the Author does not exactly match. */
|
|
1652
1682
|
replaceYouTubeCredentials?: boolean;
|
|
1653
1683
|
/** The last.fm API key.
|
|
1654
1684
|
* If you need to create one go here: https://www.last.fm/api/account/create.
|
|
1655
|
-
* If you already have one, get it from here: https://www.last.fm/api/accounts.
|
|
1656
|
-
*/
|
|
1685
|
+
* If you already have one, get it from here: https://www.last.fm/api/accounts. */
|
|
1657
1686
|
lastFmApiKey: string;
|
|
1658
1687
|
/**
|
|
1659
1688
|
* Function to send data to the websocket.
|
|
@@ -1662,10 +1691,10 @@ interface ManagerOptions {
|
|
|
1662
1691
|
*/
|
|
1663
1692
|
send(id: string, payload: Payload): void;
|
|
1664
1693
|
}
|
|
1665
|
-
declare
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
}
|
|
1694
|
+
declare enum UseNodeOptions {
|
|
1695
|
+
LeastLoad = "leastLoad",
|
|
1696
|
+
LeastPlayers = "leastPlayers"
|
|
1697
|
+
}
|
|
1669
1698
|
type UseNodeOption = keyof typeof UseNodeOptions;
|
|
1670
1699
|
declare enum SearchPlatform {
|
|
1671
1700
|
YouTubeMusic = "ytmsearch",
|
|
@@ -1840,4 +1869,4 @@ interface ManagerEvents {
|
|
|
1840
1869
|
[ManagerEventTypes.ChaptersLoaded]: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockChaptersLoaded];
|
|
1841
1870
|
}
|
|
1842
1871
|
|
|
1843
|
-
export { type CPUStats, type EqualizerBand, type Exception, type Extendable, type FrameStats, type LavalinkInfo, type LavalinkResponse, type LoadType, LoadTypes, Manager, ManagerEventTypes, type ManagerEvents, type ManagerOptions, type MemoryStats, Node, type NodeMessage, type NodeOptions, type NodeStats, type Payload, type PlayOptions, Player, type PlayerEvent, type PlayerEventType, type PlayerEvents, type PlayerOptions, PlayerStateEventTypes, type PlayerUpdate, type PlaylistData, type PlaylistInfoData, type PlaylistRawData, Plugin, Queue, SearchPlatform, type SearchQuery, type SearchResult, type Severity, type Sizes, type SponsorBlockChapterStarted, type SponsorBlockChaptersLoaded, type SponsorBlockSegment, type SponsorBlockSegmentEventType, type SponsorBlockSegmentEvents, type SponsorBlockSegmentSkipped, type SponsorBlockSegmentsLoaded, type State, Structure, type Track, type TrackData, type TrackDataInfo, type TrackEndEvent, type TrackEndReason, type TrackExceptionEvent, type TrackPluginInfo, type TrackSourceName, type TrackStartEvent, type TrackStuckEvent, TrackUtils, type UnresolvedQuery, type UnresolvedTrack, type UseNodeOption, UseNodeOptions, type VoicePacket, type VoiceServer, type VoiceState, type WebSocketClosedEvent, validSponsorBlocks };
|
|
1872
|
+
export { type CPUStats, type EqualizerBand, type Exception, type Extendable, type FrameStats, type LavalinkInfo, type LavalinkResponse, type LoadType, LoadTypes, Manager, ManagerEventTypes, type ManagerEvents, type ManagerOptions, type MemoryStats, Node, type NodeMessage, type NodeOptions, type NodeStats, type Payload, type PlayOptions, Player, type PlayerEvent, type PlayerEventType, type PlayerEvents, type PlayerOptions, PlayerStateEventTypes, type PlayerUpdate, type PlaylistData, type PlaylistInfoData, type PlaylistRawData, Plugin, Queue, SearchPlatform, type SearchQuery, type SearchResult, type Severity, SeverityTypes, type Sizes, type SponsorBlockChapterStarted, type SponsorBlockChaptersLoaded, type SponsorBlockSegment, type SponsorBlockSegmentEventType, type SponsorBlockSegmentEvents, type SponsorBlockSegmentSkipped, type SponsorBlockSegmentsLoaded, type State, StateTypes, Structure, type Track, type TrackData, type TrackDataInfo, type TrackEndEvent, type TrackEndReason, TrackEndReasonTypes, type TrackExceptionEvent, type TrackPluginInfo, type TrackSourceName, TrackSourceTypes, type TrackStartEvent, type TrackStuckEvent, TrackUtils, type UnresolvedQuery, type UnresolvedTrack, type UseNodeOption, UseNodeOptions, type VoicePacket, type VoiceServer, type VoiceState, type WebSocketClosedEvent, validSponsorBlocks };
|
|
@@ -183,7 +183,7 @@ class Manager extends events_1.EventEmitter {
|
|
|
183
183
|
// Get the player instance from the manager's collection
|
|
184
184
|
const player = this.players.get(guildId);
|
|
185
185
|
// If the player does not exist or is disconnected, or the voice channel is not specified, do not save the player state
|
|
186
|
-
if (!player || player.state ===
|
|
186
|
+
if (!player || player.state === Utils_1.StateTypes.Disconnected || !player.voiceChannel) {
|
|
187
187
|
// Clean up any inactive players
|
|
188
188
|
return this.cleanupInactivePlayers();
|
|
189
189
|
}
|
|
@@ -312,7 +312,7 @@ class Manager extends events_1.EventEmitter {
|
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
// If no node has a cumulative weight greater than or equal to the random number, return the node with the lowest load
|
|
315
|
-
return this.options.useNode ===
|
|
315
|
+
return this.options.useNode === UseNodeOptions.LeastLoad ? this.leastLoadNode.first() : this.leastPlayersNode.first();
|
|
316
316
|
}
|
|
317
317
|
/**
|
|
318
318
|
* Returns the node to use based on the configured `useNode` and `usePriority` options.
|
|
@@ -322,7 +322,11 @@ class Manager extends events_1.EventEmitter {
|
|
|
322
322
|
* @returns {Node} The node to use.
|
|
323
323
|
*/
|
|
324
324
|
get useableNodes() {
|
|
325
|
-
return this.options.usePriority
|
|
325
|
+
return this.options.usePriority
|
|
326
|
+
? this.priorityNode
|
|
327
|
+
: this.options.useNode === UseNodeOptions.LeastLoad
|
|
328
|
+
? this.leastLoadNode.first()
|
|
329
|
+
: this.leastPlayersNode.first();
|
|
326
330
|
}
|
|
327
331
|
lastSaveTimes = new Map();
|
|
328
332
|
eventBatchInterval = null;
|
|
@@ -396,6 +400,7 @@ class Manager extends events_1.EventEmitter {
|
|
|
396
400
|
* @param options.plugins - An array of plugins to load.
|
|
397
401
|
* @param options.nodes - An array of node options to create nodes from.
|
|
398
402
|
* @param options.autoPlay - Whether to automatically play the first track in the queue when the player is created.
|
|
403
|
+
* @param options.autoPlaySearchPlatform - The search platform autoplay will use. Failback to Youtube if not found.
|
|
399
404
|
* @param options.usePriority - Whether to use the priority when selecting a node to play on.
|
|
400
405
|
* @param options.clientName - The name of the client to send to Lavalink.
|
|
401
406
|
* @param options.defaultSearchPlatform - The default search platform to use when searching for tracks.
|
|
@@ -429,7 +434,8 @@ class Manager extends events_1.EventEmitter {
|
|
|
429
434
|
usePriority: false,
|
|
430
435
|
clientName: "Magmastream",
|
|
431
436
|
defaultSearchPlatform: SearchPlatform.YouTube,
|
|
432
|
-
|
|
437
|
+
autoPlaySearchPlatform: SearchPlatform.YouTube,
|
|
438
|
+
useNode: UseNodeOptions.LeastPlayers,
|
|
433
439
|
...options,
|
|
434
440
|
};
|
|
435
441
|
if (this.options.plugins) {
|
|
@@ -769,10 +775,11 @@ class Manager extends events_1.EventEmitter {
|
|
|
769
775
|
}
|
|
770
776
|
}
|
|
771
777
|
exports.Manager = Manager;
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
778
|
+
var UseNodeOptions;
|
|
779
|
+
(function (UseNodeOptions) {
|
|
780
|
+
UseNodeOptions["LeastLoad"] = "leastLoad";
|
|
781
|
+
UseNodeOptions["LeastPlayers"] = "leastPlayers";
|
|
782
|
+
})(UseNodeOptions || (exports.UseNodeOptions = UseNodeOptions = {}));
|
|
776
783
|
var SearchPlatform;
|
|
777
784
|
(function (SearchPlatform) {
|
|
778
785
|
SearchPlatform["YouTubeMusic"] = "ytmsearch";
|
package/dist/structures/Node.js
CHANGED
|
@@ -476,7 +476,7 @@ class Node {
|
|
|
476
476
|
this.handleFailedTrack(player, track, payload);
|
|
477
477
|
}
|
|
478
478
|
// If the track was forcibly replaced
|
|
479
|
-
else if (reason ===
|
|
479
|
+
else if (reason === Utils_1.TrackEndReasonTypes.Replaced) {
|
|
480
480
|
this.manager.emit(Manager_1.ManagerEventTypes.TrackEnd, player, track, payload);
|
|
481
481
|
player.queue.previous = player.queue.current;
|
|
482
482
|
}
|
|
@@ -533,12 +533,13 @@ class Node {
|
|
|
533
533
|
return false;
|
|
534
534
|
const previousTrack = player.queue.previous;
|
|
535
535
|
const apiKey = this.manager.options.lastFmApiKey;
|
|
536
|
+
const enabledSources = this.info.sourceManagers;
|
|
536
537
|
// If Last.fm API is not available and YouTube is not supported
|
|
537
|
-
if (!apiKey && !
|
|
538
|
+
if (!apiKey && !enabledSources.includes("youtube"))
|
|
538
539
|
return false;
|
|
539
540
|
// Handle YouTube autoplay logic
|
|
540
|
-
if ((!apiKey &&
|
|
541
|
-
(attempt === player.autoplayTries - 1 && !(apiKey && player.autoplayTries === 1) &&
|
|
541
|
+
if ((!apiKey && enabledSources.includes("youtube")) ||
|
|
542
|
+
(attempt === player.autoplayTries - 1 && !(apiKey && player.autoplayTries === 1) && enabledSources.includes("youtube"))) {
|
|
542
543
|
const hasYouTubeURL = ["youtube.com", "youtu.be"].some((url) => previousTrack.uri.includes(url));
|
|
543
544
|
const videoID = hasYouTubeURL
|
|
544
545
|
? previousTrack.uri.split("=").pop()
|
|
@@ -563,17 +564,51 @@ class Node {
|
|
|
563
564
|
}
|
|
564
565
|
// Handle Last.fm-based autoplay logic
|
|
565
566
|
let { author: artist } = previousTrack;
|
|
566
|
-
const { title
|
|
567
|
-
|
|
568
|
-
const
|
|
569
|
-
|
|
567
|
+
const { title } = previousTrack;
|
|
568
|
+
// Create a mapping of enum values to their string representations
|
|
569
|
+
const platformMapping = {
|
|
570
|
+
[Manager_1.SearchPlatform.AppleMusic]: "applemusic",
|
|
571
|
+
[Manager_1.SearchPlatform.Bandcamp]: "bandcamp",
|
|
572
|
+
[Manager_1.SearchPlatform.Deezer]: "deezer",
|
|
573
|
+
[Manager_1.SearchPlatform.Jiosaavn]: "jiosaavn",
|
|
574
|
+
[Manager_1.SearchPlatform.SoundCloud]: "soundcloud",
|
|
575
|
+
[Manager_1.SearchPlatform.Spotify]: "spotify",
|
|
576
|
+
[Manager_1.SearchPlatform.Tidal]: "tidal",
|
|
577
|
+
[Manager_1.SearchPlatform.YouTube]: "youtube",
|
|
578
|
+
[Manager_1.SearchPlatform.YouTubeMusic]: "youtube",
|
|
579
|
+
};
|
|
570
580
|
let selectedSource = null;
|
|
571
|
-
|
|
572
|
-
|
|
581
|
+
// Get the autoPlaySearchPlatform and available sources
|
|
582
|
+
const { autoPlaySearchPlatform } = this.manager.options;
|
|
583
|
+
if (enabledSources.includes(platformMapping[autoPlaySearchPlatform])) {
|
|
584
|
+
selectedSource = autoPlaySearchPlatform;
|
|
573
585
|
}
|
|
574
586
|
else {
|
|
575
|
-
|
|
587
|
+
// Fallback to SearchPlatform.YouTube
|
|
588
|
+
const fallbackPlatform = Manager_1.SearchPlatform.YouTube;
|
|
589
|
+
if (enabledSources.includes(platformMapping[fallbackPlatform])) {
|
|
590
|
+
selectedSource = fallbackPlatform;
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
// Check for other platforms in the specified order
|
|
594
|
+
const alternativePlatforms = [
|
|
595
|
+
Manager_1.SearchPlatform.Deezer, // 1
|
|
596
|
+
Manager_1.SearchPlatform.SoundCloud, // 2
|
|
597
|
+
Manager_1.SearchPlatform.AppleMusic, // 2
|
|
598
|
+
Manager_1.SearchPlatform.Bandcamp, // 3
|
|
599
|
+
Manager_1.SearchPlatform.Jiosaavn, // 4
|
|
600
|
+
Manager_1.SearchPlatform.Tidal, // 5
|
|
601
|
+
];
|
|
602
|
+
for (const platform of alternativePlatforms) {
|
|
603
|
+
if (enabledSources.includes(platformMapping[platform])) {
|
|
604
|
+
selectedSource = platform;
|
|
605
|
+
break; // Exit the loop once a valid platform is found
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
576
609
|
}
|
|
610
|
+
if (!selectedSource)
|
|
611
|
+
return false;
|
|
577
612
|
if (!artist || !title) {
|
|
578
613
|
if (!title) {
|
|
579
614
|
const noTitleUrl = `https://ws.audioscrobbler.com/2.0/?method=artist.getTopTracks&artist=${artist}&autocorrect=1&api_key=${apiKey}&format=json`;
|
|
@@ -591,7 +626,7 @@ class Node {
|
|
|
591
626
|
player.play();
|
|
592
627
|
return true;
|
|
593
628
|
}
|
|
594
|
-
|
|
629
|
+
if (!artist) {
|
|
595
630
|
const noArtistUrl = `https://ws.audioscrobbler.com/2.0/?method=track.search&track=${title}&api_key=${apiKey}&format=json`;
|
|
596
631
|
const response = await axios_1.default.get(noArtistUrl);
|
|
597
632
|
artist = response.data.results.trackmatches?.track?.[0]?.artist;
|
|
@@ -671,7 +706,7 @@ class Node {
|
|
|
671
706
|
// Emit the track end event
|
|
672
707
|
this.manager.emit(Manager_1.ManagerEventTypes.TrackEnd, player, track, payload);
|
|
673
708
|
// If the track was stopped manually and there are no more tracks in the queue, end the queue
|
|
674
|
-
if (payload.reason ===
|
|
709
|
+
if (payload.reason === Utils_1.TrackEndReasonTypes.Stopped && !(queue.current = queue.shift())) {
|
|
675
710
|
this.queueEnd(player, track, payload);
|
|
676
711
|
return;
|
|
677
712
|
}
|
|
@@ -39,7 +39,7 @@ class Player {
|
|
|
39
39
|
/**The now playing message. */
|
|
40
40
|
nowPlayingMessage;
|
|
41
41
|
/** The current state of the player. */
|
|
42
|
-
state =
|
|
42
|
+
state = Utils_1.StateTypes.Disconnected;
|
|
43
43
|
/** The equalizer bands array. */
|
|
44
44
|
bands = new Array(15).fill(0.0);
|
|
45
45
|
/** The voice state object from Discord. */
|
|
@@ -143,7 +143,7 @@ class Player {
|
|
|
143
143
|
connect() {
|
|
144
144
|
if (!this.voiceChannel)
|
|
145
145
|
throw new RangeError("No voice channel has been set.");
|
|
146
|
-
this.state =
|
|
146
|
+
this.state = Utils_1.StateTypes.Connecting;
|
|
147
147
|
const oldPlayer = this ? { ...this } : null;
|
|
148
148
|
// Send the voice state update to the gateway
|
|
149
149
|
this.manager.options.send(this.guild, {
|
|
@@ -156,13 +156,13 @@ class Player {
|
|
|
156
156
|
},
|
|
157
157
|
});
|
|
158
158
|
// Set the player state to connected
|
|
159
|
-
this.state =
|
|
159
|
+
this.state = Utils_1.StateTypes.Connected;
|
|
160
160
|
// Emit the player state update event
|
|
161
161
|
this.manager.emit(Manager_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this, {
|
|
162
162
|
changeType: Manager_1.PlayerStateEventTypes.ConnectionChange,
|
|
163
163
|
details: {
|
|
164
164
|
changeType: "connect",
|
|
165
|
-
previousConnection: oldPlayer?.state ===
|
|
165
|
+
previousConnection: oldPlayer?.state === Utils_1.StateTypes.Connected,
|
|
166
166
|
currentConnection: true,
|
|
167
167
|
},
|
|
168
168
|
});
|
|
@@ -176,7 +176,7 @@ class Player {
|
|
|
176
176
|
disconnect() {
|
|
177
177
|
if (this.voiceChannel === null)
|
|
178
178
|
return this;
|
|
179
|
-
this.state =
|
|
179
|
+
this.state = Utils_1.StateTypes.Disconnecting;
|
|
180
180
|
const oldPlayer = this ? { ...this } : null;
|
|
181
181
|
this.pause(true);
|
|
182
182
|
this.manager.options.send(this.guild, {
|
|
@@ -189,12 +189,12 @@ class Player {
|
|
|
189
189
|
},
|
|
190
190
|
});
|
|
191
191
|
this.voiceChannel = null;
|
|
192
|
-
this.state =
|
|
192
|
+
this.state = Utils_1.StateTypes.Disconnected;
|
|
193
193
|
this.manager.emit(Manager_1.ManagerEventTypes.PlayerStateUpdate, oldPlayer, this, {
|
|
194
194
|
changeType: Manager_1.PlayerStateEventTypes.ConnectionChange,
|
|
195
195
|
details: {
|
|
196
196
|
changeType: "disconnect",
|
|
197
|
-
previousConnection: oldPlayer.state ===
|
|
197
|
+
previousConnection: oldPlayer.state === Utils_1.StateTypes.Connected,
|
|
198
198
|
currentConnection: false,
|
|
199
199
|
},
|
|
200
200
|
});
|
|
@@ -210,7 +210,7 @@ class Player {
|
|
|
210
210
|
*/
|
|
211
211
|
destroy(disconnect = true) {
|
|
212
212
|
const oldPlayer = this ? { ...this } : null;
|
|
213
|
-
this.state =
|
|
213
|
+
this.state = Utils_1.StateTypes.Destroying;
|
|
214
214
|
if (disconnect) {
|
|
215
215
|
this.disconnect();
|
|
216
216
|
}
|
package/dist/structures/Utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LoadTypes = exports.Plugin = exports.Structure = exports.TrackUtils = void 0;
|
|
3
|
+
exports.TrackSourceTypes = exports.SeverityTypes = exports.TrackEndReasonTypes = exports.StateTypes = exports.LoadTypes = exports.Plugin = exports.Structure = exports.TrackUtils = void 0;
|
|
4
4
|
/** @hidden */
|
|
5
5
|
const TRACK_SYMBOL = Symbol("track"),
|
|
6
6
|
/** @hidden */
|
|
@@ -271,3 +271,32 @@ var LoadTypes;
|
|
|
271
271
|
LoadTypes["Empty"] = "empty";
|
|
272
272
|
LoadTypes["Error"] = "error";
|
|
273
273
|
})(LoadTypes || (exports.LoadTypes = LoadTypes = {}));
|
|
274
|
+
var StateTypes;
|
|
275
|
+
(function (StateTypes) {
|
|
276
|
+
StateTypes["Connected"] = "CONNECTED";
|
|
277
|
+
StateTypes["Connecting"] = "CONNECTING";
|
|
278
|
+
StateTypes["Disconnected"] = "DISCONNECTED";
|
|
279
|
+
StateTypes["Disconnecting"] = "DISCONNECTING";
|
|
280
|
+
StateTypes["Destroying"] = "DESTROYING";
|
|
281
|
+
})(StateTypes || (exports.StateTypes = StateTypes = {}));
|
|
282
|
+
var TrackEndReasonTypes;
|
|
283
|
+
(function (TrackEndReasonTypes) {
|
|
284
|
+
TrackEndReasonTypes["Finished"] = "finished";
|
|
285
|
+
TrackEndReasonTypes["LoadFailed"] = "loadFailed";
|
|
286
|
+
TrackEndReasonTypes["Stopped"] = "stopped";
|
|
287
|
+
TrackEndReasonTypes["Replaced"] = "replaced";
|
|
288
|
+
TrackEndReasonTypes["Cleanup"] = "cleanup";
|
|
289
|
+
})(TrackEndReasonTypes || (exports.TrackEndReasonTypes = TrackEndReasonTypes = {}));
|
|
290
|
+
var SeverityTypes;
|
|
291
|
+
(function (SeverityTypes) {
|
|
292
|
+
SeverityTypes["Common"] = "common";
|
|
293
|
+
SeverityTypes["Suspicious"] = "suspicious";
|
|
294
|
+
SeverityTypes["Fault"] = "fault";
|
|
295
|
+
})(SeverityTypes || (exports.SeverityTypes = SeverityTypes = {}));
|
|
296
|
+
var TrackSourceTypes;
|
|
297
|
+
(function (TrackSourceTypes) {
|
|
298
|
+
TrackSourceTypes["Spotify"] = "spotify";
|
|
299
|
+
TrackSourceTypes["Deezer"] = "deezer";
|
|
300
|
+
TrackSourceTypes["SoundCloud"] = "soundcloud";
|
|
301
|
+
TrackSourceTypes["YouTube"] = "youtube";
|
|
302
|
+
})(TrackSourceTypes || (exports.TrackSourceTypes = TrackSourceTypes = {}));
|
|
@@ -10,7 +10,7 @@ const Manager_1 = require("../structures/Manager");
|
|
|
10
10
|
function managerCheck(options) {
|
|
11
11
|
if (!options)
|
|
12
12
|
throw new TypeError("ManagerOptions must not be empty.");
|
|
13
|
-
const { autoPlay, clientName, defaultSearchPlatform, nodes, plugins, send, trackPartial, usePriority, useNode, replaceYouTubeCredentials, lastFmApiKey } = options;
|
|
13
|
+
const { autoPlay, clientName, defaultSearchPlatform, autoPlaySearchPlatform, nodes, plugins, send, trackPartial, usePriority, useNode, replaceYouTubeCredentials, lastFmApiKey } = options;
|
|
14
14
|
// Validate autoPlay option
|
|
15
15
|
if (typeof autoPlay !== "boolean") {
|
|
16
16
|
throw new TypeError('Manager option "autoPlay" must be a boolean.');
|
|
@@ -27,6 +27,12 @@ function managerCheck(options) {
|
|
|
27
27
|
throw new TypeError(`Manager option "defaultSearchPlatform" must be one of: ${Object.values(Manager_1.SearchPlatform).join(", ")}.`);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
// Validate autoPlaySearchPlatform
|
|
31
|
+
if (typeof autoPlaySearchPlatform !== "undefined") {
|
|
32
|
+
if (!Object.values(Manager_1.SearchPlatform).includes(autoPlaySearchPlatform)) {
|
|
33
|
+
throw new TypeError(`Manager option "autoPlaySearchPlatform" must be one of: ${Object.values(Manager_1.SearchPlatform).join(", ")}.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
30
36
|
// Validate nodes option
|
|
31
37
|
if (typeof nodes === "undefined" || !Array.isArray(nodes)) {
|
|
32
38
|
throw new TypeError('Manager option "nodes" must be an array.');
|
|
@@ -65,7 +71,7 @@ function managerCheck(options) {
|
|
|
65
71
|
if (typeof useNode !== "string") {
|
|
66
72
|
throw new TypeError('Manager option "useNode" must be a string "leastLoad" or "leastPlayers".');
|
|
67
73
|
}
|
|
68
|
-
if (!(
|
|
74
|
+
if (!Object.values(Manager_1.UseNodeOptions).includes(useNode)) {
|
|
69
75
|
throw new TypeError('Manager option "useNode" must be either "leastLoad" or "leastPlayers".');
|
|
70
76
|
}
|
|
71
77
|
}
|