goat
command
dice
๐ฒ Dice betting game
0
views
0
likes
0
installs
Aliases: dicegame, rolldice, dg, dicebet
raw source
module.exports = {
config: {
name: "dice",
aliases: ["dicegame", "rolldice", "dg", "dicebet"],
version: "3.0",
author: "ARIYAN AI",
role: 0,
category: "economy",
shortDescription: "๐ฒ Dice betting game",
guide: "{pn} <bet> <amount>\n{pn} <bet1> <bet2> <amount>\nExample: {pn} low odd 300k"
},
onStart: async function ({ args, usersData, event, message }) {
const userID = event.senderID;
const MAX_BET = 1_000_000;
/* ===== PARSE AMOUNT ===== */
const parseAmount = (input) => {
const text = String(input).toLowerCase().trim();
const match = text.match(/^(\d+(?:\.\d+)?)(k|m|b|t|qt)?$/);
if (!match) return NaN;
const num = Number(match[1]);
const unit = match[2];
const map = {
k: 1e3,
m: 1e6,
b: 1e9,
t: 1e12,
qt: 1e15
};
return Math.floor(num * (map[unit] || 1));
};
/* ===== FORMAT MONEY ===== */
const formatMoney = (n) => {
if (n >= 1e15) return Math.floor(n / 1e15) + "qt";
if (n >= 1e12) return Math.floor(n / 1e12) + "t";
if (n >= 1e9) return Math.floor(n / 1e9) + "b";
if (n >= 1e6) return Math.floor(n / 1e6) + "m";
if (n >= 1e3) return Math.floor(n / 1e3) + "k";
return String(n);
};
/* ===== INPUT CHECK ===== */
if (args.length < 2) {
return message.reply(
`๐ฒ Dice Game\n\nUse:\n.dice <bet> <amount>\n.dice <bet1> <bet2> <amount>\n\nExample: .dice low odd 300k`
);
}
let bet1, bet2, rawAmount;
if (args.length === 2) {
bet1 = args[0].toLowerCase();
rawAmount = args[1];
} else {
bet1 = args[0].toLowerCase();
bet2 = args[1].toLowerCase();
rawAmount = args[2];
}
const valid = ["high", "low", "even", "odd", "7", "double"];
const amount = parseAmount(rawAmount);
if (!valid.includes(bet1) || (bet2 && !valid.includes(bet2))) {
return message.reply("โ Invalid bet.\nUse: high, low, even, odd, 7 or double.");
}
if (!Number.isFinite(amount) || amount < 10) {
return message.reply("โ Minimum bet is 10.");
}
if (amount > MAX_BET) {
return message.reply(`โ Max bet is ${formatMoney(MAX_BET)}.`);
}
const balance = await usersData.getMoney(userID);
if (balance < amount) {
return message.reply(
`โ Not enough balance.\nYou have ${formatMoney(balance)}.`
);
}
/* ===== SUBTRACT BET ===== */
await usersData.subtractMoney(userID, amount);
/* ===== ROLL DICE ===== */
const dice1 = Math.floor(Math.random() * 6) + 1;
const dice2 = Math.floor(Math.random() * 6) + 1;
const total = dice1 + dice2;
const check = (b) => {
if (b === "high") return total >= 8;
if (b === "low") return total <= 6;
if (b === "even") return total % 2 === 0;
if (b === "odd") return total % 2 === 1;
if (b === "7") return total === 7;
if (b === "double") return dice1 === dice2;
return false;
};
const win = check(bet1) && (bet2 ? check(bet2) : true);
/* ===== MULTIPLIER ===== */
let multiplier = 0;
let title;
if (win && bet2) {
multiplier = 5;
title = "๐ BIG WIN!";
}
else if (win) {
if (bet1 === "double") multiplier = 4;
else if (bet1 === "7") multiplier = 5;
else multiplier = 2;
title = "โ
You won!";
}
else {
title = "โ You lost!";
}
/* ===== PAYOUT ===== */
let payout = 0;
if (multiplier > 0) {
payout = amount * multiplier;
await usersData.addMoney(userID, payout);
}
const newBalance = await usersData.getMoney(userID);
return message.reply(
`${title}\n\n` +
`๐ฒ Dice: ${dice1} + ${dice2} = ${total}\n` +
`๐ฏ Bet: ${[bet1, bet2].filter(Boolean).join(" + ")}\n\n` +
`${multiplier
? `๐ฐ You received ${formatMoney(payout)}`
: `๐ธ You lost ${formatMoney(amount)}`}\n` +
`๐ณ Balance: ${formatMoney(newBalance)}`
);
}
};