← back to browse
goat command

anya

š–ŗš—‡š—’š–ŗ š–æš—ˆš—‹š—€š–¾š—‹ š—š—š—Œ

0
views
0
likes
0
installs
raw source
const axios = require("axios");
const fs = require("fs-extra");
const path = require("path");

module.exports = {
  config: {
    name: "anya",
    author: "JABED",
    version: "3.0",
    countDown: 5,
    role: 0,
    shortDescription: { en: "š–ŗš—‡š—’š–ŗ š–æš—ˆš—‹š—€š–¾š—‹ š—š—š—Œ" },
    longDescription: { en: "š–¼š—ˆš—‡š—š–¾š—‹š— š—š–¾š—‘š— š—š—ˆ š—Œš—‰š–¾š–¾š–¼š— š—Žš—Œš—‚š—‡š—€ š–ŗš—‡š—’š–ŗ š–æš—ˆš—‹š—€š–¾š—‹'š—Œ š—š—ˆš—‚š–¼š–¾" },
    category: "ai",
    guide: { en: "怎 {pn} [š—š–¾š—‘š—] 怏" }
  },

  onStart: async function ({ api, event, args }) {
    const { messageID, threadID, senderID } = event;

    try {
      if (!args[0]) {
        return api.sendMessage(
          `╭── į²˜š‘¼ š–¹­ š–ŗš—‡š—’š–ŗ š—š—š—Œ š–¹­ į²˜š‘¼ ──╮\n\n  įÆ“ā˜… š—‰š—…š–¾š–ŗš—Œš–¾ š—‰š—‹š—ˆš—š—‚š–½š–¾ š—š–¾š—‘š— .ᐟ\n  ⋆ š—Žš—Œš–¾: {pn} š—š–ŗš—„š—Ž š—š–ŗš—„š—Ž\n\n╰── įÆ“ā˜…Ė™šƒ·Ė™Ż Ė–į²˜š‘¼ā‹†š–¹­.ᐟ ──╯`,
          threadID, messageID
        );
      }

      const text = args.join(" ");
      api.setMessageReaction("🄵", messageID, () => {}, true);

      const apiUrl = `https://api.tts.quest/v3/voicevox/synthesis?text=${encodeURIComponent(text)}&speaker=3`;
      const response = await axios.get(apiUrl);

      if (!response.data.success) {
        throw new Error("š–ŗš—‰š—‚ š–æš–ŗš—‚š—…š–¾š–½");
      }

      const audioUrl = response.data.mp3StreamingUrl;
      const cachePath = path.resolve(__dirname, 'cache');
      
      if (!fs.existsSync(cachePath)) fs.mkdirSync(cachePath, { recursive: true });
      const filePath = path.join(cachePath, `anya_${senderID}_${Date.now()}.mp3`);

      const getAudio = await axios.get(audioUrl, { responseType: "arraybuffer" });
      fs.writeFileSync(filePath, Buffer.from(getAudio.data));

      const successMsg = `╭── į²˜š‘¼ š–¹­ š–ŗš—‡š—’š–ŗ š—š—ˆš—‚š–¼š–¾ š–¹­ į²˜š‘¼ ──╮\n\n  įÆ“ā˜… š—†š–¾š—Œš—Œš–ŗš—€š–¾: "${text}"\n  ⋆ š—Œš–¾š—‹š—š–¾š–½ š–»š—’ š—ŒšŸ£š–æš—Ž į²˜š‘¼\n\n╰── įÆ“ā˜…Ė™šƒ·Ė™Ż Ė–į²˜š‘¼ā‹†š–¹­.ᐟ ──╯`;

      return api.sendMessage({
        body: successMsg,
        attachment: fs.createReadStream(filePath)
      }, threadID, () => {
        if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
        api.setMessageReaction("šŸŽ€", messageID, () => {}, true);
      }, messageID);

    } catch (error) {
      console.error(error);
      api.setMessageReaction("āŒ", messageID, () => {}, true);
      
      return api.sendMessage(
        `╭── į²˜š‘¼ š–¹­ š–¾š—‹š—‹š—ˆš—‹ š–¹­ į²˜š‘¼ ──╮\n\n  įÆ“ā˜… š—Œš—’š—Œš—š–¾š—† š–æš–ŗš—‚š—…š—Žš—‹š–¾ .ᐟ\n\n╰── įÆ“ā˜…Ė™šƒ·Ė™Ż Ė–į²˜š‘¼ā‹†š–¹­.ᐟ ──╯`,
        threadID, messageID
      );
    }
  }
};

View raw file