File size: 1,842 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
const axios = require('axios');
const fs = require('fs');
const path = require('path');

module.exports.config = {
  name: "autoreact",
  version: "1.2",
  hasPermssion: 0,
  credits: "Jonell Magallanes",
  description: "Auto react based on the context of users",
  usePrefix: true,
  commandCategory: "No Prefix",
  usage: "Type ?autoreact on or ?autoreact off to enable or disable the feature.",
  cooldowns: 3,
};

const autoreactFilePath = path.join(__dirname, 'autoreact.txt');

module.exports.handleEvent = async function ({ api, event }) {
  if (event.body !== null && event.isGroup && (!event.attachments || event.attachments.length === 0)) {
    let autoreactStatus = 'off';
    if (fs.existsSync(autoreactFilePath)) {
      autoreactStatus = fs.readFileSync(autoreactFilePath, 'utf8').trim();
    }

    if (autoreactStatus === 'on') {
      axios.get(`https://ccprojectapis.ddns.net/api/message/emoji?text=${encodeURIComponent(event.body)}`)
        .then(response => {
          const emoji = response.data.emoji;
          api.setMessageReaction(emoji, event.messageID, () => { }, true);
        })
        .catch(error => {
          console.error('Error fetching auto reaction:', error);
        });
    }
  }
};

module.exports.run = async function ({ api, event, args }) {
  const option = args[0]?.toLowerCase();

  if (option === 'on') {
    fs.writeFileSync(autoreactFilePath, 'on', 'utf8');
    api.sendMessage('Auto react has been enabled.', event.threadID);
  } else if (option === 'off') {
    fs.writeFileSync(autoreactFilePath, 'off', 'utf8');
    api.sendMessage('Auto react has been disabled.', event.threadID);
  } else {
    api.sendMessage('Invalid option. Use "?autoreact on" to enable or "?autoreact off" to disable auto reactions.', event.threadID);
  }
};