Skip to content

Commit

Permalink
REM-BOT
Browse files Browse the repository at this point in the history
  • Loading branch information
davidprospero123 authored Apr 16, 2024
1 parent fdf1f8d commit 5841241
Showing 1 changed file with 68 additions and 77 deletions.
145 changes: 68 additions & 77 deletions plugins/econ-gamble.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,82 @@
import axios from 'axios';


let rouletteBets = {}; // Object to store all the bets
let rouletteResult = {}; // Object to store the result
const rouletteBets = {};
const rouletteResult = {};

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 `✳️ El usuario no esta en mi base de datos :c`

if (rouletteBets[chatId] && rouletteBets[chatId].length > 0) {
let colores = ['red', 'black'];
let colour = colores[Math.floor(Math.random() * colores.length)];

let winners = [];
let resultMessage = `La pelota aterrizΓ³ en ${colour}\n\nπŸŽ‰ Ganaste πŸŽ‰\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;
const resolveRoulette = async (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 `✳️ 𝙴𝙻 πš„πš‚πš„π™°πšπ™Έπ™Ύ 𝙽𝙾 π™΄πš‚πšƒπ™° 𝙴𝙽 𝙼𝙸 π™±π™°πš‚π™΄ 𝙳𝙴 π™³π™°πšƒπ™Ύπš‚ :c`;

if (rouletteBets[chatId] && rouletteBets[chatId].length > 0) {
let colours = ['rojo', 'negro'];
let colour = colours[Math.floor(Math.random() * colours.length)];

let winners = [];
let resultMessage = `🎰 𝙻𝙰 π™Ώπ™΄π™»π™Ύπšƒπ™° π™°πšƒπ™΄πšπšπ™Έπš‰π™Ύ 𝙴𝙽 ${colour} 🎰\n━━━━━━━━━━━━━━━━━━━━\n`;

for (let bet of rouletteBets[chatId]) {
let result = '';
if (colour === bet.color) {
result = `πŸ‘‘ @${bet.user.split('@')[0]} 𝙢𝙰𝙽𝙾 ${bet.amount} 𝙳𝙴 π™Ύπšπ™Ύ πŸ’°`;
global.db.data.users[bet.user].credit += bet.amount;
winners.push(result);
} else {
result = `πŸ’Έ @${bet.user.split('@')[0]} π™Ώπ™΄πšπ™³π™Έπ™Ύ ${bet.amount} 𝙳𝙴 π™Ύπšπ™Ύ πŸ’Έ`;
global.db.data.users[bet.user].credit -= bet.amount;
}
}
}

resultMessage += winners.join('\n');
if (winners.length === 0) {
resultMessage += 'No Ganaron';
}
resultMessage += '\nπŸŽ‰ Β‘π™ΆπšŠπš—πšŠπšπš˜πš›πšŽπšœ! πŸŽ‰\n' + winners.join('\n');
if (winners.length === 0) {
resultMessage += '\nπŸ‘₯ π™½πšŠπšπš’πšŽ πšπšŠπš—Γ³';
}

rouletteResult[chatId] = resultMessage;
delete rouletteBets[chatId];
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)
}
};
// EnvΓ­a la imagen junto con el mensaje del resultado
const url = "https://i.imgur.com/APg4Nl7.jpg";
const responseImg = await axios.get(url, { responseType: 'arraybuffer' });
const thumbnail = await conn.sendFile(m.chat, responseImg.data, "thumbnail.jpg", resultMessage, m);
}
};

const runRoulette = (chatId, conn) => {
const delay = 10 * 1000; // 30 seconds
const runRoulette = (chatId, conn) => {
const delay = 10 * 1000;

setTimeout(() => {
resolveRoulette(chatId, conn);
}, delay);
};
setTimeout(() => {
resolveRoulette(chatId, conn);
}, delay);
};

const betRoulette = (user, chatId, amount, color) => {
let colores = ['red', 'black'];
if (isNaN(amount) || amount < 500) {
throw `✳️ La apuesta mínima es 500 de oro`;
}
if (!colores.includes(color)) {
throw '✳️ Debes especificar un color vÑlido: rojo o negro';
}
if (users.credit < amount) {
throw '✳️ ‘Usted no tiene suficiente oro';
}
if (amount > 100000) {
throw `πŸŸ₯ No puedes apostar oro mΓ‘s de 100000`;
}
const betRoulette = (user, chatId, amount, color) => {
let colours = ['rojo', 'negro'];
if (isNaN(amount) || amount < 500) {
throw `✳️ π™»πšŠ πšŠπš™πšžπšŽπšœπšπšŠ πš–Γ­πš—πš’πš–πšŠ 𝚎𝚜 𝚍𝚎 𝟻𝟢𝟢 𝚍𝚎 πš˜πš›πš˜`;
}
if (!colours.includes(color)) {
throw '✳️ π™³πšŽπš‹πšŽπšœ πšŽπšœπš™πšŽπšŒπš’πšπš’πšŒπšŠπš› πšžπš— πšŒπš˜πš•πš˜πš› πšŸΓ‘πš•πš’πšπš˜: πš›πš˜πš“πš˜ 𝚘 πš—πšŽπšπš›πš˜';
}
if (users.credit < amount) {
throw '✳️ Β‘π™½πš˜ πšπš’πšŽπš—πšŽπšœ πšœπšžπšπš’πšŒπš’πšŽπš—πšπšŽ πš˜πš›πš˜!';
}
if (amount > 100000) {
throw `πŸŸ₯ π™½πš˜ πš™πšžπšŽπšπšŽπšœ πšŠπš™πš˜πšœπšπšŠπš› πš–Γ‘πšœ 𝚍𝚎 𝟷𝟢𝟢𝟢𝟢𝟢 𝚍𝚎 πš˜πš›πš˜`;
}

if (!rouletteBets[chatId]) {
rouletteBets[chatId] = [];
}
rouletteBets[chatId].push({ user, amount, color });
return `βœ… Your bet of ${amount} gold on ${color} has been placed!`;
};
if (!rouletteBets[chatId]) {
rouletteBets[chatId] = [];
}
rouletteBets[chatId].push({ user, amount, color });
return `βœ… πšƒπšž πšŠπš™πšžπšŽπšœπšπšŠ 𝚍𝚎 ${amount} 𝚍𝚎 πš˜πš›πš˜ πšŽπš— ${color} πš‘πšŠ πšœπš’πšπš˜ πš›πšŽπšŠπš•πš’πš£πšŠπšπšŠ`;
};

//const handler = async (m, { conn, args, usedPrefix, command }) => {
let amount = parseInt(args[0]);
let color = args[1]?.toLowerCase();
if (args.length < 2) {
throw `✳️ Usa el comando haci: ${usedPrefix + command} <amount> <color>\n\n Ejemplo ${usedPrefix + command} 500 red`;
throw `✳️ πš„πšœπšŠ πšŽπš• πšŒπš˜πš–πšŠπš—πšπš˜ 𝚊𝚜í: ${usedPrefix + command} <cantidad> <color>\n\n π™΄πš“πšŽπš–πš™πš•πš˜: ${usedPrefix + command} 500 rojo`;
}

let users = global.db.data.users[m.sender];
Expand All @@ -93,10 +86,8 @@ const betRoulette = (user, chatId, amount, color) => {
runRoulette(m.chat, conn);
};

handler.help = ['gamble <amount> <color(red/black)>'];
handler.tags = ['economy'];
handler.command = ['gamble','apostar','roulette'];

handler.group = true;
handler.help = ['ruleta <cantidad> <color(rojo/negro)>'];
handler.tags = ['economΓ­a'];
handler.command = ['ruleta', 'apostar', 'gamble'];

export default handler;
export default handler;

0 comments on commit 5841241

Please sign in to comment.