Finish roleinit command

This commit is contained in:
2026-08-22 18:04:08 -04:00
parent 669af5ad14
commit 20465abcaa
4 changed files with 17 additions and 13 deletions
+5
View File
@@ -1,10 +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;
+7 -2
View File
@@ -22,8 +22,13 @@ client.on("guildMemberAdd", async (guildMember) => {
client.on("messageCreate", async (message) => {
if (message.author.bot) return;
const command = CommandService.parse(message);
if (command) command.execute(message);
try {
const command = CommandService.parse(message);
if (command) command.execute(message);
}
catch (err) {
console.error(err);
}
});
Bun.cron("0 */6 * * *", async () => {
+1 -1
View File
@@ -9,7 +9,7 @@ export default abstract class CommandService {
static async init() {
const commands = await Promise.all(
(await readdir(`${import.meta.dir}/registry`)).map(async file => (await import(`./registry/${file}`)).default satisfies Command)
(await readdir(`${import.meta.dir}/../cmd/registry`)).map(async file => (await import(`../cmd/registry/${file}`)).default satisfies Command)
);
for (const command of commands)
CommandService.registry[command.name] = command;
+4 -10
View File
@@ -8,52 +8,44 @@ export default abstract class RoleService {
colors: { primaryColor: "#58a9df" },
hoist: true,
mentionable: true,
position: 1,
},
"FEMOID": {
name: "femoid",
colors: { primaryColor: "#ffb2f4" },
hoist: true,
mentionable: true,
position: 2,
},
"NORMALFAG": {
name: "normalfag",
colors: { primaryColor: "#e26254" },
hoist: true,
mentionable: true,
position: 3,
},
"GAY": {
name: "gay",
colors: { primaryColor: "#71368a" },
hoist: true,
mentionable: true,
position: 4,
},
"TROID": {
name: "troid",
colors: { primaryColor: "#992d22" },
hoist: true,
mentionable: true,
position: 5,
},
"LURKER": {
name: "lurker",
colors: { primaryColor: "#546e7a" },
hoist: true,
mentionable: true,
position: 6,
},
// Utility
"NEWFAG": {
name: "newfag",
mentionable: true,
position: 7,
},
"LIMBO": {
name: "limbo",
position: 8,
}
};
@@ -66,10 +58,12 @@ export default abstract class RoleService {
});
}
static async createRoles(guild: Guild, roles: RoleCreateOptions[]) {
static async createRolesIfNotExist(guild: Guild, roles: RoleCreateOptions[]) {
for (const role of roles) {
try {
await guild.roles.create(role);
if (!this.getRoleByName(guild, role.name)) {
await guild.roles.create(role);
}
}
catch (err) {
console.error(`Failed to create role: ${role.name}`, err);