Skip to content

Commit dc4b32e

Browse files
committed
initial
0 parents  commit dc4b32e

25 files changed

Lines changed: 3456 additions & 0 deletions

.env.template

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
NODE_ENV="dev"
2+
3+
# Discord API credentials
4+
DISCORD_BOT_TOKEN=
5+
DISCORD_GUILD_ID=
6+
7+
# Pterodactyl configuration
8+
PTERODACTYL_URL=
9+
PTERODACTYL_SERVER_ID=
10+
PTERODACTYL_API_KEY=
11+
12+
# MongoDB connection URI
13+
DATABASE_URI=

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.github/pull_request_template.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!-- IF A SECTION IS NOT APPLICABLE TO YOU, PLEASE DELETE IT!! -->
2+
3+
<!-- Your title should be able to summarize what changes you've made in one sentence. For example: "Exclude staff from the check for follows". For stacked PRs, please indicate clearly in the title where in the stack you are. For example: "[Eatery Refactor][4/5] Converted all files to MVP model" -->
4+
5+
## Overview
6+
7+
<!-- Summarize your changes here. -->
8+
9+
## Changes Made
10+
11+
<!-- Include details of what your changes actually are and how it is intended to work. -->
12+
13+
## Test Coverage
14+
15+
<!-- Describe how you tested this feature. Manual testing and/or unit testing. Please include repro steps and/or how to turn the feature on if applicable. -->
16+
17+
## Next Steps (delete if not applicable)
18+
19+
<!-- If this is part of a multi-PR change, please describe what changes you plan on addressing in future PRs. -->
20+
21+
## Related PRs or Issues (delete if not applicable)
22+
23+
<!-- List related PRs against other branches/repositories. -->
24+
25+
## Screenshots (delete if not applicable)
26+
27+
<!-- This could include of screenshots of the new feature / proof that the changes work. -->
28+
29+
<details>
30+
31+
<summary>Screen Shot Name</summary>
32+
33+
<!-- Insert file link here. Newlines above and below your link are necessary for this to work. -->
34+
35+
</details>

.github/workflows/deploy.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build and Deploy to Cloud VM
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
8+
jobs:
9+
setup-build-publish-deploy:
10+
name: Setup, Build, Publish, and Deploy
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
17+
- name: Auth Docker
18+
uses: docker/login-action@v2
19+
with:
20+
username: ${{ secrets.DOCKERHUB_USERNAME }}
21+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
22+
23+
- name: Get SHA
24+
id: vars
25+
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
26+
27+
# Build the Docker image
28+
- name: Build
29+
run: |-
30+
docker build --tag "cornellappdev/discord-bot:${{ steps.vars.outputs.sha_short }}" .
31+
- name: Publish
32+
run: |-
33+
docker push "cornellappdev/discord-bot:${{ steps.vars.outputs.sha_short }}"
34+
- name: SSH & Deploy
35+
uses: appleboy/ssh-action@master
36+
with:
37+
host: ${{ secrets.SERVER_HOST }}
38+
username: ${{ secrets.SERVER_USER }}
39+
key: ${{ secrets.PRIVATE_KEY }}
40+
script: |
41+
export BOT_IMAGE_TAG="${{ steps.vars.outputs.sha_short }}"
42+
docker stop discord-bot-backend-web-1
43+
docker rm discord-bot-backend-web-1
44+
yes | sudo docker container prune
45+
yes | sudo docker system prune
46+
cd discord-bot
47+
docker compose -p discord-bot-backend up -d

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
.env
3+
node_modules/
4+
*.log
5+
service_account.json
6+
secrets/
7+
ca-certificate.crt
8+
coverage/

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore artifacts:
2+
build
3+
coverage

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Build stage
2+
FROM node:24.13.1-alpine AS builder
3+
4+
WORKDIR /usr/app
5+
6+
COPY package.json package-lock.json ./
7+
RUN npm ci --only=production && npm cache clean --force
8+
9+
# Production stage
10+
FROM node:24.13.1-alpine
11+
12+
WORKDIR /usr/app
13+
14+
# Copy dependencies from builder
15+
COPY --from=builder /usr/app/node_modules ./node_modules
16+
17+
# Copy application files
18+
COPY package.json package-lock.json ./
19+
COPY tsconfig.json ./
20+
COPY src ./src
21+
22+
# Run as non-root user
23+
RUN addgroup -g 1001 -S nodejs && \
24+
adduser -S nodejs -u 1001 && \
25+
chown -R nodejs:nodejs /usr/app
26+
27+
USER nodejs
28+
29+
CMD ["npm", "start"]

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Discord Minecraft whitelist bot
2+
3+
TypeScript [Discord.js](https://discord.js.org/) bot that registers `/whitelist` and `/unwhitelist` slash commands, syncs with a Minecraft server over Pterodactyl (WebSocket console), resolves names via Mojang, and stores per-Discord-user slots in MongoDB.
4+
5+
## Setup
6+
7+
Copy `.env.template` to `.env` and set:
8+
9+
- **Discord:** `DISCORD_BOT_TOKEN`, optional `DISCORD_GUILD_ID` (guild-scoped commands if set; otherwise global).
10+
- **Database:** `DATABASE_URI`
11+
- **Pterodactyl:** `PTERODACTYL_URL`, `PTERODACTYL_SERVER_ID`, `PTERODACTYL_API_KEY`
12+
13+
Run: `npm install` then `npm run dev` or `npm start`.
14+
15+
## Docker
16+
17+
Build and run with `docker compose`. The compose file expects `BOT_IMAGE_TAG` in the environment (see `.github/workflows/deploy.yml`).

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
web:
3+
image: cornellappdev/discord-bot:${BOT_IMAGE_TAG}
4+
env_file: .env
5+
volumes:
6+
- ./ca-certificate.crt:/usr/app/ca-certificate.crt:ro
7+
restart: on-failure

0 commit comments

Comments
 (0)