Finish roleinit command
This commit is contained in:
@@ -1,10 +1,15 @@
|
|||||||
import type { Message } from "discord.js";
|
import type { Message } from "discord.js";
|
||||||
import type { Command } from "../../models";
|
import type { Command } from "../../models";
|
||||||
|
import RoleService from "../../services/role";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "roleinit",
|
name: "roleinit",
|
||||||
description: "Creates all of the required roles, if they do not exist yet.",
|
description: "Creates all of the required roles, if they do not exist yet.",
|
||||||
usage: ".roleinit",
|
usage: ".roleinit",
|
||||||
execute: async (message: Message) => {
|
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;
|
} satisfies Command;
|
||||||
|
|||||||
+7
-2
@@ -22,8 +22,13 @@ client.on("guildMemberAdd", async (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 {
|
||||||
if (command) command.execute(message);
|
const command = CommandService.parse(message);
|
||||||
|
if (command) command.execute(message);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Bun.cron("0 */6 * * *", async () => {
|
Bun.cron("0 */6 * * *", async () => {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default abstract class CommandService {
|
|||||||
|
|
||||||
static async init() {
|
static async init() {
|
||||||
const commands = await Promise.all(
|
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)
|
for (const command of commands)
|
||||||
CommandService.registry[command.name] = command;
|
CommandService.registry[command.name] = command;
|
||||||
|
|||||||
+4
-10
@@ -8,52 +8,44 @@ export default abstract class RoleService {
|
|||||||
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,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -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) {
|
for (const role of roles) {
|
||||||
try {
|
try {
|
||||||
await guild.roles.create(role);
|
if (!this.getRoleByName(guild, role.name)) {
|
||||||
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user