Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Adam Molnar commited on
serial experiments cache
Browse files29 unmodified lines30313233343536160 unmodified lines197198199200201199200201202203204205206207208209210211212213214215216217202203204205206207208209210211212213214215216217218219220221222223224 unmodified lines44844945044844945045145245345445445545645745829 unmodified lineslogging.basicConfig(level=logging.DEBUG)
#rate_limiter = RateLimiter(max_calls=10, period=60) # needs testingmessage_cache = {}
# stats stuff ---------------------------------------------------------------------------------------------------------------------------------------------------------number_of_messages = 0160 unmodified lines@bot.eventasync def on_message_delete(message): try: cached_message = message_cache.pop(message.id, None) if cached_message: if message.author == bot.user: return embed = Embed(color=Color.red()) embed.set_author(name=f"{message.author} ID: {message.author.id}", icon_url=message.author.avatar.url if message.author.avatar else bot.user.avatar.url) embed.title = "Message Deleted" embed.description = message.content or "*(empty message)*" embed.add_field(name="Author Username", value=message.author.name, inline=True) embed.add_field(name="Channel", value=message.channel.mention, inline=True) #embed.add_field(name="Message Created On", value=message.created_at.strftime("%Y-%m-%d %H:%M:%S UTC"), inline=True) embed.add_field(name="Message Created On", value=convert_to_timezone(message.created_at, zurich_tz), inline=True) embed.add_field(name="Message ID", value=message.id, inline=True) embed.add_field(name="Message Jump URL", value=f"[Jump to message!](https://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id})", inline=True) if message.attachments: attachment_urls = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachment_urls, inline=False) #embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}") embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}") await bot.log_channel.send(embed=embed) if message.author == bot.user: return embed = Embed(color=Color.red()) embed.set_author(name=f"{message.author} ID: {message.author.id}", icon_url=message.author.avatar.url if message.author.avatar else bot.user.avatar.url) embed.title = "Message Deleted" embed.description = message.content or "*(empty message)*" embed.add_field(name="Author Username", value=message.author.name, inline=True) embed.add_field(name="Channel", value=message.channel.mention, inline=True) #embed.add_field(name="Message Created On", value=message.created_at.strftime("%Y-%m-%d %H:%M:%S UTC"), inline=True) embed.add_field(name="Message Created On", value=convert_to_timezone(message.created_at, zurich_tz), inline=True) embed.add_field(name="Message ID", value=message.id, inline=True) embed.add_field(name="Message Jump URL", value=f"[Jump to message!](https://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id})", inline=True) if message.attachments: attachment_urls = "\n".join([attachment.url for attachment in message.attachments]) embed.add_field(name="Attachments", value=attachment_urls, inline=False) #embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}") embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}") await bot.log_channel.send(embed=embed) except Exception as e: print(f"on_message_delete Error: {e}") 224 unmodified lines guild = bot.get_guild(879548962464493619) for channel in guild.text_channels: # helps with more accurate logging across restarts try: # Fetch and cache the most recent 100 messages from the channel async for message in channel.history(limit=100): pass message_cache.update({m.id: m async for m in channel.history(limit=100)}) print(f"Finished caching messages for channel: {channel.name}") except Exception as e: print(f"An error occurred while fetching messages from {channel.name}: {e}") await asyncio.sleep(1) await asyncio.sleep(0.1)
def run_bot():app.py+24-23