Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
9a00a19
1
Parent(s): b1a0f8b
possible fix
Browse files- Dockerfile +8 -2
- __pycache__/logger.cpython-312.pyc +0 -0
- __pycache__/logging.cpython-312.pyc +0 -0
- __pycache__/my_logging.cpython-312.pyc +0 -0
- __pycache__/pydvpl_bot.cpython-312.pyc +0 -0
- logger.py +78 -0
Dockerfile
CHANGED
|
@@ -2,14 +2,20 @@ FROM python:3.12-slim
|
|
| 2 |
|
| 3 |
WORKDIR /code
|
| 4 |
|
| 5 |
-
RUN pip install --no-cache-dir -U discord pydvpl
|
| 6 |
|
| 7 |
COPY ./pydvpl_bot.py /code
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
RUN ls -ln /code
|
| 10 |
|
| 11 |
RUN chmod 775 /code
|
| 12 |
|
| 13 |
ENV PYTHONUNBUFFERED 1
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /code
|
| 4 |
|
| 5 |
+
RUN pip install --no-cache-dir -U discord pydvpl fastapi uvicorn
|
| 6 |
|
| 7 |
COPY ./pydvpl_bot.py /code
|
| 8 |
|
| 9 |
+
COPY ./logger.py /code
|
| 10 |
+
|
| 11 |
+
COPY ./ /code
|
| 12 |
+
|
| 13 |
RUN ls -ln /code
|
| 14 |
|
| 15 |
RUN chmod 775 /code
|
| 16 |
|
| 17 |
ENV PYTHONUNBUFFERED 1
|
| 18 |
|
| 19 |
+
RUN python pydvpl_bot.py &
|
| 20 |
+
|
| 21 |
+
CMD ["uvicorn", "logger:app", "--host", "0.0.0.0", "--port", "7860"]
|
__pycache__/logger.cpython-312.pyc
ADDED
|
Binary file (3.49 kB). View file
|
|
|
__pycache__/logging.cpython-312.pyc
ADDED
|
Binary file (2.61 kB). View file
|
|
|
__pycache__/my_logging.cpython-312.pyc
ADDED
|
Binary file (3.48 kB). View file
|
|
|
__pycache__/pydvpl_bot.cpython-312.pyc
ADDED
|
Binary file (4.91 kB). View file
|
|
|
logger.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 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 |
+
static_folder = "static"
|
| 13 |
+
if not os.path.exists(static_folder):
|
| 14 |
+
os.makedirs(static_folder)
|
| 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 = 'MTIxOTYxNDA0OTg1NjM5MzIxNg.GaiTho.YEkOxi7UGs8yCq6NxjYstIVPy5fqN3mi0_qm4E'
|
| 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}')
|