songqueue module

Implementation of a queue to be used by the music cog.

class songqueue.SongQueue

Bases: object

Class to manage queues of Song(s). Uses a list of Songs and adds some methods to simplify operations in the cogs.

push(song: cogs.ext.song.Song)

Add a song at the end of the queue.

Parameters

song (Song) – The song to append.

pop(index: int = 1) Optional[cogs.ext.song.Song]

Pop the song at position index, if it exists.

Parameters

index (int) – The index of the song to pop. 1 by default to pop the first song.

Returns

The song at position index if it exists, None if not.

Return type

Union[Song, None]

get_songs() Deque[cogs.ext.song.Song]

Simple getter.

Returns

The actual deque of Songs.

Return type

deque[Song]

get_size() int

Simple getter.

Returns

The length of the list of songs.

Return type

int

is_empty() bool

Check the length of the list to determine whether the queue is empty.

Returns

True if the list is empty, False otherwise.

Return type

bool

clear()

Remove all songs from the queue.

skip(index: int)

Pops ‘index’ songs to skip them.

Parameters

index (int) – The number of songs to skip.

Raises

IndexError – If the index is out of bounds.

remove(index: int) Tuple[bool, str]

Removes the song at position index.

Parameters

index (int) – The index of the song to remove.

Returns

The result of the operation.

Return type

bool

Returns

A message to pass to the user: a reason if an error occured, or the title of the song if not.

Return type

str

insert(song: cogs.ext.song.Song, index: int) int

Inserts a song at position index.

Parameters
  • song (Song) – The song to insert.

  • index (int) – The index of the position to insert the song into.

Returns

If the queue is empty, returns 0. Else, it returns the index.

Return type

int

Note

If index is less than 1, inserts the song at the beginning. If the index is greater than the size of the queue, the song is simply appended to the end of the queue.

move(index1: int, index2: int) str

Moves the song from position index1 to position index2 in the queue.

Parameters
  • index1 (int) – The position of the song to be moved.

  • index2 (int) – Where to move the song to.

Raises

IndexError – If any index is out of range.

Returns

A message about the result of the operation

Return type

str

Warning

This method only checks if the first index is valid, i.e. corresponds to a song in the queue. If the second index is less than 1, the song is left-appended. If it’s greater than the queue size, the song is appended.

get_song_info(index: int)

Unused.

exception songqueue.EmptyQueueError

Bases: Exception

Raised when attempting an operation on an empty queue