From fff925bf988e786f9fd1a3e17dfa66ea5867dea6 Mon Sep 17 00:00:00 2001 From: Jinzo <91829829+pernio@users.noreply.github.com> Date: Thu, 10 Sep 2026 13:53:41 +0200 Subject: [PATCH 1/2] Automate motd --- .github/workflows/update-main-conf.yml | 82 ++++++++++++++++++++++++++ README.md | 6 +- edit-me.txt | 3 + main.conf | 8 +-- settings.yml | 8 +++ 5 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/update-main-conf.yml create mode 100644 edit-me.txt create mode 100644 settings.yml 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..41310a2 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 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}" From 61f0e66052318289092e4b107270f725ea986e59 Mon Sep 17 00:00:00 2001 From: Jinzo <91829829+pernio@users.noreply.github.com> Date: Thu, 10 Sep 2026 14:00:49 +0200 Subject: [PATCH 2/2] Finish readme --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 41310a2..9c331c4 100644 --- a/README.md +++ b/README.md @@ -16,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