Compare commits
11
Commits
cc116c2ec3
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0963ef4bb | ||
|
|
8329187eb7 | ||
|
|
ac087c458d | ||
|
|
2982c1ee99 | ||
|
|
4bd77fad8a | ||
|
|
e0fb166dd2 | ||
|
|
62e8465a94 | ||
|
|
1c24a19be1 | ||
|
|
a744a95307 | ||
|
|
20465abcaa | ||
|
|
669af5ad14 |
@@ -13,3 +13,5 @@ dist/
|
|||||||
# OS
|
# OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
|
data.json
|
||||||
|
|||||||
+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"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Message } from "discord.js";
|
import type { Message } from "discord.js";
|
||||||
import type { Command } from "../service";
|
import ChanService from "../../services/chan";
|
||||||
import Chan from "../../util/chan";
|
import type { Command } from "../../models";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "chan",
|
name: "chan",
|
||||||
@@ -14,11 +14,11 @@ export default {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Chan.isNsfwBoard(board)) {
|
if (ChanService.isNsfwBoard(board)) {
|
||||||
await message.reply("Fuck off nigger")
|
await message.reply("Fuck off nigger")
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
await message.reply(await Chan.getMediaLink(board, search));
|
await message.reply(await ChanService.getMediaLink(board, search));
|
||||||
}
|
}
|
||||||
} satisfies Command;
|
} satisfies Command;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Message } from "discord.js";
|
import type { Message } from "discord.js";
|
||||||
import type { Command } from "../service";
|
import ChanService from "../../services/chan";
|
||||||
import Chan from "../../util/chan";
|
import type { Command } from "../../models";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "comfy",
|
name: "comfy",
|
||||||
@@ -9,6 +9,6 @@ export default {
|
|||||||
execute: async (message: Message) => {
|
execute: async (message: Message) => {
|
||||||
const boards = ["wsg", "wg"];
|
const boards = ["wsg", "wg"];
|
||||||
const board = boards[Math.floor(Math.random() * boards.length)] ?? "wsg";
|
const board = boards[Math.floor(Math.random() * boards.length)] ?? "wsg";
|
||||||
await message.reply(await Chan.getMediaLink(board, "comfy"));
|
await message.reply(await ChanService.getMediaLink(board, "comfy"));
|
||||||
}
|
}
|
||||||
} satisfies Command;
|
} satisfies Command;
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
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,10 +0,0 @@
|
|||||||
import type { Message } from "discord.js";
|
|
||||||
import type { Command } from "../service";
|
|
||||||
|
|
||||||
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) => {
|
|
||||||
}
|
|
||||||
} satisfies Command;
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Message } from "discord.js";
|
import type { Message } from "discord.js";
|
||||||
import type { Command } from "../service";
|
import type { Command } from "../../models";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "redpillme",
|
name: "redpillme",
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import type { Message } from "discord.js";
|
||||||
|
import type { Command } from "../../models";
|
||||||
|
import RoleService from "../../services/role";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "roleinit",
|
||||||
|
description: "Creates all of the required roles, if they do not exist yet.",
|
||||||
|
usage: ".roleinit",
|
||||||
|
execute: async (message: Message) => {
|
||||||
|
if (!message.guild) return;
|
||||||
|
const reply = await message.reply("Initializing roles...");
|
||||||
|
await RoleService.createRolesIfNotExist(message.guild, Object.values(RoleService.ROLES));
|
||||||
|
await reply.edit("Finished initializing roles.");
|
||||||
|
}
|
||||||
|
} satisfies Command;
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import type { Client, Message } from "discord.js";
|
|
||||||
import { readdir } from "fs/promises";
|
|
||||||
|
|
||||||
const CMD_PREFIX = ".";
|
|
||||||
|
|
||||||
export interface Command {
|
|
||||||
name: string,
|
|
||||||
description: string,
|
|
||||||
usage: string,
|
|
||||||
execute: (message: Message) => void | Promise<void>
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CommandService {
|
|
||||||
private client: Client
|
|
||||||
private registry: Record<string, Command> = {}
|
|
||||||
|
|
||||||
constructor(client: Client) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
async init() {
|
|
||||||
const commands = await Promise.all(
|
|
||||||
(await readdir(`${import.meta.dir}/registry`)).map(async file => (await import(`./registry/${file}`)).default as Command)
|
|
||||||
);
|
|
||||||
for (const command of commands)
|
|
||||||
this.registry[command.name] = command;
|
|
||||||
};
|
|
||||||
|
|
||||||
parse(message: Message): Command | undefined {
|
|
||||||
if (!message.content.startsWith(CMD_PREFIX)) return;
|
|
||||||
const name = message.content.slice(CMD_PREFIX.length).split(/\s+/)[0];
|
|
||||||
return this.registry[name ?? ""];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+17
-12
@@ -1,36 +1,41 @@
|
|||||||
import { Client, Events, GatewayIntentBits } from 'discord.js';
|
import { Client, Events, GatewayIntentBits } from 'discord.js';
|
||||||
import { CommandService } from './cmd/service';
|
|
||||||
import RoleService from './services/role';
|
import RoleService from './services/role';
|
||||||
|
import CommandService from './services/command';
|
||||||
|
import DataService from './services/data';
|
||||||
|
|
||||||
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
|
const client = new Client({
|
||||||
|
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
|
||||||
// Services
|
});
|
||||||
const commandService = new CommandService(client);
|
|
||||||
const roleService = new RoleService(client);
|
|
||||||
|
|
||||||
client.once(Events.ClientReady, async (readyClient) => {
|
client.once(Events.ClientReady, async (readyClient) => {
|
||||||
// Initialize & validate
|
// Initialize services
|
||||||
await commandService.init();
|
await DataService.init();
|
||||||
roleService.validate(client.guilds.cache);
|
await CommandService.init();
|
||||||
|
await RoleService.init(client.guilds.cache);
|
||||||
|
|
||||||
// Ready!
|
// Ready!
|
||||||
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
|
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("guildMemberAdd", async (guildMember) => {
|
client.on("guildMemberAdd", async (guildMember) => {
|
||||||
await roleService.giveStarterRoles(guildMember);
|
await RoleService.giveStarterRoles(guildMember);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("messageCreate", async (message) => {
|
client.on("messageCreate", async (message) => {
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
|
|
||||||
const command = commandService.parse(message);
|
try {
|
||||||
|
const command = CommandService.parse(message);
|
||||||
if (command) command.execute(message);
|
if (command) command.execute(message);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Bun.cron("0 */6 * * *", async () => {
|
Bun.cron("0 */6 * * *", async () => {
|
||||||
for (const guild of client.guilds.cache.values()) {
|
for (const guild of client.guilds.cache.values()) {
|
||||||
const lurkerRole = roleService.getRoleByName(guild, RoleService.ROLES["LURKER"]?.name);
|
const lurkerRole = RoleService.getRoleByName(guild, RoleService.ROLES["LURKER"]?.name);
|
||||||
if (!lurkerRole) continue;
|
if (!lurkerRole) continue;
|
||||||
|
|
||||||
await guild.members.prune({ days: 5, roles: [lurkerRole] });
|
await guild.members.prune({ days: 5, roles: [lurkerRole] });
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import type { Message } from "discord.js";
|
||||||
|
|
||||||
|
// COMMANDS
|
||||||
|
|
||||||
|
export interface Command {
|
||||||
|
name: string,
|
||||||
|
description: string,
|
||||||
|
usage: string,
|
||||||
|
execute: (message: Message) => void | Promise<void>
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
export default class Chan {
|
export default abstract class ChanService {
|
||||||
private static readonly nsfwBoards = new Set([
|
private static readonly nsfwBoards = new Set([
|
||||||
"b", "d", "e", "h", "hc", "hr", "gif", "s", "t", "u", "r9k", "soc", "vr", "w",
|
"b", "d", "e", "h", "hc", "hr", "gif", "s", "t", "u", "r9k", "soc", "vr", "w",
|
||||||
"i", "ic", "r", "p", "cgl", "cm", "n", "vip", "qa", "y", "trash", "hm", "aco", "lgbt"
|
"i", "ic", "r", "p", "cgl", "cm", "n", "vip", "qa", "y", "trash", "hm", "aco", "lgbt"
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import type { Message } from "discord.js";
|
||||||
|
import { readdir } from "fs/promises";
|
||||||
|
import { dirname } from "path";
|
||||||
|
import type { Command } from "../models";
|
||||||
|
|
||||||
|
const CMD_PREFIX = ".";
|
||||||
|
const CMD_REGISTRY_DIR = `${dirname(Bun.main)}/cmd/registry`;
|
||||||
|
|
||||||
|
export default abstract class CommandService {
|
||||||
|
private static registry: Record<string, Command> = {}
|
||||||
|
|
||||||
|
static async init() {
|
||||||
|
const commands = await Promise.all(
|
||||||
|
(await readdir(CMD_REGISTRY_DIR)).map(async file => (await import(`${CMD_REGISTRY_DIR}/${file}`)).default satisfies Command)
|
||||||
|
);
|
||||||
|
for (const command of commands)
|
||||||
|
CommandService.registry[command.name] = command;
|
||||||
|
};
|
||||||
|
|
||||||
|
static parse(message: Message): Command | undefined {
|
||||||
|
if (!message.content.startsWith(CMD_PREFIX)) return;
|
||||||
|
const name = message.content.slice(CMD_PREFIX.length).split(/\s+/)[0];
|
||||||
|
return this.registry[name ?? ""];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
interface Data {
|
||||||
|
limboMode: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class DataService {
|
||||||
|
private static readonly DATA_PATH = "./data/data.json";
|
||||||
|
private static file: Bun.BunFile | undefined;
|
||||||
|
private static _data: Data = {
|
||||||
|
// default values (will be overwritten)
|
||||||
|
limboMode: false
|
||||||
|
};
|
||||||
|
|
||||||
|
static async init() {
|
||||||
|
if (!(await Bun.file(this.DATA_PATH).exists()))
|
||||||
|
await Bun.write(Bun.file(this.DATA_PATH), JSON.stringify(this._data, null, 2));
|
||||||
|
|
||||||
|
this.file = Bun.file(this.DATA_PATH);
|
||||||
|
this._data = { ...this._data, ...(await this.file.json()) };
|
||||||
|
}
|
||||||
|
|
||||||
|
static set data(data: Data) {
|
||||||
|
if (!this.file) throw new Error("DataService is not initialized. Please call DataService.init()");
|
||||||
|
this._data = data;
|
||||||
|
void Bun.write(this.file, JSON.stringify(this._data, null, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
static get data() {
|
||||||
|
if (!this.file) throw new Error("DataService is not initialized. Please call DataService.init()");
|
||||||
|
return this._data
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
-21
@@ -1,89 +1,82 @@
|
|||||||
import type { Client, Guild, GuildMember, Collection, RoleCreateOptions } from "discord.js";
|
import type { Guild, GuildMember, Collection, RoleCreateOptions } from "discord.js";
|
||||||
|
import DataService from "./data";
|
||||||
|
|
||||||
export default class RoleService {
|
export default abstract class RoleService {
|
||||||
static readonly ROLES: Record<string, RoleCreateOptions> = {
|
static readonly ROLES = {
|
||||||
// Main
|
// Main
|
||||||
"ROBOT": {
|
"ROBOT": {
|
||||||
name: "robot",
|
name: "robot",
|
||||||
colors: { primaryColor: "#58a9df" },
|
colors: { primaryColor: "#58a9df" },
|
||||||
hoist: true,
|
hoist: true,
|
||||||
mentionable: true,
|
mentionable: true,
|
||||||
position: 1,
|
|
||||||
},
|
},
|
||||||
"FEMOID": {
|
"FEMOID": {
|
||||||
name: "femoid",
|
name: "femoid",
|
||||||
colors: { primaryColor: "#ffb2f4" },
|
colors: { primaryColor: "#ffb2f4" },
|
||||||
hoist: true,
|
hoist: true,
|
||||||
mentionable: true,
|
mentionable: true,
|
||||||
position: 2,
|
|
||||||
},
|
},
|
||||||
"NORMALFAG": {
|
"NORMALFAG": {
|
||||||
name: "normalfag",
|
name: "normalfag",
|
||||||
colors: { primaryColor: "#e26254" },
|
colors: { primaryColor: "#e26254" },
|
||||||
hoist: true,
|
hoist: true,
|
||||||
mentionable: true,
|
mentionable: true,
|
||||||
position: 3,
|
|
||||||
},
|
},
|
||||||
"GAY": {
|
"GAY": {
|
||||||
name: "gay",
|
name: "gay",
|
||||||
colors: { primaryColor: "#71368a" },
|
colors: { primaryColor: "#71368a" },
|
||||||
hoist: true,
|
hoist: true,
|
||||||
mentionable: true,
|
mentionable: true,
|
||||||
position: 4,
|
|
||||||
},
|
},
|
||||||
"TROID": {
|
"TROID": {
|
||||||
name: "troid",
|
name: "troid",
|
||||||
colors: { primaryColor: "#992d22" },
|
colors: { primaryColor: "#992d22" },
|
||||||
hoist: true,
|
hoist: true,
|
||||||
mentionable: true,
|
mentionable: true,
|
||||||
position: 5,
|
|
||||||
},
|
},
|
||||||
"LURKER": {
|
"LURKER": {
|
||||||
name: "lurker",
|
name: "lurker",
|
||||||
colors: { primaryColor: "#546e7a" },
|
colors: { primaryColor: "#546e7a" },
|
||||||
hoist: true,
|
hoist: true,
|
||||||
mentionable: true,
|
mentionable: true,
|
||||||
position: 6,
|
|
||||||
},
|
},
|
||||||
// Utility
|
// Utility
|
||||||
"NEWFAG": {
|
"NEWFAG": {
|
||||||
name: "newfag",
|
name: "newfag",
|
||||||
mentionable: true,
|
mentionable: true,
|
||||||
position: 7,
|
|
||||||
},
|
},
|
||||||
"LIMBO": {
|
"LIMBO": {
|
||||||
name: "limbo",
|
name: "limbo",
|
||||||
position: 8,
|
|
||||||
}
|
}
|
||||||
};
|
} satisfies Record<string, RoleCreateOptions>;
|
||||||
|
|
||||||
static readonly STARTER_ROLES = [RoleService.ROLES["LURKER"], RoleService.ROLES["NEWFAG"]];
|
static readonly STARTER_ROLES = [RoleService.ROLES["LURKER"], RoleService.ROLES["NEWFAG"]];
|
||||||
|
|
||||||
private client: Client
|
public static get limboMode() { return DataService.data.limboMode; }
|
||||||
|
public static set limboMode(mode: boolean) { DataService.data = { ...DataService.data, limboMode: mode }; }
|
||||||
|
|
||||||
constructor(client: Client) {
|
static async init(guilds: Collection<string, Guild>) {
|
||||||
this.client = client;
|
// Check if any roles are missing
|
||||||
}
|
|
||||||
|
|
||||||
validate(guilds: Collection<string, Guild>): void {
|
|
||||||
guilds.forEach(guild => {
|
guilds.forEach(guild => {
|
||||||
const missing = Object.values(RoleService.ROLES).filter(role => !this.getRoleByName(guild, role.name));
|
const missing = Object.values(RoleService.ROLES).filter(role => !this.getRoleByName(guild, role.name));
|
||||||
if (missing.length) console.error(`${guild.name} is missing roles: ${missing.map(r => r.name).join(", ")}`);
|
if (missing.length) console.error(`${guild.name} is missing roles: ${missing.map(r => r.name).join(", ")}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async createRoles(guild: Guild, roles: RoleCreateOptions[]) {
|
static async createRolesIfNotExist(guild: Guild, roles: RoleCreateOptions[]) {
|
||||||
for (const role of roles) {
|
for (const role of roles) {
|
||||||
try {
|
try {
|
||||||
|
if (!this.getRoleByName(guild, role.name)) {
|
||||||
await guild.roles.create(role);
|
await guild.roles.create(role);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(`Failed to create role: ${role.name}`, err);
|
console.error(`Failed to create role: ${role.name}`, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async giveStarterRoles(guildMember: GuildMember) {
|
static async giveStarterRoles(guildMember: GuildMember) {
|
||||||
for (const starterRole of RoleService.STARTER_ROLES) {
|
for (const starterRole of RoleService.STARTER_ROLES) {
|
||||||
const role = this.getRoleByName(guildMember.guild, starterRole?.name);
|
const role = this.getRoleByName(guildMember.guild, starterRole?.name);
|
||||||
if (!role) continue;
|
if (!role) continue;
|
||||||
@@ -95,9 +88,15 @@ export default class RoleService {
|
|||||||
console.error(`Failed to add starter role: ${role.name}`, err);
|
console.error(`Failed to add starter role: ${role.name}`, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.limboMode) {
|
||||||
|
const limboRole = this.getRoleByName(guildMember.guild, this.ROLES["LIMBO"].name)
|
||||||
|
if (!limboRole) return;
|
||||||
|
await guildMember.roles.add(limboRole);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getRoleByName(guild: Guild, roleName?: string) {
|
static getRoleByName(guild: Guild, roleName?: string) {
|
||||||
return guild.roles.cache.find(role => role.name === roleName);
|
return guild.roles.cache.find(role => role.name === roleName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user