Skip to content

Commit 741f5e1

Browse files
committed
Make a get_category utility
1 parent d1da79f commit 741f5e1

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/bot-utilities.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,13 @@ export class BotUtilities {
242242
assert(channel instanceof Discord.ThreadChannel, `Channel ${channel} (${id}) not of the expected type`);
243243
return channel;
244244
}
245+
246+
async get_category(id: string) {
247+
const category = await this.wheatley.client.channels.fetch(id);
248+
if (!category) {
249+
throw Error(`Category ${id} not found`);
250+
}
251+
assert(category instanceof Discord.CategoryChannel, `Category ${category} (${id}) not of the expected type`);
252+
return category;
253+
}
245254
}

src/modules/tccpp/components/permissions-manager.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,7 @@ export default class PermissionManager extends BotComponent {
391391
async sync_permissions() {
392392
await Promise.all(
393393
Object.entries(this.category_permissions).map(async ([id, permissions]) => {
394-
const category = await this.wheatley.client.channels.fetch(id);
395-
if (!category) {
396-
throw Error(`Category ${id} not found`);
397-
}
398-
if (!(category instanceof Discord.CategoryChannel)) {
399-
throw Error(`Category ${id} not of the expected type`);
400-
}
394+
const category = await this.utilities.get_category(id);
401395
await this.sync_category_permissions(category, permissions);
402396
}),
403397
);

0 commit comments

Comments
 (0)