Advertisement
samiroexpikachu

Memegen

May 7th, 2024
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require('axios');
  2.  
  3. module.exports = {
  4.   config: {
  5.     name: "memegen",
  6.     version: "1.8",
  7.     author: "Samir Œ",
  8.     shortDescription: "Generate meme image",
  9.     longDescription: "Generate a meme image with custom top and bottom text.",
  10.     category: "Image Generation"
  11.   },
  12.  
  13.   onStart: async function ({ api, event, args }) {
  14.     const [input, top, bottom] = args.join(" ").split("|").map(arg => arg.trim());
  15.  
  16.     if (!input || !top || !bottom) {
  17.       return api.sendMessage({ body: "Please provide theme number, top text, and bottom text." }, event.threadID);
  18.     }
  19.  
  20.     const thmNumber = parseInt(input);
  21.  
  22.     if (isNaN(thmNumber) || thmNumber < 1) {
  23.       return api.sendMessage({ body: "Invalid theme number." }, event.threadID);
  24.     }
  25.  
  26.     try {
  27.       const themesResponse = await axios.get('https://apis-samir.onrender.com/getall/memegen');
  28.       const memeThemes = themesResponse.data;
  29.  
  30.       if (thmNumber > memeThemes.length) {
  31.         return api.sendMessage({ body: "Invalid theme number." }, event.threadID);
  32.       }
  33.  
  34.       const themeName = memeThemes[thmNumber - 1];
  35.       const memeUrl = `https://apis-samir.onrender.com/Memegen?thmNumber=${thmNumber}&top=${encodeURIComponent(top)}&bottom=${encodeURIComponent(bottom)}`;
  36.       const messageBody = `Meme theme: ${themeName}`;
  37.  
  38.       api.sendMessage({ body: messageBody, attachment: await global.utils.getStreamFromURL(memeUrl) }, event.threadID);
  39.     } catch (error) {
  40.       console.error("Failed to fetch meme themes:", error.message);
  41.       api.sendMessage({ body: "Failed to generate meme." }, event.threadID);
  42.     }
  43.   }
  44. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement