← back to browse
goat command

cat

Get random cat images or check list count

0
views
0
likes
0
installs

Aliases: catimg

raw source
const axios = require('axios');

module.exports = {
    config: {
        name: "cat",
        aliases: ["catimg"],
        version: "1.2.0",
        author: "xalman",
        countDown: 5,
        role: 0,
        shortDescription: "Get random cat images or check list count",
        category: "media",
        guide: "{pn} or {pn} list"
    },

    onStart: async function ({ api, event, args }) {
        const { threadID, messageID } = event;
        const BASE_URL = "https://xalman-apis.vercel.app/api/cat"; 

        if (args[0] === "list" || args[0] === "total") {
            try {
                const info = await axios.get(`${BASE_URL}?list=true`);
                return api.sendMessage(
                    `๐Ÿพ ๐—–๐—”๐—ง ๐——๐—”๐—ง๐—”๐—•๐—”๐—ฆ๐—˜ ๐—œ๐—ก๐—™๐—ข\nโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n` +
                    `Total Images: ${info.data.total_images}\n` +
                    `Status: Active`, 
                    threadID, messageID
                );
            } catch (e) {
                return api.sendMessage("โœ• Could not fetch the cat image list.", threadID, messageID);
            }
        }

        api.setMessageReaction("๐Ÿฑ", messageID, () => {}, true);

        try {
            const res = await axios.get(BASE_URL);
            const imageUrl = res.data.url;

            const imageStream = await axios.get(imageUrl, { 
                responseType: 'stream' 
            });

            api.setMessageReaction("โœ…", messageID, () => {}, true);
            
            return api.sendMessage({
                body: "โ– ๐—–๐—จ๐—ง๐—˜ ๐—–๐—”๐—ง โ–\nโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”",
                attachment: imageStream.data
            }, threadID, messageID);

        } catch (error) {
            console.error(error);
            api.setMessageReaction("โŒ", messageID, () => {}, true);
            return api.sendMessage("โœ• Failed to load the cat image!", threadID, messageID);
        }
    }
};

View raw file