Facebook
From Jarif, 1 Month ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 188
  1. const axios = require("axios");
  2.  
  3. module.exports = {
  4.   config: {
  5.     name: "chat",
  6.     version: "1.1",
  7.     author: "JARiF@Cock | Modified By NZ R ",
  8.     category: "simSimi-bn",
  9.     cooldown: 0,
  10.     role: 0,
  11.     guide: {
  12.       en: "{p}chat hi\nfor deleting: {p}chat delete hi\nfor teaching: {p}chat teach hi | hello"
  13.     }
  14.   },
  15.   makeApiRequest: async function (question) {
  16.     try {
  17.       const response = await axios.get(`https://simsimi.vyturex.com/chat?ques=${encodeURIComponent(question)}`);
  18.       return response.data;
  19.     } catch (error) {
  20.       throw error;
  21.     }
  22.   },
  23.   handleCommand: async function ({ args, message }) {
  24.     try {
  25.       const subCommand = args[0];
  26.  
  27.       if (subCommand === 'teach') {
  28.         const content = args.slice(1).join(" ").split("|").map((item) => item.trim());
  29.  
  30.         if (content.length < 2) {
  31.           return message.reply("Please provide both the question and the answer separated by '|'.");
  32.         }
  33.  
  34.          const questi
  35.         const answer = content.slice(1).join('|');
  36.  
  37.         try {
  38.           const teachUrl = `https://simsimi.vyturex.com/teach?ques=${encodeURIComponent(question)}&ans;=${encodeURIComponent(answer)}`;
  39.            const teachResp axios.get(teachUrl);
  40.           message.reply(teachResponse.data);
  41.         } catch (error) {
  42.           console.error(error);
  43.           message.reply("Try again later dear.");
  44.         }
  45.       } else if (subCommand === 'delete') {
  46.         try {
  47.            const questi ');
  48.          if (!questionToDelete) {
  49.            message.reply('Please provide the question you want to delete.');
  50.            return;
  51.          }
  52.  
  53.          const deleteUrl = `https://simsimi.vyturex.com/delete?ques=${encodeURIComponent(questionToDelete)}`;
  54.           const deleteResp axios.get(deleteUrl);
  55.  
  56.          message.reply(deleteResponse.data);
  57.  
  58.        } catch (error) {
  59.          console.error(error);
  60.          message.reply(error.message);
  61.        }
  62.      } else {
  63.        const name = args.join(' ');
  64.  
  65.        try {
  66.          const result = await this.makeApiRequest(name);
  67.          message.reply(result, (err, info) => {
  68.            global.GoatBot.onReply.set(info.messageID, {
  69.              commandName: this.config.name,
  70.              messageID: info.messageID,
  71.              author: message.senderID
  72.            });
  73.          });
  74.        } catch (error) {
  75.          console.error(error);
  76.          message.reply('Oops! An error occurred.');
  77.        }
  78.      }
  79.    } catch (error) {
  80.      message.reply('Oops! An error occurred: ' + error.message);
  81.    }
  82.  },
  83.  onStart: function ({ args, message }) {
  84.    return this.handleCommand({ args, message });
  85.  },
  86.  onReply: function ({ args, message }) {
  87.    return this.handleCommand({ args, message });
  88.  }
  89. };
  90.