Advertisement
samiroexpikachu

Quotely

Oct 15th, 2024 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require('axios');
  2. const fs = require('fs');
  3. const path = require('path');
  4. const TinyURL = require('tinyurl');
  5.  
  6. async function onStart({ event, api, message, usersData, args }) {
  7.     try {
  8.         let uid = event.type === "message_reply" ? event.messageReply.senderID : event.senderID;
  9.         const sexInfo = await api.getUserInfo([uid]);
  10.         const username = sexInfo[uid].name;
  11.  
  12.         const tinyUrl = await TinyURL.shorten(`https://api-turtle.vercel.app/api/facebook/pfp?uid=${uid}`);
  13.         const imgbbResponse = await axios.get(`https://www.noobs-api.000.pe/dipto/imgbb?url=${encodeURIComponent(tinyUrl)}`);
  14.         const postImgResponse = await axios.get(`https://www.noobs-api.000.pe/dipto/postimg?imageUrl=${encodeURIComponent(imgbbResponse.data.data.url)}`);
  15.         const avatarUrl = postImgResponse.data.directLink;
  16.  
  17.         const color = args.includes('--color') ? args[args.indexOf('--color') + 1] === 'false' ? false : true : true;
  18.         let quoteText = args.join(' ');
  19.         const authorIndex = args.indexOf('--author');
  20.         let displayName = username;
  21.        
  22.         if (authorIndex !== -1) {
  23.             displayName = args[authorIndex + 1];
  24.             quoteText = quoteText.replace(`--author ${displayName}`, '').trim();
  25.         }
  26.        
  27.         if (!quoteText) {
  28.             const quoteResponse = await axios.get('https://api.mininxd.my.id/quotes');
  29.             quoteText = quoteResponse.data.text;
  30.             displayName = quoteResponse.data.author;
  31.         }
  32.  
  33.         const response = await axios.post('https://samirxpikachu.frii.site/myquote', {
  34.             text: quoteText,
  35.             avatar: avatarUrl,
  36.             username: username,
  37.             display_name: displayName,
  38.             color: color,
  39.             watermark: "Architectdevs",
  40.             returnRawImage: true
  41.         }, {
  42.             headers: {
  43.                 'Content-Type': 'application/json'
  44.             },
  45.             responseType: 'arraybuffer'
  46.         });
  47.  
  48.         const imagePath = path.join(__dirname, 'quote_image.png');
  49.         fs.writeFileSync(imagePath, response.data);
  50.         await message.reply({
  51.             body: "",
  52.             attachment: fs.createReadStream(imagePath)
  53.         });
  54.         fs.unlinkSync(imagePath);
  55.     } catch (error) {
  56.         console.error("Error generating or sending the image:", error);
  57.         await message.reply(`An error occurred while generating the quote image: ${error.message}`);
  58.     }
  59. }
  60.  
  61. const config = {
  62.     name: "quote",
  63.     aliases: ["quotly"],
  64.     version: "1.0",
  65.     author: "Samir Œ",
  66.     countDown: 5,
  67.     role: 0,
  68.     shortDescription: "Generate a quote image.",
  69.     longDescription: "Generate an image with a custom quote and user details.",
  70.     category: "Fun",
  71.     guide: {
  72.         en: "{pn} [quote text] --author [author name] --color [true/false]"
  73.     }
  74. };
  75.  
  76. module.exports = {
  77.     config,
  78.     onStart
  79. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement