import { Command, sendMessage } from "lib/commandUtils";
import { redis } from "lib/redis";
import { timeout } from "lib/timeout";

const barrelCount = 6;

export default new Command({
	name: "roulette",
	aliases: ["roulette"],
	usertype: "chatter",
	execution: async (msg, user) => {
		if (!(await redis.exists("rouletteCount")))
			await redis.set("rouletteCount", "0");
		const currentChamber = Number(await redis.get("rouletteCount"));
		const shot = Math.random() < 1 / (barrelCount - currentChamber);
		if (!shot)
			await Promise.all([
				redis.incr("rouletteCount"),
				sendMessage("SWEAT Click SWEAT", msg.messageId),
			]);
		else
			await Promise.all([
				redis.set("rouletteCount", "0"),
				sendMessage("wybuh BANG!! wybuh"),
				timeout(user, "You lost at russian roulette!", 5 * 60),
			]);
	},
});
