AI

javascript 286 views May 5, 2026
Raw
javascript 59 lines ยท 1,283 chars
import axios from "axios";
import te from "../../src/lib/ourin-error.js";

const pluginConfig = {
  name: "ai",
  alias: ["ask"],
  category: "ai",
  description: "Chat dengan AI Claude",
  usage: ".claude <pertanyaan>",
  example: ".claude apa itu javascript",
  isOwner: false,
  isPremium: false,
  isGroup: false,
  isPrivate: false,
  cooldown: 5,
  energi: 1,
  isEnabled: true,
};

async function askClaude(query) {
  const url = `https://api.azbry.com/api/ai/claude?q=${encodeURIComponent(query)}`;

  const res = await axios.get(url, {
    timeout: 120000,
    headers: {
      "user-agent": "Mozilla/5.0",
      accept: "application/json",
    },
  });

  if (!res.data?.status || !res.data?.result) {
    throw new Error("Claude AI gagal merespon");
  }

  return res.data.result;
}

async function handler(m, { text }) {
  if (!text) {
    return m.reply(
      `๐Ÿค– *AI*\n\nMasukkan pertanyaan\n\nContoh:\n\`${m.prefix}ai halo\``,
    );
  }

  m.react("๐Ÿ••");

  try {
    const result = await askClaude(text);

    m.react("โœ…");
    m.reply(result);
  } catch (error) {
    console.log(error);
    m.react("โ˜ข");
    m.reply(te(m.prefix, m.command, m.pushName));
  }
}

export { pluginConfig as config, handler };