mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
* Limit Playlists Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Hotfix Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Hotfix Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * [Audio] Hotfix an edge case where an attribute error can be raised (#3328) * Limit Playlists Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Hotfix Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Hotfix Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * flame's review Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> * Delete 3328.hotfix.1.rst * lets be extra safe here Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>
This commit is contained in:
parent
d6936c87f3
commit
fdfbfe7b60
1
changelog.d/audio/3328.hotfix.2.rst
Normal file
1
changelog.d/audio/3328.hotfix.2.rst
Normal file
@ -0,0 +1 @@
|
||||
Check data before it is inserted into the database to avoid corruption.
|
||||
@ -746,13 +746,13 @@ class MusicCache:
|
||||
(val, update) = await self.database.fetch_one("lavalink", "data", {"query": query})
|
||||
if update:
|
||||
val = None
|
||||
if val and not isinstance(val, str):
|
||||
if val and isinstance(val, dict):
|
||||
log.debug(f"Querying Local Database for {query}")
|
||||
task = ("update", ("lavalink", {"query": query}))
|
||||
self.append_task(ctx, *task)
|
||||
else:
|
||||
val = None
|
||||
if val and not forced:
|
||||
if val and not forced and isinstance(val, dict):
|
||||
data = val
|
||||
data["query"] = query
|
||||
results = LoadResult(data)
|
||||
@ -780,21 +780,25 @@ class MusicCache:
|
||||
):
|
||||
with contextlib.suppress(SQLError):
|
||||
time_now = int(datetime.datetime.now(datetime.timezone.utc).timestamp())
|
||||
task = (
|
||||
"insert",
|
||||
(
|
||||
"lavalink",
|
||||
[
|
||||
{
|
||||
"query": query,
|
||||
"data": json.dumps(results._raw),
|
||||
"last_updated": time_now,
|
||||
"last_fetched": time_now,
|
||||
}
|
||||
],
|
||||
),
|
||||
)
|
||||
self.append_task(ctx, *task)
|
||||
data = json.dumps(results._raw)
|
||||
if all(
|
||||
k in data for k in ["loadType", "playlistInfo", "isSeekable", "isStream"]
|
||||
):
|
||||
task = (
|
||||
"insert",
|
||||
(
|
||||
"lavalink",
|
||||
[
|
||||
{
|
||||
"query": query,
|
||||
"data": data,
|
||||
"last_updated": time_now,
|
||||
"last_fetched": time_now,
|
||||
}
|
||||
],
|
||||
),
|
||||
)
|
||||
self.append_task(ctx, *task)
|
||||
return results, called_api
|
||||
|
||||
async def run_tasks(self, ctx: Optional[commands.Context] = None, _id=None):
|
||||
@ -855,7 +859,7 @@ class MusicCache:
|
||||
query_data["maxage"] = maxage_int
|
||||
|
||||
vals = await self.database.fetch_all("lavalink", "data", query_data)
|
||||
recently_played = [r.tracks for r in vals if r]
|
||||
recently_played = [r.tracks for r in vals if r if isinstance(tracks, dict)]
|
||||
|
||||
if recently_played:
|
||||
track = random.choice(recently_played)
|
||||
|
||||
@ -246,14 +246,19 @@ class Audio(commands.Cog):
|
||||
uri = t.get("info", {}).get("uri")
|
||||
if uri:
|
||||
t = {"loadType": "V2_COMPACT", "tracks": [t], "query": uri}
|
||||
database_entries.append(
|
||||
{
|
||||
"query": uri,
|
||||
"data": json.dumps(t),
|
||||
"last_updated": time_now,
|
||||
"last_fetched": time_now,
|
||||
}
|
||||
)
|
||||
data = json.dumps(t)
|
||||
if all(
|
||||
k in data
|
||||
for k in ["loadType", "playlistInfo", "isSeekable", "isStream"]
|
||||
):
|
||||
database_entries.append(
|
||||
{
|
||||
"query": uri,
|
||||
"data": data,
|
||||
"last_updated": time_now,
|
||||
"last_fetched": time_now,
|
||||
}
|
||||
)
|
||||
await asyncio.sleep(0)
|
||||
if guild_playlist:
|
||||
all_playlist[str(guild_id)] = guild_playlist
|
||||
@ -5883,14 +5888,16 @@ class Audio(commands.Cog):
|
||||
uri = t.get("info", {}).get("uri")
|
||||
if uri:
|
||||
t = {"loadType": "V2_COMPACT", "tracks": [t], "query": uri}
|
||||
database_entries.append(
|
||||
{
|
||||
"query": uri,
|
||||
"data": json.dumps(t),
|
||||
"last_updated": time_now,
|
||||
"last_fetched": time_now,
|
||||
}
|
||||
)
|
||||
data = json.dumps(t)
|
||||
if all(k in data for k in ["loadType", "playlistInfo", "isSeekable", "isStream"]):
|
||||
database_entries.append(
|
||||
{
|
||||
"query": uri,
|
||||
"data": data,
|
||||
"last_updated": time_now,
|
||||
"last_fetched": time_now,
|
||||
}
|
||||
)
|
||||
if database_entries:
|
||||
await self.music_cache.database.insert("lavalink", database_entries)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user