Injekta is a Discord bot built with TypeScript designed to help manage and track Hormone Replacement Therapy (HRT) injections. It logs injection data (alternating between 'Right' and 'Left' legs), tracks medication and dose, supports flexible cadences (e.g., every 3.5 days, 10 days, or monthly), automatically keeps only the last 5 records per user, and sends reminders—all integrated with a self-hosted PostgreSQL database for persistent data storage.
- Simple Logging: Log injections easily using the
/injectioncommand with button confirmation; optionally record medication name and dose (mg). - Automatic Leg Alternation: The bot automatically determines whether the 'Right' or 'Left' leg is next based on your previous log.
- Log History: View your last 5 injection logs using
/checklogs(now includes medication and dose). Older logs are automatically removed. - Stats Tracking: Check your total logged injections and current weekly streak with
/stats. - Scheduling & Reminders:
- Set a global injection schedule (day, time, timezone, interval) using
/setinjectionschedule(Admin-only) with non-weekly cadences like every 3.5 days or every 10/30 days.
- Receive automatic reminders 1 hour before the scheduled time in a designated channel, including medication name and dose.
- Receive a prompt in the designated channel when it's time to log your injection.
- Set a global injection schedule (day, time, timezone, interval) using
- Hormone Test Reminders: Set monthly (or custom interval) E/T lab reminders starting from a chosen date using
/sethormonetest. - Dosing Helpers: Convert syringe units to mg with
/convertunits(requires vial concentration). - Log Deletion:
- Users can delete their own latest log (or a specific one by ID) using
/deletemylog(with confirmation). - Admins can delete any specific log entry for any user using
/admindeletelog.
- Users can delete their own latest log (or a specific one by ID) using
- Admin Tools:
- Admins can check logs (
/checklogs user:@username) and stats (/stats user:@username) for other users. - Admins can log injections for other users using the
/logfor user:@usernamecommand.
- Admins can check logs (
- Persistent Storage: All injection records and settings are stored securely in a PostgreSQL database.
- Modern Development Stack:
- Built with TypeScript and Discord.js v14.
- Uses
pg(node-postgres) for database interaction. - Uses
node-cronfor scheduling. - Includes ESLint, Prettier, Husky, and lint-staged for code quality and Git hooks.
- Uses Winston for structured and readable logging.
- Node.js (v18 or higher recommended)
- Bun (or npm/yarn for package management)
- Git
- Access to a PostgreSQL database server (v12 or higher recommended)
-
Clone the Repository:
git clone [https://github.com/ShinniUwU/Injekta.git](https://github.com/ShinniUwU/Injekta.git) cd Injekta -
Install Dependencies: Using Bun (recommended):
bun install
Using npm:
npm install
-
Set Up Git Hooks (Optional but Recommended): Initialize Husky hooks (used for pre-commit linting/formatting):
bun run prepare # or npm run prepare(Proceed to Database Setup next)
This bot requires a running PostgreSQL database server.
-
Ensure PostgreSQL is Running: Install and run PostgreSQL on your local machine or server. Refer to the official PostgreSQL documentation for your operating system:
- PostgreSQL Downloads (Choose your OS)
- Example setup commands for Debian/Ubuntu or Fedora.
-
Create Database and User: Connect to your PostgreSQL instance (e.g., using
psql) and create a dedicated database and user for the bot. Replaceyour_secure_passwordwith a strong password.-- Example commands using psql: CREATE DATABASE injekta_db; CREATE USER injekta_user WITH PASSWORD 'your_secure_password'; GRANT ALL PRIVILEGES ON DATABASE injekta_db TO injekta_user;
-
Create Database Schema: Navigate to the project directory (
Injekta) in your terminal and use thepsqlclient to run the providedschema.sqlscript. This will create the necessary tables (injections,global_settings). Replace placeholders with your actual connection details.psql -h <hostname> -p <port> -U injekta_user -d injekta_db -f schema.sql
(Example:
psql -h localhost -p 5432 -U injekta_user -d injekta_db -f schema.sql) Enter the password forinjekta_userwhen prompted.Upgrading from an older schema? Run the following before the bot restarts to migrate
injection_datefrom the oldDD-MM-YYYYstring to a proper timestamptz:ALTER TABLE injections ALTER COLUMN injection_date TYPE TIMESTAMPTZ USING to_timestamp(injection_date, 'DD-MM-YYYY'), ALTER COLUMN injection_date SET DEFAULT CURRENT_TIMESTAMP;
Create a .env file in the root of the project directory (Injekta/.env). Copy the following variables and fill them with your specific credentials:
# Discord Bot Credentials
BOT_TOKEN=your_discord_bot_token # Your bot's secret token
CLIENT_ID=your_discord_client_id # Your bot's application ID
GUILD_ID=your_discord_guild_id # The ID of the server where commands will be registered initially
# PostgreSQL Database Connection URL
# Format: postgresql://<user>:<password>@<host>:<port>/<database_name>
DATABASE_URL=postgresql://injekta_user:your_secure_password@localhost:5432/injekta_db
# Bot Configuration
DESIGNATED_CHANNEL_ID=your_discord_channel_id # ID of the channel for reminders and '/injection' command
BOT_OWNER_ID=your_discord_user_id # Optional: Your Discord user ID for potential owner-specific checksReplace placeholders like <user>, <password>, <host>, <port>, <database_name> in DATABASE_URL with the actual values for your PostgreSQL setup created in the Database Setup step.
Timezone: /setinjectionschedule validates the timezone you pass (IANA names like UTC, America/New_York). Invalid values are rejected and scheduler falls back to UTC if misconfigured.
- Development: For local testing and development:
bun run dev
- Production/Deployment: For running the bot continuously on a server, it's highly recommended to use a process manager like
pm2:# Install pm2 globally (if not already installed) npm install -g pm2 # or bun install -g pm2 # Start the bot with pm2 # Make sure you are in the project directory pm2 start bun --name injekta -- run dev # Or specify the script directly: # pm2 start src/bot.ts --name injekta --interpreter bun # Optional: Save the pm2 process list to restart automatically on server reboot pm2 save # Monitor logs pm2 logs injekta # Stop the bot pm2 stop injekta
- Go to your server’s HRT/injection channel, run
/help, and log with/injection(dose/medication optional). /nextinjectionshows when you’re due;/checklogsshows your last five;/deletemylogfixes mistakes.- Stored: your Discord ID, timestamps, leg, and any optional medication/dose/units you provide. Replies stay private. This is a tracking/reminder tool, not medical advice.
- Copy
.env.example→.env; fill BOT_TOKEN, CLIENT_ID, GUILD_ID, DATABASE_URL, DESIGNATED_CHANNEL_ID (and optional VERSION_NOTIFY_CHANNEL_ID). - Run
bun install. - Create DB tables with
schema.sql(e.g.,psql ... -f schema.sql). - Start the bot:
bun run dev. - In Discord, run
/setupcheckto verify DB/channel. - Run
/setinjectionscheduleonce so reminders and/nextinjectionwork./sethormonetestis optional.
- The bot checks npm for a newer Injekta version on startup. If found, it posts in the configured channel with update instructions (
git pull && bun install+ restart).
- A lightweight site lives in
site/(moving to its own branch). Runs on Vercel + Neon Postgres. Seesite/README.mdif you want a click-to-deploy web logger.
/injection [dose_mg] [medication] [performed_at] [raw_units]/help·/setupcheck(admin) ·/checklogs [user]·/stats [user]/nextinjection·/deletemylog [log_id]/setinjectionschedule <day> <time> [timezone] [interval_days] [medication] [dose_mg](admin)/sethormonetest [start_date] [interval_days] [timezone](admin)/logfor <user> [dose_mg] [medication](admin)/convertunits <units> <concentration_mg_per_ml>/admindeletelog <user> <log_id>(admin)
This project uses ESLint for linting and Prettier for code formatting. Git hooks are set up using Husky and lint-staged to automatically lint and format code on commit.
- Check formatting:
bun run prettier-check - Apply formatting:
bun run prettier-write - Run linter:
bun run lint
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue.
This project is licensed under the MIT License - see the LICENSE file for details.