mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -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})
|
(val, update) = await self.database.fetch_one("lavalink", "data", {"query": query})
|
||||||
if update:
|
if update:
|
||||||
val = None
|
val = None
|
||||||
if val and not isinstance(val, str):
|
if val and isinstance(val, dict):
|
||||||
log.debug(f"Querying Local Database for {query}")
|
log.debug(f"Querying Local Database for {query}")
|
||||||
task = ("update", ("lavalink", {"query": query}))
|
task = ("update", ("lavalink", {"query": query}))
|
||||||
self.append_task(ctx, *task)
|
self.append_task(ctx, *task)
|
||||||
else:
|
else:
|
||||||
val = None
|
val = None
|
||||||
if val and not forced:
|
if val and not forced and isinstance(val, dict):
|
||||||
data = val
|
data = val
|
||||||
data["query"] = query
|
data["query"] = query
|
||||||
results = LoadResult(data)
|
results = LoadResult(data)
|
||||||
@ -780,21 +780,25 @@ class MusicCache:
|
|||||||
):
|
):
|
||||||
with contextlib.suppress(SQLError):
|
with contextlib.suppress(SQLError):
|
||||||
time_now = int(datetime.datetime.now(datetime.timezone.utc).timestamp())
|
time_now = int(datetime.datetime.now(datetime.timezone.utc).timestamp())
|
||||||
task = (
|
data = json.dumps(results._raw)
|
||||||
"insert",
|
if all(
|
||||||
(
|
k in data for k in ["loadType", "playlistInfo", "isSeekable", "isStream"]
|
||||||
"lavalink",
|
):
|
||||||
[
|
task = (
|
||||||
{
|
"insert",
|
||||||
"query": query,
|
(
|
||||||
"data": json.dumps(results._raw),
|
"lavalink",
|
||||||
"last_updated": time_now,
|
[
|
||||||
"last_fetched": time_now,
|
{
|
||||||
}
|
"query": query,
|
||||||
],
|
"data": data,
|
||||||
),
|
"last_updated": time_now,
|
||||||
)
|
"last_fetched": time_now,
|
||||||
self.append_task(ctx, *task)
|
}
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
self.append_task(ctx, *task)
|
||||||
return results, called_api
|
return results, called_api
|
||||||
|
|
||||||
async def run_tasks(self, ctx: Optional[commands.Context] = None, _id=None):
|
async def run_tasks(self, ctx: Optional[commands.Context] = None, _id=None):
|
||||||
@ -855,7 +859,7 @@ class MusicCache:
|
|||||||
query_data["maxage"] = maxage_int
|
query_data["maxage"] = maxage_int
|
||||||
|
|
||||||
vals = await self.database.fetch_all("lavalink", "data", query_data)
|
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:
|
if recently_played:
|
||||||
track = random.choice(recently_played)
|
track = random.choice(recently_played)
|
||||||
|
|||||||
@ -246,14 +246,19 @@ class Audio(commands.Cog):
|
|||||||
uri = t.get("info", {}).get("uri")
|
uri = t.get("info", {}).get("uri")
|
||||||
if uri:
|
if uri:
|
||||||
t = {"loadType": "V2_COMPACT", "tracks": [t], "query": uri}
|
t = {"loadType": "V2_COMPACT", "tracks": [t], "query": uri}
|
||||||
database_entries.append(
|
data = json.dumps(t)
|
||||||
{
|
if all(
|
||||||
"query": uri,
|
k in data
|
||||||
"data": json.dumps(t),
|
for k in ["loadType", "playlistInfo", "isSeekable", "isStream"]
|
||||||
"last_updated": time_now,
|
):
|
||||||
"last_fetched": time_now,
|
database_entries.append(
|
||||||
}
|
{
|
||||||
)
|
"query": uri,
|
||||||
|
"data": data,
|
||||||
|
"last_updated": time_now,
|
||||||
|
"last_fetched": time_now,
|
||||||
|
}
|
||||||
|
)
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
if guild_playlist:
|
if guild_playlist:
|
||||||
all_playlist[str(guild_id)] = guild_playlist
|
all_playlist[str(guild_id)] = guild_playlist
|
||||||
@ -5883,14 +5888,16 @@ class Audio(commands.Cog):
|
|||||||
uri = t.get("info", {}).get("uri")
|
uri = t.get("info", {}).get("uri")
|
||||||
if uri:
|
if uri:
|
||||||
t = {"loadType": "V2_COMPACT", "tracks": [t], "query": uri}
|
t = {"loadType": "V2_COMPACT", "tracks": [t], "query": uri}
|
||||||
database_entries.append(
|
data = json.dumps(t)
|
||||||
{
|
if all(k in data for k in ["loadType", "playlistInfo", "isSeekable", "isStream"]):
|
||||||
"query": uri,
|
database_entries.append(
|
||||||
"data": json.dumps(t),
|
{
|
||||||
"last_updated": time_now,
|
"query": uri,
|
||||||
"last_fetched": time_now,
|
"data": data,
|
||||||
}
|
"last_updated": time_now,
|
||||||
)
|
"last_fetched": time_now,
|
||||||
|
}
|
||||||
|
)
|
||||||
if database_entries:
|
if database_entries:
|
||||||
await self.music_cache.database.insert("lavalink", database_entries)
|
await self.music_cache.database.insert("lavalink", database_entries)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user