aboutsummaryrefslogtreecommitdiff
path: root/src/tasks/feature/memberCount.ts
blob: 9c31c5bce7866374fe8f476db1dca68db94d58a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { BushTask, MemberCount, Time } from '#lib';
import assert from 'assert/strict';

export default class MemberCountTask extends BushTask {
	public constructor() {
		super('memberCount', {
			delay: Time.Minute,
			runOnStart: true
		});
	}

	public override async exec() {
		if (!this.client.config.isProduction) return;

		const res = await Promise.allSettled(
			this.client.guilds.cache
				.filter((g) => g.memberCount >= 100)
				.map((g) => MemberCount.create({ guildId: g.id, memberCount: g.memberCount }))
		);

		res
			.filter((r) => r.status === 'rejected')
			.forEach((r) => {
				assert(r.status === 'rejected');
				void this.client.console.error('memberCount', r.status);
			});
	}
}