Skip to content

Repository files navigation

Supportmail Helper

The source code of the helper bot for the SupportMail support server.

If you want to use this code, you can do so by forking this repository and modifying the code to fit your needs.

Installation and Usage

Prerequisites

Setup

1. Fork the repository

Fork this repository to your own GitHub account to create a personal copy of the code.

2. Clone the repository

git clone https://github.com/<your-username>/<repositoryname>.git
cd <repositoryname>

2. Install dependencies

bun install

3. Environment Configuration

Create environment files in the root directory, based on the .env.example file:

  • .env.dev: For development environment variables
  • .env.production: For production environment variables

DB_ENCRYPTION_KEY is the AES-256-GCM key for encrypted DB fields: 64 hex chars, generate with openssl rand -hex 32.

4. Configure the bot

  • Invite your bot to your Discord server with the necessary permissions
  • Set up the required channels and roles according to your server structure
  • Copy example.config.json to config.json and edit it (validated against config-schema.json)
  • Copy example.vote.yaml to vote.yaml to customize the vote message, the role-lost DM and the vote bots. The file is re-read on change (no restart); if it is missing or invalid, the example file is used.

Running the Bot

Development mode:

bun dev

Production mode (systemd):

The bot runs as the systemd unit sm-helper.service (user helper, checkout /home/helper/bot). One-time setup, by a user with sudo, from the checkout:

sudo make install   # unit, MongoDB wait script, sudo rule for the deploy script

Then, as helper:

# Deploy: pull, install, build, restart
bash ~/bot/scripts/deploy.sh

# Stop / restart the bot
sudo systemctl stop sm-helper.service
sudo systemctl restart sm-helper.service

# View logs
journalctl -u sm-helper -f

Building only:

bun build

This doesn't have any output though as Bun handles builds internally.

Bot Permissions

The bot requires the following Discord permissions:

  • Send Messages
  • Use Slash Commands
  • Manage Messages
  • Manage Threads
  • Add Reactions
  • Read Message History
  • Embed Links
  • Attach Files
  • Mention Everyone
  • Use External Emojis

Support post reminders

Each support post gets a reminder after 24h without a message from its author and is closed automatically after 48h if the author does not react. To repair or backfill these Agenda jobs:

bun run --env-file=.env.production src/scripts/fixPostReminders.ts --dry   # preview
bun run --env-file=.env.production src/scripts/fixPostReminders.ts --days=7

Database Setup

The bot uses MongoDB to store data. Make sure your MongoDB instance is running and accessible via the MONGODB_URI in your environment file. The bot will automatically create the necessary collections and indexes on startup.

Current Features

Please refer to the FEATURES.md file for a detailed list of current features, components, event-driven automations, cron jobs, database models, caches, utilities, and configuration options.


License

MIT


TODOs?

  • Add suggestion tracking to the bot
    • one command for starting the "filling" of the db with the current backlog of suggestions
    • one command for showing the current suggestions in a paginated message
    • modify suggestion command to do the DB stuff instead of just editing the post
  • Add a way to input ends_at on /incident create field for maintenance