Awarn and leaderboard improve - #1
Merged
Merged
Conversation
Reviewer's GuideRefactors the /leaderboard command to support both per-department and global leaderboards with richer embeds, introduces configurable per-department warn weight limits that drive awarn severity coloring and gauges, and extends the database schema and department/shop admin tooling to support these new capabilities (including shop item icons). Sequence diagram for the updated /leaderboard commandsequenceDiagram
actor User
participant Discord
participant PointsCog
participant Database
User->>Discord: invoke /leaderboard [department?, limit]
Discord->>PointsCog: leaderboard(interaction, department, limit)
PointsCog->>Database: require_configured_guild
Database-->>PointsCog: configured?
alt not configured or not in guild
PointsCog-->>Discord: error embed (only works in guild)
else configured
PointsCog->>PointsCog: branch on department is not None
alt single department mode
PointsCog->>Database: get_department_by_key / resolve_department
Database-->>PointsCog: Department or None
alt department not found
PointsCog-->>Discord: unknown department error
else department found
PointsCog->>Database: _can_view_leaderboard(caller, dept.id)
Database-->>PointsCog: allowed?
alt not allowed
PointsCog-->>Discord: "Нет доступа" error embed
else allowed
PointsCog->>Database: dept_leaderboard(dept.id, limit)
Database-->>PointsCog: list of (user_id, points)
alt empty rows
PointsCog-->>Discord: info "Доска пуста" embed
else has rows
PointsCog->>Database: dept_user_rank(dept.id, caller.id)
PointsCog->>Database: get_dept_balance(caller.id, dept.id)
Database-->>PointsCog: rank, caller_points
PointsCog->>PointsCog: build bars with _mini_bar and lines
PointsCog->>Discord: send embed (single dept leaderboard)
end
end
end
else global mode (all departments)
PointsCog->>Database: list_departments(guild.id)
Database-->>PointsCog: list of Department
alt no departments
PointsCog-->>Discord: info "Нет департаментов" embed
else departments exist
PointsCog->>Database: is_admin / is_auditor / is_curator_of_department / get_dept_balance
Database-->>PointsCog: visible departments for caller
alt caller sees no departments and not privileged
PointsCog-->>Discord: info "Нет данных" embed
else has visibility or privileged
PointsCog->>Database: guild_leaderboard(guild.id, limit, visible_dept_ids)
Database-->>PointsCog: list of (user_id, total, breakdown)
alt no rows
PointsCog-->>Discord: info "Доска пуста" embed
else rows
PointsCog->>PointsCog: build per user bars and breakdown lines
PointsCog->>Database: guild_user_total_rank(guild.id, caller.id, visible_dept_ids)
Database-->>PointsCog: (rank, total)
PointsCog->>Discord: send embed (global leaderboard)
end
end
end
end
end
ER diagram for departments, balances, and shop_items with new fieldserDiagram
DEPARTMENTS {
int id PK
int guild_id
text key
text name
int sort_order
datetime created_at
int log_channel_id
real max_awarn_weight
}
DEPARTMENT_BALANCES {
int user_id
int department_id FK
int points
}
SHOP_ITEMS {
int guild_id
int department_id FK
int role_id
int price
int duration_days
text description
text icon_emoji
real price_growth
}
DEPARTMENTS ||--o{ DEPARTMENT_BALANCES : has
DEPARTMENTS ||--o{ SHOP_ITEMS : offers
Class diagram for updated Department, ShopItem, and Database methodsclassDiagram
class Department {
int id
int guild_id
str key
str name
int sort_order
datetime created_at
int log_channel_id
float max_awarn_weight
}
class ShopItem {
int guild_id
int department_id
int role_id
int price
int duration_days
str description
str icon_emoji
float price_growth
int effective_price(prior_count)
}
class Database {
int CURRENT_SCHEMA_VERSION
run()
_migrate_to_v9()
_migrate_to_v10()
create_department(guild_id, key, name, sort_order, max_awarn_weight) Department
get_department(department_id) Department
get_department_by_key(guild_id, key) Department
list_departments(guild_id) list~Department~
set_department_log_channel(department_id, channel_id)
set_department_max_awarn_weight(department_id, max_awarn_weight)
get_user_dept_balances(guild_id, user_id) list~tuple~
dept_leaderboard(department_id, limit) list~tuple~
guild_leaderboard(guild_id, limit, dept_ids) list~tuple~
guild_user_total_rank(guild_id, user_id, dept_ids) tuple
dept_user_rank(department_id, user_id) int
upsert_shop_item(guild_id, department_id, role_id, price, duration_days, description, icon_emoji)
list_shop_items(guild_id, department_id) list~ShopItem~
get_shop_item(guild_id, department_id, role_id) ShopItem
_department_from_row(row) Department
_shop_item_from_row(row) ShopItem
}
Database "1" --> "*" Department : manages
Database "1" --> "*" ShopItem : manages
Department "1" --> "*" ShopItem : optional_shop_items
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
_join_truncated, the length checkif total + needed + (len(sep) if parts else 0) + len(ellipsis) > max_lenappears to double-count the separator (it’s already included inneeded), which can cause earlier-than-necessary truncation; consider re-deriving this condition so each separator is only counted once.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_join_truncated`, the length check `if total + needed + (len(sep) if parts else 0) + len(ellipsis) > max_len` appears to double-count the separator (it’s already included in `needed`), which can cause earlier-than-necessary truncation; consider re-deriving this condition so each separator is only counted once.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Summary by Sourcery
Introduce configurable warning thresholds per department and enhance guild-wide leaderboard visibility and formatting.
New Features:
Enhancements:
Build: