forked from Guru322/GURU-Ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecon-gamble.js
102 lines (79 loc) · 3.28 KB
/
econ-gamble.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
let rouletteBets = {}; // Object to store all the bets
let rouletteResult = {}; // Object to store the result
const handler = async (m, { conn, args, usedPrefix, command }) => {
/*if (global.db.data.users[m.sender].level < 5) {
return conn.reply(m.chat, 'You must be at least level 5 to use this command.', m);
}*/
const resolveRoulette = (chatId, conn) => {
let who = m.quoted ? m.quoted.sender : m.mentionedJid && m.mentionedJid[0] ? m.mentionedJid[0] : m.fromMe ? conn.user.jid : m.sender
let username = conn.getName(who)
if (!(who in global.db.data.users)) throw `✳️ The user is not found in my database`
if (rouletteBets[chatId] && rouletteBets[chatId].length > 0) {
let colores = ['red', 'black'];
let colour = colores[Math.floor(Math.random() * colores.length)];
let winners = [];
let resultMessage = `The ball landed on ${colour}\n\n🎉 Winners 🎉\n\n`;
for (let bet of rouletteBets[chatId]) {
let result = '';
if (colour === bet.color) {
result = `@${bet.user.split('@')[0]} won ${bet.amount}`;
global.db.data.users[bet.user].credit += bet.amount;
winners.push(result);
} else {
result = `@${bet.user.split('@')[0]} lost ${bet.amount}`;
global.db.data.users[bet.user].credit -= bet.amount;
}
}
resultMessage += winners.join('\n');
if (winners.length === 0) {
resultMessage += 'No winners';
}
rouletteResult[chatId] = resultMessage;
delete rouletteBets[chatId];
//conn.sendFile(m.chat, pp, 'gamble.jpg', resultMessage, m, false, { mentions: [who] })
conn.reply(m.chat, resultMessage, m, { mentions: [who] })
//m.reply(resultMessage)
}
};
const runRoulette = (chatId, conn) => {
const delay = 10 * 1000; // 30 seconds
setTimeout(() => {
resolveRoulette(chatId, conn);
}, delay);
};
const betRoulette = (user, chatId, amount, color) => {
let colores = ['red', 'black'];
if (isNaN(amount) || amount < 500) {
throw `✳️ The minimum bet is 500 gold`;
}
if (!colores.includes(color)) {
throw '✳️ You must specify a valid color: red or black';
}
if (users.credit < amount) {
throw '✳️ You do not have enough gold!';
}
if (amount > 100000) {
throw `🟥 You can't bet gold more than 100000`;
}
if (!rouletteBets[chatId]) {
rouletteBets[chatId] = [];
}
rouletteBets[chatId].push({ user, amount, color });
return `✅ Your bet of ${amount} gold on ${color} has been placed!`;
};
//const handler = async (m, { conn, args, usedPrefix, command }) => {
let amount = parseInt(args[0]);
let color = args[1]?.toLowerCase();
if (args.length < 2) {
throw `✳️ Command Usage: ${usedPrefix + command} <amount> <color>\n\n Example: ${usedPrefix + command} 500 red`;
}
let users = global.db.data.users[m.sender];
let response = betRoulette(m.sender, m.chat, amount, color);
m.reply(response);
runRoulette(m.chat, conn);
};
handler.help = ['gamble <amount> <color(red/black)>'];
handler.tags = ['economy'];
handler.command = ['gamble'];
handler.group = true;
export default handler;