2026-02-08 22:04:01 +01:00
|
|
|
"""
|
|
|
|
|
API routes for Kuby Discord bot
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from flask import jsonify
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/guilds")
|
|
|
|
|
def get_guilds():
|
2026-02-08 22:20:36 +01:00
|
|
|
"""Get all guilds where the bot is present"""
|
2026-02-08 22:04:01 +01:00
|
|
|
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,
|
2026-02-08 22:20:36 +01:00
|
|
|
"owner_id": guild.owner_id,
|
|
|
|
|
"description": guild.description if guild.description else None,
|
|
|
|
|
"features": list(guild.features) if guild.features else [],
|
|
|
|
|
"created_at": guild.created_at.isoformat() if guild.created_at else None
|
2026-02-08 22:04:01 +01:00
|
|
|
})
|
|
|
|
|
return jsonify(guilds_info)
|
2026-02-08 22:20:36 +01:00
|
|
|
|
|
|
|
|
@app.route("/api/guild/<int:guild_id>")
|
|
|
|
|
def get_guild(guild_id):
|
|
|
|
|
"""Get specific guild information by ID"""
|
|
|
|
|
guild = bot.get_guild(guild_id)
|
|
|
|
|
if not guild:
|
|
|
|
|
return jsonify({"error": "Serveur non trouvé"}), 404
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
|
|
|
|
"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,
|
|
|
|
|
"description": guild.description if guild.description else None,
|
|
|
|
|
"features": list(guild.features) if guild.features else [],
|
|
|
|
|
"created_at": guild.created_at.isoformat() if guild.created_at else None,
|
|
|
|
|
"channels": [
|
|
|
|
|
{
|
|
|
|
|
"id": channel.id,
|
|
|
|
|
"name": channel.name,
|
|
|
|
|
"type": str(channel.type),
|
|
|
|
|
"category": channel.category.name if channel.category else None
|
|
|
|
|
}
|
|
|
|
|
for channel in guild.channels
|
|
|
|
|
],
|
|
|
|
|
"roles": [
|
|
|
|
|
{
|
|
|
|
|
"id": role.id,
|
|
|
|
|
"name": role.name,
|
|
|
|
|
"color": role.color,
|
|
|
|
|
"position": role.position,
|
|
|
|
|
"member_count": len(role.members)
|
|
|
|
|
}
|
|
|
|
|
for role in guild.roles
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
@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",
|
|
|
|
|
"user_id": bot.user.id if bot.user else None,
|
|
|
|
|
"guild_count": len(bot.guilds),
|
|
|
|
|
"total_members": sum(guild.member_count for guild in bot.guilds) if bot.guilds else 0,
|
|
|
|
|
"total_channels": sum(len(guild.channels) for guild in bot.guilds) if bot.guilds else 0,
|
|
|
|
|
"uptime": "N/A", # TODO: Implement uptime tracking
|
|
|
|
|
"version": "2.0.0",
|
|
|
|
|
"api_endpoints": [
|
|
|
|
|
"/api/user/<user_id>",
|
|
|
|
|
"/api/guilds",
|
|
|
|
|
"/api/guild/<guild_id>",
|
|
|
|
|
"/api/status"
|
|
|
|
|
]
|
|
|
|
|
})
|