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

Scaffold server config via a bootstrapping script #2408

Merged
merged 195 commits into from
Mar 9, 2023

Conversation

shtlrs
Copy link
Member

@shtlrs shtlrs commented Feb 15, 2023

TL;DR

Removes the the needed manual work to fill the config.yaml file with all the channel/role/category values of the test server

Pain point

Configuring the bot is a very painful procedure due to how overwhelming & big the configuration file is. This makes contribution to people who aren't familiar with our project very discouraging, and people would often find themselves too lazy to configure it, confused in terms of what to configure and what not, or unable to configure since the contribution guide needs to be read thouroughly, etc.

Idea

The idea is to have a script that would magically build the necessary configuration with a click of a button/a single command.
Since the bot doesn't need all the channels, roles, categories, icons, emojis, etc. to be configured, the script would only prepare the necessary server related variables

This is simply achievable by following these steps

  1. Create a test server out of our test server's template
  2. Configure the bootstrapping script
  3. Run the script
  4. Run the bot

Configuring & launching the site project is out of scope of this tutorial but necessary for the bot to work. Details on how to configure it can be found here

Configuring the script

This is as simple as

  1. Making sure there's a .env file created in the root directory of your project (if not, please add it)
  2. Setting the BOT_TOKEN variable with a value likewise: BOT_TOKEN=your-bot-token
  3. Setting the GUILD_ID variable with a value likewise: GUILD_ID=your-discord-server-id

Running the script

Once BOT_TOKEN and GUILD_ID are configured, it should be as simple as running python bootstrap_config.py

The script will

  1. Fetch all channels, categories and roles in the server
  2. Save data in a dictionaries where keys represent the channel name, category name or role name, and the value will be the id of that item
  3. Iterate the fields in the constants classes that are related to the server, namely Categories, Channels and Categories
  4. Try to find a match for each field of the class constants in the previously populated dictionaries.
  5. Save the matched ids in the .env.server environment variables file

Changelog

  1. Replace the usage of .yaml files for configuration with .env files
  2. Use Pydantic for parsing values from the environment variables AND the environment files

Todo:

  • Add checks on mandatory variables that need to be present
  • Update guide on site
  • Discuss backwards compatibility solutions (if supported)
  • Renew the template so that warnings of missing channels/roles/categories/etc. reduce down

@HassanAbouelela HassanAbouelela marked this pull request as draft February 15, 2023 16:21
@shtlrs shtlrs changed the title [POC] Scaffold server config via a bootstrap script [POC] Scaffold server config via a bootstrapping script Feb 16, 2023
@shtlrs shtlrs requested a review from wookie184 as a code owner March 2, 2023 09:55
@shtlrs
Copy link
Member Author

shtlrs commented Mar 2, 2023

Hey there's one thing I forgot, the current bootstrap doesn't handle off-topic channels which automatically change names every 24 hours. Can we special case OT channels during bootsrap? Generally, the names will always take the form of ot<int>-name..., and be in the Off-Topic category. If you have a preferred implementation, please proceed with it, otherwise let me know.

It's been handled in 4b4b65b

@python-discord-policy-bot python-discord-policy-bot bot dismissed HassanAbouelela’s stale review March 4, 2023 07:35

Dismissed because the approval was invalidated by another commit

Comment on lines +143 to +144

contributors = 295488872404484098
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be a comment before these. Right now at first glance it looks as if they're self assignable

Copy link
Member

@ChrisLovering ChrisLovering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, tested locally and all looks good.

@mbaruh mbaruh changed the title [POC] Scaffold server config via a bootstrapping script Scaffold server config via a bootstrapping script Mar 8, 2023
@HassanAbouelela
Copy link
Member

This is being merged now, handling any issues.

@HassanAbouelela HassanAbouelela removed the review: do not merge The PR can be reviewed but cannot be merged now label Mar 9, 2023
@HassanAbouelela HassanAbouelela merged commit 12fe15b into python-discord:main Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: 2 - normal Normal Priority review: needs devops s: needs review Author is waiting for someone to review and approve t: enhancement Changes or improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto Config/Setup
4 participants