-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🏗️ Structure refactor T0 (discussion 31) #45
Conversation
You should add the LRFutils module to the |
I don't think storing the configuration in a python file is a good idea. From a code perspective, a python file is not ideal: importing the file to read the configuration will miss default value if the user decide to empty the file; there is also security concerns: if a user give his configuration file to another user, he can insert code that will be executed in the workspace of the second user, generally runing code in the configuration is a bad idea. I should also mention that a python file cannot really handle configuration levels, like what you can do in a json or a ini file. Storing configurations for all plugins in one file could also be a bad idea, because the constant used by a plugin could have the same name as a constant from an other plugin, resoulting in conflicts (this type of issue can easely be resolved in a json or yaml file by requiring a namespace for each plugin). If you create a module that handles default values, I don't see the advantages of using a python file instead of a json, yaml, ini file or whatever format you want. |
Using python as config files doesn't come from nowhere. Sphinx is using this method and it's proven to work. The problem you mentioned
Ok, the user can empty everything without consideration of what he will break... the config using python is not the problem here.
Yes, the user can accept a configuration file that will run weird code... as he can accept a plugin that will run weird code, the user is supposed to look at what he put in his bot... whatever the type of config you use, as long as the user put something in his bot without verification, it's dangerous.
wdym? As a JSON file is strictely equivalent to a python dictionary, nothing can be done using JSON that cannot using python 🤔
Then it's more a question of conventions, it's also possible to apply the same type of convention using python files (ex: start every config variable with the name of the plugin, or put them in a class that have the name of the plugin ... or even using a unique dictionary for each plugin ! There is plenty of possible solutions). If two plugin share the same name (ie namespace), the problem is the same using json files. The advantage of this solutionUsing python file allow to deal with variables instead of dictionnary entries, which is way more conveniant. Moreover, it's easier to enderstand that "import config" will... import the configuration variables contained in the file than using a function defined somewhere and that return something... that we have to check the doc to deal with. Moreover, running code in the configuration can have benefits. It's a file called at the very begining of the bot start and it is never overwritten, so it allow for users to add pre-run procedure to the bot, such I did in docs/conf.py (run by sphinx) TL;DRThe bot is made to be user friendly, not to prevent user stupidity |
Hum, actually, about conventions, maybe it would be better to enforce them, or else you'll be taking the risk of them not being respected. I would advocate restricting plugins to only seeing their own configuration, that would prevent a plugin trying to reinvent the wheel by reading itself some config which would otherwise be handled by the core.
Well, we can make a config.py which setup all those variables by reading the config. We would still need to e.g. for the friendly-ban plugin, upon installation you would be asked some questions like "which server would you like to enable friendly-ban in?" and then this may be added at the end of the config file: - friendly-ban:
- enabled-servers:
- 125723125685026816
- 835218602511958116
- disabled-events:
# this is empty by default, feel free to add any event id you want to disable Actually, I'm not sure about the |
If the config is setup properly, there should be default values for settings that the user did not fill. This is not possible using the python file for the configuration directly, but if you setup a json-based system for example, the configuration reader could fill the empty values.
As Aeris1One said, we should be in a zero-trust policy: the user is more likely to edit the configuration file that install plugins that are not ship with the installer (I think we will make an installer to improve the user accessibility).
It's much more intuitive to store nested data in JSON than in python. {
"levels": {
"default_levelup": {
"type": "message",
"content": "GG {user.mention}! You are now at the level {user.level}!",
"delete_after": "5s",
}
} class Levels:
class DefaultLevelup:
type=discord.Message
content="GG {user.mention}! You are now at the level {user.level}!"
delete_after=datetime.timedelta(seconds=5) I think using the types is the best way to do it for the Python configuration, as you don't need any extra parsing but the user needs to handle imports and to exactly know what he is doing.
Just imagine there is a plugin called archive_manager, and there is a sub option called archive_duration. The key for the configuration could quickly go very long?
As said before, what is the point of using a dictionnary where you could directly use a JSON file? |
Aussi, cette classe peut définir des accesseurs custom sur ces attributs, ce qui permet de faire de la validation/protection des données |
Bon je viens également donner mon avis sur le type de config, et je suis assez d'accord avec @ascpial et @Aeris1One. Pour moi, aucun intérêt de faire de la config avec un langage de programmation, et cela pour plusieurs raisons :
Si vous décidez tout de même de rester sur Python : ne JAMAIS faire un import comme ça de la config, ça pose de gros problèmes de sécurités (voulu par l'utilisateur, ou non). Au moins passez par le service de parsing de Python (module |
J'ai donc changé la gestion de la config pour utiliser des fichiers yaml. Il y a donc désmorais dans les plugins un fichier "config.yaml" et un fichier "setup.py" contenant une fonction "run()". Cette dernière est appelé lorsque le script Il y a donc :
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quelques petits points à revoir mais sinon ça me semble pas mal !
Je suis cependant pas fan de cela :
Pour être utilisé, il faut donc faire from core.config import global_config
Pour moi, un plugin ne devrait pas pouvoir avoir accès à la config des autres plugins, d'autant plus si l'accès est en édition. Je pense que la config devrait être injectée à la classe principale du plugin.
Dans d'autres projets j'aurais été d'accord mais je doute que ça soit nécessaire ici... et je ne vois pas trop comment faire ça proprement 😅 Le fait d'y avoir accès en lecture peut être intéressant, mais en effet, en écriture ça ne devrait pas arriver. |
Une classe s'occupe de charger les plugins (appelons-la PluginLoader ou PluginManager). Celui-ci est le seul à avoir accès à l'ensemble de la config. Au chargement du plugin (appel d'une fonction spéficique au plugin), il passe à celui-ci la config spécifique au dit plugin. |
Je suis tout à fait d'accord, et ca pourra aussi permettre de charger des données liées à l'extension sans lancer le bot (par exemple vérifier la configuration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'ai relu les changements et testé les nouvelles fonctionnalités et tout fonctionne comme attendu !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mettre à jour le README pour indiquer comment cloner les plugins de Gunivers
Le merge de cette PR est trop complexe du à l'arrivée du submodule, le merge s'est donc bricolé de cette façon :
(cette PR peut donc être considéré comme merged) |
* fix(readme): dead badge * fix(stats): merge failure * feat(antiscam): improve regex matching * feat(antiscam): improve training logs * fix(check): config reset bypass ignored guilds * fix(rss): DM commands + no tweet found * refract(stats): remove statuspage RAM usage * fix(yt): new youtube channel URL * refract(xp): better logs * fix(antiscam): regex replacement * feat(antiscam): improve training/saving process * fix(roles-react): deleted custom emoji * refract(tokens): improve credentials fetching * fix(top.gg): API stats posting for axobot * refract: rename Zbot class to Axobot * refract(doc): rename Zbot to Axobot in doc * refract(errors): variable name * fix(args): circular import * fix(logs): message update with pin/unpin * fix(twitch): log when loop fails * fix(help): config fetching * feat(serverconfig): 1st version of the new system * feat(serverconfig): update every config call * fix(serverconfig): xp stats * refract(alias): avoid using ctx.invoke * feat(doc): refresh documentation * feat(doc): use spinx book theme * fix(doc): references and tocdepth * fix(doc): dependencies list * feat(doc): v4.3.0 * feat(config): french translations * feat(modlogs): add msg creation time when deleted * fix(find): rss with NUL date * fix(error): slash command name * fix(logs): difference between nick and username * New Crowdin updates (#44) * Update source file en.json * Update source file en.json * Update source file en.json * feat(actions): upgrade to checkout v3
* V4.3.0 (#45) * fix(readme): dead badge * fix(stats): merge failure * feat(antiscam): improve regex matching * feat(antiscam): improve training logs * fix(check): config reset bypass ignored guilds * fix(rss): DM commands + no tweet found * refract(stats): remove statuspage RAM usage * fix(yt): new youtube channel URL * refract(xp): better logs * fix(antiscam): regex replacement * feat(antiscam): improve training/saving process * fix(roles-react): deleted custom emoji * refract(tokens): improve credentials fetching * fix(top.gg): API stats posting for axobot * refract: rename Zbot class to Axobot * refract(doc): rename Zbot to Axobot in doc * refract(errors): variable name * fix(args): circular import * fix(logs): message update with pin/unpin * fix(twitch): log when loop fails * fix(help): config fetching * feat(serverconfig): 1st version of the new system * feat(serverconfig): update every config call * fix(serverconfig): xp stats * refract(alias): avoid using ctx.invoke * feat(doc): refresh documentation * feat(doc): use spinx book theme * fix(doc): references and tocdepth * fix(doc): dependencies list * feat(doc): v4.3.0 * feat(config): french translations * feat(modlogs): add msg creation time when deleted * fix(find): rss with NUL date * fix(error): slash command name * fix(logs): difference between nick and username * New Crowdin updates (#44) * Update source file en.json * Update source file en.json * Update source file en.json * feat(actions): upgrade to checkout v3 * fix(admin): update command * fix(logs): database backup detection * feat(tr): new guild features translations * fix(doc): `config change` being renamed to `set` * rmv(prefix): `prefix change` subcommand * feat(fun): re-enable weather command * fix(help): not working in DMs * fix(logs): DM logs with nearly 2k characters * fix(prefix): make it a command instead of group * feat(tickets): better error when fails to create * feat(tickets): add `tickets review-config` cmd * feat(doc): v4.3.1 * fix(doc): typo in "antiscam" server logs * feat(rss): use paginator for rss list * refract(paginator): faster view refresh * refract(rss): cap list to 10 feeds/page * refract(pagination): better disabling workflow * fix(xp): always disabled * fix(xp): always disabled * fix(xp): levelup channel config * fix(xp): levelup channel config * New Crowdin updates (#47) * Update source file en.json * Update source file en.json * fix(xp): levelup check * fix(xp): levelup check * fix(memberchannel): error log * feat(serverlogs): add tickets errors * feat(doc): emojis and cards * feat(reminder): new creation example * feat(deps): update LRFutils * fix(error): help command mention * feat(modlogs): add role deletion * feat(serverlogs): role_update logs * feat(xp): private rank command * fix(db): remote connection * fix(xp): font usage * Create .github/FUNDING.yml * refract(ticket): better ticket summary text * refract(serverlogs): factorise audit logs search * feat(slash): migrate about command * feat(usernames): disable usernames history feature * fix(sconfig): hidden config options * feat(stats): save audit logs search success rate * feat(slash): migrate remindme command * refract(lint): remove unusued import * refract(lint): add missing space * feat(tips): add rank card background tip * feat(tips): implement cache * feat(tips): lower rank card tip probability * feat(crowdin): better commit message * Revert "feat(crowdin): better commit message" This reverts commit 6b9f52f. * New Crowdin updates (#48) * Update source file en.json * Update source file en.json * New translations en.json (LOLCAT) * New translations en.json (LOLCAT) * New translations en.json (LOLCAT) * New translations en.json (LOLCAT) * Update source file en.json * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * Update translations %original_path% (%language%) * Update translations %original_path% (Finnish) * Update translations %original_path% (LOLCAT) * Update translations %original_path% (Spanish) * feat(readme): update d.py version badge * feat(doc): update `profile` cmd doc * feat(git): update pre-commits actions * refract(requirements): cleanup requirements file * feat(lint): cleanup all files * feat(slash): migrate profile command * feat(error): avoid truncating the traceback * fix(clear): users check * fix(mc): server status JSON error * refract(user): cleaner user config change+query * feat(tips): disable card tip if already changed * Update source file en.json (#50) * V4.3.1 (#51) * fix(logs): database backup detection * feat(tr): new guild features translations * fix(doc): `config change` being renamed to `set` * rmv(prefix): `prefix change` subcommand * feat(fun): re-enable weather command * fix(help): not working in DMs * fix(logs): DM logs with nearly 2k characters * fix(prefix): make it a command instead of group * feat(tickets): better error when fails to create * feat(tickets): add `tickets review-config` cmd * feat(doc): v4.3.1 * fix(doc): typo in "antiscam" server logs * feat(rss): use paginator for rss list * refract(paginator): faster view refresh * refract(rss): cap list to 10 feeds/page * refract(pagination): better disabling workflow * fix(xp): always disabled * fix(xp): levelup channel config * New Crowdin updates (#47) * Update source file en.json * Update source file en.json * fix(xp): levelup check * fix(memberchannel): error log * feat(serverlogs): add tickets errors * feat(doc): emojis and cards * feat(reminder): new creation example * feat(deps): update LRFutils * fix(error): help command mention * feat(modlogs): add role deletion * feat(serverlogs): role_update logs * feat(xp): private rank command * fix(db): remote connection * fix(xp): font usage * Create .github/FUNDING.yml * refract(ticket): better ticket summary text * refract(serverlogs): factorise audit logs search * feat(slash): migrate about command * feat(usernames): disable usernames history feature * fix(sconfig): hidden config options * feat(stats): save audit logs search success rate * feat(slash): migrate remindme command * refract(lint): remove unusued import * refract(lint): add missing space * feat(tips): add rank card background tip * feat(tips): implement cache * feat(tips): lower rank card tip probability * feat(crowdin): better commit message * Revert "feat(crowdin): better commit message" This reverts commit 6b9f52f. * New Crowdin updates (#48) * Update source file en.json * Update source file en.json * New translations en.json (LOLCAT) * New translations en.json (LOLCAT) * New translations en.json (LOLCAT) * New translations en.json (LOLCAT) * Update source file en.json * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * New translations en.json (Finnish) * Update translations %original_path% (%language%) * Update translations %original_path% (Finnish) * Update translations %original_path% (LOLCAT) * Update translations %original_path% (Spanish) * feat(readme): update d.py version badge * feat(doc): update `profile` cmd doc * feat(git): update pre-commits actions * refract(requirements): cleanup requirements file * feat(lint): cleanup all files * feat(slash): migrate profile command * feat(error): avoid truncating the traceback * fix(clear): users check * fix(mc): server status JSON error * refract(user): cleaner user config change+query * feat(tips): disable card tip if already changed * Update source file en.json (#50) * refract(action): update CodeQL triggers * feat(doc): update documentation URLs * fix(usernames): disable new usernames storing * feat(rank): delete invocation for private rankcard * fix(config): code using old table * fix(stats): antiscam enabled count
Discussion 31
ToDo List: