import { api } from "index";
import { Command, sendMessage } from "lib/commandUtils";
import { streamerId } from "main";
import { playAlert } from "web/alerts/serverFunctions";

export default new Command({
	name: "randomchatter",
	aliases: ["randomchatter"],
	usertype: "moderator",
	execution: async (msg) => {
		const data = await api.chat.getChatters(streamerId).then((a) => a.data);
		const target = data[Math.floor(Math.random() * data.length)];
		await playAlert({
			name: "blastinRoulette",
			user: msg.chatterName,
			targets: data.map((a) => a.userDisplayName),
			finaltarget: target?.userDisplayName,
		});
		await new Promise((res, _) => setTimeout(res, 4000));
		await sendMessage(`${target?.userDisplayName}`, msg.messageId);
	},
});
