63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
|
|
"""
|
||
|
|
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)
|