0.5.1.2.a3

- Small patch to repair orphaned fedaykin requests
This commit is contained in:
Franz Rolfsvaag 2025-08-25 23:57:39 +02:00
parent f3bc0ef670
commit 9b94280e8b
2 changed files with 42 additions and 1 deletions

2
bot.py
View File

@ -9,7 +9,7 @@ from modules.common.boot_notice import post_boot_notice
# Version consists of: # Version consists of:
# Major.Enhancement.Minor.Patch.Test (Test is alphanumeric; doesnt trigger auto update) # Major.Enhancement.Minor.Patch.Test (Test is alphanumeric; doesnt trigger auto update)
VERSION = "0.5.1.2.a2" VERSION = "0.5.1.2.a3"
# ---------- Env loading ---------- # ---------- Env loading ----------
load_dotenv() load_dotenv()

View File

@ -215,6 +215,12 @@ class ReactionRoleCog(commands.Cog):
except Exception: except Exception:
pass pass
try:
if guild:
await self._repair_orphaned_pending_cards(guild)
except Exception:
pass
async def _save_fedaykin_request(self, req: Dict[str, Any]): async def _save_fedaykin_request(self, req: Dict[str, Any]):
"""Upsert by (guild_id, user_id).""" """Upsert by (guild_id, user_id)."""
dm = self.bot.data_manager dm = self.bot.data_manager
@ -576,6 +582,7 @@ class ReactionRoleCog(commands.Cog):
# Head appeared — flush queued to cards # Head appeared — flush queued to cards
self._fedaykin_headless = False self._fedaykin_headless = False
posted = await self._flush_pending_to_cards(guild) posted = await self._flush_pending_to_cards(guild)
await self._repair_orphaned_pending_cards(guild)
await self._modlog_head_summary(guild, head_present=True, posted=posted) await self._modlog_head_summary(guild, head_present=True, posted=posted)
elif not has_head_now and not self._fedaykin_headless: elif not has_head_now and not self._fedaykin_headless:
# Became headless — revoke all fedaykins and queue pendings # Became headless — revoke all fedaykins and queue pendings
@ -583,6 +590,40 @@ class ReactionRoleCog(commands.Cog):
revoked, queued = await self._headless_revoke_and_queue(guild) revoked, queued = await self._headless_revoke_and_queue(guild)
await self._modlog_head_summary(guild, head_present=False, revoked=revoked, queued=queued) await self._modlog_head_summary(guild, head_present=False, revoked=revoked, queued=queued)
# inside ReactionRoleCog class
async def _repair_orphaned_pending_cards(self, guild: discord.Guild) -> int:
"""Detect pending requests whose review message was deleted; reset them so they can be re-posted."""
dm = self.bot.data_manager
repaired = 0
for req in list(_as_list(dm.get('fedaykin_requests'))):
if int(req.get("guild_id", 0)) != guild.id or req.get("status") != "pending":
continue
mid = int(req.get("review_message_id", 0) or 0)
cid = int(req.get("review_channel_id", 0) or 0)
if not mid or not cid:
continue # already queued (no card)
ch = self.bot.get_channel(cid)
exists = False
if isinstance(ch, (discord.TextChannel, discord.Thread)):
try:
await ch.fetch_message(mid)
exists = True
except (discord.NotFound, discord.Forbidden):
exists = False
except Exception:
exists = False
if not exists:
# reset to "queued" so normal flow can re-post
req["review_message_id"] = 0
req["review_channel_id"] = 0
await self._save_fedaykin_request(req)
repaired += 1
# If we repaired and a head exists, immediately flush to new cards
if repaired and not self._fedaykin_headless and self._has_fedaykin_head(guild):
await self._flush_pending_to_cards(guild)
return repaired
# ------------------ listeners ------------------ # ------------------ listeners ------------------
@commands.Cog.listener() @commands.Cog.listener()