← back to browse
goat command

casino

No description

0
views
0
likes
0
installs
raw source
const request = require("request");
const { createReadStream, createWriteStream, existsSync } = require("fs-extra");
const path = require("path");

async function emojiEdit(api, threadID, emojis, delay = 700) {
  return new Promise(async (resolve) => {
    api.sendMessage(emojis[0], threadID, async (err, info) => {
      if (err) return;
      const msgID = info.messageID;

      for (let i = 1; i < emojis.length; i++) {
        await new Promise(r => setTimeout(r, delay));
        api.editMessage(emojis[i], msgID);
      }

      resolve(msgID);
    });
  });
}

async function animatedMenu(api, threadID, frames, delay = 500) {
  return new Promise(resolve => {
    api.sendMessage(frames[0], threadID, (err, info) => {
      if (err) return;
      const msgID = info.messageID;
      (async () => {
        for (let i = 1; i < frames.length; i++) {
          await new Promise(r => setTimeout(r, delay));
          api.editMessage(frames[i], msgID);
        }
      })();
      resolve(msgID);
    });
  });
}

module.exports = {
  config: {
    name: "casino",
    version: "2.1.0",
    author: "Azadx69x",
    role: 0,
    category: "games",
    guide: "{p}casino"
  },

  onStart: async function ({ api, event, args, usersData }) {
    const { threadID, messageID, senderID } = event;
    const moneyUser = await usersData.get(senderID, "money") || 0;

    const choose = args[0];
    const kqua = parseInt(args[1]);
    const betAmount = parseInt(args[2]);
    
    const imgPath = path.join(__dirname, "cache", "casino.png");
    if (!existsSync(imgPath)) {
      request("https://files.catbox.moe/ijl2ub.png").pipe(createWriteStream(imgPath));
    }
    
    if (!choose) {
      const menuFrames = [
`๐ŸŽฐ โ”€โ”€ WELCOME TO CASINO โ”€โ”€ ๐ŸŽฐ

๐ŸŽฒ 1. Big / Small
๐ŸŽด 2. Even / Odd
๐Ÿ’ธ 3. Lottery
๐ŸŽซ 4. Difference
๐Ÿ’ 5. Slot

๐Ÿ’ก Reply with the number of the game you want to play
๐Ÿ’ฐ Minimum bet: 50$`,
`๐ŸŽฐ โ”€โ”€ WELCOME TO CASINO โ”€โ”€ ๐ŸŽฐ

๐ŸŽฒ 1. Big / Small
๐ŸŽด 2. Even / Odd
๐Ÿ’ธ 3. Lottery
๐ŸŽซ 4. Difference
๐Ÿ’ 5. Slot

โœจ Reply with the number to start! ๐Ÿ’ฐ`,
`๐ŸŽฐ โ”€โ”€ WELCOME TO CASINO โ”€โ”€ ๐ŸŽฐ

๐ŸŽฒ 1. Big / Small
๐ŸŽด 2. Even / Odd
๐Ÿ’ธ 3. Lottery
๐ŸŽซ 4. Difference
๐Ÿ’ 5. Slot

๐Ÿ’ก Ready? Type the number! ๐Ÿ’ฐ`
      ];

      const msgID = await animatedMenu(api, threadID, menuFrames, 500);
      
      global.GoatBot.onReply.set(msgID, {
        commandName: "casino",
        author: senderID,
        type: "choosee"
      });

      return;
    }
    
    if (choose === "big" || choose === "small") {
      if (kqua < 50 || isNaN(kqua)) return api.sendMessage("Minimum bet 50$", threadID, messageID);
      if (moneyUser < kqua) return api.sendMessage("Not enough money", threadID, messageID);

      const loadID = await emojiEdit(api, threadID, ["๐ŸŽฒ", "๐ŸŽฒ ๐ŸŽฒ", "๐ŸŽฒ ๐ŸŽฒ ๐ŸŽฒ"], 500);
      const result = Math.random() < 0.5 ? "big" : "small";

      if (choose === result) {
        await usersData.addMoney(senderID, kqua * 2);
        return api.editMessage(`๐ŸŽ‰ YOU WON\nResult: ${result}\n+${kqua * 2}$`, loadID);
      } else {
        await usersData.subtractMoney(senderID, kqua);
        return api.editMessage(`๐Ÿ˜ข YOU LOST\nResult: ${result}\n-${kqua}$`, loadID);
      }
    }
    
    if (choose === "even" || choose === "odd") {
      if (kqua < 50 || isNaN(kqua)) return api.sendMessage("Minimum bet 50$", threadID, messageID);
      if (moneyUser < kqua) return api.sendMessage("Not enough money", threadID, messageID);

      const loadID = await emojiEdit(api, threadID, ["๐ŸŽด", "๐ŸŽด โžก๏ธ", "๐ŸŽด โžก๏ธ ๐ŸŽด"], 500);
      const num = Math.floor(Math.random() * 10);
      const result = num % 2 === 0 ? "even" : "odd";

      if (choose === result) {
        await usersData.addMoney(senderID, kqua * 2);
        return api.editMessage(`๐ŸŽ‰ YOU WON\nNumber: ${num}\n+${kqua * 2}$`, loadID);
      } else {
        await usersData.subtractMoney(senderID, kqua);
        return api.editMessage(`๐Ÿ˜ข YOU LOST\nNumber: ${num}\n-${kqua}$`, loadID);
      }
    }
    
    if (choose === "lottery") {
      if (betAmount < 50 || isNaN(betAmount)) return api.sendMessage("Minimum bet 50$", threadID, messageID);
      if (moneyUser < betAmount) return api.sendMessage("Not enough money", threadID, messageID);

      const lottery = Math.floor(Math.random() * 100);
      const loadID = await emojiEdit(api, threadID, ["๐Ÿ’ธ", "๐Ÿ’ธ ๐Ÿ’ธ", "๐Ÿ’ธ ๐Ÿ’ธ ๐Ÿ’ธ"], 200);
      
      setTimeout(async () => {
        if (args[1] == lottery) {
          await usersData.addMoney(senderID, betAmount * 2);
          api.editMessage(`๐ŸŽ‰ YOU WON\nResult: ${lottery}\n+${betAmount * 2}$`, loadID);
        } else {
          await usersData.subtractMoney(senderID, betAmount);
          api.editMessage(`๐Ÿ˜ข YOU LOST\nResult: ${lottery}\n-${betAmount}$`, loadID);
        }
      }, 10000);
    }
    
    if (choose === "slot") {
      if (kqua < 50 || isNaN(kqua)) return api.sendMessage("Minimum bet 50$", threadID, messageID);
      if (moneyUser < kqua) return api.sendMessage("Not enough money", threadID, messageID);

      const items = ["๐Ÿ’","๐Ÿ‰","๐ŸŠ","๐Ÿ","๐Ÿ“","๐ŸŒ"];
      const loadID = await emojiEdit(api, threadID, ["๐ŸŽฐ", "๐ŸŽฐ ๐ŸŽฒ", "๐ŸŽฐ ๐ŸŽฒ ๐ŸŽฐ", "๐ŸŽฐ ๐ŸŽฒ ๐ŸŽฐ ๐ŸŽฒ"], 600);

      const a = Math.floor(Math.random() * items.length);
      const b = Math.floor(Math.random() * items.length);
      const c = Math.floor(Math.random() * items.length);
      const win = a === b || b === c || a === c;

      if (win) await usersData.addMoney(senderID, kqua * 2);
      else await usersData.subtractMoney(senderID, kqua);

      return api.editMessage(
`๐ŸŽฐ ${items[a]} | ${items[b]} | ${items[c]} ๐ŸŽฐ
${win ? "๐ŸŽ‰ YOU WON +" + kqua * 2 : "๐Ÿ˜ข YOU LOST -" + kqua}`,
        loadID
      );
    }
  },

  onReply: async function ({ api, event, Reply }) {
    if (event.senderID !== Reply.author) return;

    const guide = {
      "1": "casino big/small [amount]",
      "2": "casino even/odd [amount]",
      "3": "casino lottery [number] [amount]",
      "4": "casino difference [number] [amount]",
      "5": "casino slot [amount]"
    };

    return api.sendMessage(
      guide[event.body]
        ? `Use: ${global.GoatBot.config.prefix}${guide[event.body]}`
        : "Invalid option",
      event.threadID,
      event.messageID
    );
  }
};

View raw file