← back to browse
goat command

npsr

Anime edits from TikTok

0
views
0
likes
0
installs

Aliases: animesr

raw source
const axios = require('axios');
const fs = require('fs-extra');
const path = require('path');

if (!global.instaMemory) global.instaMemory = new Set();

const TUTORIAL_KEYWORDS = [
  "tutorial", "how to edit", "how to make", "how i edit", "how to create",
  "cara edit", "cara buat", "cara membuat", "edit tutorial", "editing tutorial",
  "step by step", "tuto edit", "tuto ", "learn how", "edit guide",
  "guide to edit", "capcut tutorial", "alight motion tutorial",
  "kaise edit", "edit kaise", "edit karna", "editing kaise", "coba edit",
  "belajar edit", "trik edit", "tips edit", "preset tutorial"
];

function isTutorialVideo(video) {
  const text = `${video.title || ""} ${video.desc || ""} ${video.description || ""}`.toLowerCase();
  return TUTORIAL_KEYWORDS.some(kw => text.includes(kw));
}

module.exports = {
  config: {
    name: "npsr",
    aliases: ["animesr"],
    version: "1.3.4",
    author: "Arafat",
    countDown: 5,
    role: 0,
    description: "Anime edits from TikTok",
    category: "media",
    guide: {
      en: "{pn} [anime name]\nOr use: -[anime name] anywhere in chat"
    }
  },

  onStart: async function ({ api, event, args, message }) {
    const query = args.join(" ").trim();
    if (!query) {
      return message.reply(
        serifBold("๐ŸŒธ ๐๐ฅ๐ž๐š๐ฌ๐ž ๐ฉ๐ซ๐จ๐ฏ๐ข๐๐ž ๐š๐ง ๐š๐ง๐ข๐ฆ๐ž ๐ง๐š๐ฆ๐ž!") +
        "\n\n๐Ÿ“Œ ๐„๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž:\n.npsr naruto\n- naruto shippuden"
      );
    }
    return sendAnimeVideo({ api, event, message, query });
  },

  onChat: async function ({ api, event, message }) {
    const body = (event.body || "").trim();

    // Match: -anime name  (dash + optional space)
    const match = body.match(/^-\s*(.+)$/s);
    if (!match) return;

    const query = match[1].trim();
    if (!query) return;

    return sendAnimeVideo({ api, event, message, query });
  }
};

