switch (event.logMessageType) {
case "log:subscribe" : {
api.getThreadInfo(event.threadID, function(err, threadInfo) {
if (err) return console.log(err)
let tname = threadInfo.threadName;
let participants = threadInfo.userInfo;
let addedParticipants = event.logMessageData.addedParticipants;
let botID1 = api.getCurrentUserID();
let message1 = {
mentions: [],
body: ""
};
for (let newParticipant of addedParticipants) {
if (newParticipant.userFbId == botID1) {
message1.body = `Hi, I am 🤖KenBot🤖. Thank you for having me as the ${toOrdinalNumber(participants.length)} member of "${tname}".\n\n`;
message1.body += `Type ${prefix}help to see the list of available commands. Please remember to not spam the bot to avoid the bot from being muted by fb. Thank you for your kind understanding! <3\n\n~Developer: Yung Pogi HAHA`;
message1.mentions.push({
tag: "Yung Pogi HAHA", id: "100002428934209"
});
// Set bot's nickname
api.changeNickname("🤖KenBot", event.threadID, botID1, (err) => {
if (err) return console.error(err);
})
} else {
let firstName = newParticipant.firstName;
let id = newParticipant.userFbId;
message1.body = `Welcome @${firstName}, you are the ${toOrdinalNumber(participants.length)} member of "${tname}"!\n\nPlease follow the rules and regulations of this group, respect all members and admins.\n\nWe hope that we'll know about you better and we'd have a great friendship ahead. <3`;
message1.mentions.push({
id, tag: `@${firstName}`
});
}
}
api.sendMessage(message1, event.threadID);
})
}
break;
case "log:unsubscribe": {
api.getThreadInfo(event.threadID, function(err, threadInfo) {
if (err) return console.log(err)
let tname = threadInfo.threadName;
let leftParticipantFbId = event.logMessageData.leftParticipantFbId;
let botID = api.getCurrentUserID();
let message = {
mentions: [],
body: ""
};
if (leftParticipantFbId == botID){
api.sendMessage(`Your bot is not a member anymore of ${tname}.`, log);
} else {
let us = api.getUserInfo(leftParticipantFbId);
let name = user[leftParticipantFbId].name;
message.body = `Farewell @${name}, the whole ${threadName} will be awaiting for your return!\n\nGoodbye for now and may you have a blessed day ahead! :>`;
message.mentions.push({
id: leftParticipantFbId, tag: `@${name}`
});
api.sendMessage(message, event.threadID);
}
})
}
}