import { api, eventSub } from "index";
import kleur from "kleur";
import logger from "lib/logger";

eventSub.onRevoke((event) => {
	logger.ok(
		`Successfully revoked EventSub subscription: ${kleur.underline(event.id)}`,
	);
});

eventSub.onSubscriptionCreateSuccess((event) => {
	logger.ok(
		`Successfully created EventSub subscription: ${kleur.underline(event.id)}`,
	);
});

eventSub.onSubscriptionCreateFailure((event) => {
	logger.err(
		`Failed to create EventSub subscription: ${kleur.underline(event.id)}`,
	);
});

eventSub.onSubscriptionDeleteSuccess((event) => {
	logger.ok(
		`Successfully deleted EventSub subscription: ${kleur.underline(event.id)}`,
	);
});

eventSub.onSubscriptionDeleteFailure((event) => {
	logger.err(
		`Failed to delete EventSub subscription: ${kleur.underline(event.id)}`,
	);
});

await api.eventSub.deleteAllSubscriptions();

import { readdir } from "node:fs/promises";

const files = await readdir(import.meta.dir);
for (const file of files) {
	if (!file.endsWith(".ts")) continue;
	if (file === import.meta.file) continue;
	await import(`${import.meta.dir}/${file.slice(0, -3)}`);
}

eventSub.start();
