modified: app.py
modified: requirements.txt modified: templates/index.html new file: templates/login.html
This commit is contained in:
80
app.py
80
app.py
@@ -1,36 +1,76 @@
|
||||
from flask import Flask, render_template, request, jsonify, redirect, url_for
|
||||
from flask import Flask, render_template, request, redirect, url_for, session, jsonify
|
||||
import os
|
||||
import requests
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
# Discord bot setup
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
bot = commands.Bot(command_prefix="!", intents=intents)
|
||||
|
||||
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
||||
CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
|
||||
|
||||
# Flask app setup
|
||||
app = Flask(__name__)
|
||||
app.secret_key = os.urandom(24)
|
||||
|
||||
# Beispiel-Datenstruktur für gespeicherte Webhooks
|
||||
webhooks = []
|
||||
# Function to check the status of the other bot
|
||||
def check_bot_status():
|
||||
try:
|
||||
response = requests.get("https://nww8w44sgg0c8okcc8wg8soc.simolzimol.net/")
|
||||
if response.status_code == 200:
|
||||
return "Online"
|
||||
else:
|
||||
return "Offline"
|
||||
except requests.exceptions.RequestException:
|
||||
return "Offline"
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return render_template("index.html", webhooks=webhooks)
|
||||
if "username" in session:
|
||||
bot_status = check_bot_status()
|
||||
return render_template("index.html", bot_status=bot_status)
|
||||
return redirect(url_for("login"))
|
||||
|
||||
@app.route("/add_webhook", methods=["POST"])
|
||||
def add_webhook():
|
||||
url = request.form.get("url")
|
||||
event = request.form.get("event")
|
||||
webhooks.append({"url": url, "event": event})
|
||||
return redirect(url_for("index"))
|
||||
@app.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
if request.method == "POST":
|
||||
username = request.form["username"]
|
||||
password = request.form["password"]
|
||||
# Simple auth check, replace with a proper method
|
||||
if username == "admin" and password == "password":
|
||||
session["username"] = username
|
||||
return redirect(url_for("index"))
|
||||
else:
|
||||
return "Login Failed"
|
||||
return render_template("login.html")
|
||||
|
||||
@app.route("/remove_webhook", methods=["POST"])
|
||||
def remove_webhook():
|
||||
url = request.form.get("url")
|
||||
webhooks[:] = [hook for hook in webhooks if hook["url"] != url]
|
||||
return redirect(url_for("index"))
|
||||
@app.route("/logout")
|
||||
def logout():
|
||||
session.pop("username", None)
|
||||
return redirect(url_for("login"))
|
||||
|
||||
@app.route("/post_message", methods=["POST"])
|
||||
def post_message():
|
||||
category = request.form.get("category")
|
||||
message = request.form.get("message")
|
||||
bot.loop.create_task(post_manual(category, message))
|
||||
return jsonify({"status": "success"}), 200
|
||||
if "username" in session:
|
||||
category = request.form.get("category")
|
||||
message = request.form.get("message")
|
||||
bot.loop.create_task(post_to_discord(category, message))
|
||||
return redirect(url_for("index"))
|
||||
return redirect(url_for("login"))
|
||||
|
||||
# Weitere Routen und Logik...
|
||||
async def post_to_discord(category, message):
|
||||
channel = bot.get_channel(CHANNEL_ID)
|
||||
await channel.send(f"**[{category.upper()}]** {message}")
|
||||
|
||||
# Run the Flask app and Discord bot
|
||||
def start_bot():
|
||||
bot.run(DISCORD_TOKEN)
|
||||
|
||||
if __name__ == "__main__":
|
||||
from threading import Thread
|
||||
bot_thread = Thread(target=start_bot)
|
||||
bot_thread.start()
|
||||
app.run(host="0.0.0.0", port=5000)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
discord.py
|
||||
flask
|
||||
requests
|
||||
psutil
|
||||
psutil
|
||||
@@ -9,34 +9,11 @@
|
||||
<body>
|
||||
<div class="container mt-5">
|
||||
<h1 class="text-center">Info-Bot Admin Panel</h1>
|
||||
|
||||
<h2>Add Webhook</h2>
|
||||
<form action="/add_webhook" method="post">
|
||||
<div class="form-group">
|
||||
<label for="url">Webhook URL:</label>
|
||||
<input type="url" class="form-control" id="url" name="url" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="event">Event:</label>
|
||||
<input type="text" class="form-control" id="event" name="event" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Add Webhook</button>
|
||||
</form>
|
||||
|
||||
<h2 class="mt-4">Current Webhooks</h2>
|
||||
<ul class="list-group">
|
||||
{% for webhook in webhooks %}
|
||||
<li class="list-group-item">
|
||||
{{ webhook.url }} - {{ webhook.event }}
|
||||
<form action="/remove_webhook" method="post" style="display: inline;">
|
||||
<input type="hidden" name="url" value="{{ webhook.url }}">
|
||||
<button type="submit" class="btn btn-danger btn-sm">Remove</button>
|
||||
</form>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<h2 class="mt-4">Bot Status</h2>
|
||||
<p class="lead">Other Bot Status: <strong>{{ bot_status }}</strong></p>
|
||||
|
||||
<h2 class="mt-4">Post a Message</h2>
|
||||
<h2 class="mt-4">Post a Message to Discord</h2>
|
||||
<form action="/post_message" method="post">
|
||||
<div class="form-group">
|
||||
<label for="category">Category:</label>
|
||||
@@ -52,6 +29,8 @@
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success">Post Message</button>
|
||||
</form>
|
||||
|
||||
<a href="/logout" class="btn btn-secondary btn-block mt-4">Logout</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
25
templates/login.html
Normal file
25
templates/login.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login</title>
|
||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container mt-5">
|
||||
<h1 class="text-center">Login</h1>
|
||||
<form action="/login" method="post">
|
||||
<div class="form-group">
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" class="form-control" id="username" name="username" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-block">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user