-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
258 lines (204 loc) · 8.85 KB
/
Copy pathmain.js
File metadata and controls
258 lines (204 loc) · 8.85 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
// 🧹 Fix for ENOSPC / temp overflow in hosted panels
const fs = require('fs');
const path = require('path');
// Redirect temp storage away from system /tmp
const customTemp = path.join(process.cwd(), 'temp');
if (!fs.existsSync(customTemp)) fs.mkdirSync(customTemp, { recursive: true });
process.env.TMPDIR = customTemp;
process.env.TEMP = customTemp;
process.env.TMP = customTemp;
// Auto-cleaner every 3 hours
setInterval(() => {
fs.readdir(customTemp, (err, files) => {
if (err) return;
for (const file of files) {
const filePath = path.join(customTemp, file);
fs.stat(filePath, (err, stats) => {
if (!err && Date.now() - stats.mtimeMs > 3 * 60 * 60 * 1000) {
fs.unlink(filePath, () => { });
}
});
}
});
console.log('🧹 Temp folder auto-cleaned');
}, 3 * 60 * 60 * 1000);
const settings = require('./settings');
require('./config.js');
const { isBanned } = require('./lib/isBanned');
const isOwnerOrSudo = require('./lib/isOwner');
const { isSudo } = require('./lib/index');
const {
autotypingCommand,
handleAutotypingForMessage,
showTypingAfterCommand
} = require('./commands/autotyping');
const { autoreadCommand, handleAutoread } = require('./commands/autoread');
// Commands
const tagAllCommand = require('./commands/tagall');
const helpCommand = require('./commands/help');
const banCommand = require('./commands/ban');
const { promoteCommand } = require('./commands/promote');
const { demoteCommand } = require('./commands/demote');
const muteCommand = require('./commands/mute');
const unmuteCommand = require('./commands/unmute');
const stickerCommand = require('./commands/sticker');
const warnCommand = require('./commands/warn');
const warningsCommand = require('./commands/warnings');
const ttsCommand = require('./commands/tts');
const { handleTicTacToeMove } = require('./commands/tictactoe');
const ownerCommand = require('./commands/owner');
const deleteCommand = require('./commands/delete');
const { handleAntilinkCommand } = require('./commands/antilink');
const { handleAntitagCommand } = require('./commands/antitag');
const memeCommand = require('./commands/meme');
const tagCommand = require('./commands/tag');
const tagNotAdminCommand = require('./commands/tagnotadmin');
const hideTagCommand = require('./commands/hidetag');
const jokeCommand = require('./commands/joke');
const quoteCommand = require('./commands/quote');
const factCommand = require('./commands/fact');
const weatherCommand = require('./commands/weather');
const newsCommand = require('./commands/news');
const kickCommand = require('./commands/kick');
const simageCommand = require('./commands/simage');
const attpCommand = require('./commands/attp');
const { startHangman, guessLetter } = require('./commands/hangman');
const { startTrivia, answerTrivia } = require('./commands/trivia');
const pingCommand = require('./commands/ping');
const aliveCommand = require('./commands/alive');
// ===================== MAIN HANDLER =====================
async function handleMessages(sock, messageUpdate) {
try {
const { messages, type } = messageUpdate;
if (type !== 'notify') return;
const message = messages[0];
if (!message?.message) return;
const chatId = message.key.remoteJid;
const senderId = message.key.participant || chatId;
const rawText =
message.message?.conversation ||
message.message?.extendedTextMessage?.text ||
message.message?.imageMessage?.caption ||
'';
const userMessage = rawText.trim().toLowerCase();
// store typing / autoread
await handleAutoread(sock, message);
if (!userMessage.startsWith('.')) {
await handleAutotypingForMessage(sock, chatId, userMessage);
return;
}
// ================= COMMANDS =================
switch (true) {
case userMessage === '.ping':
await pingCommand(sock, chatId, message);
break;
case userMessage === '.menu':
await helpCommand(sock, chatId, message);
break;
case userMessage.startsWith('.kick'):
await kickCommand(sock, chatId, senderId, message);
break;
case userMessage.startsWith('.mute'):
await muteCommand(sock, chatId, senderId, message);
break;
case userMessage === '.unmute':
await unmuteCommand(sock, chatId, senderId);
break;
case userMessage.startsWith('.ban'):
await banCommand(sock, chatId, message);
break;
case userMessage.startsWith('.unban'):
const unbanCommand = require('./commands/unban');
await unbanCommand(sock, chatId, message);
break;
case userMessage.startsWith('.tagall'):
await tagAllCommand(sock, chatId, senderId, message);
break;
case userMessage.startsWith('.sticker'):
await stickerCommand(sock, chatId, message);
break;
case userMessage.startsWith('.warn'):
await warnCommand(sock, chatId, senderId, message);
break;
case userMessage.startsWith('.warnings'):
await warningsCommand(sock, chatId, message);
break;
case userMessage.startsWith('.tts'):
await ttsCommand(sock, chatId, rawText.slice(4));
break;
case userMessage.startsWith('.simage'):
await simageCommand(sock, message, chatId);
break;
case userMessage.startsWith('.attp'):
await attpCommand(sock, chatId, message);
break;
case userMessage === '.owner':
await ownerCommand(sock, chatId);
break;
case userMessage.startsWith('.delete'):
await deleteCommand(sock, chatId, message, senderId);
break;
case userMessage.startsWith('.tag'):
await tagCommand(sock, chatId, senderId, rawText, message);
break;
case userMessage.startsWith('.hidetag'):
await hideTagCommand(sock, chatId, senderId, rawText, message);
break;
case userMessage.startsWith('.menu') || userMessage === '.help':
await helpCommand(sock, chatId, message);
break;
case userMessage.startsWith('.joke'):
await jokeCommand(sock, chatId, message);
break;
case userMessage.startsWith('.quote'):
await quoteCommand(sock, chatId, message);
break;
case userMessage.startsWith('.fact'):
await factCommand(sock, chatId, message);
break;
case userMessage.startsWith('.weather'):
await weatherCommand(sock, chatId, message, rawText);
break;
case userMessage.startsWith('.news'):
await newsCommand(sock, chatId);
break;
case userMessage.startsWith('.tictactoe'):
await handleTicTacToeMove(sock, chatId, senderId, rawText);
break;
case userMessage.startsWith('.guess'):
await guessLetter(sock, chatId, rawText.split(' ')[1]);
break;
case userMessage.startsWith('.hangman'):
await startHangman(sock, chatId);
break;
case userMessage.startsWith('.trivia'):
await startTrivia(sock, chatId);
break;
case userMessage.startsWith('.answer'):
await answerTrivia(sock, chatId, rawText);
break;
case userMessage.startsWith('.simp'):
const simpCommand = require('./commands/simp');
await simpCommand(sock, chatId, message);
break;
case userMessage.startsWith('.stupid'):
const stupidCommand = require('./commands/stupid');
await stupidCommand(sock, chatId, message);
break;
case userMessage.startsWith('.removebg'):
const removebgCommand = require('./commands/removebg');
await removebgCommand(sock, chatId, message);
break;
case userMessage.startsWith('.play'):
const playCommand = require('./commands/play');
await playCommand(sock, chatId, message);
break;
default:
break;
}
await showTypingAfterCommand(sock, chatId);
} catch (err) {
console.log('Error:', err);
}
}
module.exports = { handleMessages };