feat: add new rosters system endpoints#22
Open
Destinea wants to merge 81 commits into
Open
Conversation
Add missing reminders collection to the new MongoClient class. The reminders endpoints in routers/v2/server/reminders.py require access to mongo.reminders, which was missing from the MongoClient init. The reminders collection is located in the 'usafam' database alongside server_db and clan_db collections.
Corrected field names to match ClashKingBot's database schema: - Clan Capital: use 'townhalls' instead of 'townhall_filter' - Clan Games: use 'townhalls' instead of 'townhall_filter' - War/Inactivity: keep 'townhall_filter' (already correct) - Roster: ensure ObjectId conversion for roster field Changes: - POST: Create reminders with correct field names per type - GET: Read 'townhalls' for Capital/Games, 'townhall_filter' for War/Inactivity - PUT: Update correct field based on reminder type This ensures compatibility with existing ClashKingBot reminder data.
Complete comparison between ClashKingBot v2.0 and ClashKingAPI feat/dashboard: - ✅ 6 endpoint categories already implemented (reminders, logs, autoboards, links, server/clan settings) - ❌ ~62 missing endpoints identified across 4 priority categories -⚠️ Schema compatibility issues documented Missing endpoints breakdown: - Server Settings (general, nickname, eval, roles): ~24 endpoints - HIGH priority - Clan Settings (basic, war, member warning, buttons): ~18 endpoints - HIGH priority - Role Management (TH, league, achievement, status): ~18 endpoints - MEDIUM priority - Clan Management (add/remove): ~2 endpoints - MEDIUM priority Recommendations: - Phase 1: Basic server/clan settings (2-3 days) - Phase 2: Advanced settings (nickname, eval, warnings) (2-3 days) - Phase 3: Role management (3-4 days) - Phase 4: Clan management (1-2 days) Includes detailed field mappings from ClashKingBot database schema.
Create consolidated endpoints instead of 40+ individual PUT endpoints:
Server Settings (PATCH /v2/server/{server_id}/settings):
- Nickname conventions (family/non-family rules, auto-eval, flair)
- Auto-eval configuration (triggers, log channel, status)
- Role management (blacklist, treatment, whitelist)
- Channels (banlist, strike log, reddit feed)
- Link parse settings (clan, army, player, base, show)
- General settings (leadership eval, tied stats, autoboard limit, etc.)
Clan Settings (PATCH /v2/server/{server_id}/clan/{clan_tag}/settings):
- Basic settings (member/leader roles, channel, category, abbreviation, greeting)
- War settings (countdown channels, ban alert)
- Member count warnings (channel, thresholds, ping role)
- Log buttons (profile, strike, ban buttons)
Benefits:
- Single request to update multiple settings (more efficient)
- Consistent pattern across server and clan configurations
- Only provided fields are updated (partial updates)
- Full Pydantic validation with field descriptions
- Compatible with ClashKingBot v2.0 database schema
Each endpoint:
- Uses @linkd.ext.fastapi.inject for MongoClient
- Uses @check_authentication for security
- Returns updated field count in response
- Validates server/clan existence before update
Clan Management Endpoints:
- POST /v2/server/{server_id}/clans
* Add clan to server with CoC API validation
* Creates default clan settings document
* Prevents duplicate clans per server
- DELETE /v2/server/{server_id}/clans/{clan_tag}
* Remove clan from server
* Cascades deletion to associated reminders
* Returns deleted count
Unified Role Management Endpoints (3 endpoints for 7 role types):
- GET /v2/server/{server_id}/roles/{role_type}
* List all roles of specific type
* Returns role configuration and count
- POST /v2/server/{server_id}/roles/{role_type}
* Create role with type-specific validation
* Prevents duplicate role configurations
* Dynamic request body based on role type
- DELETE /v2/server/{server_id}/roles/{role_type}/{role_id}
* Remove role by Discord role ID
* Handles special status role structure
Supported Role Types:
- townhall: TH level-based roles (TH 1-17)
- league: League-based roles (Legend, Titan, etc.)
- builderhall: BH level-based roles (BH 1-10)
- builder_league: Builder league roles
- achievement: Achievement-based roles
- status: Discord tenure roles (months in server)
- family_position: Position roles (elder, co-leader, leader)
Benefits:
- 18 individual endpoints reduced to 3 unified endpoints
- Type-safe with Pydantic models per role type
- Consistent pattern across all role types
- Direct access to separate MongoDB collections
- Compatible with ClashKingBot schema
Database Collections:
- townhallroles, legendleagueroles, builderhallroles
- builderleagueroles, achievementroles, statusroles
- family_roles (position roles)
Mark all high-priority endpoints as complete: - ✅ Server Settings: 24 fields → 1 PATCH endpoint - ✅ Clan Settings: 18 fields → 1 PATCH endpoint - ✅ Clan Management: POST/DELETE endpoints - ✅ Role Management: 7 types → 3 unified endpoints - ✅ Reminders: Schema fixes applied Summary: - 89% endpoint reduction (65 → 7) - 100% schema compatibility with ClashKingBot v2.0 - Complete API usage examples - Production-ready status All dashboard configuration needs are now covered.
Add DELETE /v2/server/{server_id}/clan/{clan_tag}/logs endpoint to remove
log configurations for specific log types.
Features:
- Delete multiple log types in one request via query parameter
- Query parameter accepts comma-separated log type list
- Uses MongoDB $unset to remove log configurations
- Compatible with dashboard branch claude/logs-channel-thread-fix-017B7mrL1LqN7ZGi3Gy4WAYs
Example usage:
DELETE /v2/server/123/clan/%232PP/logs?log_types=join_log,leave_log,donation_log
This endpoint complements the existing PUT endpoint which updates/creates log configurations.
Complete API reference for ClashKingDashboard integration: - All server settings endpoints - Clan management and settings endpoints - Logs configuration endpoints (including new DELETE endpoint) - Discord channels/threads endpoints - Reminders CRUD endpoints - Role management endpoints (unified) - Autoboards and links endpoints Each endpoint documented with: - Complete parameter list (including injected dependencies) - rest: hikari.RESTApp explicitly listed where used - Request/response examples - Authentication requirements - Error codes This document can be used in ClashKingDashboard repository as .claude/stats-endpoints-analysis.md
Added high and medium priority endpoints for ClashKingDashboard: Capital Endpoints: - GET /v2/capital/player-stats - Player raid statistics with pagination - GET /v2/capital/guild-leaderboard - Server clan leaderboard Activity Endpoints: - GET /v2/activity/guild-summary - Server-wide activity overview - GET /v2/activity/inactive-players - List of inactive members Legends Endpoints: - GET /v2/legends/guild-stats - Aggregate legend statistics - GET /v2/legends/daily-tracking - Daily trophy progression All endpoints follow established patterns: - Use @linkd.ext.fastapi.inject for dependency injection - Use @check_authentication with rest: hikari.RESTApp parameter - Include Pydantic models for request/response validation - Proper error handling (404, 400, etc.)
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
…int (#18) Co-authored-by: Claude <noreply@anthropic.com> fix: add missing aiohttp and requests dependencies
…ering
- Add GET /clan/{clan_tag}/members endpoint and register clan router in startup.py
- Fix FastAPI route ordering: /roster/missing-members before /roster/{roster_id}
- Add null clan_tag guard in analyze_roster_missing_members
- Remove allowed_signup_categories restriction from admin PATCH member endpoint
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add recurrence_day_of_month (1–31) to RosterUpdateModel as a mutually exclusive alternative to recurrence_days for fixed monthly events like CWL (e.g. always on the 1st of the month). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
create_standard_role and create_status_role previously updated existing records without error, allowing the same criterion to silently switch roles or be submitted multiple times. New behavior: - Same criterion + same role → 409 "This criterion is already linked to this role." - Same criterion + different role → 409 "This criterion already has a role assigned. Delete it first." Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ation
- Remove le=17 on TownhallRoleCreate.th (TH18 exists, max comes from
static endpoint /v2/static/buildings/{name}/maxlevel)
- Remove le=10 on BuilderHallRoleCreate.bh for same reason
- Replace Union[...] body parsing with model_class.model_validate(body)
so Pydantic only validates against the correct model for the given
role_type, eliminating cascading 'Field required' errors from all
other union variants
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… endpoint - Add _process_opponent_attacks_on_clan in utils.py to compute defensive stats (defenses count, stars_given, avg_stars_given) per clan member using best opponent attack per attacker, returned as defense field in each player stats item - Fix war_types pipeline filter to use data.type instead of root-level type field (random/friendly were never matching) - Add include_cwl parameter to /war/clan/stats endpoint (mirrors /previous) - Fix townhall_filter to avoid variable shadowing (war_types_list) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.