Update usage of last_fetched and last_updated to be Ints... However column migration still pending

This commit is contained in:
Draper
2019-12-18 17:28:57 +00:00
parent 6b2114406a
commit 9f50d83545
2 changed files with 31 additions and 74 deletions

View File

@@ -274,7 +274,7 @@ class Audio(commands.Cog):
).clear_raw("playlists") ).clear_raw("playlists")
if from_version < 3 <= to_version: if from_version < 3 <= to_version:
for scope in PlaylistScope.list(): for scope in PlaylistScope.list():
scope_playlist = await get_all_playlist_for_migration23(scope, self.bot) scope_playlist = await get_all_playlist_for_migration23(scope)
for p in scope_playlist: for p in scope_playlist:
await p.save() await p.save()
await self.config.custom(scope).clear() await self.config.custom(scope).clear()

View File

@@ -258,11 +258,11 @@ class Database:
_UPSET, _UPSET,
( (
{ {
"scope_type": scope_type, "scope_type": str(scope_type),
"playlist_id": playlist_id, "playlist_id": int(playlist_id),
"playlist_name": playlist_name, "playlist_name": str(playlist_name),
"scope_id": scope_id, "scope_id": int(scope_id),
"author_id": author_id, "author_id": int(author_id),
"playlist_url": playlist_url, "playlist_url": playlist_url,
"tracks": json.dumps(tracks), "tracks": json.dumps(tracks),
} }
@@ -353,7 +353,6 @@ class PlaylistMigration23: # TODO: remove me in a future version ?
def __init__( def __init__(
self, self,
bot: Red,
scope: str, scope: str,
author: int, author: int,
playlist_id: int, playlist_id: int,
@@ -362,57 +361,17 @@ class PlaylistMigration23: # TODO: remove me in a future version ?
tracks: Optional[List[dict]] = None, tracks: Optional[List[dict]] = None,
guild: Union[discord.Guild, int, None] = None, guild: Union[discord.Guild, int, None] = None,
): ):
self.bot = bot
self.guild = guild self.guild = guild
self.scope = standardize_scope(scope) self.scope = standardize_scope(scope)
self.config_scope = _prepare_config_scope_for_migration23(self.scope, author, guild)
self.author = author self.author = author
self.guild_id = (
getattr(guild, "id", guild) if self.scope == PlaylistScope.GLOBAL.value else None
)
self.id = playlist_id self.id = playlist_id
self.name = name self.name = name
self.url = playlist_url self.url = playlist_url
self.tracks = tracks or [] self.tracks = tracks or []
self.tracks_obj = [lavalink.Track(data=track) for track in self.tracks]
async def edit(self, data: dict):
"""
Edits a Playlist.
Parameters
----------
data: dict
The attributes to change.
"""
# Disallow ID editing
if "id" in data:
raise NotAllowed("Playlist ID cannot be edited.")
for item in list(data.keys()):
setattr(self, item, data[item])
await _config.custom(*self.config_scope, str(self.id)).set(self.to_json())
def to_json(self) -> dict:
"""Transform the object to a dict.
Returns
-------
dict
The playlist in the form of a dict.
"""
data = dict(
id=self.id,
author=self.author,
guild=self.guild_id,
name=self.name,
playlist_url=self.url,
tracks=self.tracks,
)
return data
@classmethod @classmethod
async def from_json(cls, bot: Red, scope: str, playlist_number: int, data: dict, **kwargs): async def from_json(cls, scope: str, playlist_number: int, data: dict, **kwargs):
"""Get a Playlist object from the provided information. """Get a Playlist object from the provided information.
Parameters Parameters
---------- ----------
@@ -446,10 +405,9 @@ class PlaylistMigration23: # TODO: remove me in a future version ?
playlist_id = data.get("id") or playlist_number playlist_id = data.get("id") or playlist_number
name = data.get("name", "Unnamed") name = data.get("name", "Unnamed")
playlist_url = data.get("playlist_url", None) playlist_url = data.get("playlist_url", None)
tracks = data.get("tracks", []) tracks = json.loads(data.get("tracks", "[]"))
return cls( return cls(
bot=bot,
guild=guild, guild=guild,
scope=scope, scope=scope,
author=author, author=author,
@@ -477,7 +435,6 @@ class PlaylistMigration23: # TODO: remove me in a future version ?
async def get_all_playlist_for_migration23( # TODO: remove me in a future version ? async def get_all_playlist_for_migration23( # TODO: remove me in a future version ?
scope: str, scope: str,
bot: Red,
guild: Union[discord.Guild, int] = None, guild: Union[discord.Guild, int] = None,
author: Union[discord.abc.User, int] = None, author: Union[discord.abc.User, int] = None,
) -> List[PlaylistMigration23]: ) -> List[PlaylistMigration23]:
@@ -512,14 +469,14 @@ async def get_all_playlist_for_migration23( # TODO: remove me in a future versi
if scope == PlaylistScope.GLOBAL.value: if scope == PlaylistScope.GLOBAL.value:
return [ return [
await PlaylistMigration23.from_json( await PlaylistMigration23.from_json(
bot, scope, playlist_number, playlist_data, guild=guild, author=author scope, playlist_number, playlist_data, guild=guild, author=int(playlist_data.get("author", 0))
) )
for playlist_number, playlist_data in playlists.items() for playlist_number, playlist_data in playlists.items()
] ]
elif scope == PlaylistScope.USER.value: elif scope == PlaylistScope.USER.value:
return [ return [
await PlaylistMigration23.from_json( await PlaylistMigration23.from_json(
bot, scope, playlist_number, playlist_data, guild=guild, author=author scope, playlist_number, playlist_data, guild=guild, author=int(user_id)
) )
for user_id, scopedata in playlists.items() for user_id, scopedata in playlists.items()
for playlist_number, playlist_data in scopedata.items() for playlist_number, playlist_data in scopedata.items()
@@ -527,7 +484,7 @@ async def get_all_playlist_for_migration23( # TODO: remove me in a future versi
else: else:
return [ return [
await PlaylistMigration23.from_json( await PlaylistMigration23.from_json(
bot, scope, playlist_number, playlist_data, guild=guild, author=author scope, playlist_number, playlist_data, guild=int(guild_id), author=int(playlist_data.get("author", 0))
) )
for guild_id, scopedata in playlists.items() for guild_id, scopedata in playlists.items()
for playlist_number, playlist_data in scopedata.items() for playlist_number, playlist_data in scopedata.items()