async function sendAnimeVideo({ api, event, message, query }) {
  /* โ•โ•โ•โ•โ•โ•โ• SAFE REACTION HELPER โ•โ•โ•โ•โ•โ•โ• */
  const react = (emoji) => {
    try {
      api.setMessageReaction(emoji, event.messageID, (err) => {
        if (err) console.log("[npsr] Reaction failed:", err.message || err);
      }, true);
    } catch (e) {
      console.log("[npsr] Reaction error:", e.message);
    }
  };

  /* โ•โ•โ•โ•โ•โ•โ• INITIAL REACTION: โœจ (loading) โ•โ•โ•โ•โ•โ•โ• */
  react("โœจ");

  const cacheDir = path.join(__dirname, 'cache');
  if (!fs.existsSync(cacheDir)) fs.mkdirSync(cacheDir);
  const pathVideo = path.join(cacheDir, `npsr_${Date.now()}.mp4`);

  try {
    const searchTerms = `${query} anime edit amv no watermark`;

    const res = await axios.get(`https://azadx69x-tiktok-api.vercel.app/tiktok/search`, {
      params: { query: searchTerms },
      timeout: 15000
    });

    const rawVideos = res.data?.list;

    if (!rawVideos || rawVideos.length === 0) {
      react("โŒ");
      return message.reply(serifBold("โŒ ๐๐จ ๐ฏ๐ข๐๐ž๐จ๐ฌ ๐Ÿ๐จ๐ฎ๐ง๐!"));
    }

    const videos = rawVideos.filter(v => !isTutorialVideo(v));

    if (videos.length === 0) {
      react("โŒ");
      return message.reply(serifBold("โŒ ๐๐จ ๐š๐ง๐ข๐ฆ๐ž ๐ž๐๐ข๐ญ๐ฌ ๐Ÿ๐จ๐ฎ๐ง๐!"));
    }

    const getVideoId = (v) => v.video_id || v.id || v.url;

    let selectedVideo = videos.find(v => !global.instaMemory.has(getVideoId(v)));
    if (!selectedVideo) {
      global.instaMemory.clear();
      selectedVideo = videos[0];
    }
    global.instaMemory.add(getVideoId(selectedVideo));

    const downloadUrl = selectedVideo.noWatermark || selectedVideo.play || selectedVideo.wmplay;

    if (!downloadUrl) {
      react("โŒ");
      return message.reply(serifBold("โŒ ๐•๐ข๐๐ž๐จ ๐ฎ๐ซ๐ฅ ๐ง๐จ๐ญ ๐Ÿ๐จ๐ฎ๐ง๐!"));
    }

    const videoResponse = await axios({
      method: 'get',
      url: downloadUrl,
      responseType: 'arraybuffer',
      timeout: 30000,
      headers: { 'User-Agent': 'Mozilla/5.0' }
    });

    await fs.writeFile(pathVideo, Buffer.from(videoResponse.data));

    await message.reply({
      body: serifBold(`โ€ข ๐‡๐ž๐ซ๐ž ๐ข๐ฌ ๐ฒ๐จ๐ฎ๐ซ ๐ฏ๐ข๐๐ž๐จ ๐›๐š๐›๐ฒ  <๐Ÿ˜˜`),
      attachment: fs.createReadStream(pathVideo)
    });

    /* โ•โ•โ•โ•โ•โ•โ• SUCCESS REACTION: ๐ŸŒธ โ•โ•โ•โ•โ•โ•โ• */
    react("๐ŸŒธ");

  } catch (err) {
    console.error("NPSR ERROR:", err.message);
    react("โš ๏ธ");

    const errorMsg = err.code === 'ECONNABORTED'
      ? "โš ๏ธ | ๐‚๐จ๐ง๐ง๐ž๐œ๐ญ๐ข๐จ๐ง ๐ญ๐ข๐ฆ๐ž๐ ๐จ๐ฎ๐ญ. ๐“๐ซ๐ฒ ๐š๐ ๐š๐ข๐ง!"
      : "โš ๏ธ | ๐’๐ž๐ซ๐ฏ๐ž๐ซ ๐ข๐ฌ ๐›๐ฎ๐ฌ๐ฒ ๐จ๐ซ ๐€๐๐ˆ ๐ข๐ฌ ๐๐จ๐ฐ๐ง. ๐“๐ซ๐ฒ ๐š๐ ๐š๐ข๐ง!";

    return message.reply(serifBold(errorMsg));
  } finally {
    if (fs.existsSync(pathVideo)) {
      setTimeout(() => {
        try { fs.unlinkSync(pathVideo); } catch(e) {}
      }, 20000);
    }
  }
}

function serifBold(text) {
  const letters = {
    'a': '๐š', 'b': '๐›', 'c': '๐œ', 'd': '๐', 'e': '๐ž', 'f': '๐Ÿ', 'g': '๐ ', 'h': '๐ก', 'i': '๐ข', 'j': '๐ฃ', 'k': '๐ค', 'l': '๐ฅ', 'm': '๐ฆ',
    'n': '๐ง', 'o': '๐จ', 'p': '๐ฉ', 'q': '๐ช', 'r': '๐ซ', 's': '๐ฌ', 't': '๐ญ', 'u': '๐ฎ', 'v': '๐ฏ', 'w': '๐ฐ', 'x': '๐ฑ', 'y': '๐ฒ', 'z': '๐ณ',
    'A': '๐€', 'B': '๐', 'C': '๐‚', 'D': '๐ƒ', 'E': '๐„', 'F': '๐…', 'G': '๐†', 'H': '๐‡', 'I': '๐ˆ', 'J': '๐‰', 'K': '๐Š', 'L': '๐‹', 'M': '๐Œ',
    'N': '๐', 'O': '๐Ž', 'P': '๐', 'Q': '๐', 'R': '๐‘', 'S': '๐’', 'T': '๐“', 'U': '๐”', 'V': '๐•', 'W': '๐–', 'X': '๐—', 'Y': '๐˜', 'Z': '๐™',
    '0': '๐ŸŽ', '1': '๐Ÿ', '2': '๐Ÿ', '3': '๐Ÿ‘', '4': '๐Ÿ’', '5': '๐Ÿ“', '6': '๐Ÿ”', '7': '๐Ÿ•', '8': '๐Ÿ–', '9': '๐Ÿ—'
  };
  return text.split('').map(char => letters[char] || char).join('');
}

View raw file