MemoryQueue
Table of Contentsโ
Class Definitionโ
export class MemoryQueue extends Array<Track> implements IQueue {}
Propertiesโ
Property Type Description currentTrack| nullThe current track. guildIdstring The guild ID. managerManagerThe Manager instance. previousTrack[]| []The previous tracks.
Constructorโ
new MemoryQueue(guildId: string, manager: Manager)
Parameter Type Description Optional guildIdstring The guild ID managerManagerThe Manager instance.
Methodsโ
add()โ
add(track: Track | Track[], offset?: number): voidAdds a track or an array of tracks to the queue.
Parametersโ
Parameter Type Description Optional trackTrack|Track[]The track or an array of tracks to add to the queue. offsetnumber The offset to add the track at.
addPrevious()โ
addPrevious(track: Track | Track[]): voidAdds one or more tracks to the "previous" history list.
Parametersโ
Parameter Type Description Optional trackTrack|Track[]The track to add to the "previous" history list.
clear()โ
clear(): voidClears the queue.
clearPrevious()โ
clearPrevious(): voidClears the "previous" history list.
dequeue()โ
dequeue(): Track | undefinedRemoves the first element from the queue.
Returnsโ
Type Description Track| undefinedThe first element in the queue, or undefinedif the queue is empty.
destroy()โ
destroy(): voidDestroys the queue and releases all resources. After calling this method, the queue must not be used again.
duration()โ
duration(): numberReturns the total duration of the queue.
Returnsโ
Type Description number The total duration of the queue in milliseconds.
enqueueFront()โ
enqueueFront(track: Track | Track[]): voidAdds a track or an array of tracks to the front of the queue.
Parametersโ
Parameter Type Description Optional trackTrack|Track[]The track or an array of tracks to add to the queue.
everyAsync()โ
everyAsync(callback: (track: Track, index: number, array: Track[]) => boolean): booleanTests whether all elements in the queue pass the test implemented by the provided function.
Parametersโ
Parameter Type Description Optional callbackFunction The callback function. Returnsโ
Type Description boolean trueif the callback function returns a truthy value for every element in the queue, otherwisefalse.
filterAsync()โ
filterAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Track | undefinedFilters the queue.
Parametersโ
Parameter Type Description Optional callbackFunction The callback function. Returnsโ
Type Description Track| undefinedThe first element in the queue, or undefinedif the queue is empty.
findAsync()โ
findAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Track | undefinedReturns the first element in the queue that satisfies the provided testing function.
Parametersโ
Parameter Type Description Optional callbackFunction The callback function. Returnsโ
Type Description Track| undefinedThe first element in the queue, or undefinedif the queue is empty.
getCurrent()โ
getCurrent(): Track | nullReturns the currently playing track.
Returnsโ
Type Description Track| nullThe current track, or nullif no track is playing.
getPrevious()โ
getPrevious(): Track[]Returns the previous tracks.
Returnsโ
Type Description Track[]The previous tracks.
getSlice()โ
getSlice(start?: number, end?: number): Track[]Returns a slice of the queue.
Parametersโ
Parameter Type Description Optional startnumber Start index of the range of tracks to remove. endnumber End index (exclusive) of the range of tracks to remove. Returnsโ
Type Description Track[]The tracks in the queue.
getTracks()โ
getTracks(): Track[]Returns the tracks in the queue.
Returnsโ
Type Description Track[]The tracks in the queue.
mapAsync()โ
mapAsync<T>(callback: (track: Track, index: number, array: Track[]) => T): T[]Maps the queue to an array of values.
Parametersโ
Parameter Type Description Optional callbackFunction The callback function.
modifyAt()โ
modifyAt(start: number, deleteCount = 0, ...items: Track[]): Track[]Modifies a range of tracks in the queue.
Parametersโ
Parameter Type Description Optional startnumber Start index of the range of tracks to remove. deleteCountnumber Number of tracks to remove. itemsTrack[]Array of tracks to insert. Returnsโ
Type Description Track[]The tracks in the queue.
popPrevious()โ
popPrevious(): Track | nullRemoves and returns the last track from the "previous" history list.
Returnsโ
Type Description Track| nullThe last track in the "previous" history list, or nullif the list is empty.
remove()โ
remove(position?: number): Track[]remove(start: number, end: number): Track[]Removes a track or a range of tracks from the queue.
Parametersโ
Parameter Type Description Optional positionnumber Index of the track to remove. startnumber Start index of the range of tracks to remove. endnumber End index (exclusive) of the range of tracks to remove. Returnsโ
Type Description Track[]The removed track(s).
roundRobinShuffle()โ
roundRobinShuffle(): voidShuffles the queue to play tracks requested by each user one by one.
setCurrent()โ
setCurrent(track: Track | null): voidSets the currently playing track.
Parametersโ
Parameter Type Description Optional trackTrack| nullThe track to set as the current track.
setPrevious()โ
setPrevious(tracks: Track[]): voidSets the previous tracks.
Parametersโ
Parameter Type Description Optional tracksTrack[]The previous tracks to set.
shuffle()โ
shuffle(): voidShuffles the queue.
size()โ
size(): numberReturns the size of the queue not including the current track.
Returnsโ
Type Description number The size of the queue.
someAsync()โ
someAsync(callback: (track: Track, index: number, array: Track[]) => boolean): booleanTests whether at least one element in the queue passes the test implemented by the provided function.
Parametersโ
Parameter Type Description Optional callbackFunction The callback function. Returnsโ
Type Description boolean trueif the callback function returns a truthy value for at least one element in the queue, otherwisefalse.
totalSize()โ
totalSize(): numberReturns the total size of the queue.
Returnsโ
Type Description number The total size of the queue.
userBlockShuffle()โ
userBlockShuffle(): voidShuffles the queue to play tracks requested by each user one block at a time.