𝐃𝐀𝐑𝐑𝐄𝐋𝐋 πŒπ”π‚π‡π„π‘πˆ ⚑ commited on
Commit
231eeee
Β·
unverified Β·
1 Parent(s): d4fa73f

Update ai-gemini.js

Browse files
Files changed (1) hide show
  1. plugins/ai-gemini.js +13 -9
plugins/ai-gemini.js CHANGED
@@ -1,6 +1,7 @@
 
 
1
  const config = require('../config');
2
  const { cmd, commands } = require('../command');
3
- const { fetchJson } = require('../lib/functions');
4
 
5
  cmd({
6
  pattern: "bot",
@@ -35,15 +36,18 @@ cmd({
35
  }) => {
36
  try {
37
  if (!q) return reply("Please ask a question or provide input for the AI.");
38
-
39
- const data = await fetchJson(`https://api.giftedtech.web.id/api/ai/geminiaipro?apikey=gifted&q=${q}`);
40
- console.log(data);
41
-
42
- if (!data.message) return reply("No response from the AI.");
43
-
44
- return reply(` \`πŸ€– GEMINI AI RESPONSE:\` \n\n${data.message}`);
 
 
 
45
  } catch (error) {
46
- console.error(error);
47
  reply(`An error occurred: ${error.message}`);
48
  }
49
  });
 
1
+
2
+ const axios = require('axios');
3
  const config = require('../config');
4
  const { cmd, commands } = require('../command');
 
5
 
6
  cmd({
7
  pattern: "bot",
 
36
  }) => {
37
  try {
38
  if (!q) return reply("Please ask a question or provide input for the AI.");
39
+ const userInput = q.trim();
40
+ if (userInput === "") return reply("Please provide a valid input.");
41
+ const apiUrl = `https://api.giftedtech.web.id/api/ai/geminiaipro?apikey=gifted&q=${encodeURIComponent(userInput)}`;
42
+ const response = await axios.get(apiUrl);
43
+ console.log('API Response:', response.data);
44
+ if (!response.data || !response.data.message) {
45
+ return reply("No response from the AI or invalid API response.");
46
+ }
47
+ const aiResponse = response.data.message.trim();
48
+ return reply(`\`πŸ€– GEMINI AI RESPONSE:\` \n\n${aiResponse}`);
49
  } catch (error) {
50
+ console.error('Error:', error);
51
  reply(`An error occurred: ${error.message}`);
52
  }
53
  });