← back to browse
goat command

card

Small Higher or Lower card game

0
views
0
likes
0
installs

Aliases: cg, higherlower, hl

raw source
module.exports = {
  config: {
    name: "card",
    aliases: ["cg", "higherlower", "hl"],
    version: "1.4",
    author: "Mehedi-saito",
    countDown: 6,
    role: 0,
    shortDescription: {
      en: "Small Higher or Lower card game",
      vi: "Game bài nhỏ Higher or Lower"
    },
    description: {
      en: "Bet on Higher or Lower with tiny cards",
      vi: "Cược Higher or Lower với bài siêu nhỏ"
    },
    category: "game",
    guide: {
      en: "{pn} <amount>",
      vi: "{pn} <số tiền>"
    }
  },

  langs: {
    en: {
      missingAmount: "❌ Enter amount\nEx: %1 500",
      invalidAmount: "❌ Invalid amount",
      notEnough: "❌ Not enough money\nBal: %1$",
      minBet: "❌ Min 50$",
      maxBet: "❌ Max 50k$",
      start: "🎴 𝐂𝐀𝐑𝐃\n\n%1\n💰 %2$\n\n▸ higher / h\n▸ lower / l",
      win: "🎉 𝐖𝐈𝐍\n%1 → %2\n+ %3\( \nBal: %4 \)",
      lose: "😢 𝐋𝐎𝐒𝐄\n%1 → %2\n- %3\( \nBal: %4 \)",
      tie: "🤝 𝐓𝐈𝐄\n%1 = %2\nBal: %3$",
      invalidReply: "⚠️ higher / lower only"
    },
    vi: {
      missingAmount: "❌ Nhập số tiền\nVd: %1 500",
      invalidAmount: "❌ Số tiền sai",
      notEnough: "❌ Không đủ tiền\nSố dư: %1$",
      minBet: "❌ Tối thiểu 50$",
      maxBet: "❌ Tối đa 50k$",
      start: "🎴 𝐂𝐀𝐑𝐃\n\n%1\n💰 %2$\n\n▸ higher / h\n▸ lower / l",
      win: "🎉 𝐓𝐇Ắ𝐍𝐆\n%1 → %2\n+ %3\( \nSố dư: %4 \)",
      lose: "😢 𝐓𝐇𝐔𝐀\n%1 → %2\n- %3\( \nSố dư: %4 \)",
      tie: "🤝 𝐇Ò𝐀\n%1 = %2\nSố dư: %3$",
      invalidReply: "⚠️ Chỉ higher / lower"
    }
  },

  onStart: async function ({ message, args, event, usersData, commandName, getLang }) {
    const { senderID } = event;
    const amount = parseInt(args[0]);

    if (!args[0]) return message.reply(getLang("missingAmount", commandName));
    if (isNaN(amount) || amount <= 0) return message.reply(getLang("invalidAmount"));
    if (amount < 50) return message.reply(getLang("minBet"));
    if (amount > 50000) return message.reply(getLang("maxBet"));

    const userData = await usersData.get(senderID);
    const money = userData.money || 0;
    if (money < amount) return message.reply(getLang("notEnough", money));

    const ranks = [
      { name: "A", value: 14, code: "A" },
      { name: "2", value: 2, code: "2" },
      { name: "3", value: 3, code: "3" },
      { name: "4", value: 4, code: "4" },
      { name: "5", value: 5, code: "5" },
      { name: "6", value: 6, code: "6" },
      { name: "7", value: 7, code: "7" },
      { name: "8", value: 8, code: "8" },
      { name: "9", value: 9, code: "9" },
      { name: "10", value: 10, code: "0" },
      { name: "J", value: 11, code: "J" },
      { name: "Q", value: 12, code: "Q" },
      { name: "K", value: 13, code: "K" }
    ];
    const suits = [
      { emoji: "♠️", code: "S" },
      { emoji: "♥️", code: "H" },
      { emoji: "♦️", code: "D" },
      { emoji: "♣️", code: "C" }
    ];

    const firstRank = ranks[Math.floor(Math.random() * ranks.length)];
    const firstSuit = suits[Math.floor(Math.random() * suits.length)];
    const firstCode = firstRank.code + firstSuit.code;
    const firstCardName = `\( {firstRank.name} \){firstSuit.emoji}`;

    // Extremely small card
    const firstImage = `https://images.weserv.nl/?url=deckofcardsapi.com/static/img/${firstCode}.png&w=75&h=105&fit=contain&output=png`;

    await usersData.set(senderID, { money: money - amount });

    const form = {
      body: getLang("start", firstCardName, amount),
      attachment: await global.utils.getStreamFromURL(firstImage)
    };

    const sent = await message.reply(form);

    global.GoatBot.onReply.set(sent.messageID, {
      commandName,
      author: senderID,
      amount,
      firstCardName,
      firstValue: firstRank.value,
      firstCode,
      messageID: sent.messageID
    });
  },

  onReply: async function ({ message, event, Reply, usersData, getLang }) {
    const { author, amount, firstCardName, firstValue, firstCode, messageID } = Reply;
    const { senderID, body } = event;

    if (senderID !== author) return;

    const choice = body.trim().toLowerCase();
    const isHigher = ["higher", "h", "উঁচু", "উচু", "cao", "high"].includes(choice);
    const isLower = ["lower", "l", "নিচু", "thấp", "low"].includes(choice);

    if (!isHigher && !isLower) {
      return message.reply(getLang("invalidReply"));
    }

    const ranks = [
      { name: "A", value: 14, code: "A" },
      { name: "2", value: 2, code: "2" },
      { name: "3", value: 3, code: "3" },
      { name: "4", value: 4, code: "4" },
      { name: "5", value: 5, code: "5" },
      { name: "6", value: 6, code: "6" },
      { name: "7", value: 7, code: "7" },
      { name: "8", value: 8, code: "8" },
      { name: "9", value: 9, code: "9" },
      { name: "10", value: 10, code: "0" },
      { name: "J", value: 11, code: "J" },
      { name: "Q", value: 12, code: "Q" },
      { name: "K", value: 13, code: "K" }
    ];
    const suits = [
      { emoji: "♠️", code: "S" },
      { emoji: "♥️", code: "H" },
      { emoji: "♦️", code: "D" },
      { emoji: "♣️", code: "C" }
    ];

    const secondRank = ranks[Math.floor(Math.random() * ranks.length)];
    const secondSuit = suits[Math.floor(Math.random() * suits.length)];
    const secondCode = secondRank.code + secondSuit.code;
    const secondCardName = `\( {secondRank.name} \){secondSuit.emoji}`;
    const secondValue = secondRank.value;

    // Extremely small cards
    const firstImage = `https://images.weserv.nl/?url=deckofcardsapi.com/static/img/${firstCode}.png&w=70&h=98&fit=contain&output=png`;
    const secondImage = `https://images.weserv.nl/?url=deckofcardsapi.com/static/img/${secondCode}.png&w=70&h=98&fit=contain&output=png`;

    const userData = await usersData.get(senderID);
    let newMoney = userData.money || 0;
    let resultText = "";

    if (secondValue === firstValue) {
      newMoney += amount;
      await usersData.set(senderID, { money: newMoney });
      resultText = getLang("tie", firstCardName, secondCardName, newMoney);
    } else if ((isHigher && secondValue > firstValue) || (isLower && secondValue < firstValue)) {
      const winAmount = amount * 2;
      newMoney += winAmount;
      await usersData.set(senderID, { money: newMoney });
      resultText = getLang("win", firstCardName, secondCardName, winAmount, newMoney);
    } else {
      resultText = getLang("lose", firstCardName, secondCardName, amount, newMoney);
    }

    const form = {
      body: resultText,
      attachment: [
        await global.utils.getStreamFromURL(firstImage),
        await global.utils.getStreamFromURL(secondImage)
      ]
    };

    global.GoatBot.onReply.delete(messageID);
    return message.reply(form);
  }
};

View raw file