Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions ai.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports.config = {
name: "adduser",
version: "1.0.1",
role: 0,
credits: "cliff",
description: "Add user to group by id",
hasPrefix: false,
usage: "[args]",
cooldowns: 5
};

module.exports.run = async function ({ api, event, args }) {
const { threadID, messageID } = event;
const botID = api.getCurrentUserID();
const out = msg => api.sendMessage(msg, threadID, messageID);
var { participantIDs, approvalMode, adminIDs } = await api.getThreadInfo(threadID);
var participantIDs = participantIDs.map(e => parseInt(e));
if (!args[0]) return out("Please enter an id/link profile user to add.");
if (!isNaN(args[0])) return adduser(args[0], undefined);
else {
try {
var [id, name, fail] = await getUID(args[0], api);
if (fail == true && id != null) return out(id);
else if (fail == true && id == null) return out("User ID not found.")
else {
await adduser(id, name || "Facebook users");
}
} catch (e) {
return out(`${e.name}: ${e.message}.`);
}
}

async function adduser(id, name) {
id = parseInt(id);
if (participantIDs.includes(id)) return out(`${name ? name : "Member"} is already in the group.`);
else {
var admins = adminIDs.map(e => parseInt(e.id));
try {
await api.addUserToGroup(id, threadID);
}
catch {
return out(`Can't add ${name ? name : "user"} in group.`);
}
if (approvalMode === true && !admins.includes(botID)) return out(`Added ${name ? name : "member"} to the approved list !`);
else return out(`Added ${name ? name : "member"} to the group !`)
}
}
}