Closed Atmois closed 1 month ago
Almost ready just waiting on @AmilieCoding to push the embeds
This pull request implements a leveling system for the Discord bot. It introduces new commands for managing user levels and XP, adds a database model for storing level data, and includes a service for handling XP increments and level-ups. The implementation allows for configuration of blacklisted channels, XP multipliers, and level role rewards through a settings file.
journey
title User Journey for Leveling System Commands
section Level Commands
level: User -> Bot: Fetch XP and level
levelset: Admin -> Bot: Set user level
section XP Commands
xpset: Admin -> Bot: Set user XP
xpreset: Admin -> Bot: Reset user XP
section Blacklist Commands
xpblacklist: Admin -> Bot: Toggle XP blacklist for user
erDiagram
GUILD {
int guild_id
}
LEVELS {
int member_id
int guild_id
float xp
int level
datetime last_message
bool blacklisted
}
GUILD ||--o{ LEVELS : "has"
LEVELS }|--|| GUILD : "belongs to"
classDiagram
class LevelsService {
- Tux bot
- LevelsController levels_controller
- int xp_cooldown
- float levels_exponent
- dict xp_roles
- dict xp_multipliers
+ xp_listener(discord.Message)
+ process_xp_gain(discord.Member, discord.Guild)
+ is_on_cooldown(datetime.datetime) bool
+ handle_level_up(discord.Member, discord.Guild, int)
+ update_roles(discord.Member, discord.Guild, int)
+ try_assign_role(discord.Member, discord.Role)
+ calculate_xp_for_level(int) float
+ calculate_xp_increment(discord.Member) float
+ calculate_level(float) int
+ valid_xplevel_input(int) discord.Embed | None
+ generate_progress_bar(int, int, int) str
+ get_level_progress(float, int) tuple[int, int]
}
class LevelsController {
+ ensure_guild_exists(int) Guild
+ get_xp(int, int) float
+ get_level(int, int) int
+ get_xp_and_level(int, int) tuple[float, int]
+ get_last_message_time(int, int) datetime.datetime | None
+ is_blacklisted(int, int) bool
+ update_xp_and_level(int, int, float, int, datetime.datetime)
+ toggle_blacklist(int, int) bool
+ reset_xp(int, int)
}
LevelsService --> LevelsController
Change | Details | Files |
---|---|---|
Implemented a leveling system service |
|
tux/cogs/services/levels.py |
Added database controller for levels |
|
tux/database/controllers/levels.py |
Implemented level-related commands |
|
tux/cogs/levels/level.py tux/cogs/levels/levelset.py tux/cogs/levels/xpset.py tux/cogs/levels/xpblacklist.py tux/cogs/levels/xpreset.py |
Description
Implements levelling system, allows configuration of blacklisted channels and mutlipliers & level role rewards in settings.yml.
New commands: xpset levelset xpblacklist xp xpreset xplacklist is toggleable bool to make user unable to gain xp xpreset sets level and xp to 0 xpset and levelset update the relevant value and change the other to the appropiate amount
New db model "levels" to store all the new data into the db
New service levels.py to increment xp on message send
Checks to ensure that inputs are valid
Guidelines
My code follows the style guidelines of this project (formatted with Ruff)
I have performed a self-review of my own code
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation if needed
My changes generate no new warnings
I have tested this change
Any dependent changes have been merged and published in downstream modules
I have added all appropriate labels to this PR
[X] I have followed all of these guidelines.
How Has This Been Tested? (if applicable)
Tested extensivly in ATL Dev sandbox
Screenshots (if applicable)
n/a
Additional Information
thanks to @AmilieCoding for some coding contributions and @wlinator and @kzndotsh for improvements for a PR and all the contributors for input on how to implement and help on testing this!