Skip to content

- Auto-scan roles/*.json on startup and merge into built-in roles - #2891

Merged
zhayujie merged 1 commit into
zhayujie:masterfrom
sufan721:feat-add-role-module
Jun 13, 2026
Merged

zhayujie merged 1 commit into
zhayujie:masterfrom
sufan721:feat-add-role-module

Conversation

@sufan721

Copy link
Copy Markdown
Contributor
  • Same title overrides built-in role; different title appends as new
  • roles/ directory is optional — no impact when absent

Users can now add custom roles by simply dropping a .json file
into the roles/ directory and restarting. No config changes needed.

What does this PR do?

Previously, adding a custom role required editing roles.json directly,
which is bundled with the plugin and easily overwritten on updates.
This PR adds an optional roles/ directory: users can place individual
.json role files there, and they are auto-loaded and merged on startup.
A role with the same title as a built-in one overrides it; otherwise
it is appended as a new role. No mapping files or config changes needed.

Changes

File Change Description
role.py +30 lines Added roles/ directory scan in __init__ and new _load_role_file method
README.md Updated Documented the new roles/ directory usage
Function Role
_load_role_file(filepath) Load a single .json role file; if title matches an existing role, evict it from
old tag lists and replace; otherwise append as new. Unknown tags are auto-registered.
__init__ (modified) After loading built-in roles.json, scan roles/ for *.json files and merge them via
_load_role_file. Clean up empty tags afterward.

Type of change

  • Bug fix
  • New feature
  • Docs
  • Refactor / chore

Checklist

  • I have read the Contributing Guide
  • I tested this change locally
  • Code comments and docs are in English
  • Linked related issue (if any): closes #

  - Same title overrides built-in role; different title appends as new
  - roles/ directory is optional — no impact when absent

  Users can now add custom roles by simply dropping a .json file
  into the roles/ directory and restarting. No config changes needed.
@zhayujie

Copy link
Copy Markdown
Owner

thanks for the quick turnaround, this is exactly the right approach! Keeping roles.json untouched and scanning an optional roles/ directory makes it fully backward compatible: default installs are unaffected (the os.path.isdir guard skips when the dir is absent), and per-file load failures are caught so they can't break plugin init. Clean and minimal. Merging now
thanks for the contribution 🎉

@zhayujie
zhayujie merged commit 047fb57 into zhayujie:master Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants