From 04f4cd91ccc0b3cbd7ce01f29fc2931a9415be62 Mon Sep 17 00:00:00 2001 From: Pakyuw <166945403+Pakyuw@users.noreply.github.com> Date: Sat, 4 May 2024 09:56:20 +0800 Subject: [PATCH] Create ai.js Warren --- ai.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 ai.js diff --git a/ai.js b/ai.js new file mode 100644 index 000000000..bdf4914b5 --- /dev/null +++ b/ai.js @@ -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 !`) + } + } + }