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), automatically keeps only the last 5 records per user, and sends weekly reminders—all integrated with a self-hosted PostgreSQL database for persistent data storage.
- Simple Logging: Log injections easily using the
/injection
command with button confirmation. - 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
. 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) using
/setinjectionschedule
(Admin-only).
- Receive automatic reminders 1 hour before the scheduled time in a designated channel.
- Receive a prompt in the designated channel when it's time to log your injection.
- Set a global injection schedule (day, time, timezone) using
- 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:@username
command.
- 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-cron
for 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_password
with 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 thepsql
client to run the providedschema.sql
script. 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_user
when prompted.
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 checks
Replace 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.
- 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
/injection
: Log your weekly injection (requires confirmation). Must be used in the designated channel./checklogs [user]
: Display the last 5 injection logs for yourself or the specified user (user option requires Admin permissions)./stats [user]
: Show injection statistics (total logs, current streak) for yourself or the specified user (user option requires Admin permissions)./nextinjection
: Check the approximate time remaining until the next scheduled injection based on the global schedule./deletemylog [log_id]
: Delete one of your own log entries. Iflog_id
is provided, deletes that specific entry. If omitted, deletes your most recent entry (requires confirmation)./setinjectionschedule <day> <time> [timezone]
(Admin-only): Set the global injection schedule (day of week, HH:MM time, optional IANA timezone like 'UTC' or 'America/New_York')./logfor <user>
(Admin-only): Log an injection for the specified user./admindeletelog <user> <log_id>
(Admin-only): Delete a specific log entry (using its unique ID) for the specified user.
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.