Let an owner clear an uncertain playlist write before reimport

The import guard already required verification, but no command could clear
the pending mutation, so a flagged playlist stayed stuck.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
Ziad Arafat committed 2026-11-25 15:16:47 -07:00
1 parent 9f3d751432
commit 4d62c7928d
2 files changed
+111

No files matched your search

+47
View File
@@ -370,3 +370,50 @@ async def test_uncertain_prior_create_requires_verification_before_reimport(
await asyncio.gather(*cog._pollers)
assert edge.creations == 0
assert any("verification" in text for text in ctx.texts)
async def test_playlist_verify_clears_mutation_and_allows_reimport(
playlist_command: CommandCase,
) -> None:
"""Catch a dead end after an uncertain playlist write."""
cog, ctx, _edge, _channel, _bot = playlist_command
key = "1:playlist:7kRUsOsraSiY4fyDcu7Bnb"
await cog.config.pending_jobs.set(
{
key: {
"owner": 1,
"notified": True,
"stage": "attention",
"kind": "playlist",
"mutation": "Jellyfin playlist create",
}
}
)
await Watch.playlist_verify.callback(cog, ctx)
job = (await cog.config.pending_jobs())[key]
assert "mutation" not in job
assert any("Verified" in text for text in ctx.texts)
async def test_playlist_verify_is_owner_only(
playlist_command: CommandCase,
) -> None:
"""Catch a non-owner clearing an uncertain write."""
cog, ctx, _edge, _channel, bot = playlist_command
bot.owner = False
key = "1:playlist:7kRUsOsraSiY4fyDcu7Bnb"
await cog.config.pending_jobs.set(
{
key: {
"owner": 1,
"notified": True,
"stage": "attention",
"kind": "playlist",
"mutation": "Jellyfin playlist create",
}
}
)
await Watch.playlist_verify.callback(cog, ctx)
job = (await cog.config.pending_jobs())[key]
assert job["mutation"] == "Jellyfin playlist create"
assert any("Only the bot owner" in text for text in ctx.texts)
+64
View File
@@ -1469,6 +1469,70 @@ class Watch(commands.Cog):
allowed_mentions=discord.AllowedMentions.none(),
)
@playlist.command(name="verify")
@commands.is_owner()
async def playlist_verify(
self, ctx: commands.Context, *, target: str = ""
) -> None:
"""Bot owner: clear an uncertain playlist write."""
if not await self.bot.is_owner(ctx.author):
await ctx.send(
"Only the bot owner can verify playlist writes."
)
return
async with self.config.pending_jobs() as jobs:
flagged = [
(key, job)
for key, job in jobs.items()
if job.get("kind") == "playlist"
and job.get("mutation")
]
if not flagged:
await ctx.send(
"No playlist jobs need owner "
"verification."
)
return
needle = target.strip().lower()
matches = [
(key, job)
for key, job in flagged
if not needle
or needle in key.lower()
or needle in str(job.get("name", "")).lower()
]
if not matches:
await ctx.send(
"No flagged playlist job matched "
f"`{target.strip()}`."
)
return
if len(matches) > 1:
listing = "\n".join(
f"- `{key}` "
f"({job.get('name', 'unknown')}): "
f"{job.get('mutation')}"
for key, job in matches[:10]
)
await ctx.send(
"Multiple playlist jobs need "
"verification; name one:\n"
f"{listing}",
allowed_mentions=(
discord.AllowedMentions.none()
),
)
return
key, job = matches[0]
action = job.pop("mutation", None)
name = discord.utils.escape_markdown(
str(job.get("name", key))
)
await ctx.send(
f"Verified **{name}**: cleared `{action}`. "
"You can reimport or resume the playlist."
)
@watch.command(name="link")
async def watch_link(self, ctx: commands.Context, *, name: str) -> None:
"""Link your Jellyfin user name, for "next" requests."""