test 1 de la récupération de pp discord sur site web
This commit is contained in:
parent
9d0bb77225
commit
ee31269209
9 changed files with 591 additions and 0 deletions
62
src/api/routes.py
Normal file
62
src/api/routes.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
"""
|
||||
API routes for Kuby Discord bot
|
||||
"""
|
||||
|
||||
from flask import jsonify
|
||||
from .config import PARTNER_IDS
|
||||
|
||||
|
||||
def setup_routes(app, bot):
|
||||
"""Setup all API routes"""
|
||||
|
||||
@app.route("/api/user/<int:user_id>")
|
||||
def get_user(user_id):
|
||||
"""Get user information by ID"""
|
||||
user = bot.get_user(user_id)
|
||||
if not user:
|
||||
return jsonify({
|
||||
"username": "Utilisateur inconnu",
|
||||
"avatar_url": "https://cdn.discordapp.com/embed/avatars/0.png",
|
||||
})
|
||||
return jsonify({
|
||||
"username": user.display_name,
|
||||
"avatar_url": str(user.display_avatar.url) if user.display_avatar else "https://cdn.discordapp.com/embed/avatars/0.png",
|
||||
})
|
||||
|
||||
@app.route("/api/partners")
|
||||
def get_partners():
|
||||
"""Get partner server information"""
|
||||
partners = []
|
||||
for guild_id in PARTNER_IDS:
|
||||
guild = bot.get_guild(guild_id)
|
||||
if guild:
|
||||
partners.append({
|
||||
"name": guild.name,
|
||||
"icon_url": guild.icon.url if guild.icon else None,
|
||||
"member_count": guild.member_count
|
||||
})
|
||||
return jsonify(partners)
|
||||
|
||||
@app.route("/api/status")
|
||||
def get_status():
|
||||
"""Get bot status and basic information"""
|
||||
return jsonify({
|
||||
"status": "online" if bot.is_ready() else "connecting",
|
||||
"username": bot.user.name if bot.user else "Unknown",
|
||||
"guild_count": len(bot.guilds),
|
||||
"total_members": sum(guild.member_count for guild in bot.guilds) if bot.guilds else 0
|
||||
})
|
||||
|
||||
@app.route("/api/guilds")
|
||||
def get_guilds():
|
||||
"""Get basic information about all guilds the bot is in"""
|
||||
guilds_info = []
|
||||
for guild in bot.guilds:
|
||||
guilds_info.append({
|
||||
"id": guild.id,
|
||||
"name": guild.name,
|
||||
"icon_url": guild.icon.url if guild.icon else None,
|
||||
"member_count": guild.member_count,
|
||||
"owner_id": guild.owner_id
|
||||
})
|
||||
return jsonify(guilds_info)
|
||||
Loading…
Add table
Add a link
Reference in a new issue