| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : D:/laragon4/www/wa-gateway/server/database/ |
Upload File : |
const { dbQuery } = require("./index");
const cache = require("./../lib/cache");
const myCache = cache.myCache;
// autoreplies table
const isExistsEqualCommand = async (command, number) => {
// find in autoreplies where has device.body = numberWa
if (myCache.has(command + number)) {
return myCache.get(command + number);
}
let checkDevice = await dbQuery(
`SELECT * FROM devices WHERE body = '${number}' LIMIT 1`
);
if (checkDevice.length === 0) return [];
let device_id = checkDevice[0].id;
let data = await dbQuery(
`SELECT * FROM autoreplies WHERE keyword = "${command}" AND type_keyword = 'Equal' AND device_id = ${device_id} AND status = 'Active' LIMIT 1`
);
if (data.length === 0) return [];
myCache.set(command + number, data);
return data;
};
const isExistsContainCommand = async (command, number) => {
// find in autoreplies where has device.body = numberWa
if (myCache.has("contain" + command + number)) {
return myCache.get("contain" + command + number);
}
let checkDevice = await dbQuery(
`SELECT * FROM devices WHERE body = '${number}' LIMIT 1`
);
if (checkDevice.length === 0) return [];
let device_id = checkDevice[0].id;
let data = await dbQuery(
`SELECT * FROM autoreplies WHERE LOCATE(keyword, "${command}") > 0 AND type_keyword = 'Contain' AND device_id = ${device_id} AND status = 'Active' LIMIT 1`
);
if (data.length === 0) return [];
myCache.set("contain" + command + number, data);
return data;
};
const getUrlWebhook = async (number) => {
if (myCache.has("webhook" + number)) {
return myCache.get("webhook" + number);
}
let url = null;
let data = await dbQuery(
`SELECT webhook FROM devices WHERE body = '${number}' LIMIT 1`
);
if (data.length > 0) {
url = data[0].webhook;
}
myCache.set("webhook" + number, url);
return url;
};
const getDevice = async (deviceBody) => {
if (myCache.has("deviceall" + deviceBody)) {
return myCache.get("deviceall" + deviceBody);
}
let deviceall = null,
deviceResult = await dbQuery(
"SELECT * FROM devices WHERE body = '" + deviceBody + "' LIMIT 1"
);
return (
deviceResult.length > 0 && (deviceall = deviceResult),
myCache.set("deviceall" + deviceBody, deviceall),
deviceall
);
};
// end autoreplies table
module.exports = {
isExistsEqualCommand,
isExistsContainCommand,
getUrlWebhook,
getDevice,
};