Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
f59a505
1
Parent(s): 0b9fdec
improvements!
Browse files- __pycache__/logger.cpython-312.pyc +0 -0
- logger.py +4 -75
- pydvpl_bot.py +14 -0
__pycache__/logger.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/logger.cpython-312.pyc and b/__pycache__/logger.cpython-312.pyc differ
|
|
|
logger.py
CHANGED
|
@@ -1,78 +1,7 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from fastapi.responses import HTMLResponse
|
| 3 |
-
from fastapi.staticfiles import StaticFiles
|
| 4 |
-
from discord.ext import commands
|
| 5 |
-
import discord
|
| 6 |
-
from discord.ext.commands import Bot
|
| 7 |
-
import asyncio
|
| 8 |
-
import os
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
# Setup static files (e.g., CSS, JS)
|
| 18 |
-
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 19 |
-
|
| 20 |
-
bot_intents = discord.Intents.all()
|
| 21 |
-
# Discord bot setup
|
| 22 |
-
bot = commands.Bot(command_prefix=">>", intents=bot_intents)
|
| 23 |
-
discord_channel_id = '1219652168160903189'
|
| 24 |
-
discord_token = os.getenv('DISCORD_TOKEN')
|
| 25 |
-
|
| 26 |
-
# Function to fetch messages from Discord
|
| 27 |
-
async def fetch_discord_messages():
|
| 28 |
-
await bot.start(discord_token)
|
| 29 |
-
await asyncio.sleep(5) # Allow time for bot to connect
|
| 30 |
-
channel = bot.get_channel(int(discord_channel_id))
|
| 31 |
-
messages = await channel.history(limit=20).flatten() # Fetch latest 20 messages
|
| 32 |
-
await bot.close()
|
| 33 |
-
return messages
|
| 34 |
-
|
| 35 |
-
# Fetch messages endpoint
|
| 36 |
-
@app.get("/messages", response_class=HTMLResponse)
|
| 37 |
-
async def get_messages():
|
| 38 |
-
try:
|
| 39 |
-
messages = await fetch_discord_messages()
|
| 40 |
-
return {"messages": messages}
|
| 41 |
-
except Exception as e:
|
| 42 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 43 |
-
|
| 44 |
-
# HTML Template
|
| 45 |
-
html_template = """
|
| 46 |
-
<!DOCTYPE html>
|
| 47 |
-
<html lang="en">
|
| 48 |
-
<head>
|
| 49 |
-
<meta charset="UTF-8">
|
| 50 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 51 |
-
<title>Discord Message Logs</title>
|
| 52 |
-
<link rel="stylesheet" href="/static/style.css">
|
| 53 |
-
</head>
|
| 54 |
-
<body>
|
| 55 |
-
<h1>Discord Message Logs</h1>
|
| 56 |
-
<ul>
|
| 57 |
-
{% for message in messages %}
|
| 58 |
-
<li>{{ message.content }}</li>
|
| 59 |
-
{% endfor %}
|
| 60 |
-
</ul>
|
| 61 |
-
</body>
|
| 62 |
-
</html>
|
| 63 |
-
"""
|
| 64 |
-
|
| 65 |
-
# CSS for styling
|
| 66 |
-
css_style = """
|
| 67 |
-
/* Your CSS styles here */
|
| 68 |
-
"""
|
| 69 |
-
|
| 70 |
-
# Route to serve HTML
|
| 71 |
-
@app.get("/", response_class=HTMLResponse)
|
| 72 |
-
async def home():
|
| 73 |
-
return HTMLResponse(content=html_template, status_code=200)
|
| 74 |
-
|
| 75 |
-
# Start Discord bot
|
| 76 |
-
@bot.event
|
| 77 |
-
async def on_ready():
|
| 78 |
-
print(f'Logged in as {bot.user.name}')
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
| 5 |
+
@app.get("/")
|
| 6 |
+
async def read_root():
|
| 7 |
+
return {"message": "PyDVPL DISCORD BOT DOCKER!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pydvpl_bot.py
CHANGED
|
@@ -88,4 +88,18 @@ async def decompress(ctx):
|
|
| 88 |
else:
|
| 89 |
await ctx.send("Failed to decompress the file.")
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
bot.run(TOKEN)
|
|
|
|
| 88 |
else:
|
| 89 |
await ctx.send("Failed to decompress the file.")
|
| 90 |
|
| 91 |
+
@bot.command()
|
| 92 |
+
async def ping(ctx):
|
| 93 |
+
latency = round(bot.latency * 1000) # latency in milliseconds
|
| 94 |
+
await ctx.send(f"Pong! Bot latency is {latency}ms.")
|
| 95 |
+
|
| 96 |
+
@bot.event
|
| 97 |
+
async def on_disconnect():
|
| 98 |
+
print('Bot disconnected from Discord. Attempting to reconnect...')
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
@bot.event
|
| 102 |
+
async def on_error(event, *args):
|
| 103 |
+
print(f'An error occurred during event {event}: {args[0]}')
|
| 104 |
+
|
| 105 |
bot.run(TOKEN)
|