-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
93 lines (79 loc) · 3.22 KB
/
Copy pathapp.py
File metadata and controls
93 lines (79 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from flask import Flask, request, jsonify
import requests
import csv
import io
import os
app = Flask(__name__)
# Retrieve Discord webhook URL from Render secret
WEBHOOK_URL = os.getenv("DISCORDWEBHOOK")
@app.route("/game-upload", methods=["POST"])
def game_upload():
try:
# Parse incoming JSON request
data = request.json
if not data:
return jsonify({"error": "Invalid request, JSON payload is missing."}), 400
# Extract necessary information
username = data.get("username")
user_id = data.get("user_id")
group_id = data.get("group_id")
group_name = data.get("group_name")
if not username or not user_id or not group_id or not group_name:
return jsonify({"error": "Missing required fields: username, user_id, group_id, or group_name."}), 400
# Create Roblox user and group links
user_link = f"https://www.roblox.com/users/{user_id}/profile"
group_link = f"https://www.roblox.com/groups/{group_id}/about"
# Construct the Discord embed (matching your desired format)
embed = {
"title": "Moderation Log",
"description": "Server Activity Report",
"color": 3447003, # Blue color
"fields": [
{
"name": "Uploader",
"value": f"[{username}]({user_link})",
"inline": True
},
{
"name": "User ID",
"value": f"`{user_id}`",
"inline": True
},
{
"name": "Group",
"value": f"[{group_name}]({group_link})",
"inline": True
},
{
"name": "Group ID",
"value": f"`{group_id}`",
"inline": True
}
],
"footer": {
"text": "CondoWare has been activated",
"icon_url": "https://example.com/footer-icon.png" # Replace with a valid image URL if needed
}
}
# Create a CSV file in memory
csv_output = io.StringIO()
csv_writer = csv.writer(csv_output)
csv_writer.writerow(["Username", "User ID", "Group ID", "Group Name"])
csv_writer.writerow([username, user_id, group_id, group_name])
csv_output.seek(0)
# Prepare the multipart/form-data payload
files = {
"file": ("game_upload.csv", csv_output.read(), "text/csv"),
"payload_json": (None, jsonify({"embeds": [embed]}).data, "application/json"),
}
# Send the embed and CSV to Discord webhook
response = requests.post(WEBHOOK_URL, files=files)
# Check if the webhook request was successful
if response.status_code == 204:
return jsonify({"message": "Notification sent successfully!"}), 200
else:
return jsonify({"error": "Failed to send notification to Discord.", "details": response.text}), 500
except Exception as e:
return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)