Improve service handling
This commit is contained in:
+6
-12
@@ -1,6 +1,6 @@
|
||||
import type { Client, Guild, GuildMember, Collection, RoleCreateOptions } from "discord.js";
|
||||
import type { Guild, GuildMember, Collection, RoleCreateOptions } from "discord.js";
|
||||
|
||||
export default class RoleService {
|
||||
export default abstract class RoleService {
|
||||
static readonly ROLES: Record<string, RoleCreateOptions> = {
|
||||
// Main
|
||||
"ROBOT": {
|
||||
@@ -59,20 +59,14 @@ export default class RoleService {
|
||||
|
||||
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 {
|
||||
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(", ")}`);
|
||||
});
|
||||
}
|
||||
|
||||
async createRoles(guild: Guild, roles: RoleCreateOptions[]) {
|
||||
static async createRoles(guild: Guild, roles: RoleCreateOptions[]) {
|
||||
for (const role of roles) {
|
||||
try {
|
||||
await guild.roles.create(role);
|
||||
@@ -83,7 +77,7 @@ export default class RoleService {
|
||||
}
|
||||
}
|
||||
|
||||
async giveStarterRoles(guildMember: GuildMember) {
|
||||
static async giveStarterRoles(guildMember: GuildMember) {
|
||||
for (const starterRole of RoleService.STARTER_ROLES) {
|
||||
const role = this.getRoleByName(guildMember.guild, starterRole?.name);
|
||||
if (!role) continue;
|
||||
@@ -97,7 +91,7 @@ export default class RoleService {
|
||||
}
|
||||
}
|
||||
|
||||
getRoleByName(guild: Guild, roleName?: string) {
|
||||
static getRoleByName(guild: Guild, roleName?: string) {
|
||||
return guild.roles.cache.find(role => role.name === roleName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user