0.5.1.2.a3
- Small patch to repair orphaned fedaykin requests
This commit is contained in:
		
							parent
							
								
									f3bc0ef670
								
							
						
					
					
						commit
						9b94280e8b
					
				
							
								
								
									
										2
									
								
								bot.py
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								bot.py
									
									
									
									
									
								
							@ -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; doesn’t trigger auto update)
 | 
					# Major.Enhancement.Minor.Patch.Test  (Test is alphanumeric; doesn’t trigger auto update)
 | 
				
			||||||
VERSION = "0.5.1.2.a2"
 | 
					VERSION = "0.5.1.2.a3"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# ---------- Env loading ----------
 | 
					# ---------- Env loading ----------
 | 
				
			||||||
load_dotenv()
 | 
					load_dotenv()
 | 
				
			||||||
 | 
				
			|||||||
@ -212,6 +212,12 @@ class ReactionRoleCog(commands.Cog):
 | 
				
			|||||||
            hg = cfg(self.bot).int('home_guild_id', 0)
 | 
					            hg = cfg(self.bot).int('home_guild_id', 0)
 | 
				
			||||||
            guild = self.bot.get_guild(hg) if hg else (self.bot.guilds[0] if self.bot.guilds else None)
 | 
					            guild = self.bot.get_guild(hg) if hg else (self.bot.guilds[0] if self.bot.guilds else None)
 | 
				
			||||||
            await self._maybe_transition_head_state(guild)
 | 
					            await self._maybe_transition_head_state(guild)
 | 
				
			||||||
 | 
					        except Exception:
 | 
				
			||||||
 | 
					            pass    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            if guild:
 | 
				
			||||||
 | 
					                await self._repair_orphaned_pending_cards(guild)
 | 
				
			||||||
        except Exception:
 | 
					        except Exception:
 | 
				
			||||||
            pass
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -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()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user