Skip to content
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

Implement configuration checking #9

Closed
huenique opened this issue Sep 29, 2021 · 6 comments · Fixed by #20
Closed

Implement configuration checking #9

huenique opened this issue Sep 29, 2021 · 6 comments · Fixed by #20
Assignees
Labels
enhancement New feature or request hacktoberfest https://hacktoberfest.digitalocean.com/ help wanted Extra attention is needed

Comments

@huenique
Copy link
Member

To some degree, Dayong allows high-level customization through the config.json file. Although we only use it now to change how we experience commands and interactions, it's likely to cause erroneous behaviors, especially as the config file becomes larger as we add more features that rely on it.

Configuration checking helps us avoid any problems that may arise from using the config.json file by first verifying that software requirements are met. It's basically just a process that tells us whether a configuration is good or bad. Dayong does not have that kind of functionality yet.

@huenique huenique added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed hacktoberfest https://hacktoberfest.digitalocean.com/ labels Sep 29, 2021
@huenique
Copy link
Member Author

huenique commented Sep 29, 2021

Here's an incomplete implementation we can use as an example:

In configs.py:

def verify_config(config: dict) -> None:
    # Initialize keys expected to be in the config.json file.
    valid_keys = [
        "bot_prefix",
    ]

    for key in valid_keys:
        if key not in list(config.keys()):
            raise KeyError(f"{key} is missing from the configuration file.")

This can also be a static method. Ideally, the program should immediately fail if the config file is bad or invalid. If it does fail, it would be nice to have a more useful error message, like instruction or a tip or whatever.


It's worth noting that, in this example, the function takes a dictionary as an argument. The dictionary object is the parsed JSON file and is passed from the DayongConfigLoader.load_cfg() method in which said file is loaded.

@huenique huenique removed the good first issue Good for newcomers label Sep 30, 2021
@avinash-tiwari
Copy link
Contributor

@huenique I wanna work on this issue, can you assign this issue to me, I can start looking at it first.
Thanks.

@huenique
Copy link
Member Author

@avinash-tiwari it's yours!

@ooliver1
Copy link
Contributor

ill take this up

@huenique
Copy link
Member Author

@ooliver1 go ahead 🍻

@ooliver1
Copy link
Contributor

Lmao I may have done it pretty good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest https://hacktoberfest.digitalocean.com/ help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants