Compare commits
5
Commits
4bd77fad8a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
042ee931bf | ||
|
|
e0963ef4bb | ||
|
|
8329187eb7 | ||
|
|
ac087c458d | ||
|
|
2982c1ee99 |
+12
-3
@@ -7,11 +7,20 @@ WORKDIR /app
|
|||||||
COPY package.json bun.lock ./
|
COPY package.json bun.lock ./
|
||||||
RUN bun install --frozen-lockfile --production
|
RUN bun install --frozen-lockfile --production
|
||||||
|
|
||||||
FROM oven/bun:1-alpine AS runner
|
FROM oven/bun:1-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY tsconfig.json ./
|
COPY package.json tsconfig.json ./
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
|
|
||||||
|
RUN bun run build
|
||||||
|
|
||||||
|
FROM oven/bun:1-alpine AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
|
|
||||||
|
RUN mkdir -p /app/data && chown -R bun:bun /app/data
|
||||||
|
VOLUME ["/app/data"]
|
||||||
|
|
||||||
USER bun
|
USER bun
|
||||||
CMD ["bun", "src/index.ts"]
|
CMD ["bun", "dist/index.js"]
|
||||||
|
|||||||
@@ -1,15 +1,60 @@
|
|||||||
# kaczynski-bot-2.0
|
# kaczynski-bot-2.0
|
||||||
|
|
||||||
To install dependencies:
|
A Discord bot built with [Bun](https://bun.com).
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Install dependencies:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bun install
|
bun install
|
||||||
```
|
```
|
||||||
|
|
||||||
To run:
|
Create a `.env.development` file with:
|
||||||
|
|
||||||
```bash
|
```
|
||||||
bun run
|
DISCORD_TOKEN=your-bot-token
|
||||||
```
|
```
|
||||||
|
|
||||||
This project was created using `bun init` in bun v1.3.0. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
## Development
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
Commands live in `src/cmd/registry/` and are loaded automatically at startup — drop a file default-exporting a `Command` in that folder to register it, no manual wiring required.
|
||||||
|
|
||||||
|
## Data persistence
|
||||||
|
|
||||||
|
Bot state (e.g. limbo mode) is persisted to `data/data.json` via `DataService`. That path is gitignored.
|
||||||
|
|
||||||
|
## Production build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun run build
|
||||||
|
```
|
||||||
|
|
||||||
|
Bundles `src/index.ts` and every file in `src/cmd/registry/` into `dist/`. Run the result with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun dist/index.js
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker
|
||||||
|
|
||||||
|
Build the image:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -t kaczynski-bot .
|
||||||
|
```
|
||||||
|
|
||||||
|
Run it, mounting a volume so `data/data.json` survives container restarts:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
-e DISCORD_TOKEN=your-bot-token \
|
||||||
|
-v kaczynski-bot-data:/app/data \
|
||||||
|
kaczynski-bot
|
||||||
|
```
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
fly secrets import --stage < .env.production
|
||||||
|
fly deploy
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
# fly.toml app configuration file generated for kaczynski-bot-2-0 on 2026-05-16T14:37:01-04:00
|
# fly.toml app configuration file generated for kaczynski-bot on 2026-08-22T19:58:11-04:00
|
||||||
#
|
#
|
||||||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
||||||
#
|
#
|
||||||
|
|
||||||
app = 'kaczynski-bot-2-0'
|
app = 'kaczynski-bot'
|
||||||
primary_region = 'iad'
|
primary_region = 'iad'
|
||||||
|
|
||||||
|
[build]
|
||||||
|
[[mounts]]
|
||||||
|
source = 'data'
|
||||||
|
destination = '/app/data'
|
||||||
|
|
||||||
[http_service]
|
[http_service]
|
||||||
internal_port = 8080
|
internal_port = 8080
|
||||||
force_https = true
|
force_https = true
|
||||||
|
|||||||
+4
-2
@@ -1,12 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "kaczynski-bot-2.0",
|
"name": "@dominicferrando/kaczynski-bot",
|
||||||
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest",
|
||||||
"@types/node": "^25.9.5"
|
"@types/node": "^25.9.5"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun run src/index.ts"
|
"dev": "bun run src/index.ts",
|
||||||
|
"build": "bun build ./src/index.ts $(find src/cmd/registry -name \"*.ts\") --target bun --minify --splitting --root src --outdir ./dist"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3"
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { ChannelType, type Message } from "discord.js";
|
||||||
|
import type { Command } from "../../models";
|
||||||
|
import RoleService from "../../services/role";
|
||||||
|
import DataService from "../../services/data";
|
||||||
|
|
||||||
|
const LIMBO_CHANNEL_NAME = "limbo";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "limbo",
|
||||||
|
description: "Toggles on/off limbo mode. When limbo mode is on, new members will be placed in #limbo. When off, new members will be placed in #chat-and-shitpost.",
|
||||||
|
usage: ".limbo [on|off]",
|
||||||
|
execute: async (message: Message) => {
|
||||||
|
const ogState = RoleService.limboMode;
|
||||||
|
|
||||||
|
if (message.content.includes("on"))
|
||||||
|
RoleService.limboMode = true;
|
||||||
|
else if (message.content.includes("off"))
|
||||||
|
RoleService.limboMode = false;
|
||||||
|
else
|
||||||
|
RoleService.limboMode = !RoleService.limboMode;
|
||||||
|
|
||||||
|
// update system channel
|
||||||
|
if (RoleService.limboMode) {
|
||||||
|
if (!ogState)
|
||||||
|
DataService.data = { ...DataService.data, prevSystemChannelId: message.guild?.systemChannel?.id };
|
||||||
|
const limboChannel = message.guild?.channels.cache.find((ch) => ch.name.toLowerCase() === LIMBO_CHANNEL_NAME);
|
||||||
|
if (limboChannel && limboChannel.type === ChannelType.GuildText)
|
||||||
|
await message.guild?.setSystemChannel(limboChannel);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const prevSystemChannel = message.guild?.channels.cache.find((ch) => ch.id === DataService.data.prevSystemChannelId);
|
||||||
|
if (prevSystemChannel && prevSystemChannel.type === ChannelType.GuildText)
|
||||||
|
await message.guild?.setSystemChannel(prevSystemChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
await message.reply(`*${ogState}* -> **${RoleService.limboMode}**`);
|
||||||
|
}
|
||||||
|
} satisfies Command;
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import type { Message } from "discord.js";
|
|
||||||
import type { Command } from "../../models";
|
|
||||||
import RoleService from "../../services/role";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: "limbomode",
|
|
||||||
description: "Toggles on/off limbo mode. When limbo mode is on, new members will be placed in #limbo. When off, new members will be placed in #chat-and-shitpost.",
|
|
||||||
usage: ".limbomode [on|off]",
|
|
||||||
execute: async (message: Message) => {
|
|
||||||
const ogState = RoleService.limboMode;
|
|
||||||
|
|
||||||
if (message.content.includes("on"))
|
|
||||||
RoleService.limboMode = true;
|
|
||||||
else if (message.content.includes("off"))
|
|
||||||
RoleService.limboMode = false;
|
|
||||||
else
|
|
||||||
RoleService.limboMode = !RoleService.limboMode;
|
|
||||||
|
|
||||||
await message.reply(`*${ogState}* -> **${RoleService.limboMode}**`);
|
|
||||||
}
|
|
||||||
} satisfies Command;
|
|
||||||
+1
-1
@@ -26,7 +26,7 @@ client.on("messageCreate", async (message) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const command = CommandService.parse(message);
|
const command = CommandService.parse(message);
|
||||||
if (command) command.execute(message);
|
if (command) await command.execute(message);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import type { Message } from "discord.js";
|
import type { Message } from "discord.js";
|
||||||
import { readdir } from "fs/promises";
|
import { readdir } from "fs/promises";
|
||||||
|
import { dirname } from "path";
|
||||||
import type { Command } from "../models";
|
import type { Command } from "../models";
|
||||||
|
|
||||||
const CMD_PREFIX = ".";
|
const CMD_PREFIX = ".";
|
||||||
|
const CMD_REGISTRY_DIR = `${dirname(Bun.main)}/cmd/registry`;
|
||||||
|
|
||||||
export default abstract class CommandService {
|
export default abstract class CommandService {
|
||||||
private static registry: Record<string, Command> = {}
|
private static registry: Record<string, Command> = {}
|
||||||
|
|
||||||
static async init() {
|
static async init() {
|
||||||
const commands = await Promise.all(
|
const commands = await Promise.all(
|
||||||
(await readdir(`${import.meta.dir}/../cmd/registry`)).map(async file => (await import(`../cmd/registry/${file}`)).default satisfies Command)
|
(await readdir(CMD_REGISTRY_DIR)).map(async file => (await import(`${CMD_REGISTRY_DIR}/${file}`)).default satisfies Command)
|
||||||
);
|
);
|
||||||
for (const command of commands)
|
for (const command of commands)
|
||||||
CommandService.registry[command.name] = command;
|
CommandService.registry[command.name] = command;
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
interface Data {
|
interface Data {
|
||||||
limboMode: boolean
|
limboMode: boolean,
|
||||||
|
prevSystemChannelId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class DataService {
|
export default class DataService {
|
||||||
private static readonly DATA_PATH = "./data.json";
|
private static readonly DATA_PATH = "./data/data.json";
|
||||||
private static file: Bun.BunFile | undefined;
|
private static file: Bun.BunFile | undefined;
|
||||||
private static _data: Data = {
|
private static _data: Data = {
|
||||||
// default values (will be overwritten)
|
// default values (will be overwritten)
|
||||||
limboMode: false
|
limboMode: false,
|
||||||
|
prevSystemChannelId: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
static async init() {
|
static async init() {
|
||||||
|
|||||||
Reference in New Issue
Block a user