File size: 1,769 Bytes
0c88c2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
module.exports.config = {
  name: "join",
  eventType: ['log:subscribe'],
  version: "1.0.0",
  credits: "Jonell Magallanes",
  description: "GROUP UPDATE NOTIFICATION"
};

module.exports.run = function({ api, event }) {
  if (event.logMessageType === "log:subscribe") {
    if (event.logMessageData.addedParticipants.some(i => i.userFbId == api.getCurrentUserID())) {
      api.changeNickname(`${global.config.BOTNAME} β€’ [ ${global.config.PREFIX} ]`, event.threadID, api.getCurrentUserID());
      return api.shareContact(`βœ… π—•π—Όπ˜ π—–π—Όπ—»π—»π—²π—°π˜π—²π—±\n━━━━━━━━━━━━━━━━━━\n${global.config.BOTNAME} Bot connected successfully!\nType "${global.config.PREFIX}help" to view all commands\n\nContact: ${global.config.OWNER}`, api.getCurrentUserID(), event.threadID);
    } else {
      const { threadID } = event;
      api.getThreadInfo(threadID, async (err, threadInfo) => {
        if (err) return console.error(err);

        let { threadName, participantIDs } = threadInfo;
        var tn = threadName || "Unnamed group";
        let addedParticipants = event.logMessageData.addedParticipants;

        for (let newParticipant of addedParticipants) {
          let userID = newParticipant.userFbId;
          api.getUserInfo(parseInt(userID), (err, data) => {
            if (err) return console.error(err);

            var obj = Object.keys(data);
            var userName = data[obj].name.replace("@", "");

            if (userID !== api.getCurrentUserID()) {
              api.shareContact(`Hello ${userName}!\nWelcome to ${tn}\nYou're the ${participantIDs.length}th member on this group. Enjoy!`, newParticipant.userFbId, event.threadID);
            }
          });
        }
      });
    }
  }
};