← back to browse
goat command

deepseek

Chat with DeepSeek AI

0
views
0
likes
0
installs

Aliases: ai

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

const API_BASE = "https://azadx69x.is-a.dev";

async function fetchAI(query, retries = 2) {
  try {
    return await axios.get(
      `${API_BASE}/api/deepseek?query=${encodeURIComponent(query)}`,
      { timeout: 60000 }
    );
  } catch (err) {
    if (retries > 0) return fetchAI(query, retries - 1);
    throw err;
  }
}

function buildMessage(query, answer) {
  return `๐Ÿค– | ๐ƒ๐ž๐ž๐ฉ๐’๐ž๐ž๐ค ๐€๐ˆ

๐Ÿง  ๐๐ฎ๐ž๐ฌ๐ญ๐ข๐จ๐ง:
${query}

๐Ÿ’ฌ ๐€๐ง๐ฌ๐ฐ๐ž๐ซ:
${answer}

`;
}

module.exports = {
  config: {
    name: "deepseek",
    aliases: ["ai"],
    version: "0.0.7",
    author: "Azadx69x",
    role: 0,
    countDown: 3,
    description: "Chat with DeepSeek AI",
    category: "AI & IMAGE GENERATION",
    guide: "{pn} <question>"
  },

  onStart: async function ({ message, args, event }) {
    let query = args.join(" ").trim();

    if (!query && event.type === "message_reply" && event.messageReply) {
      query = event.messageReply.body || "";
    }

    if (!query) {
      return message.reply("โŒ Please ask something!");
    }

    try {
      const res = await fetchAI(query);
      const answer = res.data?.response || res.data?.answer || res.data?.message || "โš ๏ธ AI is not responding right now.";
      const text = buildMessage(query, answer);
      const chunks = text.match(/[\s\S]{1,1800}/g) || [text];

      let lastMsgID = null;
      for (const chunk of chunks) {
        const sent = await message.reply(chunk);
        if (sent?.messageID) lastMsgID = sent.messageID;
      }

      if (lastMsgID) {
        global.GoatBot.onReply.set(lastMsgID, {
          commandName: "deepseek",
          messageID: lastMsgID,
          author: event.senderID
        });
      }

    } catch (err) {
      return message.reply(`โŒ AI Error\n\n๐Ÿ’ก ${err.response?.data?.error || err.message}`);
    }
  },

  onReply: async function ({ message, event, Reply }) {
    if (!Reply || Reply.commandName !== "deepseek") return;
    if (Reply.author && event.senderID !== Reply.author) return;

    const query = (event.body || "").trim();
    if (!query) return message.reply("โŒ Please write something!");

    global.GoatBot.onReply.delete(Reply.messageID);

    try {
      const res = await fetchAI(query);
      const answer = res.data?.response || res.data?.answer || res.data?.message || "โš ๏ธ AI is not responding right now.";
      const text = buildMessage(query, answer);
      const chunks = text.match(/[\s\S]{1,1800}/g) || [text];

      let lastMsgID = null;
      for (const chunk of chunks) {
        const sent = await message.reply(chunk);
        if (sent?.messageID) lastMsgID = sent.messageID;
      }

      if (lastMsgID) {
        global.GoatBot.onReply.set(lastMsgID, {
          commandName: "deepseek",
          messageID: lastMsgID,
          author: event.senderID
        });
      }

    } catch (err) {
      return message.reply(`โŒ AI Error\n\n๐Ÿ’ก ${err.response?.data?.error || err.message}`);
    }
  }
};

View raw file