-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.js
More file actions
94 lines (88 loc) · 2.65 KB
/
custom.js
File metadata and controls
94 lines (88 loc) · 2.65 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
module.exports = async ({ api }) => {
const logger = require('./utils/log');
const cron = require('node-cron');
const fs = require('fs');
const yandeva = {
autoRestart: {
status: true,
time: 40, //40 minutes
note: 'To avoid problems, enable periodic bot restarts'
},
accpetPending: {
status: false,
time: 30, //30 minutes
note: 'Approve waiting messages after a certain time'
}
}
function autoRestart(config) {
if (config.status) {
setInterval(async () => {
logger(`Start rebooting the system!`, "[ Auto Restart ]")
process.exit(1)
}, config.time * 60 * 1000)
}
}
function accpetPending(config) {
if (config.status) {
setInterval(async () => {
const list = [
...(await api.getThreadList(1, null, ['PENDING'])),
...(await api.getThreadList(1, null, ['OTHER']))
];
if (list[0]) {
api.sendMessage('You have been approved for the queue. (This is an automated message)', list[0].threadID);
}
}, config.time * 60 * 1000)
}
}
autoRestart(yandeva.autoRestart)
accpetPending(yandeva.accpetPending)
cron.schedule('*/30 * * * *', () => {
api.getThreadList(25, null, ['INBOX'], async (err, data) => {
if (err) return console.error("Error [Thread List Cron]: " + err);
let i = 0;
let j = 0;
async function message(thread) {
try {
api.sendMessage(`Hello Members How are you today?\nKamustahin kayo ulit after 30 minutes`, thread.threadID, (err) => { if (err) return });
} catch (error) {
console.error("Error sending a message:", error);
}
}
while (j < 20 && i < data.length) {
if (data[i].isGroup && data[i].name != data[i].threadID) {
await message(data[i]);
j++;
}
i++;
}
});
}, {
scheduled: true,
timezone: "Asia/Manila"
});
cron.schedule('*/25 * * * *', () => {
api.getThreadList(25, null, ['INBOX'], async (err, data) => {
if (err) return console.error("Error [Thread List Cron]: " + err);
let i = 0;
let j = 0;
async function message(thread) {
try {
api.sendMessage(`› Hello🤗 How are you? (ᴗ˳ᴗ)`, thread.threadID, (err) => { if (err) return });
} catch (error) {
console.error("Error sending a message:", error);
}
}
while (j < 20 && i < data.length) {
if (data[i].isGroup && data[i].name != data[i].threadID) {
await message(data[i]);
j++;
}
i++;
}
});
}, {
scheduled: true,
timezone: "Asia/Manila"
});
};