pylav.storage.models package

Subpackages

Submodules

pylav.storage.models.config module

pylav.storage.models.equilizer module

class pylav.storage.models.equilizer.Equalizer(*, id: 'int', scope: 'int', author: 'int', name: 'str | None' = None, description: 'str | None' = None, band_25: 'float | None' = None, band_40: 'float | None' = None, band_63: 'float | None' = None, band_100: 'float | None' = None, band_160: 'float | None' = None, band_250: 'float | None' = None, band_400: 'float | None' = None, band_630: 'float | None' = None, band_1000: 'float | None' = None, band_1600: 'float | None' = None, band_2500: 'float | None' = None, band_4000: 'float | None' = None, band_6300: 'float | None' = None, band_10000: 'float | None' = None, band_16000: 'float | None' = None)[source]

Bases: CachedModel

author
band_100
band_1000
band_10000
band_160
band_1600
band_16000
band_25
band_250
band_2500
band_40
band_400
band_4000
band_63
band_630
band_6300
async can_manage(bot, requester)[source]

Check if the requester can manage the equalizer.

Parameters:
  • bot (DISCORD_BOT_TYPE) – The bot.

  • requester (discord.abc.User) – The requester.

Returns:

If the requester can manage the equalizer.

Return type:

bool

async delete()[source]

Delete the equalizer from the database

description
classmethod from_dict(data)[source]

Deserialize a Equalizer from a dict.

Parameters:

data (dict) – The data to use to build the Equalizer

Returns:

The Equalizer

Return type:

Equalizer

classmethod from_filter(equalizer, context, scope, description=None)[source]

Deserialize a Equalizer from a Filter.

Parameters:
  • equalizer (Equalizer) – The filter object

  • context (PyLavContext) – The Context

  • scope (int) – The scope number

  • description (str) – The description of the Equalizer

Returns:

The Equalizer built from the Equalizer object

Return type:

Equalizer

async classmethod from_yaml(context, scope, url)[source]

Deserialize a Equalizer from a YAML file.

Parameters:
  • context (PyLavContext) – The context.

  • scope (int) – The scope.

  • url (str) – The URL to the YAML file.

Returns:

The Equalizer.

Return type:

Equalizer

async classmethod get(identifier)[source]

Get an equalizer from the database.

Parameters:

identifier (int) – The id of the equalizer.

Returns:

The equalizer if found, else None.

Return type:

Equalizer | None

async get_author_name(bot, mention=True)[source]

Get the name of the author.

Parameters:
  • bot (DISCORD_BOT_TYPE) – The bot.

  • mention (bool) – If the name should be mentionable.

Returns:

The name of the author.

Return type:

str | None

get_cache_key()[source]
async get_scope_name(bot, mention=True, guild=None)[source]

Get the name of the scope.

Parameters:
  • bot (DISCORD_BOT_TYPE) – The bot.

  • mention (bool) – If the name should be mentionable.

  • guild (discord.Guild | None) – The guild.

Returns:

The name of the scope.

Return type:

str

id
name
async save()[source]

Save the Equalizer to the database.

Returns:

The Equalizer.

Return type:

Equalizer

scope
to_dict()[source]

Serialize the Equalizer to a dict.

Returns:

The dict representation of the Equalizer.

Return type:

dict

to_filter()[source]

Serialize the Equalizer to a Filter.

Returns:

The filter representation of the Equalizer

Return type:

Equalizer

to_yaml(guild)[source]

Serialize the Equalizer to a YAML file.

yields a tuple of (io.BytesIO, bool) where the bool is whether the playlist file was compressed using Gzip

Parameters:

guild (discord.Guild) – The guild.

Yields:

tuple[io.BytesIO, str | None] – The YAML file and the compression type.

pylav.storage.models.playlist module

class pylav.storage.models.playlist.Playlist(*args: 'Any', **kwargs: 'Any')[source]

Bases: CachedModel

async add_track(tracks)[source]

Add a track to the playlist.

Parameters:

tracks (list[str | Track]) – The tracks to add.

async bulk_remove_tracks(tracks)[source]

Remove disc jockey users from the player.

Parameters:

tracks (list[str]) – The track to remove

async bulk_update(scope, name, author, url, tracks)[source]

Bulk update the playlist.

async can_manage(bot, requester)[source]

