import discord from discord.ext import commands from database import save_result class Scan(commands.Cog): def __init__(self, bot): self.bot = bot @commands.command() async def scan(self, ctx, limit: int = 4500): """ Scan previous messages in the channel for Rule34dle posts """ found = 0 saved = 0 async for message in ctx.channel.history(limit=limit): if message.author.bot: continue content = message.content.strip() # Only process Rule34dle messages if not content.startswith("Rule34dle"): continue found += 1 try: lines = content.split("\n") # Ensure correct format if len(lines) < 3: continue # Extract date from first line # Example: "Rule34dle Daily 2026-06-12" date_line = lines[0] date = date_line.split(" ")[2] # Extract result result = int(lines[1].split("/")[0]) # Extract squares squares_line = lines[2].strip() # Validate squares if not all(c in ["🟩", "🟥"] for c in squares_line): continue # Convert to 0/1 score_values = [1 if c == "🟩" else 0 for c in squares_line] user_id = message.author.id save_result(user_id, result, score_values, date) saved += 1 except Exception as e: print("Scan parse error:", e) await ctx.send(f"Scan complete!\nFound: {found}\nSaved: {saved}") async def setup(bot): await bot.add_cog(Scan(bot))