More restructuring
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
import type { Client, Guild, GuildMember, Collection, RoleCreateOptions } from "discord.js";
|
||||
|
||||
export default class RoleService {
|
||||
static readonly ROLES: Record<string, RoleCreateOptions> = {
|
||||
// Main
|
||||
"ROBOT": {
|
||||
name: "robot",
|
||||
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,
|
||||
}
|
||||
};
|
||||
|
||||
static readonly STARTER_ROLES = [RoleService.ROLES["LURKER"], RoleService.ROLES["NEWFAG"]];
|
||||
|
||||
private client: Client
|
||||
|
||||
constructor(client: Client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
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(", ")}`);
|
||||
});
|
||||
}
|
||||
|
||||
async createRoles(guild: Guild, roles: RoleCreateOptions[]) {
|
||||
for (const role of roles) {
|
||||
try {
|
||||
await guild.roles.create(role);
|
||||
}
|
||||
catch (err) {
|
||||
console.error(`Failed to create role: ${role.name}`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getRoleByName(guild: Guild, roleName?: string) {
|
||||
return guild.roles.cache.find(role => role.name === roleName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user