Check if the requester can manage the playlist.

Parameters:
  • bot (DISCORD_BOT_TYPE) – The bot instance.

  • requester (discord.abc.User) – The requester.

Returns:

Whether the requester can manage the playlist.

Return type:

bool

async delete()[source]

Delete the playlist from the database

async exists()[source]

Check if the config exists.

Returns:

Whether the config exists.

Return type:

bool

async fetch_all()[source]

Fetch all playlists from the database.

Returns:

The playlists.

Return type:

dict

async fetch_author()[source]

Fetch the author of the playlist.

Returns:

The author of the playlist.

Return type:

int

async fetch_first()[source]

Get the first track.

Returns:

The first track

Return type:

str

async fetch_index(index)[source]

Get the track at the index.

Parameters:

index (int) – The index of the track

Returns:

The track at the index

Return type:

str

async fetch_name()[source]

Fetch the name of the playlist.

Returns:

The name of the playlist.

Return type:

str

async fetch_random()[source]

Get a random track.

Returns:

A random track

Return type:

str

async fetch_scope()[source]

Fetch the scope of the playlist.

Returns:

The scope of the playlist.

Return type:

int

async fetch_tracks()[source]

Fetch the tracks of the playlist.

Returns:

The tracks of the playlist.

Return type:

list[str]

async fetch_url()[source]

Fetch the url of the playlist.

Returns:

The url of the playlist.

Return type:

str

async classmethod from_yaml(context, scope, url)[source]

Deserialize a playlist from a YAML file.

Parameters:
  • context (PyLavContext) – The context.

  • scope (int) – The scope of the playlist.

  • url (str) – The url of the playlist.

Returns:

The playlist.

Return type:

Playlist

async get_author_name(bot, mention=True)[source]

Get the name of the author of the playlist.

Parameters:
  • bot (DISCORD_BOT_TYPE) – The bot instance.

  • mention (bool) – Whether to add a mention if it is mentionable.

Returns:

The name of the author of the playlist.

Return type:

str | None

get_cache_key()[source]
async get_name_formatted(with_url=True, escape=True)[source]

Get the name of the playlist formatted.

Parameters:
  • with_url (bool) – Whether to include the url in the name.

  • escape (bool) – Whether to markdown escape the response

Returns:

The formatted name.

Return type:

str

async get_scope_name(bot, mention=True, guild=None)[source]

Get the name of the scope of the playlist.

Parameters:
  • bot (DISCORD_BOT_TYPE) – The bot instance.

  • mention (bool) – Whether to add a mention if it is mentionable.

  • guild (discord.Guild) – The guild to get the scope name for.

Returns:

The name of the scope of the playlist.

Return type:

str

id
async remove_all_tracks()[source]

Remove all tracks from the playlist.

async remove_track(track)[source]

Remove a track from the playlist.

Parameters:

track (str) – The track to remove

async size()[source]

Count the tracks of the playlist.

Returns:

The number of tracks in the playlist.

Return type:

int

to_yaml(guild)[source]

Serialize the playlist to a YAML file.

yields a tuple of (io.BytesIO, bool) where the bool is whether the playlist file was compressed using Gzip

Parameters:

guild (discord.Guild) – The guild where the yaml will be sent to.

Yields:

tuple[io.BytesIO, str | None] – The YAML file and the compression type.

async update_author(author)[source]

Update the author of the playlist.

Parameters:

author (int) – The new author of the playlist.

async update_name(name)[source]

Update the name of the playlist.

Parameters:

name (str) – The new name of the playlist.

async update_scope(scope)[source]

Update the scope of the playlist.

Parameters:

scope (int) – The new scope of the playlist.

async update_tracks(tracks)[source]

Update the tracks of the playlist.

Parameters:

tracks (list[str]) – The new tracks of the playlist.

async update_url(url)[source]

Update the url of the playlist.

Parameters:

url (str) – The new url of the playlist.

pylav.storage.models.query module

pylav.storage.models.version module

class pylav.storage.models.version.BotVersion(*args, **kwargs)[source]

Bases: CachedModel

A class to represent the version of the bot in the database

async fetch_version()[source]

Fetch the version of the bot from the database

get_cache_key()[source]

Get the cache key for the bot version.

id
async update_version(version)[source]

Update the version of the bot in the database

Module contents