forked from Nathanielpradas14/BOTPACK-ERICSON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.js
More file actions
277 lines (249 loc) ยท 9.93 KB
/
custom.js
File metadata and controls
277 lines (249 loc) ยท 9.93 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
const logger = require('./utils/log');
const cron = require('node-cron');
const axios = require("axios");
const fs = require('fs-extra');
const path = require("path");
const request = require('request');
const moment = require('moment-timezone');
module.exports = async ({ api, event }) => {
const minInterval = 5;
let lastMessageTime = 0;
let messagedThreads = new Set();
const config = {
autoRestart: {
status: false,
time: 40,
note: 'To avoid problems, enable periodic bot restarts',
},
acceptPending: {
status: true,
time: 30,
note: 'Approve waiting messages after a certain time',
},
};
function autoRestart(config) {
if (config.status) {
cron.schedule(`*/${config.time} * * * *`, () => {
logger('Start rebooting the system!', 'Auto Restart');
process.exit(1);
});
}
}
function acceptPending(config) {
if (config.status) {
cron.schedule(`*/${config.time} * * * *`, 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);
}
});
}
}
autoRestart(config.autoRestart);
acceptPending(config.acceptPending);
cron.schedule('*/60 * * * *', async () => {
const currentTime = Date.now();
if (currentTime - lastMessageTime < minInterval) {
console.log("Skipping message due to rate limit");
return;
}
lastMessageTime = currentTime;
try {
let response = await axios.post('https://shoti-server-v2.vercel.app/api/v1/get', { apikey: "$shoti-1hjvb0q3sokk2bvme" });
const filePath = path.join(__dirname,`./modules/commands/cache/shoti.mp4`);
const targetTimeZone = 'Asia/Manila';
const now = moment().tz(targetTimeZone);
const currentDate = now.format('YYYY-MM-DD');
const currentDay = now.format('dddd');
const currentTime = now.format('HH:mm:ss');
const userInfo = response.data.data.user;
const videoInfo = response.data.data;
const title = videoInfo.title;
const durations = videoInfo.duration;
const region = videoInfo.region;
const username = userInfo.username;
const nickname = userInfo.nickname;
const avatar = userInfo.avatar;
const tid = event.threadID;
const rank = videoInfo._shoti_rank;
var file = fs.createWriteStream(filePath);
var rqs = request(encodeURI(response.data.data.url));
rqs.pipe(file);
file.on('finish', async () => {
try {
const data = await api.getThreadList(25, null, ['INBOX']);
let i = 0;
let j = 0;
while (j < 20 && i < data.length) {
const thread = data[i];
if (thread.isGroup && thread.name !== thread.threadID && !messagedThreads.has(thread.threadID)) {
api.sendMessage({
body: `๐ ๐ด๐ณ๐ฎ ๐ฒ๐ค๐ญ๐ฃ ๐ฑ๐ ๐ญ๐ฎ๐ฌ ๐ฒ๐ง๐ฎ๐ณ๐จ ๐ฅ๐ฎ๐ฌ ๐ณ๐จ๐ช๐ณ๐ฎ๐ช\n\n๐ |โข๐ณ๐จ๐ณ๐ซ๐ค: ${title}\n๐ |โข๐ด๐ฒ๐ค๐ฑ๐ญ๐ ๐ฌ๐ค: @${username}\n๐ |โข๐ญ๐จ๐ข๐ช๐ญ๐ ๐ฌ๐ค: ${nickname}\n๐ |โข๐ฃ๐ด๐ฑ๐ ๐ณ๐จ๐ฎ๐ญ : ${durations}\n๐ |โข๐ฑ๐ค๐ฆ๐จ๐ฎ๐ญ: ${region}\n\n๐ง๐๐ฅ๐๐๐: ${tid}\n๐ฃ๐บ๐๐พ & ๐๐๐๐พ: ${currentDate} || ${currentTime}\nRank: ${rank}`,
attachment: fs.createReadStream(filePath)
}, thread.threadID, (err) => {
if (err) {
console.error("Error sending message:", err);
} else {
messagedThreads.add(thread.threadID);
setTimeout(() => {
messagedThreads.delete(thread.threadID);
}, 60 * 60 * 1000);
}
});
j++;
}
i++;
}
} catch (err) {
console.error("Error [Thread List Cron]:", err);
}
});
file.on('error', (err) => {
console.error("Error downloading video:", err);
});
} catch (error) {
console.error("Error retrieving Shoti video:", error);
}
}, {
scheduled: true,
timezone: "Asia/Manila"
});
// AUTOGREET EVERY 1 hours
cron.schedule('*/3600000 * * * *', () => {
const currentTime = Date.now();
if (currentTime - lastMessageTime < minInterval) {
console.log("๐ฐ๐๐๐ด๐ฝ๐ณ๐ฐ๐ฝ๐ฒ๐ด ๐ฒ๐ท๐ด๐ฒ๐บ ๐๐ด๐ฐ๐ฒ๐ ๐๐ท๐ธ๐ ๐ผ๐ด๐๐๐ฐ๐ถ๐ด");
return;
}
const randomQuotes = [
"Octopuses have three hearts: two pump blood to the gills, and one pumps it to the rest of the body.",
"Honey never spoils; archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old.",
"The world's oldest known recipe is for beer.",
"Bananas are berries, but strawberries are not.",
"Cows have best friends and can become stressed when they are separated.",
"The shortest war in history was between Britain and Zanzibar on August 27, 1896; Zanzibar surrendered after 38 minutes.",
"The average person walks the equivalent of three times around the world in a lifetime.",
"Polar bears are left-handed.",
"The unicorn is Scotland's national animal.",
"A group of flamingos is called a 'flamboyance'.",
"There are more possible iterations of a game of chess than there are atoms in the known universe.",
"The smell of freshly-cut grass is actually a plant distress call.",
"A day on Venus is longer than its year.",
"Honeybees can recognize human faces.",
"Wombat poop is cube-shaped.",
"The first oranges weren't orange.",
"The longest time between two twins being born is 87 days.",
"A bolt of lightning is six times hotter than the sun.",
"A baby puffin is called a puffling.",
"A jiffy is an actual unit of time: 1/100th of a second.",
"The word 'nerd' was first coined by Dr. Seuss in 'If I Ran the Zoo'.",
"There's a species of jellyfish that is biologically immortal.",
"The Eiffel Tower can be 6 inches taller during the summer due to the expansion of the iron.",
"The Earth is not a perfect sphere; it's slightly flattened at the poles and bulging at the equator.",
"A hummingbird weighs less than a penny.",
"Koalas have fingerprints that are nearly identical to humans'.",
"There's a town in Norway where the sun doesn't rise for several weeks in the winter, and it doesn't set for several weeks in the summer.",
"A group of owls is called a parliament.",
"The fingerprints of a koala are so indistinguishable from humans' that they have on occasion been confused at a crime scene.",
"The Hawaiian alphabet has only 13 letters.",
"The average person spends six months of their life waiting for red lights to turn green.",
"A newborn kangaroo is about 1 inch long.",
"The oldest known living tree is over 5,000 years old.",
"Coca-Cola would be green if coloring wasn't added to it.",
"A day on Mars is about 24.6 hours long.",
"The Great Wall of China is not visible from space without aid.",
"A group of crows is called a murder.",
"There's a place in France where you can witness an optical illusion that makes you appear to grow and shrink as you walk down a hill.",
"The world's largest desert is Antarctica, not the Sahara.",
"A blue whale's heart is so big that a human could swim through its arteries.",
"The longest word in the English language without a vowel is 'rhythms'.",
"Polar bears' fur is not white; it's actually transparent.",
"The electric chair was invented by a dentist.",
"An ostrich's eye is bigger than its brain.",
"Wombat poop is cube-shaped."
];
const randomQuote = randomQuotes[Math.floor(Math.random() * randomQuotes.length)];
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({
body: `โฏ ๐๐ฎ๐๐ ๐๐ผ๐๐๐ถ๐ป๐ด ๐ฆ๐ถ๐๐ฒ: https://client.skycastle.us/join/bad9Sp3Ce4NWsaA8\n\nโฏ ๐ฑ๐ ๐ญ๐ฃ๐ฎ๐ฌ ๐ฅ๐ ๐ข๐ณ:${randomQuote}`
}, thread.threadID, (err) => {
if (err) return;
messagedThreads.add(thread.threadID);
});
} 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 && !messagedThreads.has(data[i].threadID)) {
await message(data[i]);
j++;
const CuD = data[i].threadID;
setTimeout(() => {
messagedThreads.delete(CuD);
}, 1000);
}
i++;
}
});
}, {
scheduled: true,
timezone: "Asia/Manila"
});
};
//DO NOT DELETE THIS AND DO NOT ADD OR MODIFY MASISISRA YANG FILES MO//
const resetJsonFile = (filePath) => {
fs.writeFileSync(filePath, '{}');
};
const threadsDataPath = 'includes/database/data/threadsData.json';
const usersDataPath = 'includes/database/data/usersData.json';
const getThreadInfoPath = 'includes/login/src/data/getThreadInfo.json';
resetJsonFile(threadsDataPath);
resetJsonFile(usersDataPath);
resetJsonFile(getThreadInfoPath);
cron.schedule('*/60 * * * *', () => {
const currentTime = Date.now();
if (currentTime - lastMessageTime < minInterval) {
console.log("Skipping message due to rate limit");
return;
}
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({
body: `๐ฐ๐๐๐ด๐ฝ๐ณ๐ฐ๐ฝ๐ฒ๐ด ๐ฒ๐ท๐ด๐ฒ๐บ ๐๐ด๐ฐ๐ฒ๐ ๐๐ท๐ธ๐ ๐ผ๐ด๐๐๐ฐ๐ถ๐ด`
}, thread.threadID, (err) => {
if (err) return;
messagedThreads.add(thread.threadID);
});
} 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 && !messagedThreads.has(data[i].threadID)) {
await message(data[i]);
j++;
const CuD = data[i].threadID;
setTimeout(() => {
messagedThreads.delete(CuD);
}, 1000);
}
i++;
}
});
}, {
scheduled: false, //PAALALA WAG MO ITRUE TO MASISIRA YANG BUONG FILES MO
timezone: "Asia/Manila"
});