File size: 4,449 Bytes
2821330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
module.exports.config = {
  name: "ai",
  version: "1.0.0",
  permission: 0,
  credits: "Jonell Magallanes",
  usePrefix: false,
  premium: false,
  description: "Educational AI chatbot powered by GPT-4 and image recognition.",
  commandCategory: "AI", 
  usages: "ai [question]", 
  cooldowns: 6,
};

const axios = require('axios');
const fs = require('fs');
const https = require('https');

const fontMapping = {
  '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': '๐˜‡'
};

function convertToBold(text) {
  return text.replace(/\*(.*?)\*/g, (match, p1) => [...p1].map(char => fontMapping[char] || char).join(''))
    .replace(/### (.*?)(\n|$)/g, (match, p1) => `${[...p1].map(char => fontMapping[char] || char).join('')}`);
}

module.exports.handleReply = async ({ handleReply, event, api }) => {
  const { threadID, senderID, messageID } = event;
  const followUpApiUrl = `https://ccprojectapis.ddns.net/api/gpt4?ask=${encodeURIComponent(handleReply.message)}&id=${senderID}`;

  api.setMessageReaction("โฑ๏ธ", messageID, () => {}, true);

  try {
    const response = await axios.get(followUpApiUrl);
    const followUpResult = convertToBold(response.data); // โœ… Fixed field extraction
    api.setMessageReaction("โœ…", messageID, () => {}, true);
    api.sendMessage(followUpResult, threadID, messageID);
  } catch (error) {
    api.sendMessage(`โŒ Error: ${error.message}`, threadID);
  }
};

module.exports.run = async ({ event, api, args }) => {
  const { messageID, threadID, senderID } = event;

  if (!args.length) {
    return api.sendMessage("Please provide your question.\n\nExample: ai what is the solar system?", threadID, messageID);
  }

  const apiUrl = `https://ccprojectapis.ddns.net/api/gpt4?ask=${encodeURIComponent(args.join(" "))}&id=${senderID}`;
  const lad = await api.sendMessage("๐Ÿ”Ž Searching for an answer. Please wait...", threadID, messageID);

  try {
    if (event.type === "message_reply" && event.messageReply.attachments && event.messageReply.attachments[0].type === "photo") {
      const imageURL = event.messageReply.attachments[0].url;
      const timestamp = Date.now();
      const imagePath = `./public/${timestamp}.png`;
      const file = fs.createWriteStream(imagePath);

      https.get(imageURL, (response) => {
        response.pipe(file);
        file.on("finish", async () => {
          try {
            const visionApiUrl = `https://jonellpogi.serv00.net/gemini.php?prompt=${encodeURIComponent(args.join(" "))}&url=https://letmeknowbruhhthisthestoragebot.onrender.com/${timestamp}.png`;
            const visionResponse = await axios.get(visionApiUrl);
            
            if (visionResponse.data && visionResponse.data) {
              const visionText = convertToBold(visionResponse.data); // โœ… Extracted correctly
              api.editMessage(`๐—š๐—ฒ๐—บ๐—ถ๐—ป๐—ถ ๐—ฉ๐—ถ๐˜€๐—ถ๐—ผ๐—ป ๐—ฃ๐—ฟ๐—ผ ๐—œ๐—บ๐—ฎ๐—ด๐—ฒ ๐—ฅ๐—ฒ๐—ฐ๐—ผ๐—ด๐—ป๐—ถ๐˜๐—ถ๐—ผ๐—ป\nโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n${visionText}\nโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\n`, lad.messageID);
            } else {
              api.sendMessage("๐Ÿค– Failed to recognize the image.", threadID);
            }
          } catch (error) {
            api.sendMessage(`โŒ Error processing image: ${error.message}`, threadID);
          }
        });
      });
    } else {
      const response = await axios.get(apiUrl);
      const result = convertToBold(response.data); // โœ… Fixed extraction

      api.editMessage(`${result}`, lad.messageID);
    }

    global.client.handleReply.push({
      name: this.config.name,
      messageID: lad.messageID,
      author: senderID,
    });
  } catch (error) {
    api.editMessage(`โŒ Error: ${error.message}. Try using ${global.config.PREFIX}ai2`, lad.messageID);
  }
};