DEV Community

Cover image for Keeping Discord channels up-to-date
SudoJunior
SudoJunior

Posted on

Keeping Discord channels up-to-date

Disclaimer

This uses channel-backup that I have developed and published myself under the 'TinkerStorm' organization over the last year or so. Since its creation, it has gone through 6 iterations, only the most recent iteration being published.

GitHub logo TinkerStorm / channel-backup

A command line tool to help Community Managers keep their information channels updated.

channel-backup

GitHub branch checks state GitHub repo size GitHub Repo stars npm node-current

A command line tool to help Community Managers keep their information channels updated.

Notes on progress can be found on the project board.

I am aware this program does not follow the regular conventions of an interface, but I have done my best to ensure that it is accessable with regular scripts like you would use the terminal. That said, I discourage it with upmost concern. In theory, this can be applied to monorepo setups where multiple channels are setup with webhooks to keep their information up to date, all that would need to be done is run the command across all packages.

Usage

The cache.json file that contains message IDs of all messages sent in the previous sequence (local updated). For any data structure files (including yml and json) are following the structural pattern of WebhookMessageOptions (discord.js). cache.json is both fetched and dumped wherever the…


Problem Theory

The problem most community managers may face when they need to update their information channels is that they have to update it themselves; ask a specific author; or know how to update a bot message using commands, web dashboard, etc.

While it may be a bit of a stretch to say that I've solved this problem, I think that it opens an opportunity for community members to help with contributions to the information channels instead of being reliant on an individual or selected group of delegates. No harsh feelings towards those people though, I'm sure they do just fine. πŸ™‚

Prior to being published, the script was just 180 lines stuffed into one file - which was sometimes iterated upon when I needed to do something new with it. πŸ˜‚ I finally decided to motivate myself to publish it as someone had come to me, wanting to set it up on their own community.

Explanation

The config can be setup to use direct file references or glob patterns that match to specific files in sequence. The program is theoretically accessible from an interface standpoint by importing its method directly into your own scripts, but is preferred from the command line.

{
  "$schema": "https://github.com/TinkerStorm/channel-backup/raw/main/schemas/config.json",
  "files": {
    "./rules/*.md"
  }
}
Enter fullscreen mode Exit fullscreen mode

Matching to any markdown file in the 'rules' folder (but no sub-directory).

The webhook can be specified as part of the config if you would prefer to keep it among your staff team, however it isn't preferred. With the release of v1.1.1 yesterday, it added support to set WEBHOOK_URL as an environment variable to be loaded in.

A demo of this can be seen on TinkerStorm's community repository, with it's folders, configurations and matrix run. When dispatched, this is sent directly to the Discord server.


Example workflow run (expected to expire on Nov 10th, 2021)

# INFO_CHANNEL_WEBHOOK, ./info/config.json

> channel-backup-template@1.0.0 sequence
> channel-backup "--config" "./info/config.json"

Found 4 files in ./info/0*.md
steps(handle-message) './info/01_welcome.md' -> '875471689432039494'
steps(handle-message) './info/02_rules.md' -> '875471694070943744'
steps(handle-message) './info/03_channels.md' -> '875471698718253117'
steps(handle-message) './info/04_roles.md' -> '875471703394897950'
step(cleanup:update) 4 messages.

# README_CHANNEL_WEBHOOK, ./readme/config.json

> channel-backup-template@1.0.0 sequence
> channel-backup "--config" "./readme/config.json"

Found 2 files in ./readme/*-projects.md
Found 1 files in ./readme/community-upkeep.md
steps(handle-message) './readme/core-projects.md' -> '875475818036473917'
steps(handle-message) './readme/side-projects.md' -> '875475822620864584'
steps(handle-message) './readme/community-upkeep.md' -> '875475827444301825'
step(cleanup:update) 3 messages.

# ---
# {if cache.json was modified}
# set git name and email, then commit and push

[main 08c120d] auto: Update cache.json
 1 file changed, 1 insertion(+), 1 deletion(-)
To https://github.com/TinkerStorm/community
   6196053..08c120d  main -> main
Enter fullscreen mode Exit fullscreen mode

Conclusion

As an organization, we intend to expand this further into a more cohesive ecosystem that helps to better connect communities with their members.

If you want to set this up for your own server, make your own from our repository template. If you want to deploy on a CI workflow, feel free to use our deploy workflow as a reference (which will also add the generated cache.json back into the repository. If you need any help with setting this up, drop by our Discord server and we'll see what we can do.

GitHub logo RocketDragon / channel-backup-template

A template for channel-backup.

Other possible uses

  • Interval sticky message using GitHub Actions on a cron timer (with --mode replace active).

Notes

I am aware that discord.js@v13.x requires NodeJS 16.6.x or above, which should be patched with the release of channel-backup@v1.1.2. Furthermore, we hope to further amend to community commitment by providing a custom webhook interface - designed for this library, which will hopefully support more LTS versions.

If you attempt a matrix build and try to add a ${{ secrets.* }} in as part of ${{ matrix.* }}, the workflow will fail. Instead reference the key as part of the matrix and then use ${{ secrets[matrix.*] }}.

I have also been made aware that multiple matrix runs cannot run in parallel, for which I have concluded the only way to resolve is to run sequential with max-parallel: 1. Payload trimming / sanitisation isn't done either, so entities like HTML comments become literal strings.

Planned features include:

  • GitHub Action Integration > Partial completion, with workflow demo.
  • Payload validation and comparison
  • Better cli support
  • Better logging
  • Unit tests
  • Extensive plugin support

Other possible features:

  • Discord Message Components - Requires application webhook with a server listening
  • Multi platform support (only if they have PATCH and DELETE endpoints)

Top comments (0)