diff --git a/.github/workflows/update-main-conf.yml b/.github/workflows/update-main-conf.yml new file mode 100644 index 0000000..43cd668 --- /dev/null +++ b/.github/workflows/update-main-conf.yml @@ -0,0 +1,82 @@ +name: Update main.conf + +on: + pull_request: + types: + - closed + branches: + - main + +permissions: + contents: write + +jobs: + update-main-conf: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + + steps: + - name: Check out main + uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 + + - name: Generate main.conf + run: | + python <<'PY' + import re + from pathlib import Path + + def read_setting(text, key): + match = re.search(rf'(?m)^{re.escape(key)}:\s*"(.*)"\s*$', text) + if not match: + raise SystemExit(f'Missing "{key}" in settings.yml') + return match.group(1) + + def conf_quote(value): + return value.replace('\\', '\\\\').replace('"', '\\"') + + settings = Path('settings.yml').read_text(encoding='utf-8') + title = read_setting(settings, 'title') + description_template = read_setting(settings, 'description') + + messages = [ + line.strip() + for line in Path('edit-me.txt').read_text(encoding='utf-8').splitlines() + if line.strip() + ] + + motds = ['motds=['] + for index, message in enumerate(messages): + description = description_template.replace('{motd}', message) + motds.extend([ + ' {', + f' line1="{conf_quote(title)}"', + f' line2="{conf_quote(description)}"', + ' icon=random', + f' }}{"," if index < len(messages) - 1 else ""}', + ]) + motds.append(']') + motds_block = '\n'.join(motds) + + config_path = Path('main.conf') + config = config_path.read_text(encoding='utf-8') + updated = re.sub( + r'(?s)motds=\[\s*.*?\n\]', + motds_block, + config, + count=1, + ) + if updated == config: + print('main.conf is already up to date') + else: + config_path.write_text(updated, encoding='utf-8') + print('Updated main.conf') + PY + + - name: Commit generated main.conf + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: Update main.conf from edit-me.txt + file_pattern: main.conf diff --git a/README.md b/README.md index 1a6c66e..9c331c4 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # MOTD -This is a collection of all messages that are displayed in the server list. The configuration file can be found in [main.conf](main.conf). +This is a collection of all messages that are displayed in the server list. The built configuration file can be found in [main.conf](main.conf). ![Server message of the day](images/motd.png) ## Pull requests -We accept your submissions! You may clone this repository, modify the `motds` array in [main.conf](main.conf) and create a pull request in . +We accept your submissions! You may clone this repository, add a new line in [edit-me.txt](edit-me.txt) and create a pull request in . + +When the pull request gets approved, Github will update [main.conf](main.conf) to match [edit-me.txt](edit-me.txt). ### Rules @@ -14,3 +16,15 @@ To avoid controversy or inappropriate sentences, the guideline rules below will - No advertisements - No slurs + +## How to contribute + +- Clone project using `git clone https://github.com/BorderMC/motd.git` +- Read [the rules](#rules) +- Edit [edit-me.txt](edit-me.txt) +- Make a branch with `git branch /` for example `git branch pernio/nether-reset-info` +- Switch to branch with `git switch /` for example `git switch pernio/nether-reset-info` +- Add all files to git using `git add .` +- Commit message using `git commit -m ""` for example `git commit -m "Added new motd message"` +- Push using `git push --set-upstream origin /` for example `git push --set-upstream origin pernio/nether-reset-info` +- Create a pull request in diff --git a/edit-me.txt b/edit-me.txt new file mode 100644 index 0000000..6f3d30b --- /dev/null +++ b/edit-me.txt @@ -0,0 +1,3 @@ +We're fun to play with +Now fully open! +Nether reset 1/10/2026 \ No newline at end of file diff --git a/main.conf b/main.conf index 91e06a2..aa107d0 100644 --- a/main.conf +++ b/main.conf @@ -1,7 +1,9 @@ # ----------------------------------------------- -# Add a new item in motds. +# DO NOT EDIT THIS FILE + +# ----------------------------------------------- motds=[ { @@ -16,10 +18,6 @@ motds=[ } ] -# Do not edit below this line - -# ----------------------------------------------- - motd-enabled=true icon-enabled=true diff --git a/settings.yml b/settings.yml new file mode 100644 index 0000000..437c89b --- /dev/null +++ b/settings.yml @@ -0,0 +1,8 @@ +# ----------------------------------------------- + +# DO NOT EDIT THIS FILE + +# ----------------------------------------------- + +title: "BorderMC - Released!" +description: "{motd}"