Files
kaczynski-bot/src/services/role.ts
T
2026-08-22 18:44:24 -04:00

104 lines
2.7 KiB
TypeScript

import type { Guild, GuildMember, Collection, RoleCreateOptions } from "discord.js";
export default abstract class RoleService {
static readonly ROLES = {
// Main
"ROBOT": {
name: "robot",
colors: { primaryColor: "#58a9df" },
hoist: true,
mentionable: true,
},
"FEMOID": {
name: "femoid",
colors: { primaryColor: "#ffb2f4" },
hoist: true,
mentionable: true,
},
"NORMALFAG": {
name: "normalfag",
colors: { primaryColor: "#e26254" },
hoist: true,
mentionable: true,
},
"GAY": {
name: "gay",
colors: { primaryColor: "#71368a" },
hoist: true,
mentionable: true,
},
"TROID": {
name: "troid",
colors: { primaryColor: "#992d22" },
hoist: true,
mentionable: true,
},
"LURKER": {
name: "lurker",
colors: { primaryColor: "#546e7a" },
hoist: true,
mentionable: true,
},
// Utility
"NEWFAG": {
name: "newfag",
mentionable: true,
},
"LIMBO": {
name: "limbo",
}
} satisfies Record<string, RoleCreateOptions>;
static readonly STARTER_ROLES = [RoleService.ROLES["LURKER"], RoleService.ROLES["NEWFAG"]];
public static limboMode = false;
static validate(guilds: Collection<string, Guild>): void {
guilds.forEach(guild => {
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(", ")}`);
});
}
static async createRolesIfNotExist(guild: Guild, roles: RoleCreateOptions[]) {
for (const role of roles) {
try {
if (!this.getRoleByName(guild, role.name)) {
await guild.roles.create(role);
}
}
catch (err) {
console.error(`Failed to create role: ${role.name}`, err);
}
}
}
static async giveStarterRoles(guildMember: GuildMember) {
for (const starterRole of RoleService.STARTER_ROLES) {
const role = this.getRoleByName(guildMember.guild, starterRole?.name);
if (!role) continue;
try {
await guildMember.roles.add(role);
}
catch (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);
}
}
static async setLimboMode(mode: boolean) {
}
static getRoleByName(guild: Guild, roleName?: string) {
return guild.roles.cache.find(role => role.name === roleName);
}
}