SNIPE-BOT / app.py
NihalGazi's picture
Update app.py
6ee8b88 verified
import discord
import threading
import os
import gradio as gr
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
MONITORED_CHANNEL_IDS = [1269327567534559246, 1269536568172089448, 1269327567534559245, 1270219422472077344, 1269327567740211272, 1269327567534559244]
deleted_messages = {}
intents = discord.Intents.default()
intents.message_content = True
intents.messages = True
intents.guilds = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
@client.event
async def on_message_delete(message):
global deleted_messages
if message.channel.id in MONITORED_CHANNEL_IDS:
deleted_messages[message.channel.id] = {
'message': message.content,
'username': message.author.name
}
print(f"Message deleted in channel {message.channel.id}: {message.content} by {message.author.name}")
@client.event
async def on_message(message):
global deleted_messages
if message.author == client.user:
return
if message.content.lower() == ",s":
if message.channel.id in deleted_messages:
response = f"{deleted_messages[message.channel.id]['username']} : {deleted_messages[message.channel.id]['message']}"
else:
response = "No recently deleted messages in this channel."
await message.channel.send(response)
def run_discord_bot():
client.run(DISCORD_BOT_TOKEN)
def show_snipe():
output = ""
for channel_id, data in deleted_messages.items():
output += f"Channel {channel_id}:\n{data['username']} : {data['message']}\n\n"
return output if output else "No recently deleted messages in monitored channels."
iface = gr.Interface(fn=show_snipe, inputs=None, outputs="text")
discord_thread = threading.Thread(target=run_discord_bot)
discord_thread.start()
iface.launch()