bot-mwsm 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/Mwsm.yml +188 -0
- package/.github/workflows/publish.yml +62 -0
- package/LICENSE +21 -0
- package/README.md +204 -0
- package/bash/mwsm.sh +1060 -0
- package/bash/setup.sh +173 -0
- package/docs/pix.html +146 -0
- package/fonts/OpenSans-Regular-webfont.html +0 -0
- package/fonts/css/font-awesome.min.css +4 -0
- package/fonts/fontawesome-webfont (1).eot +0 -0
- package/fonts/fontawesome-webfont.eot +0 -0
- package/fonts/fontawesome-webfont.ttf +0 -0
- package/fonts/fontawesome-webfont.woff +0 -0
- package/fonts/fontawesome-webfont.woff2 +0 -0
- package/fonts/fonts/fontawesome-webfont3e6e-2.html +0 -0
- package/fonts/fonts/fontawesome-webfont3e6e.eot +0 -0
- package/fonts/fonts/fontawesome-webfont3e6e.html +0 -0
- package/fonts/fonts/fontawesome-webfont3e6e.svg +2671 -0
- package/fonts/fonts/fontawesome-webfont3e6e.woff +0 -0
- package/fonts/fonts/fontawesome-webfontd41d.eot +0 -0
- package/fonts/glyphicons-halflings-regular.eot +0 -0
- package/fonts/glyphicons-halflings-regular.html +0 -0
- package/fonts/glyphicons-halflings-regular.svg +288 -0
- package/fonts/glyphicons-halflings-regular.woff +0 -0
- package/fonts/glyphicons-halflings-regulard41d.eot +0 -0
- package/fonts/texgyreadventor-regular-webfont.html +0 -0
- package/icon.png +0 -0
- package/img/Mwsm.png +0 -0
- package/img/auth.png +0 -0
- package/img/autobot.png +0 -0
- package/img/autupdate.png +0 -0
- package/img/cli.png +0 -0
- package/img/cronshed.png +0 -0
- package/img/debug.log +0 -0
- package/img/debug.png +0 -0
- package/img/delay.png +0 -0
- package/img/dev.png +0 -0
- package/img/endpoint.png +0 -0
- package/img/find.png +0 -0
- package/img/log.png +0 -0
- package/img/mkauth.png +0 -0
- package/img/msn.png +0 -0
- package/img/paycon.png +0 -0
- package/img/prevent.png +0 -0
- package/img/resent.png +0 -0
- package/img/reset.png +0 -0
- package/img/resync.png +0 -0
- package/img/settings.png +0 -0
- package/img/shifts.png +0 -0
- package/img/spam.png +0 -0
- package/img/spam2.png +0 -0
- package/img/status.png +0 -0
- package/img/status2.png +0 -0
- package/img/stop.png +0 -0
- package/img/success.png +0 -0
- package/img/sync.png +0 -0
- package/img/terminal.png +0 -0
- package/img/timers.png +0 -0
- package/img/uid.png +0 -0
- package/img/update.png +0 -0
- package/img/whatsapp.png +0 -0
- package/index.html +1543 -0
- package/jquery.js +2 -0
- package/mwsm.db +0 -0
- package/mwsm.js +4979 -0
- package/mwsm.json +25 -0
- package/mwsm.py +91 -0
- package/nodemon.json +3 -0
- package/package.json +62 -0
- package/script.js +24815 -0
- package/socket.io.js +9 -0
- package/style.css +8744 -0
- package/version.json +8 -0
package/mwsm.js
ADDED
|
@@ -0,0 +1,4979 @@
|
|
|
1
|
+
//******************************************************************
|
|
2
|
+
// MkAuth WhatsApp Send Message
|
|
3
|
+
//******************************************************************
|
|
4
|
+
const Playground = "00000000000";
|
|
5
|
+
const Initialize = false;
|
|
6
|
+
const {
|
|
7
|
+
Client,
|
|
8
|
+
LocalAuth,
|
|
9
|
+
Buttons,
|
|
10
|
+
List,
|
|
11
|
+
MessageMedia
|
|
12
|
+
} = require('whatsapp-web.js');
|
|
13
|
+
const express = require('express');
|
|
14
|
+
const {
|
|
15
|
+
body,
|
|
16
|
+
validationResult
|
|
17
|
+
} = require('express-validator');
|
|
18
|
+
var Delay, Wait, Reboot, Sending, Permission = false,
|
|
19
|
+
wwjsRun = true;
|
|
20
|
+
MsgBox = false,
|
|
21
|
+
Session = false;
|
|
22
|
+
const activeSupportIA = new Map();
|
|
23
|
+
const activeMenus = new Map();
|
|
24
|
+
const socketIO = require('socket.io');
|
|
25
|
+
const qrcode = require('qrcode');
|
|
26
|
+
const http = require('http');
|
|
27
|
+
const https = require('https');
|
|
28
|
+
const fileUpload = require('express-fileupload');
|
|
29
|
+
const axios = require('axios');
|
|
30
|
+
const mime = require('mime-types');
|
|
31
|
+
const app = express();
|
|
32
|
+
const os = require("os");
|
|
33
|
+
const hostName = os.hostname();
|
|
34
|
+
const emoji = require('Emoji-API');
|
|
35
|
+
const server = http.createServer(app);
|
|
36
|
+
const io = socketIO(server);
|
|
37
|
+
const sys = require('util');
|
|
38
|
+
const fs = require("fs");
|
|
39
|
+
const ip = require('ip');
|
|
40
|
+
const Url2PDF = require("Url2PDF");
|
|
41
|
+
const cron = require('node-cron');
|
|
42
|
+
const htmlPDF = new Url2PDF();
|
|
43
|
+
const exec = require('child_process').exec;
|
|
44
|
+
const {
|
|
45
|
+
execSync
|
|
46
|
+
} = require("child_process");
|
|
47
|
+
const link = require('better-sqlite3')('mwsm.db');
|
|
48
|
+
const sqlite3 = require('sqlite3').verbose();
|
|
49
|
+
const db = new sqlite3.Database('mwsm.db');
|
|
50
|
+
const register = new Date().getDate();
|
|
51
|
+
const Package = require('./package.json');
|
|
52
|
+
require('events').EventEmitter.defaultMaxListeners = Infinity;
|
|
53
|
+
const WServer = "https://raw.githubusercontent.com/MKCodec/Mwsm/main/version.json";
|
|
54
|
+
const crypto = require('crypto');
|
|
55
|
+
const Keygen = (length = 7, characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') => Array.from(crypto.randomFillSync(new Uint32Array(length))).map((x) => characters[x % characters.length]).join('');
|
|
56
|
+
var Password = [Debug('OPTIONS').token, Keygen()];
|
|
57
|
+
process.env.LANG = "pt-BR.utf8";
|
|
58
|
+
global.io = io;
|
|
59
|
+
const Print = {
|
|
60
|
+
reset: "\x1b[0m",
|
|
61
|
+
bright: "\x1b[1m",
|
|
62
|
+
dim: "\x1b[2m",
|
|
63
|
+
underscore: "\x1b[4m",
|
|
64
|
+
blink: "\x1b[5m",
|
|
65
|
+
reverse: "\x1b[7m",
|
|
66
|
+
hidden: "\x1b[8m",
|
|
67
|
+
fg: {
|
|
68
|
+
black: "\x1b[30m",
|
|
69
|
+
red: "\x1b[31m",
|
|
70
|
+
green: "\x1b[32m",
|
|
71
|
+
yellow: "\x1b[33m",
|
|
72
|
+
blue: "\x1b[34m",
|
|
73
|
+
magenta: "\x1b[35m",
|
|
74
|
+
cyan: "\x1b[36m",
|
|
75
|
+
white: "\x1b[37m",
|
|
76
|
+
gray: "\x1b[90m",
|
|
77
|
+
crimson: "\x1b[38m" // Scarlet
|
|
78
|
+
},
|
|
79
|
+
bg: {
|
|
80
|
+
black: "\x1b[40m",
|
|
81
|
+
red: "\x1b[41m",
|
|
82
|
+
green: "\x1b[42m",
|
|
83
|
+
yellow: "\x1b[43m",
|
|
84
|
+
blue: "\x1b[44m",
|
|
85
|
+
magenta: "\x1b[45m",
|
|
86
|
+
cyan: "\x1b[46m",
|
|
87
|
+
white: "\x1b[47m",
|
|
88
|
+
gray: "\x1b[100m",
|
|
89
|
+
crimson: "\x1b[48m"
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
//Delay
|
|
94
|
+
function delay(t, v) {
|
|
95
|
+
return new Promise(function(resolve) {
|
|
96
|
+
setTimeout(resolve.bind(null, v), t)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//Capitalize
|
|
101
|
+
function toCapitalize(str) {
|
|
102
|
+
return str
|
|
103
|
+
.toLowerCase()
|
|
104
|
+
.split(' ')
|
|
105
|
+
.map(word => word.charAt(0).toUpperCase() + word.substr(1))
|
|
106
|
+
.join(' ');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//Search DataBase
|
|
110
|
+
function Debug(Select, Search = '*', Mode = 'single', Find = undefined) {
|
|
111
|
+
switch (Mode.toLowerCase()) {
|
|
112
|
+
case "single":
|
|
113
|
+
Select = link.prepare('SELECT ' + Search.toLowerCase() + ' FROM ' + Select.toLowerCase() + ' ORDER BY ID DESC').get();
|
|
114
|
+
if (!Select) {
|
|
115
|
+
Select = false;
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
case "multiple":
|
|
119
|
+
Select = link.prepare('SELECT ' + Search.toLowerCase() + ' FROM ' + Select.toLowerCase()).pluck().all();
|
|
120
|
+
if (!Select) {
|
|
121
|
+
Select = false;
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
case "all":
|
|
125
|
+
Select = link.prepare('SELECT ' + Search.toLowerCase() + ' FROM ' + Select.toLowerCase() + ' ORDER BY ID DESC').all();
|
|
126
|
+
if (!Select) {
|
|
127
|
+
Select = false;
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
case "direct":
|
|
131
|
+
Select = link.prepare('SELECT ' + Search.toLowerCase() + ' FROM ' + Select.toLowerCase() + ' WHERE title = ?').get(Find);
|
|
132
|
+
if (!Select) {
|
|
133
|
+
Select = false;
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case "id":
|
|
137
|
+
Select = link.prepare('SELECT ' + Search.toLowerCase() + ' FROM ' + Select.toLowerCase() + ' WHERE id = ?').get(Find);
|
|
138
|
+
if (!Select) {
|
|
139
|
+
Select = false;
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
return Select;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function DebugMsg(Selector) {
|
|
147
|
+
var Last = Debug('MKAUTH').count,
|
|
148
|
+
Return, Mode = Debug('MKAUTH').level,
|
|
149
|
+
Message;
|
|
150
|
+
switch (Mode.toLowerCase()) {
|
|
151
|
+
case "direct":
|
|
152
|
+
Return = 1;
|
|
153
|
+
break;
|
|
154
|
+
case "random":
|
|
155
|
+
Return = Math.floor(Math.random() * (3 - 1 + 1) + 1);
|
|
156
|
+
break;
|
|
157
|
+
case "order":
|
|
158
|
+
switch (Last) {
|
|
159
|
+
case 1:
|
|
160
|
+
Return = 2;
|
|
161
|
+
break;
|
|
162
|
+
case 2:
|
|
163
|
+
Return = 3;
|
|
164
|
+
break;
|
|
165
|
+
case 3:
|
|
166
|
+
Return = 1;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
switch (Selector.toLowerCase()) {
|
|
172
|
+
case "before":
|
|
173
|
+
Message = Debug('MESSAGE', '*', 'ID', '' + Return + '').before;
|
|
174
|
+
break;
|
|
175
|
+
|
|
176
|
+
case "day":
|
|
177
|
+
Message = Debug('MESSAGE', '*', 'ID', '' + Return + '').day;
|
|
178
|
+
break;
|
|
179
|
+
|
|
180
|
+
case "later":
|
|
181
|
+
Message = Debug('MESSAGE', '*', 'ID', '' + Return + '').later;
|
|
182
|
+
break;
|
|
183
|
+
|
|
184
|
+
case "pay":
|
|
185
|
+
Message = Debug('MESSAGE', '*', 'ID', '' + Return + '').pay;
|
|
186
|
+
break;
|
|
187
|
+
|
|
188
|
+
case "lock":
|
|
189
|
+
Message = Debug('MESSAGE', '*', 'ID', '' + Return + '').lock;
|
|
190
|
+
break;
|
|
191
|
+
|
|
192
|
+
case "unlock":
|
|
193
|
+
Message = Debug('MESSAGE', '*', 'ID', '' + Return + '').unlock;
|
|
194
|
+
break;
|
|
195
|
+
|
|
196
|
+
case "maintenance":
|
|
197
|
+
Message = Debug('MESSAGE', '*', 'ID', '' + Return + '').maintenance;
|
|
198
|
+
break;
|
|
199
|
+
|
|
200
|
+
case "unistall":
|
|
201
|
+
Message = Debug('MESSAGE', '*', 'ID', '' + Return + '').unistall;
|
|
202
|
+
break;
|
|
203
|
+
|
|
204
|
+
case "speed":
|
|
205
|
+
Message = Debug('MESSAGE', '*', 'ID', '' + Return + '').speed;
|
|
206
|
+
break;
|
|
207
|
+
|
|
208
|
+
case "block":
|
|
209
|
+
Message = Debug('MESSAGE', '*', 'ID', '' + Return + '').block;
|
|
210
|
+
break;
|
|
211
|
+
|
|
212
|
+
case "support":
|
|
213
|
+
Message = Debug('MESSAGE', '*', 'ID', '' + Return + '').support;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
Dataset('MKAUTH', 'COUNT', Return, 'UPDATE');
|
|
217
|
+
return Message;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
//RegEx
|
|
221
|
+
function validPhone(phone) {
|
|
222
|
+
var regex = new RegExp('^((1[1-9])|([2-9][0-9]))((3[0-9]{3}[0-9]{4})|(9[0-9]{3}[0-9]{5}))$');
|
|
223
|
+
if (Boolean(Debug('OPTIONS').regex)) {
|
|
224
|
+
return regex.test(phone.replace('55', ''));
|
|
225
|
+
} else {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function PromiseTimeout(delayms) {
|
|
231
|
+
return new Promise(function(resolve, reject) {
|
|
232
|
+
setTimeout(resolve, delayms);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
//Manipulation DataBase
|
|
237
|
+
const Dataset = async (Table, Column, Value, Mode) => {
|
|
238
|
+
switch (Mode.toLowerCase()) {
|
|
239
|
+
case "update":
|
|
240
|
+
Select = await link.prepare('UPDATE ' + Table.toLowerCase() + ' SET ' + Column.toLowerCase() + ' = ? WHERE id = ?').run(Value, '1');
|
|
241
|
+
if (Select) {
|
|
242
|
+
Select = true;
|
|
243
|
+
} else {
|
|
244
|
+
Select = false;
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
case "insert":
|
|
248
|
+
Select = await link.prepare('INSERT INTO ' + Table.toLowerCase() + ' (' + Column.toLowerCase() + ') VALUES (?)').run(Value);
|
|
249
|
+
if (Select) {
|
|
250
|
+
Select = link.prepare('SELECT * FROM ' + Table.toLowerCase() + ' ORDER BY ID DESC').get().id;
|
|
251
|
+
} else {
|
|
252
|
+
Select = false
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
case "delete":
|
|
256
|
+
Select = await link.prepare('DELETE FROM ' + Table.toLowerCase() + ' WHERE id = ?').run(Value);
|
|
257
|
+
if (Select) {
|
|
258
|
+
Select = true;
|
|
259
|
+
} else {
|
|
260
|
+
Select = false;
|
|
261
|
+
}
|
|
262
|
+
break;
|
|
263
|
+
case "flush":
|
|
264
|
+
const Flush = (link.prepare('SELECT * FROM ' + Value.toLowerCase()).all()).length;
|
|
265
|
+
Select = await link.prepare('UPDATE ' + Table.toLowerCase() + ' SET ' + Column.toLowerCase() + ' = ? WHERE NAME = ?').run(Flush.toString(), Value.toLowerCase());
|
|
266
|
+
if (Select) {
|
|
267
|
+
Select = true;
|
|
268
|
+
} else {
|
|
269
|
+
Select = false;
|
|
270
|
+
}
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
return await Select;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
const isEmoji = (Value) => {
|
|
278
|
+
if (true) {
|
|
279
|
+
if (typeof Value === 'string') {
|
|
280
|
+
return emoji.emojify(Value);
|
|
281
|
+
} else {
|
|
282
|
+
return Value;
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
return Value;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
//Boolean Validation
|
|
290
|
+
const Boolean = function(str) {
|
|
291
|
+
if (str == null) {
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
if (typeof str === 'boolean') {
|
|
295
|
+
if (str === true) {
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
if (typeof str === 'string') {
|
|
301
|
+
if (str == "") {
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
str = str.replace(/^\s+|\s+$/g, '');
|
|
305
|
+
if (str.toLowerCase() == 'true' || str.toLowerCase() == 'yes') {
|
|
306
|
+
return true;
|
|
307
|
+
} else if (str.toLowerCase() == 'false' || str.toLowerCase() == 'not') {
|
|
308
|
+
return false;
|
|
309
|
+
} else {
|
|
310
|
+
return undefined;
|
|
311
|
+
}
|
|
312
|
+
str = str.replace(/,/g, '.');
|
|
313
|
+
str = str.replace(/^\s*\-\s*/g, '-');
|
|
314
|
+
}
|
|
315
|
+
if (!isNaN(str)) {
|
|
316
|
+
if (parseFloat(str)) {
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
return undefined;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
//ForEach Async Mode
|
|
325
|
+
Array.prototype.someAsync = function(callbackfn) {
|
|
326
|
+
return new Promise(async (resolve, reject) => {
|
|
327
|
+
await Promise.all(this.map(async item => {
|
|
328
|
+
if (await callbackfn(item)) resolve(true)
|
|
329
|
+
})).catch(reject)
|
|
330
|
+
resolve(false)
|
|
331
|
+
})
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function wget(url, dest) {
|
|
335
|
+
return new Promise((res) => {
|
|
336
|
+
https.get(url, (response) => {
|
|
337
|
+
if (response.statusCode == 302) {
|
|
338
|
+
wget(String(response.headers.location), dest);
|
|
339
|
+
} else {
|
|
340
|
+
const file = fs.createWriteStream(dest);
|
|
341
|
+
response.pipe(file);
|
|
342
|
+
file.on("finish", function() {
|
|
343
|
+
file.close();
|
|
344
|
+
res();
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function ArrayPosition(...criteria) {
|
|
352
|
+
return (a, b) => {
|
|
353
|
+
for (let i = 0; i < criteria.length; i++) {
|
|
354
|
+
const curCriteriaComparatorValue = criteria[i](a, b)
|
|
355
|
+
if (curCriteriaComparatorValue !== 0) {
|
|
356
|
+
return curCriteriaComparatorValue
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return 0
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const GetUpdate = async (GET, SET, GUPForce = false) => {
|
|
364
|
+
var Status, Conclusion = true,
|
|
365
|
+
Updated, Response,
|
|
366
|
+
isDateTime = Debug('RELEASE').mwsm;
|
|
367
|
+
const Upgrade = async (GET) => {
|
|
368
|
+
const Update = await fetch(GET).then(response => {
|
|
369
|
+
return response.json();
|
|
370
|
+
}).catch(err => {
|
|
371
|
+
return {
|
|
372
|
+
version: [{
|
|
373
|
+
release: '0.0.0',
|
|
374
|
+
patch: '0000-00-00 00:00:00'
|
|
375
|
+
}]
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
return Update;
|
|
379
|
+
};
|
|
380
|
+
const isUpdate = await Upgrade(GET);
|
|
381
|
+
const Nowdate = await Upgrade("http://" + ip.address() + ":" + Debug('OPTIONS').access + "/version.json");
|
|
382
|
+
if (isDateTime == "undefined" || isDateTime == null) {
|
|
383
|
+
isDateTime = "0000-00-00 00:00:00";
|
|
384
|
+
}
|
|
385
|
+
if ((isUpdate['version'][0].patch == Nowdate['version'][0].patch) && !SET) {
|
|
386
|
+
Status = false;
|
|
387
|
+
if (Conclusion) {
|
|
388
|
+
Conclusion = false;
|
|
389
|
+
if ((Debug('RELEASE').mwsm != Nowdate['version'][0].patch)) {
|
|
390
|
+
const Register = await Dataset('RELEASE', 'MWSM', (Nowdate['version'][0].patch), 'UPDATE');
|
|
391
|
+
if (Register) {
|
|
392
|
+
await global.io.emit('Patched', Release(Debug('RELEASE').mwsm));
|
|
393
|
+
await global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isalready);
|
|
394
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isalready);
|
|
395
|
+
await global.io.emit('update', true);
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
await global.io.emit('Patched', Release(Debug('RELEASE').mwsm));
|
|
399
|
+
await global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isalready);
|
|
400
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isalready);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
Updated = "false";
|
|
404
|
+
await global.io.emit('upgrade', true);
|
|
405
|
+
await WwjsVersion(false);
|
|
406
|
+
} else {
|
|
407
|
+
if ((isUpdate['version'][0].release > Package.version)) {
|
|
408
|
+
if (!SET) {
|
|
409
|
+
await global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isneeds);
|
|
410
|
+
await console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isneeds);
|
|
411
|
+
WwjsVersion(false);
|
|
412
|
+
}
|
|
413
|
+
Updated = "false";
|
|
414
|
+
await global.io.emit('upgrade', false);
|
|
415
|
+
} else {
|
|
416
|
+
if ((isUpdate['version'][0].patch > isDateTime)) {
|
|
417
|
+
await global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isfound);
|
|
418
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isfound);
|
|
419
|
+
await global.io.emit('upgrade', false);
|
|
420
|
+
if (SET && (Boolean(Debug('RELEASE').isupdate) || Boolean(GUPForce))) {
|
|
421
|
+
const Register = await Dataset('RELEASE', 'MWSM', (isUpdate['version'][0].patch), 'UPDATE');
|
|
422
|
+
if (Register) {
|
|
423
|
+
await global.io.emit('Patched', Release(Debug('RELEASE').mwsm));
|
|
424
|
+
await global.io.emit('upgrade', true);
|
|
425
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isupfiles);
|
|
426
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isupdated);
|
|
427
|
+
await global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isupdated);
|
|
428
|
+
await wget("https://raw.githubusercontent.com/MKCodec/Mwsm/main/script.js", "/var/api/Mwsm/script.js");
|
|
429
|
+
await wget("https://raw.githubusercontent.com/MKCodec/Mwsm/main/style.css", "/var/api/Mwsm/style.css");
|
|
430
|
+
await wget("https://raw.githubusercontent.com/MKCodec/Mwsm/main/index.html", "/var/api/Mwsm/index.html");
|
|
431
|
+
await wget("https://raw.githubusercontent.com/MKCodec/Mwsm/main/mwsm.js", "/var/api/Mwsm/mwsm.js");
|
|
432
|
+
await global.io.emit('update', true);
|
|
433
|
+
await exec('npm run restart:mwsm');
|
|
434
|
+
WwjsVersion(true);
|
|
435
|
+
Updated = "true";
|
|
436
|
+
} else {
|
|
437
|
+
Updated = "false";
|
|
438
|
+
await global.io.emit('upgrade', false);
|
|
439
|
+
}
|
|
440
|
+
Status = true;
|
|
441
|
+
} else if (Conclusion) {
|
|
442
|
+
Conclusion = false;
|
|
443
|
+
Status = true;
|
|
444
|
+
if (!SET) {
|
|
445
|
+
await global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isneeds);
|
|
446
|
+
await console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isneeds);
|
|
447
|
+
}
|
|
448
|
+
await global.io.emit('upgrade', false);
|
|
449
|
+
Updated = "false";
|
|
450
|
+
}
|
|
451
|
+
} else if (Conclusion) {
|
|
452
|
+
Conclusion = false;
|
|
453
|
+
Status = false;
|
|
454
|
+
if (!SET) {
|
|
455
|
+
await global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isalready);
|
|
456
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').isalready);
|
|
457
|
+
}
|
|
458
|
+
await global.io.emit('upgrade', true);
|
|
459
|
+
Updated = "false";
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
Response = {
|
|
464
|
+
"Status": Status,
|
|
465
|
+
"Update": Updated
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
return Response;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
//Set Debugger
|
|
472
|
+
function Terminal(Value) {
|
|
473
|
+
if (Boolean(Debug('OPTIONS').debugger)) {
|
|
474
|
+
console.error(Value);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
//Get Release
|
|
479
|
+
function Release(Value) {
|
|
480
|
+
return (new Date(Value).toLocaleString("pt-br").split(",")[0]) + " " + ((Value).split(" ")[1]).split(":")[0] + ":" + ((Value).split(" ")[1]).split(":")[1]
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
const SetSchedule = async (ShedForce = false) => {
|
|
485
|
+
if (Boolean(Debug('MKAUTH').module) && (Boolean(Debug('MKAUTH').aimbot) || Boolean(ShedForce))) {
|
|
486
|
+
var Register, Insert, hasDays = [],
|
|
487
|
+
Option, Index = 0,
|
|
488
|
+
Count = 0,
|
|
489
|
+
hasReady = [],
|
|
490
|
+
isSHED = [],
|
|
491
|
+
ShedReload = true;
|
|
492
|
+
const Month = ((DateTime()).split(" ")[0]).split("-")[1];
|
|
493
|
+
const Windows = await MkAuth(Month, "all", 'list');
|
|
494
|
+
if (Boolean(Debug('SCHEDULER').bfive)) {
|
|
495
|
+
Option = undefined;
|
|
496
|
+
GetDays = {
|
|
497
|
+
"Mode": "Later",
|
|
498
|
+
"Set": 5,
|
|
499
|
+
"Option": Option
|
|
500
|
+
};
|
|
501
|
+
hasDays.push(GetDays);
|
|
502
|
+
}
|
|
503
|
+
if (Boolean(Debug('SCHEDULER').inday)) {
|
|
504
|
+
Option = undefined;
|
|
505
|
+
GetDays = {
|
|
506
|
+
"Mode": "Now",
|
|
507
|
+
"Set": 0,
|
|
508
|
+
"Option": Option
|
|
509
|
+
};
|
|
510
|
+
hasDays.push(GetDays);
|
|
511
|
+
}
|
|
512
|
+
if (Boolean(Debug('SCHEDULER').lfive) || (Debug('SCHEDULER').speed == 5)) {
|
|
513
|
+
Option = undefined;
|
|
514
|
+
if (Boolean(Debug('SCHEDULER').onspeed) && (Debug('SCHEDULER').speed == 5)) {
|
|
515
|
+
Option = "speed";
|
|
516
|
+
}
|
|
517
|
+
GetDays = {
|
|
518
|
+
"Mode": "Before",
|
|
519
|
+
"Set": 5,
|
|
520
|
+
"Option": Option
|
|
521
|
+
};
|
|
522
|
+
hasDays.push(GetDays);
|
|
523
|
+
}
|
|
524
|
+
if (Boolean(Debug('SCHEDULER').lten) || (Debug('SCHEDULER').speed == 10)) {
|
|
525
|
+
Option = undefined;
|
|
526
|
+
if (Boolean(Debug('SCHEDULER').onspeed) && (Debug('SCHEDULER').speed == 10)) {
|
|
527
|
+
Option = "speed";
|
|
528
|
+
}
|
|
529
|
+
GetDays = {
|
|
530
|
+
"Mode": "Before",
|
|
531
|
+
"Set": 10,
|
|
532
|
+
"Option": Option
|
|
533
|
+
};
|
|
534
|
+
hasDays.push(GetDays);
|
|
535
|
+
}
|
|
536
|
+
if (Boolean(Debug('SCHEDULER').lfifteen) || (Debug('SCHEDULER').speed == 15)) {
|
|
537
|
+
Option = undefined;
|
|
538
|
+
if (Boolean(Debug('SCHEDULER').onspeed) && (Debug('SCHEDULER').speed == 15)) {
|
|
539
|
+
Option = "speed";
|
|
540
|
+
}
|
|
541
|
+
GetDays = {
|
|
542
|
+
"Mode": "Before",
|
|
543
|
+
"Set": 15,
|
|
544
|
+
"Option": Option
|
|
545
|
+
};
|
|
546
|
+
hasDays.push(GetDays);
|
|
547
|
+
}
|
|
548
|
+
if (Boolean(Debug('SCHEDULER').ltwenty) || (Debug('SCHEDULER').speed == 20)) {
|
|
549
|
+
Option = undefined;
|
|
550
|
+
if (Boolean(Debug('SCHEDULER').onspeed) && (Debug('SCHEDULER').speed == 20)) {
|
|
551
|
+
Option = "speed";
|
|
552
|
+
}
|
|
553
|
+
GetDays = {
|
|
554
|
+
"Mode": "Before",
|
|
555
|
+
"Set": 20,
|
|
556
|
+
"Option": Option
|
|
557
|
+
};
|
|
558
|
+
hasDays.push(GetDays);
|
|
559
|
+
}
|
|
560
|
+
if (Boolean(Debug('SCHEDULER').ltwentyfive) || (Debug('SCHEDULER').speed == 25)) {
|
|
561
|
+
Option = undefined;
|
|
562
|
+
if (Boolean(Debug('SCHEDULER').onspeed) && (Debug('SCHEDULER').speed == 25)) {
|
|
563
|
+
Option = "speed";
|
|
564
|
+
}
|
|
565
|
+
GetDays = {
|
|
566
|
+
"Mode": "Before",
|
|
567
|
+
"Set": 25,
|
|
568
|
+
"Option": Option
|
|
569
|
+
};
|
|
570
|
+
hasDays.push(GetDays);
|
|
571
|
+
|
|
572
|
+
}
|
|
573
|
+
if (Boolean(Debug('SCHEDULER').lthirty) || (Debug('SCHEDULER').speed == 30)) {
|
|
574
|
+
Option = undefined;
|
|
575
|
+
if (Boolean(Debug('SCHEDULER').onspeed) && (Debug('SCHEDULER').speed == 30)) {
|
|
576
|
+
Option = "speed";
|
|
577
|
+
}
|
|
578
|
+
GetDays = {
|
|
579
|
+
"Mode": "Before",
|
|
580
|
+
"Set": 30,
|
|
581
|
+
"Option": Option
|
|
582
|
+
};
|
|
583
|
+
hasDays.push(GetDays);
|
|
584
|
+
}
|
|
585
|
+
if (Boolean(Debug('SCHEDULER').lthirtyfive) || (Debug('SCHEDULER').speed == 35)) {
|
|
586
|
+
Option = undefined;
|
|
587
|
+
if (Boolean(Debug('SCHEDULER').onspeed) && (Debug('SCHEDULER').speed == 35)) {
|
|
588
|
+
Option = "speed";
|
|
589
|
+
}
|
|
590
|
+
GetDays = {
|
|
591
|
+
"Mode": "Before",
|
|
592
|
+
"Set": 35,
|
|
593
|
+
"Option": Option
|
|
594
|
+
};
|
|
595
|
+
hasDays.push(GetDays);
|
|
596
|
+
}
|
|
597
|
+
if (Boolean(Debug('SCHEDULER').lforty) || (Debug('SCHEDULER').speed == 40)) {
|
|
598
|
+
Option = undefined;
|
|
599
|
+
if (Boolean(Debug('SCHEDULER').onspeed) && (Debug('SCHEDULER').speed == 40)) {
|
|
600
|
+
Option = "speed";
|
|
601
|
+
}
|
|
602
|
+
GetDays = {
|
|
603
|
+
"Mode": "Before",
|
|
604
|
+
"Set": 40,
|
|
605
|
+
"Option": Option
|
|
606
|
+
};
|
|
607
|
+
hasDays.push(GetDays);
|
|
608
|
+
}
|
|
609
|
+
if (Boolean(Debug('SCHEDULER').onblock)) {
|
|
610
|
+
GetDays = {
|
|
611
|
+
"Mode": "Before",
|
|
612
|
+
"Set": Debug('SCHEDULER').block,
|
|
613
|
+
"Option": "Block"
|
|
614
|
+
};
|
|
615
|
+
hasDays.push(GetDays);
|
|
616
|
+
}
|
|
617
|
+
(hasDays).someAsync(async (Days) => {
|
|
618
|
+
const Master = await Scheduller(Days.Set, Days.Mode);
|
|
619
|
+
if (await Master) {
|
|
620
|
+
if (Master != undefined) {
|
|
621
|
+
(Master).someAsync(async (Send) => {
|
|
622
|
+
MsgSET = false;
|
|
623
|
+
if (Send.celular != undefined) {
|
|
624
|
+
Send.celular = (Send.celular).replace(/[^0-9\\.]+/g, '');
|
|
625
|
+
} else {
|
|
626
|
+
Send.celular = "00000000000";
|
|
627
|
+
}
|
|
628
|
+
if (Boolean(Debug('OPTIONS').regex)) {
|
|
629
|
+
switch (Boolean(validPhone(Send.celular))) {
|
|
630
|
+
case true:
|
|
631
|
+
WhatsApp = 'true';
|
|
632
|
+
break;
|
|
633
|
+
case false:
|
|
634
|
+
WhatsApp = 'false';
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
} else {
|
|
638
|
+
WhatsApp = 'true';
|
|
639
|
+
}
|
|
640
|
+
switch (Send.status) {
|
|
641
|
+
case 'aberto':
|
|
642
|
+
Send.status = 'open';
|
|
643
|
+
break;
|
|
644
|
+
case 'pago':
|
|
645
|
+
Send.status = 'paid';
|
|
646
|
+
break;
|
|
647
|
+
case 'vencido':
|
|
648
|
+
Send.status = 'due';
|
|
649
|
+
break;
|
|
650
|
+
case 'cancelado':
|
|
651
|
+
Send.status = 'cancel';
|
|
652
|
+
break;
|
|
653
|
+
}
|
|
654
|
+
switch (Send.bloqueado) {
|
|
655
|
+
case 'sim':
|
|
656
|
+
Send.bloqueado = 'false';
|
|
657
|
+
break;
|
|
658
|
+
case 'nao':
|
|
659
|
+
Send.bloqueado = 'true';
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
switch (Send.cli_ativado) {
|
|
664
|
+
case 's':
|
|
665
|
+
Send.cli_ativado = 'true';
|
|
666
|
+
break;
|
|
667
|
+
case 'n':
|
|
668
|
+
Send.cli_ativado = 'false';
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
switch (Send.zap) {
|
|
673
|
+
case 'sim':
|
|
674
|
+
Send.zap = 'true';
|
|
675
|
+
break;
|
|
676
|
+
case 'nao':
|
|
677
|
+
Send.zap = 'false';
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
if (((Send.datavenc).split(" ")[0]) == (DateTime()).split(" ")[0] && (Send.status) != 'paid' && (Send.status) != 'cancel') {
|
|
681
|
+
Send.status = 'open';
|
|
682
|
+
}
|
|
683
|
+
if (Boolean(Send.cli_ativado) && Send.status != 'paid' && Send.status != 'cancel' && Boolean(WhatsApp) && Boolean(Send.zap)) {
|
|
684
|
+
Index = Index + 1;
|
|
685
|
+
const Replies = await link.prepare('SELECT * FROM scheduling WHERE title=?').get(Send.titulo);
|
|
686
|
+
if (!Boolean(ShedForce)) {
|
|
687
|
+
GetSHED = {
|
|
688
|
+
"TITLE": Send.titulo,
|
|
689
|
+
"CLIENT": Send.nome,
|
|
690
|
+
"REWARD": Send.datavenc
|
|
691
|
+
};
|
|
692
|
+
isSHED.push(GetSHED);
|
|
693
|
+
await global.io.emit('shedullers', isSHED);
|
|
694
|
+
}
|
|
695
|
+
if (Replies == undefined) {
|
|
696
|
+
const ShedInsert = await link.prepare("INSERT INTO scheduling(title, user, client, contact, reward, status, range, control, option, unlock) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").run(Send.titulo, Send.login, Send.nome, Send.celular, Send.datavenc, Send.status, Days.Mode, Days.Set, Days.Option, Send.cli_ativado);
|
|
697
|
+
if (ShedInsert) {
|
|
698
|
+
MsgSET = true;
|
|
699
|
+
Hwid = {
|
|
700
|
+
"ID": Send.login
|
|
701
|
+
};
|
|
702
|
+
hasReady.push(Hwid);
|
|
703
|
+
}
|
|
704
|
+
} else {
|
|
705
|
+
const exUpdate = await link.prepare('SELECT * FROM scheduling WHERE title=? AND process=?').get(Send.titulo, "wait");
|
|
706
|
+
if (exUpdate == undefined || Option != exUpdate.option) {
|
|
707
|
+
const ShedUpdate = await link.prepare('UPDATE scheduling SET process=?, contact=?, option=?, control=?, unlock=? WHERE title=?').run("wait", Send.celular, Days.Option, Days.Set, Send.cli_ativado, Send.titulo);
|
|
708
|
+
if (ShedUpdate) {
|
|
709
|
+
MsgSET = true;
|
|
710
|
+
Hwid = {
|
|
711
|
+
"ID": Send.login
|
|
712
|
+
};
|
|
713
|
+
hasReady.push(Hwid);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
} else {
|
|
718
|
+
//Client Disable
|
|
719
|
+
}
|
|
720
|
+
if ((hasReady.length == Index) && MsgSET) {
|
|
721
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').schedule);
|
|
722
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').schedule);
|
|
723
|
+
MsgSET = false;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
if (await Windows) {
|
|
731
|
+
Register = (Windows).filter(function(Send) {
|
|
732
|
+
return Send.Payment != 'paid';
|
|
733
|
+
}).length;
|
|
734
|
+
if (!Boolean(ShedForce)) {
|
|
735
|
+
ShedReload = Debug('MKAUTH').backup;
|
|
736
|
+
}
|
|
737
|
+
if (Boolean(ShedReload) && Register >= 1) {
|
|
738
|
+
if (Windows != undefined) {
|
|
739
|
+
(Windows).someAsync(async (Bank) => {
|
|
740
|
+
if (Bank.Payment != "paid" && Boolean(Bank.Ready)) {
|
|
741
|
+
if (Bank.Contact == undefined) {
|
|
742
|
+
Bank.Contact = "00000000000";
|
|
743
|
+
}
|
|
744
|
+
if (Debug('SCHEDULING', 'TITLE', 'MULTIPLE').some(Row => (Bank.Identifier).includes(Row))) {
|
|
745
|
+
await link.prepare('UPDATE scheduling SET cash=?, gateway=?, unlock=? WHERE title=?').run(Bank.Cash, Bank.Gateway, Bank.unLock, Bank.Identifier);
|
|
746
|
+
} else {
|
|
747
|
+
await link.prepare('INSERT INTO scheduling(title,user,client,contact,reward,status,process,cash,gateway,unlock) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(Bank.Identifier, Bank.Connect, Bank.Client, Bank.Contact, Bank.Reward, Bank.Payment, 'load', Bank.Cash, Bank.Gateway, Bank.unLock);
|
|
748
|
+
}
|
|
749
|
+
} else {
|
|
750
|
+
(Debug('SCHEDULING', '*', 'ALL')).someAsync(async (Del) => {
|
|
751
|
+
if (Del.process == "success" && Del.status == "paid") {
|
|
752
|
+
await link.prepare('DELETE FROM scheduling WHERE title=?').run(Del.title);
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return true;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
const GetSchedule = async () => {
|
|
765
|
+
if (Boolean(Debug('MKAUTH').module) && Boolean(Debug('MKAUTH').aimbot)) {
|
|
766
|
+
var Check = 0,
|
|
767
|
+
IsPaid = 0,
|
|
768
|
+
isLock = 0,
|
|
769
|
+
isUnLock = 0,
|
|
770
|
+
isDue = 0;
|
|
771
|
+
const DataBase = await Debug('SCHEDULING', 'TITLE', 'MULTIPLE');
|
|
772
|
+
if (await DataBase.length >= 1) {
|
|
773
|
+
if (DataBase != undefined) {
|
|
774
|
+
(await DataBase).someAsync(async (Target) => {
|
|
775
|
+
var Check = 0,
|
|
776
|
+
IsPaid = 0;
|
|
777
|
+
const Local = await link.prepare('SELECT * FROM scheduling WHERE title=?').get(Target);
|
|
778
|
+
const Rebase = await MkAuth('all', Target, 'list');
|
|
779
|
+
if (Rebase != undefined && Rebase.Status == undefined) {
|
|
780
|
+
const Bank = await Object.assign({}, Rebase)[0];
|
|
781
|
+
|
|
782
|
+
Check = await (Object.values(Rebase)).filter(function(Send) {
|
|
783
|
+
if (Send.unLock != Local.unlock && Boolean(Send.Ready)) {
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
}).length;
|
|
787
|
+
|
|
788
|
+
IsPaid = await (Object.values(Rebase)).filter(function(Send) {
|
|
789
|
+
if (Send.Payment != Local.status && Boolean(Send.Ready)) {
|
|
790
|
+
return true;
|
|
791
|
+
}
|
|
792
|
+
}).length;
|
|
793
|
+
|
|
794
|
+
if (IsPaid >= 1 && Local.process != "success" && Bank.Payment == "paid") {
|
|
795
|
+
await link.prepare('UPDATE scheduling SET status=?, cash=?, gateway=?, unlock=? WHERE title=?').run(Bank.Payment, Bank.Cash, Bank.Gateway, Bank.unLock, Target);
|
|
796
|
+
} else if (Check >= 1 && Local.process != "wait" && Local.process != "success") {
|
|
797
|
+
if (Bank.unLock == 'false' && Local.process != "unlock") {
|
|
798
|
+
await link.prepare('UPDATE scheduling SET process=?, unlock=? WHERE title=?').run('lock', 'false', Target);
|
|
799
|
+
} else if (Bank.unLock == 'true') {
|
|
800
|
+
await link.prepare('UPDATE scheduling SET process=?, unlock=? WHERE title=?').run('unlock', 'true', Target);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
} else {
|
|
804
|
+
await link.prepare('DELETE FROM scheduling WHERE title=?').run(Target);
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
const Search = await link.prepare('SELECT * FROM scheduling').all();
|
|
809
|
+
if (await Search) {
|
|
810
|
+
if (Search != undefined) {
|
|
811
|
+
isPaid = await (Object.values(Search)).filter(function(Send) {
|
|
812
|
+
if (Send.process != "success" && Send.status == "paid") {
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
}).length;
|
|
816
|
+
|
|
817
|
+
isLock = await (Object.values(Search)).filter(function(Send) {
|
|
818
|
+
if (Send.process == "lock" && Send.unlock == "false" && Send.status == "due") {
|
|
819
|
+
return true;
|
|
820
|
+
}
|
|
821
|
+
}).length;
|
|
822
|
+
|
|
823
|
+
isUnLock = await (Object.values(Search)).filter(function(Send) {
|
|
824
|
+
if (Send.process == "unlock" && Send.unlock == "true" && Send.status == "due") {
|
|
825
|
+
return true;
|
|
826
|
+
}
|
|
827
|
+
}).length;
|
|
828
|
+
|
|
829
|
+
isDue = await (Object.values(Search)).filter(function(Send) {
|
|
830
|
+
if (Send.process == "wait" && Send.status != "paid") {
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
833
|
+
}).length;
|
|
834
|
+
}
|
|
835
|
+
isLoad = {
|
|
836
|
+
"Paid": isPaid,
|
|
837
|
+
"Lock": isLock,
|
|
838
|
+
"unLock": isUnLock,
|
|
839
|
+
"Due": isDue
|
|
840
|
+
};
|
|
841
|
+
isReturn = await Object.assign({}, isLoad);
|
|
842
|
+
if (typeof isLoad === 'object') {
|
|
843
|
+
isReturn = JSON.stringify(isReturn, null, 4);
|
|
844
|
+
}
|
|
845
|
+
if (Boolean(Debug('OPTIONS').tag) && Boolean(Debug('MKAUTH').aimbot)) {
|
|
846
|
+
FrontEnd = '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').shedstatus;
|
|
847
|
+
console.log(Print.bg.red, Print.fg.white, FrontEnd, Print.reset);
|
|
848
|
+
console.log(Print.reset, Print.fg.white, isReturn, Print.reset);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
if (Boolean(Debug('SCHEDULER').onpay) && isPaid >= 1) {
|
|
853
|
+
const Paid = await link.prepare('SELECT * FROM scheduling WHERE status=? AND NOT process=?').get('paid', 'success');
|
|
854
|
+
if (await Paid != undefined) {
|
|
855
|
+
const Resolve = await MkAuth('all', Paid.title, 'list');
|
|
856
|
+
const isBank = await Object.assign({}, Resolve)[0];
|
|
857
|
+
if (await Resolve != undefined) {
|
|
858
|
+
if (Paid.status == "paid" && Boolean(isBank.Ready)) {
|
|
859
|
+
Data = {
|
|
860
|
+
client: Paid.client,
|
|
861
|
+
user: Paid.user,
|
|
862
|
+
code: Paid.title,
|
|
863
|
+
status: "pending",
|
|
864
|
+
contact: Paid.contact,
|
|
865
|
+
reward: Paid.reward,
|
|
866
|
+
push: '00/00/0000 00:00:00',
|
|
867
|
+
option: Paid.option,
|
|
868
|
+
unlock: Paid.unlock,
|
|
869
|
+
process: Paid.process,
|
|
870
|
+
token: Debug('OPTIONS').token,
|
|
871
|
+
cash: Paid.cash,
|
|
872
|
+
gateway: Paid.gateway,
|
|
873
|
+
payment: Paid.status
|
|
874
|
+
};
|
|
875
|
+
const isReady = await axios.post("http://" + ip.address() + ":" + Debug('OPTIONS').access + "/send-mkauth", Data);
|
|
876
|
+
if (await isReady) {
|
|
877
|
+
await global.io.emit('schedresume', Paid.title);
|
|
878
|
+
await link.prepare('UPDATE scheduling SET process=?, unlock=? WHERE title=?').run('success', 'true', Paid.title);
|
|
879
|
+
}
|
|
880
|
+
} else {
|
|
881
|
+
await global.io.emit('schedresume', Paid.title);
|
|
882
|
+
await link.prepare('UPDATE scheduling SET process=?, unlock=? WHERE title=?').run('success', 'true', Paid.title);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
} else if (Boolean(Debug('SCHEDULER').onlock) && isLock >= 1) {
|
|
887
|
+
const Lock = await link.prepare('SELECT * FROM scheduling WHERE process=? AND unlock=?').get('lock', 'false');
|
|
888
|
+
if (await Lock != undefined) {
|
|
889
|
+
const Resolve = await MkAuth('all', Lock.title, 'list');
|
|
890
|
+
const isBank = await Object.assign({}, Resolve)[0];
|
|
891
|
+
if (await Resolve != undefined) {
|
|
892
|
+
if (Lock.status != "paid" && Boolean(isBank.Ready)) {
|
|
893
|
+
Data = {
|
|
894
|
+
client: Lock.client,
|
|
895
|
+
user: Lock.user,
|
|
896
|
+
code: Lock.title,
|
|
897
|
+
status: "pending",
|
|
898
|
+
contact: Lock.contact,
|
|
899
|
+
reward: Lock.reward,
|
|
900
|
+
push: '00/00/0000 00:00:00',
|
|
901
|
+
option: Lock.option,
|
|
902
|
+
unlock: Lock.unlock,
|
|
903
|
+
process: Lock.process,
|
|
904
|
+
token: Debug('OPTIONS').token,
|
|
905
|
+
payment: Lock.status
|
|
906
|
+
};
|
|
907
|
+
const isReady = await axios.post("http://" + ip.address() + ":" + Debug('OPTIONS').access + "/send-mkauth", Data);
|
|
908
|
+
if (await isReady) {
|
|
909
|
+
await global.io.emit('schedresume', Lock.title);
|
|
910
|
+
await link.prepare('UPDATE scheduling SET process=?, unlock=? WHERE title=?').run('unlock', 'false', Lock.title);
|
|
911
|
+
}
|
|
912
|
+
} else {
|
|
913
|
+
await global.io.emit('schedresume', Lock.title);
|
|
914
|
+
await link.prepare('UPDATE scheduling SET process=?, unlock=? WHERE title=?').run('unlock', 'false', Lock.title);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
} else if (Boolean(Debug('SCHEDULER').onunlock) && isUnLock >= 1) {
|
|
919
|
+
const UnLock = await link.prepare('SELECT * FROM scheduling WHERE process=? AND unlock=?').get('unlock', 'true');
|
|
920
|
+
if (await UnLock != undefined) {
|
|
921
|
+
const Resolve = await MkAuth('all', UnLock.title, 'list');
|
|
922
|
+
const isBank = await Object.assign({}, Resolve)[0];
|
|
923
|
+
if (await Resolve != undefined) {
|
|
924
|
+
if (UnLock.status != "paid" && Boolean(isBank.Ready)) {
|
|
925
|
+
Data = {
|
|
926
|
+
client: UnLock.client,
|
|
927
|
+
user: UnLock.user,
|
|
928
|
+
code: UnLock.title,
|
|
929
|
+
status: "pending",
|
|
930
|
+
contact: UnLock.contact,
|
|
931
|
+
reward: UnLock.reward,
|
|
932
|
+
push: '00/00/0000 00:00:00',
|
|
933
|
+
option: UnLock.option,
|
|
934
|
+
unlock: UnLock.unlock,
|
|
935
|
+
process: UnLock.process,
|
|
936
|
+
token: Debug('OPTIONS').token,
|
|
937
|
+
payment: UnLock.status
|
|
938
|
+
};
|
|
939
|
+
const isReady = await axios.post("http://" + ip.address() + ":" + Debug('OPTIONS').access + "/send-mkauth", Data);
|
|
940
|
+
if (await isReady) {
|
|
941
|
+
await global.io.emit('schedresume', UnLock.title);
|
|
942
|
+
await link.prepare('UPDATE scheduling SET process=?, unlock=? WHERE title=?').run('load', UnLock.unlock, UnLock.title);
|
|
943
|
+
}
|
|
944
|
+
} else {
|
|
945
|
+
await global.io.emit('schedresume', UnLock.title);
|
|
946
|
+
await link.prepare('UPDATE scheduling SET process=?, unlock=? WHERE title=?').run('load', UnLock.unlock, UnLock.title);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
} else if ((isWeek(DateTime(0))) && (isShift((DateTime(0).split(" ")[1]).split(":")[0])) || (validPhone(Playground) && Initialize)) {
|
|
951
|
+
const Due = await link.prepare('SELECT * FROM scheduling WHERE NOT status=? AND process=?').get('paid', 'wait');
|
|
952
|
+
if (await Due != undefined) {
|
|
953
|
+
const Resolve = await MkAuth('all', Due.title, 'list');
|
|
954
|
+
const isBank = await Object.assign({}, Resolve)[0];
|
|
955
|
+
if (await Resolve != undefined) {
|
|
956
|
+
if (isDue >= 1) {
|
|
957
|
+
if (Due.process != "load" && Boolean(isBank.Ready)) {
|
|
958
|
+
Data = {
|
|
959
|
+
client: Due.client,
|
|
960
|
+
user: Due.user,
|
|
961
|
+
code: Due.title,
|
|
962
|
+
status: "pending",
|
|
963
|
+
contact: Due.contact,
|
|
964
|
+
reward: Due.reward,
|
|
965
|
+
push: '00/00/0000 00:00:00',
|
|
966
|
+
option: Due.option,
|
|
967
|
+
unlock: undefined,
|
|
968
|
+
process: Due.process,
|
|
969
|
+
token: Debug('OPTIONS').token,
|
|
970
|
+
payment: Due.status
|
|
971
|
+
};
|
|
972
|
+
const isReady = await axios.post("http://" + ip.address() + ":" + Debug('OPTIONS').access + "/send-mkauth", Data);
|
|
973
|
+
if (await isReady) {
|
|
974
|
+
await global.io.emit('schedresume', Due.title);
|
|
975
|
+
if (isBank.unLock == 'false' && Boolean(Debug('SCHEDULER').onlock)) {
|
|
976
|
+
await link.prepare('UPDATE scheduling SET process=?, unlock=? WHERE title=?').run("lock", isBank.unLock, Due.title);
|
|
977
|
+
} else {
|
|
978
|
+
await link.prepare('UPDATE scheduling SET process=?, unlock=? WHERE title=?').run("load", isBank.unLock, Due.title);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
} else {
|
|
982
|
+
await global.io.emit('schedresume', Due.title);
|
|
983
|
+
await link.prepare('UPDATE scheduling SET process=?, unlock=? WHERE title=?').run("load", isBank.unLock, Due.title);
|
|
984
|
+
}
|
|
985
|
+
} else {
|
|
986
|
+
await global.io.emit('schedresume', 'true');
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
//Scheduller
|
|
998
|
+
cron.schedule('*/2 1-2 * * *', async () => {
|
|
999
|
+
await GetUpdate(WServer, true);
|
|
1000
|
+
await WwjsVersion(false);
|
|
1001
|
+
}, {
|
|
1002
|
+
scheduled: true,
|
|
1003
|
+
timezone: "America/Sao_Paulo"
|
|
1004
|
+
});
|
|
1005
|
+
|
|
1006
|
+
cron.schedule('0 0 * * *', async () => {
|
|
1007
|
+
await SetSchedule();
|
|
1008
|
+
}, {
|
|
1009
|
+
scheduled: true,
|
|
1010
|
+
timezone: "America/Sao_Paulo"
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
cron.schedule('*/' + Debug('SCHEDULER').cron + ' 3-23 * * *', async () => {
|
|
1014
|
+
if (!Boolean(Debug('RELEASE').reload)) {
|
|
1015
|
+
await GetSchedule();
|
|
1016
|
+
}
|
|
1017
|
+
}, {
|
|
1018
|
+
scheduled: true,
|
|
1019
|
+
timezone: "America/Sao_Paulo"
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
app.use(express.json({
|
|
1023
|
+
limit: '500mb'
|
|
1024
|
+
}));
|
|
1025
|
+
app.use(express.urlencoded({
|
|
1026
|
+
limit: '500mb',
|
|
1027
|
+
extended: true
|
|
1028
|
+
}));
|
|
1029
|
+
app.use(express.text({
|
|
1030
|
+
limit: '500mb'
|
|
1031
|
+
}));
|
|
1032
|
+
|
|
1033
|
+
app.use("/", express.static(__dirname + "/"))
|
|
1034
|
+
|
|
1035
|
+
app.get('/', (req, res) => {
|
|
1036
|
+
res.sendFile('index.html', {
|
|
1037
|
+
root: __dirname
|
|
1038
|
+
});
|
|
1039
|
+
});
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
//Get Date
|
|
1043
|
+
function AddZero(num) {
|
|
1044
|
+
return (num >= 0 && num < 10) ? "0" + num : num + "";
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
function DateTime(Days = 0, Mode) {
|
|
1048
|
+
isDate = new Date();
|
|
1049
|
+
switch (Mode) {
|
|
1050
|
+
case 'some':
|
|
1051
|
+
isDate.setDate(isDate.getDate() + Days);
|
|
1052
|
+
break;
|
|
1053
|
+
case 'subtract':
|
|
1054
|
+
isDate.setDate(isDate.getDate() - Days);
|
|
1055
|
+
break;
|
|
1056
|
+
}
|
|
1057
|
+
UTC = isDate.getTime() + (isDate.getTimezoneOffset() * 60000);
|
|
1058
|
+
now = new Date(UTC + (3600000 * -3));
|
|
1059
|
+
var strDateTime = [
|
|
1060
|
+
[now.getFullYear(), AddZero(now.getMonth() + 1), AddZero(now.getDate())].join("-"), [AddZero(now.getHours()), AddZero(now.getMinutes()), AddZero(now.getSeconds())].join(":")
|
|
1061
|
+
].join(" ");
|
|
1062
|
+
return strDateTime;
|
|
1063
|
+
};
|
|
1064
|
+
|
|
1065
|
+
const MkList = async (FIND, REFINE = "titulos") => {
|
|
1066
|
+
var Server = Debug('MKAUTH').client_link;
|
|
1067
|
+
if (Server == "tunel") {
|
|
1068
|
+
Server = Debug('MKAUTH').tunel;
|
|
1069
|
+
} else if (Server == "domain") {
|
|
1070
|
+
Server = Debug('MKAUTH').domain;
|
|
1071
|
+
}
|
|
1072
|
+
const Authentication = await axios.get('https://' + Server + '/api/', {
|
|
1073
|
+
auth: {
|
|
1074
|
+
username: Debug('MKAUTH').client_id,
|
|
1075
|
+
password: Debug('MKAUTH').client_secret
|
|
1076
|
+
}
|
|
1077
|
+
}).then(response => {
|
|
1078
|
+
return response.data;
|
|
1079
|
+
}).catch(err => {
|
|
1080
|
+
return false;
|
|
1081
|
+
});
|
|
1082
|
+
if (Authentication) {
|
|
1083
|
+
const MkSync = await axios.get('https://' + Server + '/api/titulo/' + REFINE + '/' + FIND, {
|
|
1084
|
+
headers: {
|
|
1085
|
+
'Authorization': 'Bearer ' + Authentication
|
|
1086
|
+
}
|
|
1087
|
+
}).then(response => {
|
|
1088
|
+
if ((typeof response.data !== "object") && ((response.data).slice(-1) != '}')) {
|
|
1089
|
+
return JSON.parse((response.data).substring(0, (response.data).length - 1));
|
|
1090
|
+
} else {
|
|
1091
|
+
return response.data;
|
|
1092
|
+
}
|
|
1093
|
+
}).catch(err => {
|
|
1094
|
+
return false;
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
if (await MkSync.mensagem == undefined && await MkSync.error == undefined) {
|
|
1098
|
+
const Keys = Object.keys(await MkSync).length;
|
|
1099
|
+
if (Keys == 0) {
|
|
1100
|
+
return false
|
|
1101
|
+
} else if (Keys <= 2) {
|
|
1102
|
+
return await MkSync.titulos;
|
|
1103
|
+
} else if (Keys >= 3) {
|
|
1104
|
+
return await MkSync;
|
|
1105
|
+
}
|
|
1106
|
+
} else {
|
|
1107
|
+
return false;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
function isWeek(Sysdate) {
|
|
1113
|
+
var CountDown = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"][new Date(Sysdate).getDay()]
|
|
1114
|
+
switch (CountDown) {
|
|
1115
|
+
case 'sunday':
|
|
1116
|
+
inDay = Debug('SCHEDULER').sunday;
|
|
1117
|
+
break;
|
|
1118
|
+
case 'monday':
|
|
1119
|
+
inDay = Debug('SCHEDULER').monday;
|
|
1120
|
+
break;
|
|
1121
|
+
case 'tuesday':
|
|
1122
|
+
inDay = Debug('SCHEDULER').tuesday;
|
|
1123
|
+
break;
|
|
1124
|
+
case 'wednesday':
|
|
1125
|
+
inDay = Debug('SCHEDULER').wednesday;
|
|
1126
|
+
break;
|
|
1127
|
+
case 'thursday':
|
|
1128
|
+
inDay = Debug('SCHEDULER').thursday;
|
|
1129
|
+
break;
|
|
1130
|
+
case 'friday':
|
|
1131
|
+
inDay = Debug('SCHEDULER').friday;
|
|
1132
|
+
break;
|
|
1133
|
+
case 'saturday':
|
|
1134
|
+
inDay = Debug('SCHEDULER').saturday;
|
|
1135
|
+
break;
|
|
1136
|
+
}
|
|
1137
|
+
if (Boolean(inDay)) {
|
|
1138
|
+
return true;
|
|
1139
|
+
} else {
|
|
1140
|
+
return false;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
const Scheduller = async (DAYS, MODE) => {
|
|
1145
|
+
var Date;
|
|
1146
|
+
if (MODE.toLowerCase() == "now" && DAYS == 0) {
|
|
1147
|
+
Date = [(DateTime(0)).split(" ")[0],
|
|
1148
|
+
[AddZero(0), AddZero(0), AddZero(0)].join(":")
|
|
1149
|
+
].join(" ");
|
|
1150
|
+
} else if (MODE.toLowerCase() == "before") {
|
|
1151
|
+
Date = [(DateTime(DAYS, "subtract")).split(" ")[0],
|
|
1152
|
+
[AddZero(0), AddZero(0), AddZero(0)].join(":")
|
|
1153
|
+
].join(" ");
|
|
1154
|
+
} else if (MODE.toLowerCase() == "later") {
|
|
1155
|
+
Date = [(DateTime(DAYS, "some")).split(" ")[0],
|
|
1156
|
+
[AddZero(0), AddZero(0), AddZero(0)].join(":")
|
|
1157
|
+
].join(" ");
|
|
1158
|
+
}
|
|
1159
|
+
return await MkList(Date);
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1162
|
+
function inRange(x, min, max) {
|
|
1163
|
+
return ((x - min) * (x - max) <= 0);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
function isShift(Turno) {
|
|
1167
|
+
var Return = false;
|
|
1168
|
+
if (inRange(Turno, AddZero(Debug('SCHEDULER').min), 11)) {
|
|
1169
|
+
if (Boolean(Debug('SCHEDULER').morning)) {
|
|
1170
|
+
Return = true;
|
|
1171
|
+
}
|
|
1172
|
+
} else if (inRange(Turno, 12, 17)) {
|
|
1173
|
+
if (Boolean(Debug('SCHEDULER').afternoon)) {
|
|
1174
|
+
Return = true;
|
|
1175
|
+
}
|
|
1176
|
+
} else if (inRange(Turno, 18, Debug('SCHEDULER').max)) {
|
|
1177
|
+
if (Boolean(Debug('SCHEDULER').night)) {
|
|
1178
|
+
Return = true;
|
|
1179
|
+
}
|
|
1180
|
+
} else {
|
|
1181
|
+
Return = false;
|
|
1182
|
+
}
|
|
1183
|
+
return Return;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
async function WwjsVersion(GET) {
|
|
1187
|
+
try {
|
|
1188
|
+
const installed = require("whatsapp-web.js/package.json").version;
|
|
1189
|
+
const latest = execSync("npm view whatsapp-web.js version", {
|
|
1190
|
+
encoding: "utf8"
|
|
1191
|
+
}).trim();
|
|
1192
|
+
|
|
1193
|
+
if (installed === latest) {
|
|
1194
|
+
await global.io.emit('Wwjs', true);
|
|
1195
|
+
if (GET) {
|
|
1196
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').wwjsupdate);
|
|
1197
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').wwjsupdate);
|
|
1198
|
+
}
|
|
1199
|
+
} else {
|
|
1200
|
+
await global.io.emit('Wwjs', false);
|
|
1201
|
+
if (GET) {
|
|
1202
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').wwjsfail);
|
|
1203
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').wwjsfail);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
} catch (err) {
|
|
1207
|
+
await global.io.emit('Wwjs', false);
|
|
1208
|
+
if (GET) {
|
|
1209
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').wwjsfail);
|
|
1210
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').wwjsfail);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
// ==================================================
|
|
1218
|
+
// 🧠 Inteligência Artificial
|
|
1219
|
+
// ==================================================
|
|
1220
|
+
|
|
1221
|
+
async function getEmbedding(text) {
|
|
1222
|
+
try {
|
|
1223
|
+
if (!text) return null;
|
|
1224
|
+
const mwsmHost = Debug('OPTIONS').mwsmhost;
|
|
1225
|
+
const mwsmPort = Debug('OPTIONS').mwsmport;
|
|
1226
|
+
|
|
1227
|
+
const localResp = await axios.post(
|
|
1228
|
+
`http://${mwsmHost}:${mwsmPort}/embed`,
|
|
1229
|
+
{ text },
|
|
1230
|
+
{ timeout: 10000 }
|
|
1231
|
+
);
|
|
1232
|
+
|
|
1233
|
+
if (localResp.data?.embedding) return localResp.data.embedding;
|
|
1234
|
+
throw new Error('No embedding returned');
|
|
1235
|
+
} catch {
|
|
1236
|
+
// 🔹 fallback determinístico (garante vetor estável)
|
|
1237
|
+
return Array.from(text)
|
|
1238
|
+
.map((ch, i) => ((ch.charCodeAt(0) + i * 13) % 255) / 255)
|
|
1239
|
+
.slice(0, 256);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
// ==================================================
|
|
1244
|
+
// 🕒 Timezone e Cumprimentos Dinâmicos
|
|
1245
|
+
// ==================================================
|
|
1246
|
+
async function getTimezoneByUF(uf) {
|
|
1247
|
+
return new Promise((resolve) => {
|
|
1248
|
+
db.get("SELECT timezone FROM localzone WHERE uf = ?", [uf], (err, row) => {
|
|
1249
|
+
if (err || !row) return resolve("America/Sao_Paulo"); // padrão SP
|
|
1250
|
+
resolve(row.timezone);
|
|
1251
|
+
});
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
function getGreetingPeriod(timezone) {
|
|
1256
|
+
try {
|
|
1257
|
+
const now = new Date();
|
|
1258
|
+
const localTime = new Date(now.toLocaleString("pt-BR", { timeZone: timezone }));
|
|
1259
|
+
const hour = localTime.getHours();
|
|
1260
|
+
|
|
1261
|
+
if (hour >= 5 && hour < 12) return "bom dia";
|
|
1262
|
+
if (hour >= 12 && hour < 18) return "boa tarde";
|
|
1263
|
+
return "boa noite";
|
|
1264
|
+
} catch {
|
|
1265
|
+
return "";
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
// ==================================================
|
|
1270
|
+
// 🔒 Filtro Temático (Palavras-chave no BD)
|
|
1271
|
+
// ==================================================
|
|
1272
|
+
async function isRelevantQuestion(text) {
|
|
1273
|
+
return new Promise((resolve) => {
|
|
1274
|
+
db.all("SELECT filter FROM keywords", [], (err, rows) => {
|
|
1275
|
+
if (err) {
|
|
1276
|
+
console.error("Keyword filter error:", err.message);
|
|
1277
|
+
return resolve(true); // não bloqueia em erro
|
|
1278
|
+
}
|
|
1279
|
+
if (!rows || rows.length === 0) return resolve(true);
|
|
1280
|
+
|
|
1281
|
+
const keywords = rows.map(r => (r.filter || "").toLowerCase().trim());
|
|
1282
|
+
text = (text || "").toLowerCase().trim();
|
|
1283
|
+
const found = keywords.some(k => text.includes(k));
|
|
1284
|
+
resolve(found);
|
|
1285
|
+
});
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// ==================================================
|
|
1290
|
+
// 🎯 Lógica Principal da IA
|
|
1291
|
+
// ==================================================
|
|
1292
|
+
async function askAI(question) {
|
|
1293
|
+
return new Promise(async (resolve) => {
|
|
1294
|
+
try {
|
|
1295
|
+
const text = (question || "").toLowerCase().trim();
|
|
1296
|
+
|
|
1297
|
+
// 🔹 1️⃣ Verifica se é um cumprimento antes do filtro
|
|
1298
|
+
const isGreeting = await new Promise((resolveGreet) => {
|
|
1299
|
+
db.all("SELECT word FROM greetings", [], (err, rows) => {
|
|
1300
|
+
if (err || !rows?.length) return resolveGreet(false);
|
|
1301
|
+
const greetings = rows.map(r => (r.word || "").toLowerCase());
|
|
1302
|
+
resolveGreet(greetings.some(g => text.includes(g)));
|
|
1303
|
+
});
|
|
1304
|
+
});
|
|
1305
|
+
|
|
1306
|
+
if (isGreeting) {
|
|
1307
|
+
const uf = Debug('OPTIONS').timezone || 'SP';
|
|
1308
|
+
const tz = await getTimezoneByUF(uf);
|
|
1309
|
+
const turno = getGreetingPeriod(tz);
|
|
1310
|
+
|
|
1311
|
+
if (turno) {
|
|
1312
|
+
return resolve(`👋 Olá, ${turno}! Como posso te ajudar com sua conexão de internet?`);
|
|
1313
|
+
} else {
|
|
1314
|
+
return resolve(`👋 Olá! Como posso te ajudar com sua conexão de internet?`);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
// 🔹 2️⃣ Se não for cumprimento, aplica o filtro temático
|
|
1319
|
+
const isRelevant = await isRelevantQuestion(text);
|
|
1320
|
+
if (!isRelevant) {
|
|
1321
|
+
console.log(`> ${Debug('OPTIONS').appname} : Brain: Filter → Ignored.`);
|
|
1322
|
+
return resolve("⚠️ Posso ajudar apenas com dúvidas sobre sua conexão de internet e suporte técnico.");
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
// 🔹 3️⃣ A partir daqui segue o fluxo normal da IA
|
|
1326
|
+
const aiMode = parseInt(Debug('OPTIONS').aimode);
|
|
1327
|
+
const apiKey = Debug('OPTIONS').keygen;
|
|
1328
|
+
const Engine = Debug('OPTIONS').engine;
|
|
1329
|
+
const threshold = parseFloat(Debug('OPTIONS').threshold);
|
|
1330
|
+
const systemPrompt = Debug('OPTIONS').prompt;
|
|
1331
|
+
const aiTimeout = parseInt(Debug('OPTIONS').aitimeout);
|
|
1332
|
+
const appName = Debug('OPTIONS').appname;
|
|
1333
|
+
|
|
1334
|
+
if (!apiKey) return resolve("⚠️ IA não configurada.");
|
|
1335
|
+
|
|
1336
|
+
const engineRow = await Debug("ENGINE", "*", "DIRECT", Engine);
|
|
1337
|
+
const Module = engineRow?.module || null;
|
|
1338
|
+
const Level = parseInt(engineRow?.level || 0);
|
|
1339
|
+
|
|
1340
|
+
if (!Module) return resolve("⚠️ Indisponível no momento.");
|
|
1341
|
+
|
|
1342
|
+
const qEmbedding = await getEmbedding(question);
|
|
1343
|
+
let bestMatch = null;
|
|
1344
|
+
let bestScore = 0;
|
|
1345
|
+
|
|
1346
|
+
if (aiMode === 0) {
|
|
1347
|
+
console.log(`> ${appName} : Brain: Cloud | Relevance: 0.00`);
|
|
1348
|
+
const aiAnswer = await fetchCloudAnswer(question, apiKey, Engine, Module, systemPrompt, aiTimeout, Level);
|
|
1349
|
+
return resolve(aiAnswer);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
// 🔸 Busca local
|
|
1353
|
+
const rows = await Debug('INTELIGENCE', '*', 'ALL');
|
|
1354
|
+
for (const r of rows) {
|
|
1355
|
+
if (!r.embedding) continue;
|
|
1356
|
+
try {
|
|
1357
|
+
const emb = JSON.parse(r.embedding);
|
|
1358
|
+
const score = cosineSimilarity(emb, qEmbedding);
|
|
1359
|
+
if (score > bestScore) {
|
|
1360
|
+
bestScore = score;
|
|
1361
|
+
bestMatch = r;
|
|
1362
|
+
}
|
|
1363
|
+
} catch {}
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
// 🔹 Resposta local encontrada
|
|
1367
|
+
if (bestMatch && bestScore >= threshold) {
|
|
1368
|
+
console.log(`> ${appName} : Brain: Local | Relevance: ${bestScore.toFixed(2)}`);
|
|
1369
|
+
db.run("UPDATE inteligence SET usage_count = usage_count + 1 WHERE id = ?", [bestMatch.id]);
|
|
1370
|
+
return resolve(bestMatch.answer);
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
// 🔹 Caso não tenha resposta local — vai para nuvem
|
|
1374
|
+
console.log(`> ${appName} : Brain: Cloud | Relevance: ${bestScore.toFixed(2)}`);
|
|
1375
|
+
const aiAnswer = await fetchCloudAnswer(question, apiKey, Engine, Module, systemPrompt, aiTimeout, Level);
|
|
1376
|
+
|
|
1377
|
+
// 🔸 Aprendizado local (modo 2)
|
|
1378
|
+
if (aiMode === 2 && aiAnswer && !aiAnswer.startsWith("⚠")) {
|
|
1379
|
+
try {
|
|
1380
|
+
await enforceKnowledgeLimit();
|
|
1381
|
+
const _embedding = await getEmbedding(question);
|
|
1382
|
+
const embeddingStr = _embedding ? JSON.stringify(_embedding) : null;
|
|
1383
|
+
|
|
1384
|
+
db.serialize(() => {
|
|
1385
|
+
db.get("SELECT id FROM inteligence WHERE question = ?", [question], (err, row) => {
|
|
1386
|
+
if (err) return console.error("DB check error:", err.message);
|
|
1387
|
+
|
|
1388
|
+
const sql = row
|
|
1389
|
+
? "UPDATE inteligence SET answer=?, embedding=?, source=?, usage_count=usage_count+1 WHERE id=?"
|
|
1390
|
+
: "INSERT INTO inteligence (question, answer, embedding, source, usage_count) VALUES (?, ?, ?, ?, 1)";
|
|
1391
|
+
|
|
1392
|
+
const params = row
|
|
1393
|
+
? [aiAnswer, embeddingStr, "local", row.id]
|
|
1394
|
+
: [question, aiAnswer, embeddingStr, "local"];
|
|
1395
|
+
|
|
1396
|
+
db.run(sql, params, (e) => e && console.error("DB write error:", e.message));
|
|
1397
|
+
});
|
|
1398
|
+
});
|
|
1399
|
+
} catch (e) {
|
|
1400
|
+
console.error("Embedding generation failed:", e?.message || e);
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
return resolve(aiAnswer);
|
|
1405
|
+
} catch (err) {
|
|
1406
|
+
console.error("IA error:", err.message || err);
|
|
1407
|
+
return resolve("⚠️ Não consegui acessar a inteligência artificial no momento.");
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
// ==================================================
|
|
1413
|
+
// 🌐 Comunicação com API (OpenRouter) + Limite de Tentativas
|
|
1414
|
+
// ==================================================
|
|
1415
|
+
async function fetchCloudAnswer(question, apiKey, Engine, Module, systemPrompt, aiTimeout, Level = 0) {
|
|
1416
|
+
const tried = [];
|
|
1417
|
+
try {
|
|
1418
|
+
let variants = [];
|
|
1419
|
+
|
|
1420
|
+
if (Engine.toLowerCase() === "freerouter") {
|
|
1421
|
+
variants = await new Promise((resolve) => {
|
|
1422
|
+
db.all("SELECT * FROM engine WHERE level = 0 ORDER BY active DESC, id ASC", [], (err, rows) => {
|
|
1423
|
+
if (err) return resolve([]);
|
|
1424
|
+
resolve(rows);
|
|
1425
|
+
});
|
|
1426
|
+
});
|
|
1427
|
+
} else {
|
|
1428
|
+
variants = await new Promise((resolve) => {
|
|
1429
|
+
db.all("SELECT * FROM engine WHERE title = ? AND level = ? ORDER BY active DESC, id ASC", [Engine, Level], (err, rows) => {
|
|
1430
|
+
if (err) return resolve([]);
|
|
1431
|
+
resolve(rows);
|
|
1432
|
+
});
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
if (!variants.length) throw new Error("⚠️ Erro ao buscar resposta da IA online.");
|
|
1437
|
+
|
|
1438
|
+
const activeVariant = variants.find(v => v.active === 1);
|
|
1439
|
+
const orderedVariants = activeVariant
|
|
1440
|
+
? [activeVariant, ...variants.filter(v => v.id !== activeVariant.id)]
|
|
1441
|
+
: variants;
|
|
1442
|
+
|
|
1443
|
+
const maxAttempts = parseInt(Debug('OPTIONS').aimaxattempts) || 0;
|
|
1444
|
+
let attempts = 0;
|
|
1445
|
+
|
|
1446
|
+
for (const variant of orderedVariants) {
|
|
1447
|
+
if (maxAttempts && attempts >= maxAttempts) {
|
|
1448
|
+
console.log(`> ${Debug('OPTIONS').appname} : Brain: Max Attempts (${maxAttempts}) reached.`);
|
|
1449
|
+
break;
|
|
1450
|
+
}
|
|
1451
|
+
attempts++;
|
|
1452
|
+
|
|
1453
|
+
tried.push(variant.module);
|
|
1454
|
+
try {
|
|
1455
|
+
const response = await axios.post(
|
|
1456
|
+
"https://openrouter.ai/api/v1/chat/completions",
|
|
1457
|
+
{
|
|
1458
|
+
model: variant.module,
|
|
1459
|
+
messages: [
|
|
1460
|
+
{ role: "system", content: systemPrompt },
|
|
1461
|
+
{ role: "user", content: question }
|
|
1462
|
+
]
|
|
1463
|
+
},
|
|
1464
|
+
{
|
|
1465
|
+
headers: {
|
|
1466
|
+
Authorization: `Bearer ${apiKey}`,
|
|
1467
|
+
"Content-Type": "application/json"
|
|
1468
|
+
},
|
|
1469
|
+
timeout: aiTimeout
|
|
1470
|
+
}
|
|
1471
|
+
);
|
|
1472
|
+
|
|
1473
|
+
const aiAnswer =
|
|
1474
|
+
response.data?.choices?.[0]?.message?.content?.trim() ||
|
|
1475
|
+
"Desculpe, não consegui entender sua solicitação.";
|
|
1476
|
+
|
|
1477
|
+
db.run("UPDATE engine SET active = 0 WHERE title = ?", [variant.title]);
|
|
1478
|
+
db.run("UPDATE engine SET active = 1 WHERE id = ?", [variant.id]);
|
|
1479
|
+
|
|
1480
|
+
console.log(`> ${Debug('OPTIONS').appname} : AskAI: ${variant.title} ${variant.variant} → ATIVA`);
|
|
1481
|
+
return aiAnswer.replace(/\s+/g, " ").trim();
|
|
1482
|
+
} catch (err) {
|
|
1483
|
+
console.log(`> ${Debug('OPTIONS').appname} : AskAI: ${variant.title} ${variant.variant} → INATIVA`);
|
|
1484
|
+
db.run("UPDATE engine SET active = 0 WHERE id = ?", [variant.id]);
|
|
1485
|
+
continue;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
return "⚠️ Erro ao buscar resposta da IA online.";
|
|
1490
|
+
} catch {
|
|
1491
|
+
return "⚠️ Erro ao buscar resposta da IA online.";
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
// ==================================================
|
|
1496
|
+
// 📊 Similaridade Vetorial
|
|
1497
|
+
// ==================================================
|
|
1498
|
+
function cosineSimilarity(vecA, vecB) {
|
|
1499
|
+
if (!vecA || !vecB || vecA.length !== vecB.length) return 0;
|
|
1500
|
+
let dot = 0, normA = 0, normB = 0;
|
|
1501
|
+
for (let i = 0; i < vecA.length; i++) {
|
|
1502
|
+
dot += vecA[i] * vecB[i];
|
|
1503
|
+
normA += vecA[i] * vecA[i];
|
|
1504
|
+
normB += vecB[i] * vecB[i];
|
|
1505
|
+
}
|
|
1506
|
+
return normA && normB ? dot / (Math.sqrt(normA) * Math.sqrt(normB)) : 0;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
// ==================================================
|
|
1510
|
+
// 🧹 Limpeza Dinâmica e Inteligente do Conhecimento
|
|
1511
|
+
// ==================================================
|
|
1512
|
+
async function enforceKnowledgeLimit() {
|
|
1513
|
+
try {
|
|
1514
|
+
const maxKnowledge = parseInt(Debug("OPTIONS").maxknowledge) || 1000;
|
|
1515
|
+
if (!maxKnowledge || maxKnowledge < 100) return;
|
|
1516
|
+
|
|
1517
|
+
db.all("SELECT COUNT(*) as total FROM inteligence", async (err, rows) => {
|
|
1518
|
+
if (err) return console.error("DB count error:", err.message);
|
|
1519
|
+
const total = rows[0]?.total || 0;
|
|
1520
|
+
if (total <= maxKnowledge) return;
|
|
1521
|
+
|
|
1522
|
+
const excess = total - maxKnowledge;
|
|
1523
|
+
db.run(
|
|
1524
|
+
`DELETE FROM inteligence
|
|
1525
|
+
WHERE id IN (
|
|
1526
|
+
SELECT id FROM inteligence
|
|
1527
|
+
ORDER BY usage_count ASC, id ASC
|
|
1528
|
+
LIMIT ?
|
|
1529
|
+
)`,
|
|
1530
|
+
[excess],
|
|
1531
|
+
function (delErr) {
|
|
1532
|
+
if (delErr) console.error("Cleanup error:", delErr.message);
|
|
1533
|
+
else console.log(`✅ ${this.changes} registros antigos removidos.`);
|
|
1534
|
+
}
|
|
1535
|
+
);
|
|
1536
|
+
});
|
|
1537
|
+
} catch (err) {
|
|
1538
|
+
console.error("Erro no enforceKnowledgeLimit:", err.message);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// ==================================================
|
|
1543
|
+
// 🔹 Embedding Local (Backup Seguro)
|
|
1544
|
+
// ==================================================
|
|
1545
|
+
async function getLocalEmbedding(text) {
|
|
1546
|
+
return Array.from(text).map((c, i) => ((c.charCodeAt(0) + i * 7) % 255) / 255);
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
1550
|
+
|
|
1551
|
+
delay(0).then(async function() {
|
|
1552
|
+
|
|
1553
|
+
});
|
|
1554
|
+
|
|
1555
|
+
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
1556
|
+
//Search MkAUth API
|
|
1557
|
+
const MkAuth = async (UID, FIND, EXT = 'titulos', TYPE = 'titulo', MODE = true) => {
|
|
1558
|
+
var SEARCH, LIST, STATUS, PUSH = [],
|
|
1559
|
+
JSON = [],
|
|
1560
|
+
Json = undefined,
|
|
1561
|
+
JDebug = undefined,
|
|
1562
|
+
Jump;
|
|
1563
|
+
var Server = Debug('MKAUTH').client_link;
|
|
1564
|
+
|
|
1565
|
+
if (Server == "tunel") {
|
|
1566
|
+
Server = Debug('MKAUTH').tunel;
|
|
1567
|
+
} else if (Server == "domain") {
|
|
1568
|
+
Server = Debug('MKAUTH').domain;
|
|
1569
|
+
}
|
|
1570
|
+
switch (FIND) {
|
|
1571
|
+
case 'open':
|
|
1572
|
+
FIND = 'aberto';
|
|
1573
|
+
break;
|
|
1574
|
+
case 'paid':
|
|
1575
|
+
FIND = 'pago';
|
|
1576
|
+
break;
|
|
1577
|
+
case 'due':
|
|
1578
|
+
FIND = 'vencido';
|
|
1579
|
+
break;
|
|
1580
|
+
case 'cancel':
|
|
1581
|
+
FIND = 'cancelado';
|
|
1582
|
+
break;
|
|
1583
|
+
}
|
|
1584
|
+
if (EXT == "list") {
|
|
1585
|
+
EXT = "listagem";
|
|
1586
|
+
}
|
|
1587
|
+
const Authentication = await axios.get('https://' + Server + '/api/', {
|
|
1588
|
+
auth: {
|
|
1589
|
+
username: Debug('MKAUTH').client_id,
|
|
1590
|
+
password: Debug('MKAUTH').client_secret
|
|
1591
|
+
}
|
|
1592
|
+
}).then(response => {
|
|
1593
|
+
return response.data;
|
|
1594
|
+
}).catch(err => {
|
|
1595
|
+
return false;
|
|
1596
|
+
});
|
|
1597
|
+
if (Authentication) {
|
|
1598
|
+
const MkSync = await axios.get('https://' + Server + '/api/' + TYPE + '/' + EXT + '/' + UID, {
|
|
1599
|
+
headers: {
|
|
1600
|
+
'Authorization': 'Bearer ' + Authentication
|
|
1601
|
+
}
|
|
1602
|
+
}).then(response => {
|
|
1603
|
+
if ((typeof response.data !== "object") && ((response.data).slice(-1) != '}')) {
|
|
1604
|
+
return JSON.parse((response.data).substring(0, (response.data).length - 1));
|
|
1605
|
+
} else {
|
|
1606
|
+
return response.data;
|
|
1607
|
+
}
|
|
1608
|
+
}).catch(err => {
|
|
1609
|
+
return false;
|
|
1610
|
+
});
|
|
1611
|
+
if (await MkSync.mensagem == undefined && await MkSync.error == undefined) {
|
|
1612
|
+
const SEARCH = await MkSync;
|
|
1613
|
+
const Keys = Object.keys(SEARCH).length;
|
|
1614
|
+
if (Keys == 0) {
|
|
1615
|
+
Syncron = undefined
|
|
1616
|
+
} else if (Keys <= 2) {
|
|
1617
|
+
Syncron = await SEARCH.titulos;
|
|
1618
|
+
} else if (Keys >= 3) {
|
|
1619
|
+
Syncron = await SEARCH;
|
|
1620
|
+
}
|
|
1621
|
+
if (Syncron != undefined) {
|
|
1622
|
+
(Syncron).someAsync(async (Send) => {
|
|
1623
|
+
if (EXT == 'titulos') {
|
|
1624
|
+
if ((Send.titulo == FIND.replace(/^0+/, '') || parseInt(Send.titulo) == parseInt(FIND)) || Send.linhadig == FIND) {
|
|
1625
|
+
var Bolix = '';
|
|
1626
|
+
if (Send.linhadig == undefined || Send.linhadig == null || Send.linhadig == "") {
|
|
1627
|
+
Send.linhadig = '';
|
|
1628
|
+
Json_Bar = "false";
|
|
1629
|
+
} else {
|
|
1630
|
+
switch (Debug('MKAUTH').mode) {
|
|
1631
|
+
case 'v1':
|
|
1632
|
+
Bolix = "http://" + Debug('MKAUTH').domain + "/boleto/boleto.hhvm?titulo=" + Send.uuid;
|
|
1633
|
+
break;
|
|
1634
|
+
case 'v2':
|
|
1635
|
+
Bolix = "http://" + Debug('MKAUTH').domain + "/boleto/boleto.hhvm?titulo=" + Send.titulo + "&contrato=" + Send.login;
|
|
1636
|
+
break;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
Json_Bar = "true";
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
if (Send.pix == undefined || Send.pix == null || Send.pix == "") {
|
|
1643
|
+
Send.pix = '';
|
|
1644
|
+
Json_Pix = "false";
|
|
1645
|
+
} else {
|
|
1646
|
+
|
|
1647
|
+
Json_Pix = "true";
|
|
1648
|
+
}
|
|
1649
|
+
if (Send.pix_qr == undefined || Send.pix_qr == null || Send.pix_qr == "") {
|
|
1650
|
+
Send.pix_qr = 'base64,';
|
|
1651
|
+
Json_QR = "false";
|
|
1652
|
+
} else {
|
|
1653
|
+
|
|
1654
|
+
Json_QR = "true";
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
if (Send.pix_link == undefined || Send.pix_link == null || Send.pix_link == "") {
|
|
1658
|
+
Send.pix_link = '';
|
|
1659
|
+
Json_Link = "false";
|
|
1660
|
+
} else {
|
|
1661
|
+
Json_Link = "true";
|
|
1662
|
+
}
|
|
1663
|
+
var SEND = [];
|
|
1664
|
+
if (Boolean(Debug('MKAUTH').bar)) {
|
|
1665
|
+
SEND.push(Send.linhadig);
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
if (Boolean(Debug('MKAUTH').pix)) {
|
|
1669
|
+
SEND.push(Send.pix);
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
if (Boolean(Debug('MKAUTH').qrpix)) {
|
|
1673
|
+
SEND.push(Send.pix_qr);
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
if (Boolean(Debug('MKAUTH').qrlink)) {
|
|
1677
|
+
SEND.push(Send.pix_link);
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
if (Boolean(Debug('MKAUTH').pdf)) {
|
|
1681
|
+
SEND.push(Send.uuid);
|
|
1682
|
+
}
|
|
1683
|
+
if (SEND.length >= 1) {
|
|
1684
|
+
if (SEND.some(Row => Row == '')) {
|
|
1685
|
+
STATUS = "Null";
|
|
1686
|
+
} else {
|
|
1687
|
+
STATUS = Send.status;
|
|
1688
|
+
}
|
|
1689
|
+
Json = {
|
|
1690
|
+
"Status": STATUS,
|
|
1691
|
+
"ID": Send.titulo,
|
|
1692
|
+
"Name": Send.nome,
|
|
1693
|
+
"Payments": [{
|
|
1694
|
+
"value": Send.linhadig,
|
|
1695
|
+
"caption": "Bar",
|
|
1696
|
+
"status": Json_Bar
|
|
1697
|
+
},
|
|
1698
|
+
{
|
|
1699
|
+
"value": Send.pix,
|
|
1700
|
+
"caption": "Pix",
|
|
1701
|
+
"status": Json_Pix
|
|
1702
|
+
},
|
|
1703
|
+
{
|
|
1704
|
+
"value": Send.pix_qr.split("base64,")[1],
|
|
1705
|
+
"caption": "QRCode",
|
|
1706
|
+
"status": Json_QR
|
|
1707
|
+
},
|
|
1708
|
+
{
|
|
1709
|
+
"value": Send.pix_link,
|
|
1710
|
+
"caption": "Link",
|
|
1711
|
+
"status": Json_Link
|
|
1712
|
+
},
|
|
1713
|
+
{
|
|
1714
|
+
"value": Bolix,
|
|
1715
|
+
"caption": "Boleto",
|
|
1716
|
+
"status": Json_Bar
|
|
1717
|
+
}
|
|
1718
|
+
]
|
|
1719
|
+
};
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
if (EXT == 'listagem' || EXT == 'list') {
|
|
1725
|
+
LIST = [FIND];
|
|
1726
|
+
if (FIND == 'all') {
|
|
1727
|
+
LIST = [Send.status];
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
if (UID == "all") {
|
|
1731
|
+
Jump = true;
|
|
1732
|
+
} else {
|
|
1733
|
+
if (parseInt(UID) <= 9 && parseInt(UID.length) == 1) {
|
|
1734
|
+
UID = "0" + UID;
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
Jump = (Send.datavenc).includes(((DateTime()).split(" ")[0]).split("-")[0] + "-" + UID + "-");
|
|
1738
|
+
if ((UID).replace(/[^0-9\\.]+/g, '').length > 4) {
|
|
1739
|
+
Jump = (Send.datavenc).includes(UID + "-");
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
if (Jump && LIST.some(Row => (Send.status.includes(Row) || Send.login.includes(Row) || Send.titulo.includes(Row))) && Send.cli_ativado == 's' && Send.status != 'cancelado') {
|
|
1743
|
+
switch (Send.status) {
|
|
1744
|
+
case 'aberto':
|
|
1745
|
+
Send.status = 'open';
|
|
1746
|
+
break;
|
|
1747
|
+
case 'pago':
|
|
1748
|
+
Send.status = 'paid';
|
|
1749
|
+
break;
|
|
1750
|
+
case 'vencido':
|
|
1751
|
+
Send.status = 'due';
|
|
1752
|
+
break;
|
|
1753
|
+
case 'cancelado':
|
|
1754
|
+
Send.status = 'cancel';
|
|
1755
|
+
break;
|
|
1756
|
+
}
|
|
1757
|
+
switch (Send.bloqueado) {
|
|
1758
|
+
case 'sim':
|
|
1759
|
+
Send.bloqueado = 'false';
|
|
1760
|
+
break;
|
|
1761
|
+
case 'nao':
|
|
1762
|
+
Send.bloqueado = 'true';
|
|
1763
|
+
break;
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
switch (Send.cli_ativado) {
|
|
1767
|
+
case 's':
|
|
1768
|
+
Send.cli_ativado = 'true';
|
|
1769
|
+
break;
|
|
1770
|
+
case 'n':
|
|
1771
|
+
Send.cli_ativado = 'false';
|
|
1772
|
+
break;
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
switch (Send.zap) {
|
|
1776
|
+
case 'sim':
|
|
1777
|
+
Send.zap = 'true';
|
|
1778
|
+
break;
|
|
1779
|
+
case 'nao':
|
|
1780
|
+
Send.zap = 'false';
|
|
1781
|
+
break;
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
if (Send.formapag != "dinheiro" && Send.formapag != undefined) {
|
|
1785
|
+
Send.formapag = "banco"
|
|
1786
|
+
}
|
|
1787
|
+
if (((Send.datavenc).split(" ")[0]) == (DateTime()).split(" ")[0] && (Send.status) != 'paid') {
|
|
1788
|
+
Send.status = 'open'
|
|
1789
|
+
}
|
|
1790
|
+
if (Send.celular != undefined) {
|
|
1791
|
+
Send.celular = (Send.celular).replace(/[^0-9\\.]+/g, '');
|
|
1792
|
+
}
|
|
1793
|
+
Json = {
|
|
1794
|
+
"Order": (new Date(Send.datavenc)).getDate(),
|
|
1795
|
+
"Identifier": Send.titulo,
|
|
1796
|
+
"Client": Send.nome,
|
|
1797
|
+
"Reward": Send.datavenc,
|
|
1798
|
+
"Payment": Send.status,
|
|
1799
|
+
"Connect": Send.login,
|
|
1800
|
+
"Contact": Send.celular,
|
|
1801
|
+
"Working": Send.cli_ativado,
|
|
1802
|
+
"unLock": Send.bloqueado,
|
|
1803
|
+
"LowSpeed": Send.dias_corte,
|
|
1804
|
+
"Ready": Send.zap,
|
|
1805
|
+
"Cash": Send.valorpag,
|
|
1806
|
+
"Gateway": Send.formapag
|
|
1807
|
+
};
|
|
1808
|
+
PUSH.push(Json);
|
|
1809
|
+
Json = (PUSH).sort(function(a, b) {
|
|
1810
|
+
var Nome = a.Client.localeCompare(b.Client);
|
|
1811
|
+
var Ordem = parseFloat(a.Order) - parseFloat(b.Order);
|
|
1812
|
+
return Ordem || Nome;
|
|
1813
|
+
});
|
|
1814
|
+
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
});
|
|
1818
|
+
}
|
|
1819
|
+
if (EXT == 'titulos') {
|
|
1820
|
+
if (Json == undefined) {
|
|
1821
|
+
Json = {
|
|
1822
|
+
"Status": "Error"
|
|
1823
|
+
};
|
|
1824
|
+
JDebug = {
|
|
1825
|
+
"MkAuth": "Cannot Find the Data > find"
|
|
1826
|
+
};
|
|
1827
|
+
|
|
1828
|
+
Terminal(JDebug);
|
|
1829
|
+
} else {
|
|
1830
|
+
switch (Json.Status) {
|
|
1831
|
+
case 'aberto':
|
|
1832
|
+
Json.Status = 'open';
|
|
1833
|
+
break;
|
|
1834
|
+
case 'pago':
|
|
1835
|
+
Json.Status = 'paid';
|
|
1836
|
+
break;
|
|
1837
|
+
case 'vencido':
|
|
1838
|
+
Json.Status = 'due';
|
|
1839
|
+
break;
|
|
1840
|
+
case 'cancelado':
|
|
1841
|
+
Json.Status = 'cancel';
|
|
1842
|
+
break;
|
|
1843
|
+
}
|
|
1844
|
+
JDebug = {
|
|
1845
|
+
"Payment": Json.Status,
|
|
1846
|
+
"Client": Json.Name,
|
|
1847
|
+
"MkAuth": [{
|
|
1848
|
+
"Module": "Bar",
|
|
1849
|
+
"Available": Json["Payments"][0].status,
|
|
1850
|
+
"Allowed": "" + Debug('MKAUTH').bar + ""
|
|
1851
|
+
|
|
1852
|
+
},
|
|
1853
|
+
{
|
|
1854
|
+
"Module": "Pix",
|
|
1855
|
+
"Available": Json["Payments"][1].status,
|
|
1856
|
+
"Allowed": "" + Debug('MKAUTH').pix + ""
|
|
1857
|
+
},
|
|
1858
|
+
{
|
|
1859
|
+
"Module": "QRC",
|
|
1860
|
+
"Available": Json["Payments"][2].status,
|
|
1861
|
+
"Allowed": "" + Debug('MKAUTH').qrpix + ""
|
|
1862
|
+
},
|
|
1863
|
+
{
|
|
1864
|
+
"Module": "QRL",
|
|
1865
|
+
"Available": Json["Payments"][3].status,
|
|
1866
|
+
"Allowed": "" + Debug('MKAUTH').qrlink + ""
|
|
1867
|
+
},
|
|
1868
|
+
{
|
|
1869
|
+
"Module": "PDF",
|
|
1870
|
+
"Available": Json["Payments"][4].status,
|
|
1871
|
+
"Allowed": "" + Debug('MKAUTH').pdf + ""
|
|
1872
|
+
}
|
|
1873
|
+
]
|
|
1874
|
+
}
|
|
1875
|
+
Terminal(JDebug);
|
|
1876
|
+
}
|
|
1877
|
+
return Json;
|
|
1878
|
+
}
|
|
1879
|
+
if (EXT == 'listagem' || EXT == 'list') {
|
|
1880
|
+
if (Json == undefined) {
|
|
1881
|
+
Json = {
|
|
1882
|
+
"Status": "Error"
|
|
1883
|
+
};
|
|
1884
|
+
} else {
|
|
1885
|
+
(Json).some(function(Send, index) {
|
|
1886
|
+
isJson = {
|
|
1887
|
+
"Order": (index + 1),
|
|
1888
|
+
"Identifier": Send.Identifier,
|
|
1889
|
+
"Client": Send.Client,
|
|
1890
|
+
"Reward": Send.Reward,
|
|
1891
|
+
"Payment": Send.Payment,
|
|
1892
|
+
"Connect": Send.Connect,
|
|
1893
|
+
"Contact": Send.Contact,
|
|
1894
|
+
"unLock": Send.unLock,
|
|
1895
|
+
"Working": Send.Working,
|
|
1896
|
+
"LowSpeed": Send.LowSpeed,
|
|
1897
|
+
"Ready": Send.Ready,
|
|
1898
|
+
"Cash": Send.Cash,
|
|
1899
|
+
"Gateway": Send.Gateway
|
|
1900
|
+
};
|
|
1901
|
+
JSON.push(isJson);
|
|
1902
|
+
Json = JSON;
|
|
1903
|
+
});
|
|
1904
|
+
Terminal(Json);
|
|
1905
|
+
}
|
|
1906
|
+
if (Json.Status == "Error") {
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
return Json;
|
|
1910
|
+
}
|
|
1911
|
+
} else {
|
|
1912
|
+
if (await MkSync.mensagem != undefined || await MkSync.error != undefined) {
|
|
1913
|
+
if (EXT == 'titulos') {
|
|
1914
|
+
JDebug = {
|
|
1915
|
+
"MkAuth": "Cannot Find the Data > uid",
|
|
1916
|
+
};
|
|
1917
|
+
Terminal(JDebug);
|
|
1918
|
+
return false;
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
if (EXT == 'listagem' || EXT == 'list') {
|
|
1922
|
+
JDebug = {
|
|
1923
|
+
'MkAuth': 'Cannot Find the Data',
|
|
1924
|
+
'Request': UID,
|
|
1925
|
+
'Find': FIND
|
|
1926
|
+
};
|
|
1927
|
+
Terminal(JDebug);
|
|
1928
|
+
return false;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
} else {
|
|
1933
|
+
return false;
|
|
1934
|
+
}
|
|
1935
|
+
};
|
|
1936
|
+
//Check is Json
|
|
1937
|
+
function testJSON(text) {
|
|
1938
|
+
text = text.toString().replace(/"/g, "").replace(/'/g, "");
|
|
1939
|
+
text = text.toString().replace('uid:', '"uid":"').replace(',find:', '","find":"').replace('}', '"}');
|
|
1940
|
+
if (typeof text !== "string") {
|
|
1941
|
+
return false;
|
|
1942
|
+
}
|
|
1943
|
+
try {
|
|
1944
|
+
var json = JSON.parse(text);
|
|
1945
|
+
return (typeof json === 'object');
|
|
1946
|
+
} catch (error) {
|
|
1947
|
+
return false;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
// WhatsApp-web.js Functions
|
|
1952
|
+
const client = new Client({
|
|
1953
|
+
authStrategy: new LocalAuth({
|
|
1954
|
+
clientId: Debug('OPTIONS').appname
|
|
1955
|
+
}),
|
|
1956
|
+
|
|
1957
|
+
puppeteer: {
|
|
1958
|
+
headless: true,
|
|
1959
|
+
args: [
|
|
1960
|
+
'--no-sandbox',
|
|
1961
|
+
'--disable-setuid-sandbox',
|
|
1962
|
+
'--disable-extensions',
|
|
1963
|
+
'--disable-dev-shm-usage',
|
|
1964
|
+
'--disable-accelerated-2d-canvas',
|
|
1965
|
+
'--no-first-run',
|
|
1966
|
+
'--no-zygote',
|
|
1967
|
+
'--single-process',
|
|
1968
|
+
'--disable-gpu'
|
|
1969
|
+
]
|
|
1970
|
+
},
|
|
1971
|
+
});
|
|
1972
|
+
io.on('connection', function(socket) {
|
|
1973
|
+
socket.emit('Version', Package.version);
|
|
1974
|
+
socket.emit('Manager', Debug('MKAUTH').aimbot);
|
|
1975
|
+
socket.emit('Patched', Release(Debug('RELEASE').mwsm));
|
|
1976
|
+
socket.emit('Reset', true);
|
|
1977
|
+
if (Session || Boolean(Debug('OPTIONS').auth)) {
|
|
1978
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').authenticated);
|
|
1979
|
+
socket.emit('qr', Debug('RESOURCES').authenticated);
|
|
1980
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').ready);
|
|
1981
|
+
socket.emit('qr', Debug('RESOURCES').ready);
|
|
1982
|
+
Session = false;
|
|
1983
|
+
} else {
|
|
1984
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').connection);
|
|
1985
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').connection);
|
|
1986
|
+
socket.emit('qr', Debug('RESOURCES').connection);
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
client.on('qr', (qr) => {
|
|
1990
|
+
if (!Session) {
|
|
1991
|
+
qrcode.toDataURL(qr, (err, url) => {
|
|
1992
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').connection);
|
|
1993
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').connection);
|
|
1994
|
+
socket.emit('qr', Debug('RESOURCES').connection);
|
|
1995
|
+
socket.emit('Reset', true);
|
|
1996
|
+
delay(1000).then(async function() {
|
|
1997
|
+
try {
|
|
1998
|
+
socket.emit('qr', url);
|
|
1999
|
+
} catch (err) {
|
|
2000
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + err);
|
|
2001
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + err);
|
|
2002
|
+
} finally {
|
|
2003
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').received);
|
|
2004
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').received);
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
});
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
2010
|
+
});
|
|
2011
|
+
|
|
2012
|
+
client.on('ready', async () => {
|
|
2013
|
+
if (!Boolean(Debug('OPTIONS').auth)) {
|
|
2014
|
+
await link.prepare('UPDATE options SET auth=?').run(1);
|
|
2015
|
+
}
|
|
2016
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').ready);
|
|
2017
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').ready);
|
|
2018
|
+
socket.emit('qr', Debug('RESOURCES').ready);
|
|
2019
|
+
await socket.emit('Reset', false);
|
|
2020
|
+
Session = true;
|
|
2021
|
+
if (!Permission) {
|
|
2022
|
+
Permission = true;
|
|
2023
|
+
await client.sendMessage(client.info.wid["_serialized"], "*Mwsm Token:*\n" + Password[1]);
|
|
2024
|
+
await GetUpdate(WServer, false);
|
|
2025
|
+
await WwjsVersion(false);
|
|
2026
|
+
}
|
|
2027
|
+
});
|
|
2028
|
+
|
|
2029
|
+
client.on('authenticated', (data) => {
|
|
2030
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').authenticated);
|
|
2031
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').authenticated);
|
|
2032
|
+
socket.emit('qr', Debug('RESOURCES').authenticated);
|
|
2033
|
+
Session = true;
|
|
2034
|
+
});
|
|
2035
|
+
|
|
2036
|
+
|
|
2037
|
+
client.on('auth_failure', async () => {
|
|
2038
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').auth_failure);
|
|
2039
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').auth_failure);
|
|
2040
|
+
socket.emit('qr', Debug('RESOURCES').auth_failure);
|
|
2041
|
+
const unLoad = await link.prepare('UPDATE options SET auth=?').run(0);
|
|
2042
|
+
if (await unLoad) {
|
|
2043
|
+
socket.emit('Reset', true);
|
|
2044
|
+
Session = false;
|
|
2045
|
+
wwjsRun = true;
|
|
2046
|
+
}
|
|
2047
|
+
});
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
client.on('disconnected', (reason) => {
|
|
2051
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').disconnected);
|
|
2052
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').disconnected);
|
|
2053
|
+
socket.emit('qr', Debug('RESOURCES').disconnected);
|
|
2054
|
+
db.run("UPDATE options SET auth=?, token=?", [false, null], (err) => {
|
|
2055
|
+
if (err) {
|
|
2056
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + err)
|
|
2057
|
+
}
|
|
2058
|
+
Session = false;
|
|
2059
|
+
wwjsRun = true;
|
|
2060
|
+
});
|
|
2061
|
+
socket.emit('Reset', true);
|
|
2062
|
+
});
|
|
2063
|
+
|
|
2064
|
+
|
|
2065
|
+
client.on('loading_screen', (percent, message) => {
|
|
2066
|
+
Session = false;
|
|
2067
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : Loading application', percent + '%');
|
|
2068
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : Connecting Application ' + percent + '%');
|
|
2069
|
+
if (percent >= "100") {
|
|
2070
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').authenticated);
|
|
2071
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').authenticated);
|
|
2072
|
+
socket.emit('qr', Debug('RESOURCES').authenticated);
|
|
2073
|
+
} else {
|
|
2074
|
+
socket.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').connection);
|
|
2075
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').connection);
|
|
2076
|
+
socket.emit('qr', Debug('RESOURCES').connection);
|
|
2077
|
+
socket.emit('Reset', true);
|
|
2078
|
+
}
|
|
2079
|
+
delay(1000).then(async function() {
|
|
2080
|
+
if (wwjsRun) {
|
|
2081
|
+
wwjsRun = false;
|
|
2082
|
+
WwjsVersion(true);
|
|
2083
|
+
}
|
|
2084
|
+
});
|
|
2085
|
+
});
|
|
2086
|
+
socket.emit('background', Debug('RESOURCES').background);
|
|
2087
|
+
socket.emit('donation', Debug('RESOURCES').about);
|
|
2088
|
+
socket.emit('developer', Debug('RESOURCES').developer);
|
|
2089
|
+
delay(2000).then(async function() {
|
|
2090
|
+
if (Permission) {
|
|
2091
|
+
await GetUpdate(WServer, false);
|
|
2092
|
+
await WwjsVersion(false);
|
|
2093
|
+
}
|
|
2094
|
+
});
|
|
2095
|
+
|
|
2096
|
+
});
|
|
2097
|
+
|
|
2098
|
+
// Reset
|
|
2099
|
+
app.post('/reset', async (req, res) => {
|
|
2100
|
+
const Reset = req.body.reset;
|
|
2101
|
+
const Clear = req.body.erase;
|
|
2102
|
+
const unLoad = await link.prepare('UPDATE options SET auth=?').run(0);
|
|
2103
|
+
if (await unLoad) {
|
|
2104
|
+
global.io.emit('qr', Debug('RESOURCES').connection);
|
|
2105
|
+
global.io.emit('getlog', true);
|
|
2106
|
+
if (Clear == 'true') {
|
|
2107
|
+
const Eraser = await link.prepare('DELETE FROM target').run();
|
|
2108
|
+
if (await Eraser) {
|
|
2109
|
+
const FLUSH = await Dataset('SQLITE_SEQUENCE', 'SEQ', 'TARGET', 'FLUSH');
|
|
2110
|
+
res.json({
|
|
2111
|
+
Status: "Success"
|
|
2112
|
+
});
|
|
2113
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').cleanon);
|
|
2114
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').cleanon);
|
|
2115
|
+
if (await FLUSH) {
|
|
2116
|
+
delay(2000).then(async function() {
|
|
2117
|
+
await exec('npm run restart:mwsm');
|
|
2118
|
+
});
|
|
2119
|
+
}
|
|
2120
|
+
} else {
|
|
2121
|
+
res.json({
|
|
2122
|
+
Status: "Fail"
|
|
2123
|
+
});
|
|
2124
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').cleanoff);
|
|
2125
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').cleanoff);
|
|
2126
|
+
delay(2000).then(async function() {
|
|
2127
|
+
await exec('npm run restart:mwsm');
|
|
2128
|
+
});
|
|
2129
|
+
}
|
|
2130
|
+
} else {
|
|
2131
|
+
if (Reset == "true") {
|
|
2132
|
+
res.json({
|
|
2133
|
+
Status: undefined
|
|
2134
|
+
});
|
|
2135
|
+
global.io.emit('getlog', true);
|
|
2136
|
+
delay(0).then(async function() {
|
|
2137
|
+
await exec('npm run restart:mwsm');
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
});
|
|
2143
|
+
|
|
2144
|
+
// Shutdown
|
|
2145
|
+
app.post('/shutdown', async (req, res) => {
|
|
2146
|
+
const Shutdown = req.body.shutdown;
|
|
2147
|
+
const Token = req.body.token;
|
|
2148
|
+
if (Shutdown == "true" && [Debug('OPTIONS').token, Password[1]].includes(Token)) {
|
|
2149
|
+
res.json({
|
|
2150
|
+
Status: "Success"
|
|
2151
|
+
});
|
|
2152
|
+
global.io.emit('getlog', true);
|
|
2153
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').disconnected);
|
|
2154
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').disconnected);
|
|
2155
|
+
global.io.emit('qr', Debug('RESOURCES').disconnected);
|
|
2156
|
+
const Logout = await client.logout();
|
|
2157
|
+
if (Logout) {
|
|
2158
|
+
db.run("UPDATE options SET auth=?, token=?", [false, null], (err) => {
|
|
2159
|
+
if (err) {
|
|
2160
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + err)
|
|
2161
|
+
}
|
|
2162
|
+
global.io.emit('Reset', true);
|
|
2163
|
+
Session = false;
|
|
2164
|
+
});
|
|
2165
|
+
const Destroy = await client.destroy();
|
|
2166
|
+
if (Destroy) {
|
|
2167
|
+
delay(0).then(async function() {
|
|
2168
|
+
await exec('npm run restart:mwsm');
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
} else {
|
|
2173
|
+
res.json({
|
|
2174
|
+
Status: "Fail",
|
|
2175
|
+
Return: Debug('CONSOLE').wrong
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
});
|
|
2179
|
+
|
|
2180
|
+
|
|
2181
|
+
// Authenticated
|
|
2182
|
+
app.post('/authenticated', (req, res) => {
|
|
2183
|
+
if (Boolean(Debug('OPTIONS').auth)) {
|
|
2184
|
+
res.json({
|
|
2185
|
+
Status: "Success"
|
|
2186
|
+
});
|
|
2187
|
+
|
|
2188
|
+
} else {
|
|
2189
|
+
res.json({
|
|
2190
|
+
Status: "Fail"
|
|
2191
|
+
});
|
|
2192
|
+
}
|
|
2193
|
+
});
|
|
2194
|
+
|
|
2195
|
+
// Debug
|
|
2196
|
+
app.post('/debug', (req, res) => {
|
|
2197
|
+
const debug = req.body.debug;
|
|
2198
|
+
if (Debug('OPTIONS').debugger != debug) {
|
|
2199
|
+
db.run("UPDATE options SET debugger=?", [debug], (err) => {
|
|
2200
|
+
if (err) {
|
|
2201
|
+
res.json({
|
|
2202
|
+
Status: "Fail",
|
|
2203
|
+
Return: Debug('OPTIONS').debugger
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
res.json({
|
|
2207
|
+
Status: "Success",
|
|
2208
|
+
Return: debug
|
|
2209
|
+
});
|
|
2210
|
+
});
|
|
2211
|
+
}
|
|
2212
|
+
});
|
|
2213
|
+
|
|
2214
|
+
// MkAuth Set Message
|
|
2215
|
+
app.post('/send-mkauth', async (req, res) => {
|
|
2216
|
+
const User = req.body.user;
|
|
2217
|
+
const Client = req.body.client;
|
|
2218
|
+
const Code = req.body.code;
|
|
2219
|
+
const Status = req.body.status;
|
|
2220
|
+
const Reward = req.body.reward;
|
|
2221
|
+
const Push = req.body.push;
|
|
2222
|
+
const Token = req.body.token;
|
|
2223
|
+
const Cash = req.body.cash;
|
|
2224
|
+
const Gateway = req.body.gateway;
|
|
2225
|
+
const UnLock = req.body.unlock;
|
|
2226
|
+
const Option = req.body.option;
|
|
2227
|
+
const Speed = Debug('SCHEDULER').speed;
|
|
2228
|
+
const Block = Debug('SCHEDULER').block;
|
|
2229
|
+
const Factor = req.body.process
|
|
2230
|
+
var Contact = req.body.contact;
|
|
2231
|
+
var Process, Direct, Storange;
|
|
2232
|
+
var Pulse = DateTime();
|
|
2233
|
+
var Payment = req.body.payment;
|
|
2234
|
+
if (validPhone(Playground)) {
|
|
2235
|
+
Contact = '55' + Playground;
|
|
2236
|
+
}
|
|
2237
|
+
if (Option == "support") {
|
|
2238
|
+
Payment = "support";
|
|
2239
|
+
} else if ((Reward.split(" ")[0]) == (DateTime()).split(" ")[0] && Payment != "paid") {
|
|
2240
|
+
Payment = "open";
|
|
2241
|
+
}
|
|
2242
|
+
switch (await Payment) {
|
|
2243
|
+
case 'paid':
|
|
2244
|
+
if (Boolean(Debug('SCHEDULER').onunlock) || Boolean(Debug('SCHEDULER').onlock)) {
|
|
2245
|
+
switch (Factor) {
|
|
2246
|
+
case 'unlock':
|
|
2247
|
+
Message = DebugMsg("PAY") + "##" + (DebugMsg("UNLOCK")).split(", ")[1];
|
|
2248
|
+
break;
|
|
2249
|
+
default:
|
|
2250
|
+
Message = DebugMsg("PAY");
|
|
2251
|
+
}
|
|
2252
|
+
} else {
|
|
2253
|
+
Message = DebugMsg("PAY");
|
|
2254
|
+
}
|
|
2255
|
+
if (Status.toLowerCase() != "finished") {
|
|
2256
|
+
Process = "Finished";
|
|
2257
|
+
}
|
|
2258
|
+
Direct = "Pay";
|
|
2259
|
+
break;
|
|
2260
|
+
case 'due':
|
|
2261
|
+
if ((Reward.split(" ")[0]) == (DateTime()).split(" ")[0]) {
|
|
2262
|
+
Message = DebugMsg("DAY");
|
|
2263
|
+
} else if (Option != undefined) {
|
|
2264
|
+
if (Boolean(Debug('SCHEDULER').onspeed) && Option == 'speed') {
|
|
2265
|
+
Message = DebugMsg("SPEED");
|
|
2266
|
+
} else if (Boolean(Debug('SCHEDULER').onblock) && Option == 'block') {
|
|
2267
|
+
Message = DebugMsg("BLOCK");
|
|
2268
|
+
} else {
|
|
2269
|
+
Message = DebugMsg("LATER");
|
|
2270
|
+
}
|
|
2271
|
+
} else if (UnLock != undefined) {
|
|
2272
|
+
if (Boolean(Debug('SCHEDULER').onunlock) || Boolean(Debug('SCHEDULER').onlock)) {
|
|
2273
|
+
switch (Factor) {
|
|
2274
|
+
case 'unlock':
|
|
2275
|
+
Message = DebugMsg("UNLOCK");
|
|
2276
|
+
break;
|
|
2277
|
+
case 'lock':
|
|
2278
|
+
Message = DebugMsg("LOCK");
|
|
2279
|
+
break;
|
|
2280
|
+
default:
|
|
2281
|
+
Message = DebugMsg("LATER");
|
|
2282
|
+
}
|
|
2283
|
+
} else {
|
|
2284
|
+
Message = DebugMsg("LATER");
|
|
2285
|
+
}
|
|
2286
|
+
} else {
|
|
2287
|
+
Message = DebugMsg("LATER");
|
|
2288
|
+
}
|
|
2289
|
+
if (Status.toLowerCase() == "pending" || Status.toLowerCase() == "fail") {
|
|
2290
|
+
Process = "Sent";
|
|
2291
|
+
} else if (Status.toLowerCase() == "sent" || Status.toLowerCase() == "resend") {
|
|
2292
|
+
Process = "Resend";
|
|
2293
|
+
}
|
|
2294
|
+
break;
|
|
2295
|
+
case 'open':
|
|
2296
|
+
if ((Reward.split(" ")[0]) == (DateTime()).split(" ")[0]) {
|
|
2297
|
+
Message = DebugMsg("DAY");
|
|
2298
|
+
} else {
|
|
2299
|
+
Message = DebugMsg("BEFORE");
|
|
2300
|
+
}
|
|
2301
|
+
if (Status.toLowerCase() == "pending" || Status.toLowerCase() == "fail") {
|
|
2302
|
+
Process = "Sent";
|
|
2303
|
+
} else if (Status.toLowerCase() == "sent" || Status.toLowerCase() == "resend") {
|
|
2304
|
+
Process = "Resend";
|
|
2305
|
+
}
|
|
2306
|
+
break;
|
|
2307
|
+
case 'support':
|
|
2308
|
+
Message = DebugMsg("SUPPORT");
|
|
2309
|
+
break;
|
|
2310
|
+
|
|
2311
|
+
}
|
|
2312
|
+
Mensagem = Message.replaceAll('%nomeresumido%', toCapitalize(Client.split(" ")[0])).replaceAll('%vencimento%', new Date(Reward).toLocaleString("pt-br").split(",")[0]).replaceAll('%logincliente%', User).replaceAll('%valorpago%', Cash).replaceAll('%bloqatrazo%', Block).replaceAll('%metodo%', Gateway).replaceAll('%reduzatrazo%', Speed).replaceAll('%numerotitulo%', Code).replaceAll('%pagamento%', new Date(Pulse).toLocaleString("pt-br").split(",")[0] + " as " + (Pulse.split(" ")[1]).split(":")[0] + ":" + (Pulse.split(" ")[1]).split(":")[1]);
|
|
2313
|
+
if ([Debug('OPTIONS').token, Password[1]].includes(Token) && validPhone(Contact)) {
|
|
2314
|
+
const data = {
|
|
2315
|
+
to: '55' + Contact,
|
|
2316
|
+
msg: Mensagem,
|
|
2317
|
+
pass: Token,
|
|
2318
|
+
send: Direct,
|
|
2319
|
+
user: Client,
|
|
2320
|
+
auth: Debug('MKAUTH').aimbot
|
|
2321
|
+
};
|
|
2322
|
+
Start = false;
|
|
2323
|
+
const PostMessage = await axios.post("http://" + ip.address() + ":" + Debug('OPTIONS').access + "/send-message", data);
|
|
2324
|
+
if (await PostMessage) {
|
|
2325
|
+
if (PostMessage.data.Status == "Fail") {
|
|
2326
|
+
Process = "Fail";
|
|
2327
|
+
}
|
|
2328
|
+
if (Debug("STORANGE", "*", "DIRECT", Code).title == undefined) {
|
|
2329
|
+
Storange = await link.prepare("INSERT INTO storange(title, user, client, contact, reward, status, push) VALUES(?, ?, ?, ?, ?, ?, ?)").run(Code, User, Client, Contact, Reward, Process, Pulse);
|
|
2330
|
+
} else {
|
|
2331
|
+
Storange = db.run("UPDATE storange SET push=?, status=? WHERE title=?", [Pulse, Process, Code], (err) => {
|
|
2332
|
+
if (err) {
|
|
2333
|
+
return false;
|
|
2334
|
+
}
|
|
2335
|
+
return true;
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
return res.json({
|
|
2339
|
+
Status: PostMessage.data.Status,
|
|
2340
|
+
Return: PostMessage.data.message,
|
|
2341
|
+
RPush: Pulse,
|
|
2342
|
+
RStatus: Process,
|
|
2343
|
+
RCode: Code
|
|
2344
|
+
});
|
|
2345
|
+
} else {
|
|
2346
|
+
res.json({
|
|
2347
|
+
Status: "Fail",
|
|
2348
|
+
Return: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error,
|
|
2349
|
+
RPush: Pulse,
|
|
2350
|
+
RStatus: Process,
|
|
2351
|
+
RCode: Code
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
} else {
|
|
2355
|
+
Json = {
|
|
2356
|
+
"Mwsm": "/mwsm-message",
|
|
2357
|
+
"Main": "Mwsm",
|
|
2358
|
+
"Start": DateTime()
|
|
2359
|
+
};
|
|
2360
|
+
if (typeof Json === 'object') {
|
|
2361
|
+
Json = JSON.stringify(Json);
|
|
2362
|
+
}
|
|
2363
|
+
console.error(Print.bg.blue, Print.fg.white, Json, Print.reset);
|
|
2364
|
+
Process = "Fail";
|
|
2365
|
+
if (Debug("STORANGE", "*", "DIRECT", Code).title == undefined) {
|
|
2366
|
+
Storange = await link.prepare("INSERT INTO storange(title, user, client, contact, reward, status, push) VALUES(?, ?, ?, ?, ?, ?, ?)").run(Code, User, Client, Contact, Reward, Process, Pulse);
|
|
2367
|
+
} else {
|
|
2368
|
+
Storange = db.run("UPDATE storange SET push=?, status=? WHERE title=?", [Pulse, Process, Code], (err) => {
|
|
2369
|
+
if (err) {
|
|
2370
|
+
return false;
|
|
2371
|
+
}
|
|
2372
|
+
return true;
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
|
|
2377
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
2378
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
2379
|
+
res.json({
|
|
2380
|
+
Status: "Fail",
|
|
2381
|
+
Return: Debug('CONSOLE').missing,
|
|
2382
|
+
RPush: Pulse,
|
|
2383
|
+
RStatus: Process,
|
|
2384
|
+
RCode: Code
|
|
2385
|
+
|
|
2386
|
+
});
|
|
2387
|
+
}
|
|
2388
|
+
});
|
|
2389
|
+
|
|
2390
|
+
|
|
2391
|
+
// API Update
|
|
2392
|
+
app.post('/update', async (req, res) => {
|
|
2393
|
+
const UP = req.body.uptodate;
|
|
2394
|
+
if (Debug('RELEASE').isupdate != UP) {
|
|
2395
|
+
const Update = await Dataset('RELEASE', 'ISUPDATE', UP, 'UPDATE');
|
|
2396
|
+
if (Update) {
|
|
2397
|
+
res.json({
|
|
2398
|
+
Status: "Success",
|
|
2399
|
+
Return: UP
|
|
2400
|
+
});
|
|
2401
|
+
} else {
|
|
2402
|
+
res.json({
|
|
2403
|
+
Status: "Fail",
|
|
2404
|
+
Return: Debug('RELEASE').isupdate
|
|
2405
|
+
});
|
|
2406
|
+
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
});
|
|
2410
|
+
|
|
2411
|
+
|
|
2412
|
+
// API Protect
|
|
2413
|
+
app.post('/protected', (req, res) => {
|
|
2414
|
+
const Protect = req.body.protect;
|
|
2415
|
+
if (Debug('OPTIONS').protect != Protect) {
|
|
2416
|
+
db.run("UPDATE options SET protect=?", [Protect], (err) => {
|
|
2417
|
+
if (err) {
|
|
2418
|
+
res.json({
|
|
2419
|
+
Status: "Fail",
|
|
2420
|
+
Return: Debug('OPTIONS').protect
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
res.json({
|
|
2424
|
+
Status: "Success",
|
|
2425
|
+
Return: Protect
|
|
2426
|
+
});
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
});
|
|
2430
|
+
|
|
2431
|
+
// Tag
|
|
2432
|
+
app.post('/tag', (req, res) => {
|
|
2433
|
+
const Tag = req.body.tag;
|
|
2434
|
+
if (Debug('OPTIONS').tag != Tag) {
|
|
2435
|
+
db.run("UPDATE options SET tag=?", [Tag], (err) => {
|
|
2436
|
+
if (err) {
|
|
2437
|
+
res.json({
|
|
2438
|
+
Status: "Fail",
|
|
2439
|
+
Return: Debug('OPTIONS').tag
|
|
2440
|
+
});
|
|
2441
|
+
}
|
|
2442
|
+
res.json({
|
|
2443
|
+
Status: "Success",
|
|
2444
|
+
Return: Tag
|
|
2445
|
+
});
|
|
2446
|
+
});
|
|
2447
|
+
}
|
|
2448
|
+
});
|
|
2449
|
+
|
|
2450
|
+
|
|
2451
|
+
// Backup
|
|
2452
|
+
app.post('/backup', (req, res) => {
|
|
2453
|
+
const Backup = req.body.backup;
|
|
2454
|
+
if (Debug('MKAUTH').backup != Backup) {
|
|
2455
|
+
db.run("UPDATE mkauth SET backup=?", [Backup], (err) => {
|
|
2456
|
+
if (err) {
|
|
2457
|
+
res.json({
|
|
2458
|
+
Status: "Fail",
|
|
2459
|
+
Return: Debug('MKAUTH').backup
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2462
|
+
res.json({
|
|
2463
|
+
Status: "Success",
|
|
2464
|
+
Return: Backup
|
|
2465
|
+
});
|
|
2466
|
+
});
|
|
2467
|
+
}
|
|
2468
|
+
});
|
|
2469
|
+
|
|
2470
|
+
// Prevent
|
|
2471
|
+
app.post('/prevent', (req, res) => {
|
|
2472
|
+
const Prevent = req.body.prevent;
|
|
2473
|
+
if (Debug('MKAUTH').prevent != Prevent) {
|
|
2474
|
+
db.run("UPDATE mkauth SET prevent=?", [Prevent], (err) => {
|
|
2475
|
+
if (err) {
|
|
2476
|
+
res.json({
|
|
2477
|
+
Status: "Fail",
|
|
2478
|
+
Return: Debug('MKAUTH').prevent
|
|
2479
|
+
});
|
|
2480
|
+
}
|
|
2481
|
+
res.json({
|
|
2482
|
+
Status: "Success",
|
|
2483
|
+
Return: Prevent
|
|
2484
|
+
});
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
});
|
|
2488
|
+
|
|
2489
|
+
// RegEx
|
|
2490
|
+
app.post('/regex', (req, res) => {
|
|
2491
|
+
const RegEx = req.body.regex;
|
|
2492
|
+
if (Debug('OPTIONS').regex != RegEx) {
|
|
2493
|
+
db.run("UPDATE options SET regex=?", [RegEx], (err) => {
|
|
2494
|
+
if (err) {
|
|
2495
|
+
res.json({
|
|
2496
|
+
Status: "Fail",
|
|
2497
|
+
Return: Debug('OPTIONS').regex
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2500
|
+
res.json({
|
|
2501
|
+
Status: "Success",
|
|
2502
|
+
Return: RegEx
|
|
2503
|
+
});
|
|
2504
|
+
});
|
|
2505
|
+
}
|
|
2506
|
+
});
|
|
2507
|
+
|
|
2508
|
+
const Emoticons = async (FIND, IN, OUT) => {
|
|
2509
|
+
return link.prepare('SELECT ' + OUT + ' FROM emotions WHERE ' + IN + '= ?').get(FIND);
|
|
2510
|
+
}
|
|
2511
|
+
app.post('/emoji', async (req, res) => {
|
|
2512
|
+
const FIND = req.body.find;
|
|
2513
|
+
const IN = req.body.in;
|
|
2514
|
+
const OUT = req.body.out;
|
|
2515
|
+
if (IN == "emoji") {
|
|
2516
|
+
var Emoji = emoji.unemojify(FIND);
|
|
2517
|
+
} else {
|
|
2518
|
+
var Emoji = await Emoticons(FIND, IN, OUT);
|
|
2519
|
+
}
|
|
2520
|
+
if (await Emoji) {
|
|
2521
|
+
if (IN != "emoji" && IN != "socket") {
|
|
2522
|
+
switch (OUT) {
|
|
2523
|
+
case 'unicode':
|
|
2524
|
+
Emoji = Emoji.unicode;
|
|
2525
|
+
break;
|
|
2526
|
+
case 'html':
|
|
2527
|
+
Emoji = Emoji.html;
|
|
2528
|
+
break;
|
|
2529
|
+
case 'emoji':
|
|
2530
|
+
Emoji = Emoji.emoji;
|
|
2531
|
+
break;
|
|
2532
|
+
case 'name':
|
|
2533
|
+
Emoji = Emoji.name;
|
|
2534
|
+
break;
|
|
2535
|
+
case 'key':
|
|
2536
|
+
Emoji = Emoji.key;
|
|
2537
|
+
break;
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
}
|
|
2541
|
+
if (Emoji != undefined) {
|
|
2542
|
+
res.json({
|
|
2543
|
+
Status: "Success",
|
|
2544
|
+
Return: Emoji
|
|
2545
|
+
});
|
|
2546
|
+
} else {
|
|
2547
|
+
res.json({
|
|
2548
|
+
Status: "Fail",
|
|
2549
|
+
Return: FIND
|
|
2550
|
+
});
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
});
|
|
2554
|
+
|
|
2555
|
+
// Force Update
|
|
2556
|
+
app.post('/forceupdate', async (req, res) => {
|
|
2557
|
+
const Update = req.body.update;
|
|
2558
|
+
if (Debug('RELEASE').isupdate != Update) {
|
|
2559
|
+
await Dataset('RELEASE', 'reload', 'true', 'UPDATE');
|
|
2560
|
+
const Register = await GetUpdate(WServer, true, true);
|
|
2561
|
+
await Dataset('RELEASE', 'reload', 'false', 'UPDATE');
|
|
2562
|
+
if (Register.Update == "true") {
|
|
2563
|
+
res.json({
|
|
2564
|
+
Status: "Success"
|
|
2565
|
+
});
|
|
2566
|
+
} else {
|
|
2567
|
+
res.json({
|
|
2568
|
+
Status: "Fail"
|
|
2569
|
+
});
|
|
2570
|
+
}
|
|
2571
|
+
} else {
|
|
2572
|
+
res.json({
|
|
2573
|
+
Status: "Fail"
|
|
2574
|
+
});
|
|
2575
|
+
}
|
|
2576
|
+
});
|
|
2577
|
+
|
|
2578
|
+
|
|
2579
|
+
// Force Bakcup
|
|
2580
|
+
app.post('/forcebackup', async (req, res) => {
|
|
2581
|
+
await Dataset('RELEASE', 'reload', 'true', 'UPDATE');
|
|
2582
|
+
const Backup = req.body.backup;
|
|
2583
|
+
if (Boolean(Backup)) {
|
|
2584
|
+
const Reload = await SetSchedule(true);
|
|
2585
|
+
if (await Reload) {
|
|
2586
|
+
await Dataset('RELEASE', 'reload', 'false', 'UPDATE');
|
|
2587
|
+
return res.json({
|
|
2588
|
+
Status: "Success",
|
|
2589
|
+
Return: Debug('CONSOLE').schedule
|
|
2590
|
+
});
|
|
2591
|
+
} else {
|
|
2592
|
+
await Dataset('RELEASE', 'reload', 'false', 'UPDATE');
|
|
2593
|
+
return res.json({
|
|
2594
|
+
Status: "Fail",
|
|
2595
|
+
Return: Debug('CONSOLE').request
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
});
|
|
2600
|
+
|
|
2601
|
+
|
|
2602
|
+
|
|
2603
|
+
// Spam
|
|
2604
|
+
app.post('/spam', (req, res) => {
|
|
2605
|
+
const Level = req.body.level;
|
|
2606
|
+
if (Debug('MKAUTH').level != Level) {
|
|
2607
|
+
db.run("UPDATE mkauth SET level=?", [Level], (err) => {
|
|
2608
|
+
if (err) {
|
|
2609
|
+
res.json({
|
|
2610
|
+
Status: "Fail",
|
|
2611
|
+
Return: Debug('MKAUTH').level
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
res.json({
|
|
2615
|
+
Status: "Success",
|
|
2616
|
+
Return: Level
|
|
2617
|
+
});
|
|
2618
|
+
});
|
|
2619
|
+
}
|
|
2620
|
+
});
|
|
2621
|
+
|
|
2622
|
+
|
|
2623
|
+
// Shift
|
|
2624
|
+
app.post('/shift', async (req, res) => {
|
|
2625
|
+
const Shift = req.body.shift;
|
|
2626
|
+
const Min = req.body.min;
|
|
2627
|
+
const Max = req.body.max;
|
|
2628
|
+
const hasShift = await Dataset('SCHEDULER', 'shift', Shift, 'UPDATE');
|
|
2629
|
+
if (await hasShift) {
|
|
2630
|
+
if (Boolean(Debug('SCHEDULER').shift)) {
|
|
2631
|
+
const hasMin = await Dataset('SCHEDULER', 'min', Min, 'UPDATE');
|
|
2632
|
+
const hasMax = await Dataset('SCHEDULER', 'max', Max, 'UPDATE');
|
|
2633
|
+
if (await hasMin && await hasMax) {
|
|
2634
|
+
res.json({
|
|
2635
|
+
Status: "Success",
|
|
2636
|
+
Return: true
|
|
2637
|
+
});
|
|
2638
|
+
} else {
|
|
2639
|
+
res.json({
|
|
2640
|
+
Status: "Fail",
|
|
2641
|
+
Return: false
|
|
2642
|
+
});
|
|
2643
|
+
|
|
2644
|
+
}
|
|
2645
|
+
} else {
|
|
2646
|
+
const hasMin = await Dataset('SCHEDULER', 'min', '08', 'UPDATE');
|
|
2647
|
+
const hasMax = await Dataset('SCHEDULER', 'max', '22', 'UPDATE');
|
|
2648
|
+
if (await hasMin && await hasMax) {
|
|
2649
|
+
res.json({
|
|
2650
|
+
Status: "Success",
|
|
2651
|
+
Return: false
|
|
2652
|
+
});
|
|
2653
|
+
} else {
|
|
2654
|
+
res.json({
|
|
2655
|
+
Status: "Fail",
|
|
2656
|
+
Return: false
|
|
2657
|
+
});
|
|
2658
|
+
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
});
|
|
2663
|
+
|
|
2664
|
+
// Aimbot
|
|
2665
|
+
app.post('/aimbot', async (req, res) => {
|
|
2666
|
+
const Aimbot = req.body.aimbot;
|
|
2667
|
+
const Base = await Dataset('MKAUTH', 'AIMBOT', Aimbot, 'UPDATE');
|
|
2668
|
+
if (await Base) {
|
|
2669
|
+
if (Boolean(Debug('MKAUTH').aimbot)) {
|
|
2670
|
+
res.json({
|
|
2671
|
+
Status: "Success",
|
|
2672
|
+
Return: true
|
|
2673
|
+
});
|
|
2674
|
+
|
|
2675
|
+
} else {
|
|
2676
|
+
res.json({
|
|
2677
|
+
Status: "Success",
|
|
2678
|
+
Return: false
|
|
2679
|
+
});
|
|
2680
|
+
}
|
|
2681
|
+
} else {
|
|
2682
|
+
res.json({
|
|
2683
|
+
Status: "Fail",
|
|
2684
|
+
Return: false
|
|
2685
|
+
});
|
|
2686
|
+
}
|
|
2687
|
+
});
|
|
2688
|
+
|
|
2689
|
+
|
|
2690
|
+
// Token
|
|
2691
|
+
app.post('/token', async (req, res) => {
|
|
2692
|
+
const Token = req.body.token;
|
|
2693
|
+
if ([Debug('OPTIONS').token, Password[1]].includes(Token)) {
|
|
2694
|
+
global.io.emit('interval', Debug('OPTIONS').interval);
|
|
2695
|
+
global.io.emit('sleep', Debug('OPTIONS').sleep);
|
|
2696
|
+
global.io.emit('sendwait', Debug('OPTIONS').sendwait);
|
|
2697
|
+
global.io.emit('response', Debug('OPTIONS').response);
|
|
2698
|
+
global.io.emit('call', Debug('OPTIONS').call);
|
|
2699
|
+
global.io.emit('access', Debug('OPTIONS').access);
|
|
2700
|
+
global.io.emit('port', Debug('OPTIONS').access);
|
|
2701
|
+
global.io.emit('pixfail', Debug('OPTIONS').pixfail);
|
|
2702
|
+
global.io.emit('replyes', Debug('OPTIONS').replyes);
|
|
2703
|
+
global.io.emit('alert', Debug('OPTIONS').alert);
|
|
2704
|
+
global.io.emit('count', Debug('OPTIONS').count);
|
|
2705
|
+
global.io.emit('onbot', Debug('OPTIONS').onbot);
|
|
2706
|
+
global.io.emit('reject', Debug('OPTIONS').reject);
|
|
2707
|
+
global.io.emit('limiter', Debug('OPTIONS').limiter);
|
|
2708
|
+
global.io.emit('domain', Debug('MKAUTH').domain);
|
|
2709
|
+
global.io.emit('tunel', Debug('MKAUTH').tunel);
|
|
2710
|
+
global.io.emit('username', Debug('MKAUTH').client_id);
|
|
2711
|
+
global.io.emit('password', Debug('MKAUTH').client_secret);
|
|
2712
|
+
global.io.emit('module', Debug('MKAUTH').module);
|
|
2713
|
+
global.io.emit('bar', Debug('MKAUTH').bar);
|
|
2714
|
+
global.io.emit('pix', Debug('MKAUTH').pix);
|
|
2715
|
+
global.io.emit('qrpix', Debug('MKAUTH').qrpix);
|
|
2716
|
+
global.io.emit('qrlink', Debug('MKAUTH').qrlink);
|
|
2717
|
+
global.io.emit('pdf', Debug('MKAUTH').pdf);
|
|
2718
|
+
global.io.emit('delay', Debug('MKAUTH').delay);
|
|
2719
|
+
global.io.emit('iserver', Debug('MKAUTH').client_link);
|
|
2720
|
+
global.io.emit('imode', Debug('MKAUTH').mode);
|
|
2721
|
+
|
|
2722
|
+
global.io.emit('debugger', Debug('OPTIONS').debugger);
|
|
2723
|
+
global.io.emit('Tag', Debug('OPTIONS').tag);
|
|
2724
|
+
global.io.emit('regex', Debug('OPTIONS').regex);
|
|
2725
|
+
global.io.emit('uptodate', Debug('RELEASE').isupdate);
|
|
2726
|
+
global.io.emit('protected', Debug('OPTIONS').protect);
|
|
2727
|
+
global.io.emit('spam', Debug('MKAUTH').level);
|
|
2728
|
+
global.io.emit('backup', Debug('MKAUTH').backup);
|
|
2729
|
+
global.io.emit('aimbot', Debug('MKAUTH').aimbot);
|
|
2730
|
+
global.io.emit('doublekill', Debug('MKAUTH').prevent);
|
|
2731
|
+
global.io.emit('ismonth', (DateTime().split('-')[1]));
|
|
2732
|
+
global.io.emit('isyear', (DateTime().split('-')[0]));
|
|
2733
|
+
global.io.emit('issearch', 'all');
|
|
2734
|
+
|
|
2735
|
+
global.io.emit('bfive', Debug('SCHEDULER').bfive);
|
|
2736
|
+
global.io.emit('inday', Debug('SCHEDULER').inday);
|
|
2737
|
+
global.io.emit('lfive', Debug('SCHEDULER').lfive);
|
|
2738
|
+
global.io.emit('lten', Debug('SCHEDULER').lten);
|
|
2739
|
+
global.io.emit('lfifteen', Debug('SCHEDULER').lfifteen);
|
|
2740
|
+
global.io.emit('ltwenty', Debug('SCHEDULER').ltwenty);
|
|
2741
|
+
global.io.emit('ltwentyfive', Debug('SCHEDULER').ltwentyfive);
|
|
2742
|
+
global.io.emit('lthirty', Debug('SCHEDULER').lthirty);
|
|
2743
|
+
global.io.emit('lthirtyfive', Debug('SCHEDULER').lthirtyfive);
|
|
2744
|
+
global.io.emit('lforty', Debug('SCHEDULER').lforty);
|
|
2745
|
+
global.io.emit('shift', Debug('SCHEDULER').shift);
|
|
2746
|
+
global.io.emit('min', AddZero(Debug('SCHEDULER').min));
|
|
2747
|
+
global.io.emit('max', Debug('SCHEDULER').max);
|
|
2748
|
+
|
|
2749
|
+
|
|
2750
|
+
global.io.emit('sunday', Debug('SCHEDULER').sunday);
|
|
2751
|
+
global.io.emit('monday', Debug('SCHEDULER').monday);
|
|
2752
|
+
global.io.emit('tuesday', Debug('SCHEDULER').tuesday);
|
|
2753
|
+
global.io.emit('wednesday', Debug('SCHEDULER').wednesday);
|
|
2754
|
+
global.io.emit('thursday', Debug('SCHEDULER').thursday);
|
|
2755
|
+
global.io.emit('friday', Debug('SCHEDULER').friday);
|
|
2756
|
+
global.io.emit('saturday', Debug('SCHEDULER').saturday);
|
|
2757
|
+
global.io.emit('morning', Debug('SCHEDULER').morning);
|
|
2758
|
+
global.io.emit('afternoon', Debug('SCHEDULER').afternoon);
|
|
2759
|
+
global.io.emit('night', Debug('SCHEDULER').night);
|
|
2760
|
+
|
|
2761
|
+
global.io.emit('OnPay', Debug('SCHEDULER').onpay);
|
|
2762
|
+
global.io.emit('OnLock', Debug('SCHEDULER').onlock);
|
|
2763
|
+
global.io.emit('OnUnlock', Debug('SCHEDULER').onunlock);
|
|
2764
|
+
global.io.emit('OnMaintenance', Debug('SCHEDULER').onmaintenance);
|
|
2765
|
+
global.io.emit('OnUnistall', Debug('SCHEDULER').onunistall);
|
|
2766
|
+
|
|
2767
|
+
global.io.emit('OnSpeed', Debug('SCHEDULER').onspeed);
|
|
2768
|
+
global.io.emit('OnBlock', Debug('SCHEDULER').onblock);
|
|
2769
|
+
global.io.emit('OnSupport', Debug('SCHEDULER').onsupport);
|
|
2770
|
+
global.io.emit('Speed', Debug('SCHEDULER').speed);
|
|
2771
|
+
global.io.emit('Block', Debug('SCHEDULER').block);
|
|
2772
|
+
global.io.emit('Crontab', Debug('SCHEDULER').cron);
|
|
2773
|
+
|
|
2774
|
+
|
|
2775
|
+
global.io.emit('A001', emoji.emojify(Debug('MESSAGE', '*', 'ID', '1').before));
|
|
2776
|
+
global.io.emit('A002', emoji.emojify(Debug('MESSAGE', '*', 'ID', '1').day));
|
|
2777
|
+
global.io.emit('A003', emoji.emojify(Debug('MESSAGE', '*', 'ID', '1').later));
|
|
2778
|
+
global.io.emit('A004', emoji.emojify(Debug('MESSAGE', '*', 'ID', '1').pay));
|
|
2779
|
+
global.io.emit('A005', emoji.emojify(Debug('MESSAGE', '*', 'ID', '1').lock));
|
|
2780
|
+
global.io.emit('A006', emoji.emojify(Debug('MESSAGE', '*', 'ID', '1').unlock));
|
|
2781
|
+
global.io.emit('A007', emoji.emojify(Debug('MESSAGE', '*', 'ID', '1').maintenance));
|
|
2782
|
+
global.io.emit('A008', emoji.emojify(Debug('MESSAGE', '*', 'ID', '1').unistall));
|
|
2783
|
+
|
|
2784
|
+
global.io.emit('A009', emoji.emojify(Debug('MESSAGE', '*', 'ID', '1').speed));
|
|
2785
|
+
global.io.emit('A010', emoji.emojify(Debug('MESSAGE', '*', 'ID', '1').block));
|
|
2786
|
+
global.io.emit('A011', emoji.emojify(Debug('MESSAGE', '*', 'ID', '1').support));
|
|
2787
|
+
|
|
2788
|
+
global.io.emit('B001', emoji.emojify(Debug('MESSAGE', '*', 'ID', '2').before));
|
|
2789
|
+
global.io.emit('B002', emoji.emojify(Debug('MESSAGE', '*', 'ID', '2').day));
|
|
2790
|
+
global.io.emit('B003', emoji.emojify(Debug('MESSAGE', '*', 'ID', '2').later));
|
|
2791
|
+
global.io.emit('B004', emoji.emojify(Debug('MESSAGE', '*', 'ID', '2').pay));
|
|
2792
|
+
global.io.emit('B005', emoji.emojify(Debug('MESSAGE', '*', 'ID', '2').lock));
|
|
2793
|
+
global.io.emit('B006', emoji.emojify(Debug('MESSAGE', '*', 'ID', '2').unlock));
|
|
2794
|
+
global.io.emit('B007', emoji.emojify(Debug('MESSAGE', '*', 'ID', '2').maintenance));
|
|
2795
|
+
global.io.emit('B008', emoji.emojify(Debug('MESSAGE', '*', 'ID', '2').unistall));
|
|
2796
|
+
|
|
2797
|
+
global.io.emit('B009', emoji.emojify(Debug('MESSAGE', '*', 'ID', '2').speed));
|
|
2798
|
+
global.io.emit('B010', emoji.emojify(Debug('MESSAGE', '*', 'ID', '2').block));
|
|
2799
|
+
global.io.emit('B011', emoji.emojify(Debug('MESSAGE', '*', 'ID', '2').support));
|
|
2800
|
+
|
|
2801
|
+
global.io.emit('C001', emoji.emojify(Debug('MESSAGE', '*', 'ID', '3').before));
|
|
2802
|
+
global.io.emit('C002', emoji.emojify(Debug('MESSAGE', '*', 'ID', '3').day));
|
|
2803
|
+
global.io.emit('C003', emoji.emojify(Debug('MESSAGE', '*', 'ID', '3').later));
|
|
2804
|
+
global.io.emit('C004', emoji.emojify(Debug('MESSAGE', '*', 'ID', '3').pay));
|
|
2805
|
+
global.io.emit('C005', emoji.emojify(Debug('MESSAGE', '*', 'ID', '3').lock));
|
|
2806
|
+
global.io.emit('C006', emoji.emojify(Debug('MESSAGE', '*', 'ID', '3').unlock));
|
|
2807
|
+
global.io.emit('C007', emoji.emojify(Debug('MESSAGE', '*', 'ID', '3').maintenance));
|
|
2808
|
+
global.io.emit('C008', emoji.emojify(Debug('MESSAGE', '*', 'ID', '3').unistall));
|
|
2809
|
+
|
|
2810
|
+
global.io.emit('C009', emoji.emojify(Debug('MESSAGE', '*', 'ID', '3').speed));
|
|
2811
|
+
global.io.emit('C010', emoji.emojify(Debug('MESSAGE', '*', 'ID', '3').block));
|
|
2812
|
+
global.io.emit('C011', emoji.emojify(Debug('MESSAGE', '*', 'ID', '3').support));
|
|
2813
|
+
//
|
|
2814
|
+
// if ((Debug('EMOTIONS', '*', 'ALL')).length >= 1) {
|
|
2815
|
+
// var isEMOJI = [];
|
|
2816
|
+
// Debug('EMOTIONS', '*', 'ALL').some(function(TARGET, index) {
|
|
2817
|
+
// GetEmoji = {
|
|
2818
|
+
// "ID": TARGET.id,
|
|
2819
|
+
// "EMOJI": TARGET.emoji,
|
|
2820
|
+
// "KEY": TARGET.key,
|
|
2821
|
+
// "UNICODE": TARGET.unicode,
|
|
2822
|
+
// "HTML": TARGET.html,
|
|
2823
|
+
// "NAME": TARGET.name
|
|
2824
|
+
// };
|
|
2825
|
+
//
|
|
2826
|
+
// isEMOJI.push(GetEmoji);
|
|
2827
|
+
// if (Debug('EMOTIONS', '*', 'ALL').length == (index + 1)) {
|
|
2828
|
+
// global.io.emit('Emoji', isEMOJI);
|
|
2829
|
+
// }
|
|
2830
|
+
// });
|
|
2831
|
+
// }
|
|
2832
|
+
//
|
|
2833
|
+
//
|
|
2834
|
+
if ((Debug('TARGET', '*', 'ALL')).length >= 1) {
|
|
2835
|
+
var isTARGET = [];
|
|
2836
|
+
Debug('TARGET', '*', 'ALL').some(function(TARGET, index) {
|
|
2837
|
+
if (TARGET.status == 'pending') {
|
|
2838
|
+
Dataset('TARGET', '*', TARGET.id, 'DELETE');
|
|
2839
|
+
Dataset('SQLITE_SEQUENCE', 'SEQ', 'TARGET', 'FLUSH');
|
|
2840
|
+
} else {
|
|
2841
|
+
if (TARGET.target == "900000000") {
|
|
2842
|
+
TARGET.target = "(00) 0 0000-0000";
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
GetLog = {
|
|
2846
|
+
"ID": TARGET.id,
|
|
2847
|
+
"TITLE": TARGET.title,
|
|
2848
|
+
"NAME": TARGET.client,
|
|
2849
|
+
"START": TARGET.start,
|
|
2850
|
+
"END": TARGET.end,
|
|
2851
|
+
"TARGET": TARGET.target,
|
|
2852
|
+
"STATUS": TARGET.status,
|
|
2853
|
+
};
|
|
2854
|
+
isTARGET.push(GetLog);
|
|
2855
|
+
if (Debug('TARGET', '*', 'ALL').length <= (index + 1)) {
|
|
2856
|
+
if (Boolean(Debug('OPTIONS').auth)) {
|
|
2857
|
+
global.io.emit('getlog', true);
|
|
2858
|
+
global.io.emit('setlog', isTARGET);
|
|
2859
|
+
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
});
|
|
2864
|
+
|
|
2865
|
+
} else {
|
|
2866
|
+
global.io.emit('getlog', false);
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
res.json({
|
|
2870
|
+
Status: "Success",
|
|
2871
|
+
Return: Debug('CONSOLE').right
|
|
2872
|
+
});
|
|
2873
|
+
|
|
2874
|
+
|
|
2875
|
+
} else {
|
|
2876
|
+
res.json({
|
|
2877
|
+
Status: "Fail",
|
|
2878
|
+
Return: Debug('CONSOLE').wrong
|
|
2879
|
+
});
|
|
2880
|
+
}
|
|
2881
|
+
});
|
|
2882
|
+
|
|
2883
|
+
// Set Options Mkauth
|
|
2884
|
+
app.post('/options_mkauth', (req, res) => {
|
|
2885
|
+
const define = req.body.define;
|
|
2886
|
+
const enable = req.body.enable;
|
|
2887
|
+
db.run("UPDATE mkauth SET " + define + "=?", [enable], (err) => {
|
|
2888
|
+
if (err) {
|
|
2889
|
+
res.json({
|
|
2890
|
+
Status: "Fail",
|
|
2891
|
+
Return: Debug('MKAUTH').define
|
|
2892
|
+
});
|
|
2893
|
+
}
|
|
2894
|
+
res.json({
|
|
2895
|
+
Status: "Success",
|
|
2896
|
+
Return: enable
|
|
2897
|
+
});
|
|
2898
|
+
});
|
|
2899
|
+
});
|
|
2900
|
+
|
|
2901
|
+
// Set Scheduler Mkauth
|
|
2902
|
+
app.post('/scheduler', (req, res) => {
|
|
2903
|
+
const define = (req.body.define).toLowerCase();
|
|
2904
|
+
const enable = req.body.enable;
|
|
2905
|
+
db.run("UPDATE scheduler SET " + define + "=?", [enable], (err) => {
|
|
2906
|
+
if (err) {
|
|
2907
|
+
res.json({
|
|
2908
|
+
Status: "Fail",
|
|
2909
|
+
Return: Debug('SCHEDULER').define
|
|
2910
|
+
});
|
|
2911
|
+
}
|
|
2912
|
+
res.json({
|
|
2913
|
+
Status: "Success",
|
|
2914
|
+
Return: enable,
|
|
2915
|
+
Option: Debug('SCHEDULER').speed
|
|
2916
|
+
});
|
|
2917
|
+
});
|
|
2918
|
+
});
|
|
2919
|
+
|
|
2920
|
+
|
|
2921
|
+
|
|
2922
|
+
// Get Clients Mkauth
|
|
2923
|
+
app.post('/clients_mkauth', async (req, res) => {
|
|
2924
|
+
const Year = req.body.year;
|
|
2925
|
+
const Month = req.body.month;
|
|
2926
|
+
const Payment = req.body.payment;
|
|
2927
|
+
const Findex = (((DateTime()).split(" ")[0]).split("-")[0] - Year) + '-' + Month;
|
|
2928
|
+
const Master = await MkAuth(Findex, Payment, 'list');
|
|
2929
|
+
var hasTARGET = [];
|
|
2930
|
+
var PUSH, STATUS;
|
|
2931
|
+
if (await Master.Status == "Error" || !Master) {
|
|
2932
|
+
return res.json({
|
|
2933
|
+
Status: "Fail",
|
|
2934
|
+
Return: Debug('CONSOLE').request
|
|
2935
|
+
});
|
|
2936
|
+
} else {
|
|
2937
|
+
(await Master).someAsync(async (TARGET) => {
|
|
2938
|
+
if (TARGET.Contact != undefined) {
|
|
2939
|
+
TARGET.Contact = (TARGET.Contact).replace(/[^0-9\\.]+/g, '');
|
|
2940
|
+
} else {
|
|
2941
|
+
TARGET.Contact = "00000000000";
|
|
2942
|
+
}
|
|
2943
|
+
try {
|
|
2944
|
+
TARGET.status = Debug("STORANGE", "*", "DIRECT", TARGET.Identifier).status;
|
|
2945
|
+
} catch (e) {
|
|
2946
|
+
TARGET.status = undefined;
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
try {
|
|
2950
|
+
TARGET.push = Debug("STORANGE", "*", "DIRECT", TARGET.Identifier).push;
|
|
2951
|
+
} catch (e) {
|
|
2952
|
+
TARGET.push = undefined;
|
|
2953
|
+
}
|
|
2954
|
+
GetClients = {
|
|
2955
|
+
"ORDER": TARGET.Order,
|
|
2956
|
+
"TITLE": TARGET.Identifier,
|
|
2957
|
+
"USER": TARGET.Connect,
|
|
2958
|
+
"CLIENT": TARGET.Client,
|
|
2959
|
+
"CONTACT": TARGET.Contact,
|
|
2960
|
+
"REWARD": TARGET.Reward,
|
|
2961
|
+
"PUSH": TARGET.push,
|
|
2962
|
+
"PAYMENT": TARGET.Payment,
|
|
2963
|
+
"STATUS": TARGET.status,
|
|
2964
|
+
"CASH": TARGET.Cash,
|
|
2965
|
+
"GATEWAY": TARGET.Gateway
|
|
2966
|
+
};
|
|
2967
|
+
hasTARGET.push(GetClients);
|
|
2968
|
+
if (Master.length == hasTARGET.length) {
|
|
2969
|
+
if (Boolean(Debug('OPTIONS').auth)) {
|
|
2970
|
+
global.io.emit('getclients', hasTARGET);
|
|
2971
|
+
return res.json({
|
|
2972
|
+
Status: "Success",
|
|
2973
|
+
Return: Debug('CONSOLE').successfully
|
|
2974
|
+
});
|
|
2975
|
+
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
|
|
2979
|
+
});
|
|
2980
|
+
|
|
2981
|
+
}
|
|
2982
|
+
});
|
|
2983
|
+
|
|
2984
|
+
|
|
2985
|
+
// Delay Mkauth
|
|
2986
|
+
app.post('/delay_mkauth', (req, res) => {
|
|
2987
|
+
const range = req.body.range;
|
|
2988
|
+
if (Debug('MKAUTH').delay != range) {
|
|
2989
|
+
db.run("UPDATE mkauth SET delay=?", [range], (err) => {
|
|
2990
|
+
if (err) {
|
|
2991
|
+
res.json({
|
|
2992
|
+
Status: "Fail",
|
|
2993
|
+
Return: Debug('MKAUTH').delay
|
|
2994
|
+
});
|
|
2995
|
+
}
|
|
2996
|
+
res.json({
|
|
2997
|
+
Status: "Success",
|
|
2998
|
+
Return: range
|
|
2999
|
+
});
|
|
3000
|
+
});
|
|
3001
|
+
}
|
|
3002
|
+
});
|
|
3003
|
+
|
|
3004
|
+
|
|
3005
|
+
|
|
3006
|
+
// Scheduler
|
|
3007
|
+
app.post('/scheduler_mkauth', async (req, res) => {
|
|
3008
|
+
var isSHED = [];
|
|
3009
|
+
const exUpdate = await link.prepare('SELECT * FROM scheduling WHERE process=?').all("wait");
|
|
3010
|
+
if (exUpdate.length >= 1) {
|
|
3011
|
+
exUpdate.some(function(Send, index) {
|
|
3012
|
+
GetSHED = {
|
|
3013
|
+
"TITLE": Send.title,
|
|
3014
|
+
"CLIENT": Send.client,
|
|
3015
|
+
"REWARD": Send.reward
|
|
3016
|
+
};
|
|
3017
|
+
isSHED.push(GetSHED);
|
|
3018
|
+
if (exUpdate.length == (index + 1)) {
|
|
3019
|
+
global.io.emit('shedullers', isSHED);
|
|
3020
|
+
res.json({
|
|
3021
|
+
Status: "Success"
|
|
3022
|
+
});
|
|
3023
|
+
}
|
|
3024
|
+
});
|
|
3025
|
+
} else {
|
|
3026
|
+
res.json({
|
|
3027
|
+
Status: "Fail"
|
|
3028
|
+
});
|
|
3029
|
+
}
|
|
3030
|
+
});
|
|
3031
|
+
|
|
3032
|
+
|
|
3033
|
+
|
|
3034
|
+
|
|
3035
|
+
// Save Mkauth Messages
|
|
3036
|
+
app.post('/message_mkauth', (req, res) => {
|
|
3037
|
+
const define = req.body.database
|
|
3038
|
+
const message = req.body.message
|
|
3039
|
+
const token = req.body.token
|
|
3040
|
+
const select = req.body.select
|
|
3041
|
+
if ([Debug('OPTIONS').token, Password[1]].includes(token)) {
|
|
3042
|
+
if (server != "" && message != "") {
|
|
3043
|
+
db.run("UPDATE message SET " + define + "=? WHERE id=?", [message, select], (err) => {
|
|
3044
|
+
if (err) {
|
|
3045
|
+
res.json({
|
|
3046
|
+
Status: "Fail",
|
|
3047
|
+
Return: Debug('CONSOLE').datafail
|
|
3048
|
+
});
|
|
3049
|
+
}
|
|
3050
|
+
res.json({
|
|
3051
|
+
Status: "Success",
|
|
3052
|
+
Return: Debug('CONSOLE').datasave
|
|
3053
|
+
});
|
|
3054
|
+
});
|
|
3055
|
+
} else {
|
|
3056
|
+
res.json({
|
|
3057
|
+
Status: "Fail"
|
|
3058
|
+
});
|
|
3059
|
+
|
|
3060
|
+
}
|
|
3061
|
+
} else {
|
|
3062
|
+
res.json({
|
|
3063
|
+
Status: "Fail"
|
|
3064
|
+
});
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
});
|
|
3068
|
+
|
|
3069
|
+
|
|
3070
|
+
|
|
3071
|
+
// Update SQLite
|
|
3072
|
+
app.post('/sqlite-options', (req, res) => {
|
|
3073
|
+
const Interval = req.body.interval;
|
|
3074
|
+
const Sleep = req.body.sleep;
|
|
3075
|
+
const Sendwait = req.body.sendwait;
|
|
3076
|
+
const Access = req.body.access;
|
|
3077
|
+
const Pixfail = req.body.pixfail;
|
|
3078
|
+
var Response = req.body.response;
|
|
3079
|
+
var Call = req.body.call;
|
|
3080
|
+
const Replyes = req.body.replyes;
|
|
3081
|
+
const Alert = req.body.alert;
|
|
3082
|
+
const Onbot = req.body.onbot;
|
|
3083
|
+
const Reject = req.body.reject;
|
|
3084
|
+
const Count = req.body.count;
|
|
3085
|
+
const Token = req.body.token;
|
|
3086
|
+
const Limiter = req.body.limiter;
|
|
3087
|
+
if (Access != Debug('OPTIONS').access) {
|
|
3088
|
+
Reboot = true;
|
|
3089
|
+
} else {
|
|
3090
|
+
Reboot = false;
|
|
3091
|
+
}
|
|
3092
|
+
if (Response == "") {
|
|
3093
|
+
Response = Debug('OPTIONS').response;
|
|
3094
|
+
}
|
|
3095
|
+
if ([Debug('OPTIONS').token, Password[1]].includes(Token)) {
|
|
3096
|
+
if (Interval != "" && Sleep != "" && Sendwait != "" && Access != "" && Pixfail != "" && Count != "" && Limiter != "") {
|
|
3097
|
+
db.run("UPDATE options SET interval=?, sendwait=?, access=?, pixfail=?, response=?, replyes=?, onbot=?, count=?, limiter=?, sleep=?, call=?, reject=?, alert=?", [Interval, Sendwait, Access, Pixfail, Response, Replyes, Onbot, Count, Limiter, Sleep, Call, Reject, Alert], (err) => {
|
|
3098
|
+
if (err) {
|
|
3099
|
+
res.json({
|
|
3100
|
+
Status: "Fail",
|
|
3101
|
+
Return: Debug('CONSOLE').failed
|
|
3102
|
+
});
|
|
3103
|
+
}
|
|
3104
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').settings);
|
|
3105
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').settings);
|
|
3106
|
+
res.json({
|
|
3107
|
+
Status: "Success",
|
|
3108
|
+
Return: Debug('CONSOLE').settings,
|
|
3109
|
+
Port: Access
|
|
3110
|
+
});
|
|
3111
|
+
session = false;
|
|
3112
|
+
if (Reboot) {
|
|
3113
|
+
global.io.emit('Reset', true);
|
|
3114
|
+
delay(0).then(async function() {
|
|
3115
|
+
await exec('npm run restart:mwsm');
|
|
3116
|
+
});
|
|
3117
|
+
}
|
|
3118
|
+
});
|
|
3119
|
+
|
|
3120
|
+
} else {
|
|
3121
|
+
res.json({
|
|
3122
|
+
Status: "Fail",
|
|
3123
|
+
Return: Debug('CONSOLE').unnamed
|
|
3124
|
+
});
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
} else {
|
|
3128
|
+
res.json({
|
|
3129
|
+
Status: "Fail",
|
|
3130
|
+
Return: Debug('CONSOLE').wrong
|
|
3131
|
+
});
|
|
3132
|
+
}
|
|
3133
|
+
});
|
|
3134
|
+
|
|
3135
|
+
// Send From Mikrotik
|
|
3136
|
+
app.get('/mikrotik/:pass/:to/:msg', async (req, res) => {
|
|
3137
|
+
const {
|
|
3138
|
+
to,
|
|
3139
|
+
msg,
|
|
3140
|
+
pass
|
|
3141
|
+
} = req.params;
|
|
3142
|
+
|
|
3143
|
+
var isHid;
|
|
3144
|
+
if (Boolean(Debug('OPTIONS').protect)) {
|
|
3145
|
+
isHid = (pass);
|
|
3146
|
+
} else {
|
|
3147
|
+
if ((Debug('OPTIONS').token == "" || Debug('OPTIONS').protect == undefined)) {
|
|
3148
|
+
isHid = Password[1];
|
|
3149
|
+
} else {
|
|
3150
|
+
isHid = (Debug('OPTIONS').token);
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
Json = {
|
|
3155
|
+
"Mwsm": "/mikrotik",
|
|
3156
|
+
"Main": "Mikrotik",
|
|
3157
|
+
"Start": DateTime()
|
|
3158
|
+
};
|
|
3159
|
+
if (typeof Json === 'object') {
|
|
3160
|
+
Json = JSON.stringify(Json);
|
|
3161
|
+
}
|
|
3162
|
+
console.error(Print.bg.blue, Print.fg.white, Json, Print.reset);
|
|
3163
|
+
|
|
3164
|
+
|
|
3165
|
+
var isWid = (to);
|
|
3166
|
+
if (validPhone(Playground)) {
|
|
3167
|
+
isWid = '55' + Playground;
|
|
3168
|
+
}
|
|
3169
|
+
const isDDI = isWid.substr(0, 2);
|
|
3170
|
+
const isDDD = isWid.substr(2, 2);
|
|
3171
|
+
const isCall = isWid.slice(-8);
|
|
3172
|
+
var WhatsApp = isWid + '@c.us';
|
|
3173
|
+
if ((isDDI == '55') && (parseInt(isDDD) <= 30)) {
|
|
3174
|
+
WhatsApp = isWid.substr(0, 4) + '9' + isCall + '@c.us';
|
|
3175
|
+
} else if ((isDDI == '55') && (parseInt(isDDD) > 30)) {
|
|
3176
|
+
WhatsApp = isWid.substr(0, 4) + isCall + '@c.us';
|
|
3177
|
+
}
|
|
3178
|
+
const Mensagem = (msg);
|
|
3179
|
+
|
|
3180
|
+
if ([Debug('OPTIONS').token, Password[1]].includes(isHid) && validPhone(isWid)) {
|
|
3181
|
+
setTimeout(function() {
|
|
3182
|
+
client.sendMessage(WhatsApp, Mensagem).then(response => {
|
|
3183
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').success);
|
|
3184
|
+
return res.json({
|
|
3185
|
+
Status: "Success",
|
|
3186
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').success
|
|
3187
|
+
});
|
|
3188
|
+
}).catch(err => {
|
|
3189
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
3190
|
+
return res.status(500).json({
|
|
3191
|
+
Status: "Fail",
|
|
3192
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
3193
|
+
});
|
|
3194
|
+
WwjsVersion(false);
|
|
3195
|
+
});
|
|
3196
|
+
|
|
3197
|
+
}, Math.floor(Debug('OPTIONS').interval + Math.random() * 1000));
|
|
3198
|
+
} else {
|
|
3199
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
3200
|
+
return res.status(500).json({
|
|
3201
|
+
Status: "Fail",
|
|
3202
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
3203
|
+
});
|
|
3204
|
+
}
|
|
3205
|
+
|
|
3206
|
+
});
|
|
3207
|
+
|
|
3208
|
+
|
|
3209
|
+
// Force Message
|
|
3210
|
+
app.post('/force-message', [
|
|
3211
|
+
body('p').notEmpty(),
|
|
3212
|
+
body('to').notEmpty(),
|
|
3213
|
+
body('msg').notEmpty(),
|
|
3214
|
+
], async (req, res) => {
|
|
3215
|
+
const errors = validationResult(req).formatWith(({
|
|
3216
|
+
msg
|
|
3217
|
+
}) => {
|
|
3218
|
+
return msg;
|
|
3219
|
+
});
|
|
3220
|
+
|
|
3221
|
+
if (!errors.isEmpty()) {
|
|
3222
|
+
return res.status(422).json({
|
|
3223
|
+
Status: "Fail",
|
|
3224
|
+
message: errors.mapped()
|
|
3225
|
+
});
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
Json = {
|
|
3229
|
+
"Mwsm": "/force-message",
|
|
3230
|
+
"Main": "Mwsm",
|
|
3231
|
+
"Start": DateTime()
|
|
3232
|
+
};
|
|
3233
|
+
if (typeof Json === 'object') {
|
|
3234
|
+
Json = JSON.stringify(Json);
|
|
3235
|
+
}
|
|
3236
|
+
console.error(Print.bg.blue, Print.fg.white, Json, Print.reset);
|
|
3237
|
+
|
|
3238
|
+
|
|
3239
|
+
var isHid;
|
|
3240
|
+
if (Boolean(Debug('OPTIONS').protect)) {
|
|
3241
|
+
if (req.body.pass != undefined) {
|
|
3242
|
+
isHid = req.body.pass;
|
|
3243
|
+
} else if (req.body.p != undefined) {
|
|
3244
|
+
isHid = req.body.p;
|
|
3245
|
+
} else {
|
|
3246
|
+
isHid = '';
|
|
3247
|
+
}
|
|
3248
|
+
} else {
|
|
3249
|
+
if ((Debug('OPTIONS').token == "" || Debug('OPTIONS').protect == undefined)) {
|
|
3250
|
+
isHid = Password[1];
|
|
3251
|
+
} else {
|
|
3252
|
+
isHid = (Debug('OPTIONS').token);
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3256
|
+
var Contact = req.body.to;
|
|
3257
|
+
if (validPhone(Playground)) {
|
|
3258
|
+
Contact = '55' + Playground;
|
|
3259
|
+
}
|
|
3260
|
+
const isWid = (Contact).replace(/[^0-9\\.]+/g, '');
|
|
3261
|
+
const isDDI = isWid.substr(0, 2);
|
|
3262
|
+
const isDDD = isWid.substr(2, 2);
|
|
3263
|
+
const isCall = isWid.slice(-8);
|
|
3264
|
+
var WhatsApp = isWid + '@c.us';
|
|
3265
|
+
if ((isDDI == '55') && (parseInt(isDDD) <= 30)) {
|
|
3266
|
+
WhatsApp = isWid.substr(0, 4) + '9' + isCall + '@c.us';
|
|
3267
|
+
} else if ((isDDI == '55') && (parseInt(isDDD) > 30)) {
|
|
3268
|
+
WhatsApp = isWid.substr(0, 4) + isCall + '@c.us';
|
|
3269
|
+
}
|
|
3270
|
+
const Mensagem = (req.body.msg).replaceAll("\\n", "\r\n").split("##");
|
|
3271
|
+
|
|
3272
|
+
const Reconstructor = new Promise((resolve, reject) => {
|
|
3273
|
+
if (Mensagem.some(Rows => Debug('ATTACHMENTS', 'SUFFIXES', 'MULTIPLE').some(Row => Rows.includes(Row)))) {
|
|
3274
|
+
var Array = {};
|
|
3275
|
+
Mensagem.some(function(Send, index) {
|
|
3276
|
+
if (Debug('ATTACHMENTS', 'SUFFIXES', 'MULTIPLE').some(Row => Send.includes(Row))) {
|
|
3277
|
+
const Cloud = async () => {
|
|
3278
|
+
let mimetype;
|
|
3279
|
+
const attachment = await axios.get(Url, {
|
|
3280
|
+
responseType: 'arraybuffer'
|
|
3281
|
+
}).then(response => {
|
|
3282
|
+
mimetype = response.headers['content-type'];
|
|
3283
|
+
return response.data.toString('base64');
|
|
3284
|
+
});
|
|
3285
|
+
return new MessageMedia(mimetype, attachment, 'Media');
|
|
3286
|
+
};
|
|
3287
|
+
|
|
3288
|
+
|
|
3289
|
+
console.log(WhatsApp + " - " + Mensagem);
|
|
3290
|
+
|
|
3291
|
+
Cloud(Send).then(Return => {
|
|
3292
|
+
Array[Send] = Return;
|
|
3293
|
+
resolve(Array);
|
|
3294
|
+
}).catch(err => {
|
|
3295
|
+
resolve(undefined);
|
|
3296
|
+
});
|
|
3297
|
+
}
|
|
3298
|
+
});
|
|
3299
|
+
} else {
|
|
3300
|
+
resolve(undefined);
|
|
3301
|
+
}
|
|
3302
|
+
});
|
|
3303
|
+
|
|
3304
|
+
delay(0).then(async function() {
|
|
3305
|
+
const Retorno = await Promise.all([Reconstructor]);
|
|
3306
|
+
var Assembly = [];
|
|
3307
|
+
var Sending = 1;
|
|
3308
|
+
Mensagem.some(function(Send, index) {
|
|
3309
|
+
if (Debug('ATTACHMENTS', 'SUFFIXES', 'MULTIPLE').some(Row => Send.includes(Row))) {
|
|
3310
|
+
if (Retorno[0].hasOwnProperty(Send)) {
|
|
3311
|
+
Assembly.push(Retorno[0][Send]);
|
|
3312
|
+
}
|
|
3313
|
+
} else {
|
|
3314
|
+
Assembly.push(Send);
|
|
3315
|
+
}
|
|
3316
|
+
});
|
|
3317
|
+
Assembly.some(function(Send, index) {
|
|
3318
|
+
setTimeout(function() {
|
|
3319
|
+
|
|
3320
|
+
var Preview = false;
|
|
3321
|
+
var Caption = "Media";
|
|
3322
|
+
|
|
3323
|
+
if ([Debug('OPTIONS').token, Password[1]].includes(isHid) && validPhone(isWid)) {
|
|
3324
|
+
client.sendMessage(WhatsApp, isEmoji(Send), {
|
|
3325
|
+
caption: Caption,
|
|
3326
|
+
linkPreview: Preview
|
|
3327
|
+
}).then(response => {
|
|
3328
|
+
Wait = WhatsApp;
|
|
3329
|
+
Sending = (Sending + 1);
|
|
3330
|
+
}).catch(err => {
|
|
3331
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
3332
|
+
return res.json({
|
|
3333
|
+
Status: "Fail",
|
|
3334
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
3335
|
+
});
|
|
3336
|
+
WwjsVersion(false);
|
|
3337
|
+
});
|
|
3338
|
+
} else {
|
|
3339
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
3340
|
+
return res.json({
|
|
3341
|
+
Status: "Fail",
|
|
3342
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
3343
|
+
});
|
|
3344
|
+
}
|
|
3345
|
+
|
|
3346
|
+
if (Sending >= Assembly.length) {
|
|
3347
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').success);
|
|
3348
|
+
return res.json({
|
|
3349
|
+
Status: "Success",
|
|
3350
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').success
|
|
3351
|
+
});
|
|
3352
|
+
}
|
|
3353
|
+
}, index * Debug('OPTIONS').interval);
|
|
3354
|
+
});
|
|
3355
|
+
});
|
|
3356
|
+
});
|
|
3357
|
+
|
|
3358
|
+
// Link Mkauth
|
|
3359
|
+
app.post('/link_mkauth', async (req, res) => {
|
|
3360
|
+
const User = req.body.username;
|
|
3361
|
+
const Pass = req.body.password;
|
|
3362
|
+
const Domain = req.body.domain;
|
|
3363
|
+
const Tunel = req.body.tunel;
|
|
3364
|
+
const Module = req.body.module;
|
|
3365
|
+
const Token = req.body.token;
|
|
3366
|
+
const Server = req.body.server;
|
|
3367
|
+
const Mode = req.body.mode;
|
|
3368
|
+
var iServer;
|
|
3369
|
+
|
|
3370
|
+
if (Server == "tunel") {
|
|
3371
|
+
iServer = Tunel;
|
|
3372
|
+
} else if (Server == "domain") {
|
|
3373
|
+
iServer = Domain;
|
|
3374
|
+
}
|
|
3375
|
+
|
|
3376
|
+
var ConnAuth, ResAuth;
|
|
3377
|
+
if ([Debug('OPTIONS').token, Password[1]].includes(Token)) {
|
|
3378
|
+
const Authentication = await axios.get('https://' + iServer + '/api/', {
|
|
3379
|
+
auth: {
|
|
3380
|
+
username: User,
|
|
3381
|
+
password: Pass
|
|
3382
|
+
}
|
|
3383
|
+
}).then(response => {
|
|
3384
|
+
return response.data;
|
|
3385
|
+
}).catch(err => {
|
|
3386
|
+
return false;
|
|
3387
|
+
});
|
|
3388
|
+
ConnAuth = false;
|
|
3389
|
+
ResAuth = false;
|
|
3390
|
+
if (Authentication) {
|
|
3391
|
+
ConnAuth = true;
|
|
3392
|
+
const MkSync = await axios.get('https://' + iServer + '/api/titulo/listar/limite=1&pagina=1', {
|
|
3393
|
+
headers: {
|
|
3394
|
+
'Authorization': 'Bearer ' + Authentication
|
|
3395
|
+
}
|
|
3396
|
+
}).then(response => {
|
|
3397
|
+
return response.data;
|
|
3398
|
+
}).catch(err => {
|
|
3399
|
+
return false;
|
|
3400
|
+
});
|
|
3401
|
+
|
|
3402
|
+
if ((MkSync.error == undefined)) {
|
|
3403
|
+
ResAuth = true;
|
|
3404
|
+
db.run("UPDATE mkauth SET client_id=?, client_secret=?, domain=?, tunel=?, mode=?, module=?, client_link=?", [User, Pass, Domain, Tunel, Mode, Module, Server], (err) => {
|
|
3405
|
+
if (err) {
|
|
3406
|
+
res.json({
|
|
3407
|
+
Status: "Fail",
|
|
3408
|
+
Return: Debug('CONSOLE').failed
|
|
3409
|
+
});
|
|
3410
|
+
}
|
|
3411
|
+
res.json({
|
|
3412
|
+
Status: "Success",
|
|
3413
|
+
Return: Debug('CONSOLE').mksuccess
|
|
3414
|
+
});
|
|
3415
|
+
});
|
|
3416
|
+
} else {
|
|
3417
|
+
res.json({
|
|
3418
|
+
Status: "Fail",
|
|
3419
|
+
Return: Debug('CONSOLE').refused
|
|
3420
|
+
});
|
|
3421
|
+
}
|
|
3422
|
+
} else {
|
|
3423
|
+
res.json({
|
|
3424
|
+
Status: "Fail",
|
|
3425
|
+
Return: Debug('CONSOLE').mkfail
|
|
3426
|
+
});
|
|
3427
|
+
}
|
|
3428
|
+
JDebug = {
|
|
3429
|
+
"MkAuth": [{
|
|
3430
|
+
"Authentication": "" + ConnAuth + "",
|
|
3431
|
+
"Communication": "" + ResAuth + ""
|
|
3432
|
+
}]
|
|
3433
|
+
};
|
|
3434
|
+
Terminal(JDebug);
|
|
3435
|
+
} else {
|
|
3436
|
+
res.json({
|
|
3437
|
+
Status: "Fail",
|
|
3438
|
+
Return: Debug('CONSOLE').wrong
|
|
3439
|
+
});
|
|
3440
|
+
|
|
3441
|
+
}
|
|
3442
|
+
});
|
|
3443
|
+
|
|
3444
|
+
// Send Image
|
|
3445
|
+
app.post('/send-image', [
|
|
3446
|
+
body('pass').notEmpty(),
|
|
3447
|
+
body('to').notEmpty(),
|
|
3448
|
+
body('image').notEmpty(),
|
|
3449
|
+
], async (req, res) => {
|
|
3450
|
+
const errors = validationResult(req).formatWith(({
|
|
3451
|
+
msg
|
|
3452
|
+
}) => {
|
|
3453
|
+
return msg;
|
|
3454
|
+
});
|
|
3455
|
+
|
|
3456
|
+
if (!errors.isEmpty()) {
|
|
3457
|
+
return res.status(422).json({
|
|
3458
|
+
Status: "Fail",
|
|
3459
|
+
message: errors.mapped()
|
|
3460
|
+
});
|
|
3461
|
+
}
|
|
3462
|
+
|
|
3463
|
+
const hasCaption = req.body.caption;
|
|
3464
|
+
const hasMimetype = req.body.mimetype;
|
|
3465
|
+
var isHid;
|
|
3466
|
+
|
|
3467
|
+
Json = {
|
|
3468
|
+
"Mwsm": "/send-image",
|
|
3469
|
+
"Main": "MkAuth",
|
|
3470
|
+
"Start": DateTime()
|
|
3471
|
+
};
|
|
3472
|
+
if (typeof Json === 'object') {
|
|
3473
|
+
Json = JSON.stringify(Json);
|
|
3474
|
+
}
|
|
3475
|
+
console.error(Print.bg.blue, Print.fg.white, Json, Print.reset);
|
|
3476
|
+
|
|
3477
|
+
|
|
3478
|
+
if (!Boolean(Debug('MKAUTH').aimbot)) {
|
|
3479
|
+
|
|
3480
|
+
if (Boolean(Debug('OPTIONS').protect)) {
|
|
3481
|
+
if (req.body.pass != undefined) {
|
|
3482
|
+
isHid = req.body.pass;
|
|
3483
|
+
} else if (req.body.p != undefined) {
|
|
3484
|
+
isHid = req.body.p;
|
|
3485
|
+
} else {
|
|
3486
|
+
isHid = '';
|
|
3487
|
+
}
|
|
3488
|
+
} else {
|
|
3489
|
+
if ((Debug('OPTIONS').token == "" || Debug('OPTIONS').protect == undefined)) {
|
|
3490
|
+
isHid = Password[1];
|
|
3491
|
+
} else {
|
|
3492
|
+
isHid = (Debug('OPTIONS').token);
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
var Contact = req.body.to;
|
|
3496
|
+
if (validPhone(Playground)) {
|
|
3497
|
+
Contact = '55' + Playground;
|
|
3498
|
+
}
|
|
3499
|
+
const isWid = (Contact).replace(/[^0-9\\.]+/g, '');
|
|
3500
|
+
const isDDI = isWid.substr(0, 2);
|
|
3501
|
+
const isDDD = isWid.substr(2, 2);
|
|
3502
|
+
const isCall = isWid.slice(-8);
|
|
3503
|
+
var WhatsApp = isWid + '@c.us';
|
|
3504
|
+
if ((isDDI == '55') && (parseInt(isDDD) <= 30)) {
|
|
3505
|
+
WhatsApp = isWid.substr(0, 4) + '9' + isCall + '@c.us';
|
|
3506
|
+
} else if ((isDDI == '55') && (parseInt(isDDD) > 30)) {
|
|
3507
|
+
WhatsApp = isWid.substr(0, 4) + isCall + '@c.us';
|
|
3508
|
+
}
|
|
3509
|
+
const Mensagem = new MessageMedia(hasMimetype, (req.body.image), 'Media');
|
|
3510
|
+
|
|
3511
|
+
if ([Debug('OPTIONS').token, Password[1]].includes(isHid) && validPhone(isWid)) {
|
|
3512
|
+
client.sendMessage(WhatsApp, Mensagem, {
|
|
3513
|
+
caption: hasCaption,
|
|
3514
|
+
linkPreview: false
|
|
3515
|
+
}).then(response => {
|
|
3516
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').success);
|
|
3517
|
+
return res.status(200).json({
|
|
3518
|
+
Status: "Success",
|
|
3519
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').success
|
|
3520
|
+
});
|
|
3521
|
+
}).catch(err => {
|
|
3522
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
3523
|
+
return res.status(500).json({
|
|
3524
|
+
Status: "Fail",
|
|
3525
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
3526
|
+
});
|
|
3527
|
+
WwjsVersion(false);
|
|
3528
|
+
});
|
|
3529
|
+
} else {
|
|
3530
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
3531
|
+
return res.status(500).json({
|
|
3532
|
+
Status: "Fail",
|
|
3533
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
3534
|
+
});
|
|
3535
|
+
}
|
|
3536
|
+
|
|
3537
|
+
} else {
|
|
3538
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').trigger);
|
|
3539
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').trigger);
|
|
3540
|
+
|
|
3541
|
+
return res.status(500).json({
|
|
3542
|
+
Status: "Fail",
|
|
3543
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').trigger
|
|
3544
|
+
});
|
|
3545
|
+
}
|
|
3546
|
+
});
|
|
3547
|
+
|
|
3548
|
+
// Send Document
|
|
3549
|
+
app.post('/send-document', [
|
|
3550
|
+
body('pass').notEmpty(),
|
|
3551
|
+
body('to').notEmpty(),
|
|
3552
|
+
body('document').notEmpty(),
|
|
3553
|
+
], async (req, res) => {
|
|
3554
|
+
const errors = validationResult(req).formatWith(({
|
|
3555
|
+
msg
|
|
3556
|
+
}) => {
|
|
3557
|
+
return msg;
|
|
3558
|
+
});
|
|
3559
|
+
|
|
3560
|
+
if (!errors.isEmpty()) {
|
|
3561
|
+
return res.status(422).json({
|
|
3562
|
+
Status: "Fail",
|
|
3563
|
+
message: errors.mapped()
|
|
3564
|
+
});
|
|
3565
|
+
}
|
|
3566
|
+
const hasCaption = req.body.caption;
|
|
3567
|
+
const hasMimetype = req.body.mimetype;
|
|
3568
|
+
const hasFileName = req.body.filename;
|
|
3569
|
+
|
|
3570
|
+
var isHid;
|
|
3571
|
+
Json = {
|
|
3572
|
+
"Mwsm": "/send-document",
|
|
3573
|
+
"Main": "MkAuth",
|
|
3574
|
+
"Start": DateTime()
|
|
3575
|
+
};
|
|
3576
|
+
|
|
3577
|
+
if (typeof Json === 'object') {
|
|
3578
|
+
Json = JSON.stringify(Json);
|
|
3579
|
+
}
|
|
3580
|
+
console.error(Print.bg.blue, Print.fg.white, Json, Print.reset);
|
|
3581
|
+
|
|
3582
|
+
if (!Boolean(Debug('MKAUTH').aimbot)) {
|
|
3583
|
+
if (Boolean(Debug('OPTIONS').protect)) {
|
|
3584
|
+
if (req.body.pass != undefined) {
|
|
3585
|
+
isHid = req.body.pass;
|
|
3586
|
+
} else if (req.body.p != undefined) {
|
|
3587
|
+
isHid = req.body.p;
|
|
3588
|
+
} else {
|
|
3589
|
+
isHid = '';
|
|
3590
|
+
}
|
|
3591
|
+
} else {
|
|
3592
|
+
if ((Debug('OPTIONS').token == "" || Debug('OPTIONS').protect == undefined)) {
|
|
3593
|
+
isHid = Password[1];
|
|
3594
|
+
} else {
|
|
3595
|
+
isHid = (Debug('OPTIONS').token);
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
var Contact = req.body.to;
|
|
3599
|
+
if (validPhone(Playground)) {
|
|
3600
|
+
Contact = '55' + Playground;
|
|
3601
|
+
}
|
|
3602
|
+
const isWid = (Contact).replace(/[^0-9\\.]+/g, '');
|
|
3603
|
+
const isDDI = isWid.substr(0, 2);
|
|
3604
|
+
const isDDD = isWid.substr(2, 2);
|
|
3605
|
+
const isCall = isWid.slice(-8);
|
|
3606
|
+
var WhatsApp = isWid + '@c.us';
|
|
3607
|
+
if ((isDDI == '55') && (parseInt(isDDD) <= 30)) {
|
|
3608
|
+
WhatsApp = isWid.substr(0, 4) + '9' + isCall + '@c.us';
|
|
3609
|
+
} else if ((isDDI == '55') && (parseInt(isDDD) > 30)) {
|
|
3610
|
+
WhatsApp = isWid.substr(0, 4) + isCall + '@c.us';
|
|
3611
|
+
}
|
|
3612
|
+
const Mensagem = new MessageMedia(hasMimetype, (req.body.document), hasFileName);
|
|
3613
|
+
|
|
3614
|
+
if ([Debug('OPTIONS').token, Password[1]].includes(isHid) && validPhone(isWid)) {
|
|
3615
|
+
client.sendMessage(WhatsApp, Mensagem, {
|
|
3616
|
+
caption: hasCaption,
|
|
3617
|
+
linkPreview: false
|
|
3618
|
+
}).then(response => {
|
|
3619
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').success);
|
|
3620
|
+
return res.status(200).json({
|
|
3621
|
+
Status: "Success",
|
|
3622
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').success
|
|
3623
|
+
});
|
|
3624
|
+
}).catch(err => {
|
|
3625
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
3626
|
+
return res.status(500).json({
|
|
3627
|
+
Status: "Fail",
|
|
3628
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
3629
|
+
});
|
|
3630
|
+
WwjsVersion(false);
|
|
3631
|
+
});
|
|
3632
|
+
} else {
|
|
3633
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
3634
|
+
return res.status(500).json({
|
|
3635
|
+
Status: "Fail",
|
|
3636
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
3637
|
+
});
|
|
3638
|
+
}
|
|
3639
|
+
|
|
3640
|
+
} else {
|
|
3641
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').trigger);
|
|
3642
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').trigger);
|
|
3643
|
+
|
|
3644
|
+
return res.status(500).json({
|
|
3645
|
+
Status: "Fail",
|
|
3646
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').trigger
|
|
3647
|
+
});
|
|
3648
|
+
|
|
3649
|
+
}
|
|
3650
|
+
});
|
|
3651
|
+
|
|
3652
|
+
|
|
3653
|
+
// Send Message
|
|
3654
|
+
app.post('/send-message', [
|
|
3655
|
+
body('to').notEmpty(),
|
|
3656
|
+
body('msg').notEmpty(),
|
|
3657
|
+
], async (req, res) => {
|
|
3658
|
+
const errors = validationResult(req).formatWith(({
|
|
3659
|
+
msg
|
|
3660
|
+
}) => {
|
|
3661
|
+
return msg;
|
|
3662
|
+
});
|
|
3663
|
+
|
|
3664
|
+
if (!errors.isEmpty()) {
|
|
3665
|
+
return res.status(422).json({
|
|
3666
|
+
status: false,
|
|
3667
|
+
message: errors.mapped()
|
|
3668
|
+
});
|
|
3669
|
+
}
|
|
3670
|
+
var isHid;
|
|
3671
|
+
if (Boolean(Debug('OPTIONS').protect)) {
|
|
3672
|
+
if (req.body.pass != undefined) {
|
|
3673
|
+
isHid = req.body.pass;
|
|
3674
|
+
} else if (req.body.p != undefined) {
|
|
3675
|
+
isHid = req.body.p;
|
|
3676
|
+
} else {
|
|
3677
|
+
isHid = '';
|
|
3678
|
+
}
|
|
3679
|
+
} else {
|
|
3680
|
+
if ((Debug('OPTIONS').token == "" || Debug('OPTIONS').protect == undefined)) {
|
|
3681
|
+
isHid = Password[1];
|
|
3682
|
+
} else {
|
|
3683
|
+
isHid = (Debug('OPTIONS').token);
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
|
|
3687
|
+
var isAuth = req.body.auth,
|
|
3688
|
+
Manager, inCall = req.body.to;
|
|
3689
|
+
if (validPhone(Playground)) {
|
|
3690
|
+
inCall = '55' + Playground;
|
|
3691
|
+
}
|
|
3692
|
+
const isUser = req.body.user;
|
|
3693
|
+
const isSend = req.body.send;
|
|
3694
|
+
const Simulator = req.body.simulator;
|
|
3695
|
+
const isWid = (inCall).replace(/[^0-9\\.]+/g, '');
|
|
3696
|
+
const isDDI = isWid.substr(0, 2);
|
|
3697
|
+
const isDDD = isWid.substr(2, 2);
|
|
3698
|
+
const isCall = isWid.slice(-8);
|
|
3699
|
+
var WhatsApp = isWid + '@c.us';
|
|
3700
|
+
if ((isDDI == '55') && (parseInt(isDDD) <= 30)) {
|
|
3701
|
+
WhatsApp = isWid.substr(0, 4) + '9' + isCall + '@c.us';
|
|
3702
|
+
} else if ((isDDI == '55') && (parseInt(isDDD) > 30)) {
|
|
3703
|
+
WhatsApp = isWid.substr(0, 4) + isCall + '@c.us';
|
|
3704
|
+
}
|
|
3705
|
+
switch ((Boolean(Debug('MKAUTH').aimbot) == Boolean(isAuth))) {
|
|
3706
|
+
case true:
|
|
3707
|
+
Manager = "Mwsm";
|
|
3708
|
+
break;
|
|
3709
|
+
case false:
|
|
3710
|
+
Manager = "MkAuth";
|
|
3711
|
+
break;
|
|
3712
|
+
}
|
|
3713
|
+
Json = {
|
|
3714
|
+
"Mwsm": "/send-message",
|
|
3715
|
+
"Main": Manager,
|
|
3716
|
+
"Start": DateTime()
|
|
3717
|
+
};
|
|
3718
|
+
if (typeof Json === 'object') {
|
|
3719
|
+
Json = JSON.stringify(Json);
|
|
3720
|
+
}
|
|
3721
|
+
console.error(Print.bg.blue, Print.fg.white, Json, Print.reset);
|
|
3722
|
+
|
|
3723
|
+
|
|
3724
|
+
if (!Boolean(Debug('MKAUTH').aimbot)) {
|
|
3725
|
+
isAuth = true;
|
|
3726
|
+
}
|
|
3727
|
+
|
|
3728
|
+
if (Boolean(isAuth) && validPhone(isWid)) {
|
|
3729
|
+
const Mensagem = (req.body.msg).replaceAll("\\n", "\r\n").split("##");
|
|
3730
|
+
if (Debug('OPTIONS').schedule <= Debug('OPTIONS').limiter) {
|
|
3731
|
+
var FUNCTION = [Debug('MKAUTH').bar, Debug('MKAUTH').pix, Debug('MKAUTH').qrpix, Debug('MKAUTH').qrlink, Debug('MKAUTH').pdf];
|
|
3732
|
+
const uID = await Dataset('TARGET', 'START', DateTime(), 'INSERT');
|
|
3733
|
+
if (uID == false) {
|
|
3734
|
+
uID = Debug('TARGET').id;
|
|
3735
|
+
}
|
|
3736
|
+
const Constructor = new Promise((resolve, reject) => {
|
|
3737
|
+
var Array = [];
|
|
3738
|
+
var Radeon = {};
|
|
3739
|
+
var Preview = false;
|
|
3740
|
+
var Caption, Send, Register, Renner;
|
|
3741
|
+
var RETURNS = [];
|
|
3742
|
+
Radeon['Title'] = 'xxx';
|
|
3743
|
+
Radeon['Name'] = 'Mwsm';
|
|
3744
|
+
if (isUser != undefined) {
|
|
3745
|
+
Radeon['Name'] = isUser;
|
|
3746
|
+
}
|
|
3747
|
+
if (isSend != undefined) {
|
|
3748
|
+
Radeon['Title'] = isSend;
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3751
|
+
if (Mensagem.some(Row => testJSON(Row)) && (FUNCTION.includes('true') || FUNCTION.includes('1')) && Boolean(Debug('MKAUTH').module)) {
|
|
3752
|
+
Mensagem.some(function(Send, index) {
|
|
3753
|
+
if (testJSON(Send) && (FUNCTION.includes('true') || FUNCTION.includes('1'))) {
|
|
3754
|
+
var Json = Send.toString().replace('"', '').split(',');
|
|
3755
|
+
isUid = Json[0].replace(/[{\}\\"]/g, '');
|
|
3756
|
+
if (isUid.split(':').length == 2) {
|
|
3757
|
+
isUid = isUid.split(':')[1];
|
|
3758
|
+
} else {
|
|
3759
|
+
isUid = (isUid).replace(isUid.split(':')[0], '');
|
|
3760
|
+
isUid = isUid.replace(/^:+/, '');
|
|
3761
|
+
}
|
|
3762
|
+
isFind = Json[1].replace(/[^0-9]/g, '');
|
|
3763
|
+
Json = {
|
|
3764
|
+
uid: isUid,
|
|
3765
|
+
find: isFind
|
|
3766
|
+
};
|
|
3767
|
+
Terminal(JSON.stringify(Json));
|
|
3768
|
+
MkAuth(Json.uid, Json.find).then(Synchronization => {
|
|
3769
|
+
if (Boolean(Debug('MKAUTH').bar)) {
|
|
3770
|
+
RETURNS.push('Bar');
|
|
3771
|
+
}
|
|
3772
|
+
if (Boolean(Debug('MKAUTH').pix)) {
|
|
3773
|
+
RETURNS.push('Pix');
|
|
3774
|
+
}
|
|
3775
|
+
|
|
3776
|
+
if (Boolean(Debug('MKAUTH').qrpix)) {
|
|
3777
|
+
RETURNS.push('QRCode');
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3780
|
+
if (Boolean(Debug('MKAUTH').qrlink)) {
|
|
3781
|
+
RETURNS.push('Link');
|
|
3782
|
+
}
|
|
3783
|
+
|
|
3784
|
+
if (Boolean(Debug('MKAUTH').pdf)) {
|
|
3785
|
+
RETURNS.push('Boleto');
|
|
3786
|
+
}
|
|
3787
|
+
if (Synchronization.ID != undefined) {
|
|
3788
|
+
Radeon['Title'] = Synchronization.ID;
|
|
3789
|
+
Radeon['Name'] = Synchronization.Name;
|
|
3790
|
+
db.run("UPDATE target SET title=? WHERE id=?", [Synchronization.ID, uID], (err) => {
|
|
3791
|
+
if (err) throw err;
|
|
3792
|
+
});
|
|
3793
|
+
}
|
|
3794
|
+
if (Synchronization.Status != "pago" && Synchronization.Status != "paid" && Synchronization.Status != "Error" && Synchronization.Status != "Null") {
|
|
3795
|
+
(Synchronization.Payments).forEach(function(GET, index) {
|
|
3796
|
+
if (RETURNS.includes(GET.caption)) {
|
|
3797
|
+
switch (GET.caption) {
|
|
3798
|
+
case 'Bar':
|
|
3799
|
+
Send = GET.value;
|
|
3800
|
+
Caption = GET.caption;
|
|
3801
|
+
break;
|
|
3802
|
+
case 'Pix':
|
|
3803
|
+
Send = GET.value;
|
|
3804
|
+
Caption = GET.caption;
|
|
3805
|
+
break;
|
|
3806
|
+
case 'QRCode':
|
|
3807
|
+
Send = new MessageMedia('image/png', GET.value, GET.caption);
|
|
3808
|
+
Caption = GET.caption;
|
|
3809
|
+
break;
|
|
3810
|
+
case 'Link':
|
|
3811
|
+
Send = GET.value;
|
|
3812
|
+
Caption = GET.caption;
|
|
3813
|
+
break;
|
|
3814
|
+
case 'Boleto':
|
|
3815
|
+
Send = GET.value;
|
|
3816
|
+
Caption = GET.caption;
|
|
3817
|
+
break;
|
|
3818
|
+
}
|
|
3819
|
+
if (Send != '') {
|
|
3820
|
+
Array.push(Send);
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
if (((Synchronization.Payments).length == (index + 1))) {
|
|
3824
|
+
Radeon['Message'] = Array;
|
|
3825
|
+
resolve(Radeon);
|
|
3826
|
+
}
|
|
3827
|
+
});
|
|
3828
|
+
} else {
|
|
3829
|
+
if (Synchronization.Status == "Error") {
|
|
3830
|
+
Radeon['Message'] = "Error";
|
|
3831
|
+
resolve(Radeon);
|
|
3832
|
+
|
|
3833
|
+
} else {
|
|
3834
|
+
if (Synchronization.Status == "Null") {
|
|
3835
|
+
Radeon['Message'] = "Null";
|
|
3836
|
+
resolve(Radeon);
|
|
3837
|
+
|
|
3838
|
+
} else {
|
|
3839
|
+
Radeon['Message'] = "Fail";
|
|
3840
|
+
resolve(Radeon);
|
|
3841
|
+
|
|
3842
|
+
}
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
}).catch(err => {
|
|
3846
|
+
Radeon['Message'] = false;
|
|
3847
|
+
resolve(Radeon);
|
|
3848
|
+
|
|
3849
|
+
});
|
|
3850
|
+
|
|
3851
|
+
|
|
3852
|
+
}
|
|
3853
|
+
});
|
|
3854
|
+
} else {
|
|
3855
|
+
|
|
3856
|
+
if (Mensagem.some(Row => testJSON(Row))) {
|
|
3857
|
+
Mensagem.some(function(Send, index) {
|
|
3858
|
+
if (testJSON(Send)) {
|
|
3859
|
+
var Json = Send.toString().replace('"', '').split(',');
|
|
3860
|
+
isUid = Json[0].replace(/[{\}\\"]/g, '');
|
|
3861
|
+
if (isUid.split(':').length == 2) {
|
|
3862
|
+
isUid = isUid.split(':')[1];
|
|
3863
|
+
} else {
|
|
3864
|
+
isUid = (isUid).replace(isUid.split(':')[0], '');
|
|
3865
|
+
isUid = isUid.replace(/^:+/, '');
|
|
3866
|
+
}
|
|
3867
|
+
isFind = Json[1].replace(/[^0-9]/g, '');
|
|
3868
|
+
Json = {
|
|
3869
|
+
uid: isUid,
|
|
3870
|
+
find: isFind
|
|
3871
|
+
};
|
|
3872
|
+
Terminal(JSON.stringify(Json));
|
|
3873
|
+
}
|
|
3874
|
+
});
|
|
3875
|
+
|
|
3876
|
+
if (Boolean(Debug('MKAUTH').module)) {
|
|
3877
|
+
if ((FUNCTION.includes('true') || FUNCTION.includes('1'))) {
|
|
3878
|
+
Radeon['Message'] = undefined;
|
|
3879
|
+
} else {
|
|
3880
|
+
Radeon['Message'] = "False";
|
|
3881
|
+
}
|
|
3882
|
+
} else {
|
|
3883
|
+
Radeon['Message'] = "Fatal";
|
|
3884
|
+
JDebug = {
|
|
3885
|
+
"MkAuth": "Connect was Failed",
|
|
3886
|
+
};
|
|
3887
|
+
Terminal(JDebug);
|
|
3888
|
+
}
|
|
3889
|
+
resolve(Radeon);
|
|
3890
|
+
} else {
|
|
3891
|
+
Radeon['Message'] = undefined;
|
|
3892
|
+
resolve(Radeon);
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
});
|
|
3896
|
+
|
|
3897
|
+
const Reconstructor = new Promise((resolve, reject) => {
|
|
3898
|
+
if (Mensagem.some(Row => Debug('ATTACHMENTS', 'SUFFIXES', 'MULTIPLE').some(Rows => Row.includes(Rows)))) {
|
|
3899
|
+
var isArray = {};
|
|
3900
|
+
(Mensagem).someAsync(async (Send) => {
|
|
3901
|
+
if (Debug('ATTACHMENTS', 'SUFFIXES', 'MULTIPLE').some(Row => Send.includes(Row))) {
|
|
3902
|
+
const isCloud = async (Url) => {
|
|
3903
|
+
let isMimetype;
|
|
3904
|
+
const isAttachment = await axios.get(Url, {
|
|
3905
|
+
responseType: 'arraybuffer'
|
|
3906
|
+
}).then(response => {
|
|
3907
|
+
isMimetype = response.headers['content-type'];
|
|
3908
|
+
return response.data.toString('base64');
|
|
3909
|
+
});
|
|
3910
|
+
return await new MessageMedia(isMimetype, isAttachment, 'Media');
|
|
3911
|
+
};
|
|
3912
|
+
|
|
3913
|
+
await isCloud(Send).then(Return => {
|
|
3914
|
+
isArray[Send] = Return;
|
|
3915
|
+
resolve(isArray);
|
|
3916
|
+
}).catch(err => {
|
|
3917
|
+
resolve(undefined);
|
|
3918
|
+
});
|
|
3919
|
+
|
|
3920
|
+
}
|
|
3921
|
+
});
|
|
3922
|
+
} else {
|
|
3923
|
+
resolve(undefined);
|
|
3924
|
+
}
|
|
3925
|
+
});
|
|
3926
|
+
|
|
3927
|
+
delay(0).then(async function() {
|
|
3928
|
+
const Retorno = await Promise.all([Constructor, Reconstructor]);
|
|
3929
|
+
var Boleto, PDF2Base64, Sleep = 0;
|
|
3930
|
+
if (Debug('MKAUTH').delay >= 3) {
|
|
3931
|
+
Sleep = (Sleep + (Debug('MKAUTH').delay * 1000));
|
|
3932
|
+
}
|
|
3933
|
+
if ((Retorno[0].Message != undefined) && (Retorno[0].Message != "Fail") && (Retorno[0].Message != "False") && (Retorno[0].Message != "Fatal") && (Retorno[0].Message != false) && (Retorno[0].Message != "Error") && (Retorno[0].Message != "Null")) {
|
|
3934
|
+
|
|
3935
|
+
for (let i = 0; i < Retorno[0].Message.length; i++) {
|
|
3936
|
+
if (typeof Retorno[0].Message[i] === 'string') {
|
|
3937
|
+
if ((Retorno[0].Message[i].indexOf("boleto.hhvm") > -1)) {
|
|
3938
|
+
const UID = Retorno[0].Message[i].split("=")[1];
|
|
3939
|
+
Boleto = await Build(Retorno[0].Message[i]);
|
|
3940
|
+
PDF2Base64 = await new Promise((resolve, reject) => {
|
|
3941
|
+
if (Debug('ATTACHMENTS', 'SUFFIXES', 'MULTIPLE').some(Row => Boleto.includes(Row))) {
|
|
3942
|
+
const Cloud = async (Url) => {
|
|
3943
|
+
let mimetype;
|
|
3944
|
+
const attachment = await axios.get(Url, {
|
|
3945
|
+
responseType: 'arraybuffer'
|
|
3946
|
+
}).then(response => {
|
|
3947
|
+
mimetype = response.headers['content-type'];
|
|
3948
|
+
return response.data.toString('base64');
|
|
3949
|
+
});
|
|
3950
|
+
return new MessageMedia(mimetype, attachment, 'Fatura');
|
|
3951
|
+
};
|
|
3952
|
+
Cloud(Boleto).then(Return => {
|
|
3953
|
+
resolve(Return);
|
|
3954
|
+
}).catch(err => {
|
|
3955
|
+
resolve(undefined);
|
|
3956
|
+
});
|
|
3957
|
+
}
|
|
3958
|
+
});
|
|
3959
|
+
Boleto = await PDF2Base64;
|
|
3960
|
+
if (fs.existsSync(__dirname + "/" + UID + ".pdf")) {
|
|
3961
|
+
fs.unlinkSync(__dirname + "/" + UID + ".pdf");
|
|
3962
|
+
}
|
|
3963
|
+
}
|
|
3964
|
+
}
|
|
3965
|
+
}
|
|
3966
|
+
}
|
|
3967
|
+
delay(Sleep).then(async function() {
|
|
3968
|
+
var Assembly = [];
|
|
3969
|
+
var Sending = 1;
|
|
3970
|
+
var Ryzen = 0;
|
|
3971
|
+
var PrevERROR = false;
|
|
3972
|
+
Mensagem.someAsync(async (Send) => {
|
|
3973
|
+
if (testJSON(Send)) {
|
|
3974
|
+
if ((Retorno[0].Message != undefined) && (Retorno[0].Message != "Fail") && (Retorno[0].Message != false) && (Retorno[0].Message != "Error") && (Retorno[0].Message != "Null") && (Retorno[0].Message != "Fatal") && (Retorno[0].Message != "False")) {
|
|
3975
|
+
for (let i = 0; i < Retorno[0].Message.length; i++) {
|
|
3976
|
+
Assembly.push(Retorno[0].Message[i]);
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3979
|
+
} else {
|
|
3980
|
+
if (Debug('ATTACHMENTS', 'SUFFIXES', 'MULTIPLE').some(Row => Send.includes(Row))) {
|
|
3981
|
+
if (typeof Send === 'string') {
|
|
3982
|
+
if ((Send.indexOf("http") > -1)) {
|
|
3983
|
+
if (Retorno[1][Send] != undefined) {
|
|
3984
|
+
if (Retorno[1].hasOwnProperty(Send)) {
|
|
3985
|
+
Assembly.push(Retorno[1][Send]);
|
|
3986
|
+
}
|
|
3987
|
+
|
|
3988
|
+
}
|
|
3989
|
+
} else {
|
|
3990
|
+
Assembly.push(Send);
|
|
3991
|
+
}
|
|
3992
|
+
} else {
|
|
3993
|
+
if (Retorno[1][Send] != undefined) {
|
|
3994
|
+
if (Retorno[1].hasOwnProperty(Send)) {
|
|
3995
|
+
Assembly.push(Retorno[1][Send]);
|
|
3996
|
+
}
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
} else {
|
|
4000
|
+
Assembly.push(Send);
|
|
4001
|
+
}
|
|
4002
|
+
}
|
|
4003
|
+
});
|
|
4004
|
+
|
|
4005
|
+
if (WhatsApp == Wait || Wait == undefined) {
|
|
4006
|
+
Delay = 300;
|
|
4007
|
+
} else {
|
|
4008
|
+
Delay = Debug('OPTIONS').sendwait;
|
|
4009
|
+
}
|
|
4010
|
+
if (Assembly.length >= 1) {
|
|
4011
|
+
if ((Retorno[0].Message == "Fail") || (Retorno[0].Message == false) || (Retorno[0].Message == "Error") || (Retorno[0].Message == "Null") || (Retorno[0].Message == "Fatal") || (Retorno[0].Message == "False")) {
|
|
4012
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
4013
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
4014
|
+
if (Retorno[0].Message == "Fail") {
|
|
4015
|
+
res.json({
|
|
4016
|
+
Status: "Fail",
|
|
4017
|
+
message: Debug('CONSOLE').unavailable
|
|
4018
|
+
});
|
|
4019
|
+
}
|
|
4020
|
+
if (Retorno[0].Message == "Error") {
|
|
4021
|
+
res.json({
|
|
4022
|
+
Status: "Fail",
|
|
4023
|
+
message: Debug('CONSOLE').request
|
|
4024
|
+
});
|
|
4025
|
+
}
|
|
4026
|
+
if (Retorno[0].Message == "Null") {
|
|
4027
|
+
res.json({
|
|
4028
|
+
Status: "Fail",
|
|
4029
|
+
message: Debug('CONSOLE').missing
|
|
4030
|
+
});
|
|
4031
|
+
}
|
|
4032
|
+
|
|
4033
|
+
if (Retorno[0].Message == "Fatal") {
|
|
4034
|
+
res.json({
|
|
4035
|
+
Status: "Fail",
|
|
4036
|
+
message: Debug('CONSOLE').mkfail
|
|
4037
|
+
});
|
|
4038
|
+
}
|
|
4039
|
+
|
|
4040
|
+
if (Retorno[0].Message == "False") {
|
|
4041
|
+
res.json({
|
|
4042
|
+
Status: "Fail",
|
|
4043
|
+
message: Debug('CONSOLE').mkunselect
|
|
4044
|
+
});
|
|
4045
|
+
}
|
|
4046
|
+
|
|
4047
|
+
if (Retorno[0].Message == false) {
|
|
4048
|
+
var SELECTOR = false;
|
|
4049
|
+
if (Boolean(Debug('MKAUTH').bar)) {
|
|
4050
|
+
SELECTOR = true;
|
|
4051
|
+
}
|
|
4052
|
+
|
|
4053
|
+
if (Boolean(Debug('MKAUTH').pix)) {
|
|
4054
|
+
SELECTOR = true;
|
|
4055
|
+
}
|
|
4056
|
+
|
|
4057
|
+
if (Boolean(Debug('MKAUTH').qrpix)) {
|
|
4058
|
+
SELECTOR = true;
|
|
4059
|
+
}
|
|
4060
|
+
|
|
4061
|
+
if (Boolean(Debug('MKAUTH').qrlink)) {
|
|
4062
|
+
SELECTOR = true;
|
|
4063
|
+
}
|
|
4064
|
+
|
|
4065
|
+
if (Boolean(Debug('MKAUTH').pdf)) {
|
|
4066
|
+
SELECTOR = true;
|
|
4067
|
+
}
|
|
4068
|
+
Retorno[0].Message = "Fail";
|
|
4069
|
+
if (SELECTOR) {
|
|
4070
|
+
return res.json({
|
|
4071
|
+
Status: "Fail",
|
|
4072
|
+
message: Debug('CONSOLE').refused
|
|
4073
|
+
});
|
|
4074
|
+
} else {
|
|
4075
|
+
return res.json({
|
|
4076
|
+
Status: "Fail",
|
|
4077
|
+
message: Debug('CONSOLE').mkunselect
|
|
4078
|
+
});
|
|
4079
|
+
}
|
|
4080
|
+
}
|
|
4081
|
+
db.get("SELECT * FROM target WHERE id='" + uID + "'", (err, TARGET) => {
|
|
4082
|
+
if (TARGET != undefined) {
|
|
4083
|
+
if (Retorno[0].Title == "xxx") {
|
|
4084
|
+
Retorno[0].Title = uID;
|
|
4085
|
+
}
|
|
4086
|
+
if (Retorno[0].Message == undefined) {
|
|
4087
|
+
Retorno[0].Message = "Null";
|
|
4088
|
+
}
|
|
4089
|
+
if (Retorno[0].Message == "False") {
|
|
4090
|
+
Retorno[0].Message = "Fail";
|
|
4091
|
+
}
|
|
4092
|
+
|
|
4093
|
+
db.serialize(() => {
|
|
4094
|
+
db.run("UPDATE target SET end=?, status=?, target=?, title=?, client=? WHERE id=?", [DateTime(), Retorno[0].Message, WhatsApp.replace(/^55+/, '').replace(/\D/g, ''), Retorno[0].Title, Retorno[0].Name, uID], (err) => {
|
|
4095
|
+
if (err) throw err;
|
|
4096
|
+
});
|
|
4097
|
+
db.get("SELECT * FROM target WHERE id='" + uID + "'", (err, TARGET) => {
|
|
4098
|
+
isTARGET = [];
|
|
4099
|
+
if (TARGET != undefined) {
|
|
4100
|
+
Debug('TARGET', '*', 'ALL').some(function(TARGET, index) {
|
|
4101
|
+
if (TARGET.status == 'pending') {
|
|
4102
|
+
Dataset('TARGET', '*', TARGET.id, 'DELETE');
|
|
4103
|
+
Dataset('SQLITE_SEQUENCE', 'SEQ', 'TARGET', 'FLUSH');
|
|
4104
|
+
} else {
|
|
4105
|
+
if (TARGET.target == "900000000") {
|
|
4106
|
+
TARGET.target = "(00) 0 0000-0000";
|
|
4107
|
+
}
|
|
4108
|
+
GetLog = {
|
|
4109
|
+
"ID": TARGET.id,
|
|
4110
|
+
"TITLE": TARGET.title,
|
|
4111
|
+
"NAME": TARGET.client,
|
|
4112
|
+
"START": TARGET.start,
|
|
4113
|
+
"END": TARGET.end,
|
|
4114
|
+
"TARGET": TARGET.target,
|
|
4115
|
+
"STATUS": TARGET.status,
|
|
4116
|
+
};
|
|
4117
|
+
isTARGET.push(GetLog);
|
|
4118
|
+
if (Debug('TARGET', '*', 'ALL').length <= (index + 1)) {
|
|
4119
|
+
if (Boolean(Debug('OPTIONS').auth)) {
|
|
4120
|
+
global.io.emit('setlog', isTARGET);
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
|
|
4125
|
+
});
|
|
4126
|
+
}
|
|
4127
|
+
});
|
|
4128
|
+
});
|
|
4129
|
+
}
|
|
4130
|
+
});
|
|
4131
|
+
} else {
|
|
4132
|
+
Terminal(Assembly);
|
|
4133
|
+
setTimeout(function() {
|
|
4134
|
+
var DoubleKill;
|
|
4135
|
+
Assembly.some(function(Send, index) {
|
|
4136
|
+
const PIXFAIL = [undefined, "XXX", null, ""];
|
|
4137
|
+
if (!PIXFAIL.includes(Debug('OPTIONS').pixfail) && Send == "CodigoIndisponivel") {
|
|
4138
|
+
Send = Send.replace("CodigoIndisponivel", Debug('OPTIONS').pixfail);
|
|
4139
|
+
}
|
|
4140
|
+
setTimeout(function() {
|
|
4141
|
+
setTimeout(function() {
|
|
4142
|
+
if (typeof Send === 'string') {
|
|
4143
|
+
if ((Send.indexOf("boleto.hhvm") > -1)) {
|
|
4144
|
+
if (Boleto != undefined) {
|
|
4145
|
+
if (typeof Boleto !== 'string') {
|
|
4146
|
+
Send = Boleto;
|
|
4147
|
+
}
|
|
4148
|
+
}
|
|
4149
|
+
Caption = "Boleto";
|
|
4150
|
+
Preview = true;
|
|
4151
|
+
Ryzen = 1000;
|
|
4152
|
+
} else {
|
|
4153
|
+
if ((Send.indexOf("http") > -1)) {
|
|
4154
|
+
Caption = undefined;
|
|
4155
|
+
Preview = true;
|
|
4156
|
+
} else {
|
|
4157
|
+
Caption = undefined;
|
|
4158
|
+
Preview = false;
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
4161
|
+
} else {
|
|
4162
|
+
if (JSON.parse(JSON.stringify(Send)).filename != "Media") {
|
|
4163
|
+
Caption = JSON.parse(JSON.stringify(Send)).filename;
|
|
4164
|
+
Preview = false;
|
|
4165
|
+
} else {
|
|
4166
|
+
Caption = undefined;
|
|
4167
|
+
Preview = false;
|
|
4168
|
+
}
|
|
4169
|
+
Ryzen = 1000;
|
|
4170
|
+
}
|
|
4171
|
+
|
|
4172
|
+
|
|
4173
|
+
if ([Debug('OPTIONS').token, Password[1]].includes(isHid)) {
|
|
4174
|
+
(async () => {
|
|
4175
|
+
if (Boolean(Debug('MKAUTH').prevent)) {
|
|
4176
|
+
if (DoubleKill != Send) {
|
|
4177
|
+
try {
|
|
4178
|
+
await client.sendMessage(WhatsApp, isEmoji(Send), {
|
|
4179
|
+
caption: Caption,
|
|
4180
|
+
linkPreview: Preview
|
|
4181
|
+
});
|
|
4182
|
+
} catch (err) {
|
|
4183
|
+
return res.status(500).json({
|
|
4184
|
+
Status: "Fail",
|
|
4185
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
4186
|
+
});
|
|
4187
|
+
await WwjsVersion(false);
|
|
4188
|
+
} finally {
|
|
4189
|
+
DoubleKill = Send;
|
|
4190
|
+
Wait = WhatsApp;
|
|
4191
|
+
Sending = (Sending + 1);
|
|
4192
|
+
}
|
|
4193
|
+
}
|
|
4194
|
+
} else {
|
|
4195
|
+
try {
|
|
4196
|
+
await client.sendMessage(WhatsApp, isEmoji(Send), {
|
|
4197
|
+
caption: Caption,
|
|
4198
|
+
linkPreview: Preview
|
|
4199
|
+
});
|
|
4200
|
+
} catch (err) {
|
|
4201
|
+
return res.status(500).json({
|
|
4202
|
+
Status: "Fail",
|
|
4203
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
4204
|
+
});
|
|
4205
|
+
await WwjsVersion(false);
|
|
4206
|
+
} finally {
|
|
4207
|
+
Wait = WhatsApp;
|
|
4208
|
+
Sending = (Sending + 1);
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4211
|
+
})();
|
|
4212
|
+
} else {
|
|
4213
|
+
|
|
4214
|
+
return res.status(500).json({
|
|
4215
|
+
Status: "Fail",
|
|
4216
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
4217
|
+
});
|
|
4218
|
+
|
|
4219
|
+
}
|
|
4220
|
+
|
|
4221
|
+
if ((Sending == Assembly.length) || (Assembly.length == (index + 1))) {
|
|
4222
|
+
|
|
4223
|
+
db.get("SELECT * FROM target WHERE id='" + uID + "'", (err, TARGET) => {
|
|
4224
|
+
if (TARGET != undefined) {
|
|
4225
|
+
|
|
4226
|
+
if (Retorno[0].Title == "xxx") {
|
|
4227
|
+
Retorno[0].Title = Debug('TARGET').id;
|
|
4228
|
+
}
|
|
4229
|
+
if (Retorno[0].Message == undefined) {
|
|
4230
|
+
Retorno[0].Message = "Null";
|
|
4231
|
+
}
|
|
4232
|
+
if (Retorno[0].Message == "False") {
|
|
4233
|
+
Retorno[0].Message = "Fail";
|
|
4234
|
+
}
|
|
4235
|
+
|
|
4236
|
+
|
|
4237
|
+
db.serialize(() => {
|
|
4238
|
+
db.run("UPDATE target SET end=?, status=?, target=?, title=?, client=? WHERE id=?", [DateTime(), 'Sent', WhatsApp.replace(/^55+/, '').replace(/\D/g, ''), Retorno[0].Title, Retorno[0].Name, uID], (err) => {
|
|
4239
|
+
|
|
4240
|
+
if (err) throw err;
|
|
4241
|
+
});
|
|
4242
|
+
db.get("SELECT * FROM target WHERE id='" + uID + "'", (err, TARGET) => {
|
|
4243
|
+
isTARGET = [];
|
|
4244
|
+
if (TARGET != undefined) {
|
|
4245
|
+
Debug('TARGET', '*', 'ALL').some(function(TARGET, index) {
|
|
4246
|
+
if (TARGET.status == 'pending') {
|
|
4247
|
+
Dataset('TARGET', '*', TARGET.id, 'DELETE');
|
|
4248
|
+
Dataset('SQLITE_SEQUENCE', 'SEQ', 'TARGET', 'FLUSH');
|
|
4249
|
+
} else {
|
|
4250
|
+
if (TARGET.target == "900000000") {
|
|
4251
|
+
TARGET.target = "(00) 0 0000-0000";
|
|
4252
|
+
}
|
|
4253
|
+
GetLog = {
|
|
4254
|
+
"ID": TARGET.id,
|
|
4255
|
+
"TITLE": TARGET.title,
|
|
4256
|
+
"NAME": TARGET.client,
|
|
4257
|
+
"START": TARGET.start,
|
|
4258
|
+
"END": TARGET.end,
|
|
4259
|
+
"TARGET": TARGET.target,
|
|
4260
|
+
"STATUS": TARGET.status,
|
|
4261
|
+
};
|
|
4262
|
+
isTARGET.push(GetLog);
|
|
4263
|
+
if (Debug('TARGET', '*', 'ALL').length <= (index + 1)) {
|
|
4264
|
+
if (Boolean(Debug('OPTIONS').auth)) {
|
|
4265
|
+
global.io.emit('setlog', isTARGET);
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4268
|
+
}
|
|
4269
|
+
|
|
4270
|
+
});
|
|
4271
|
+
}
|
|
4272
|
+
});
|
|
4273
|
+
});
|
|
4274
|
+
}
|
|
4275
|
+
});
|
|
4276
|
+
|
|
4277
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').success);
|
|
4278
|
+
return res.json({
|
|
4279
|
+
Status: "Success",
|
|
4280
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').success
|
|
4281
|
+
});
|
|
4282
|
+
|
|
4283
|
+
}
|
|
4284
|
+
}, ((Debug('MKAUTH').delay + index) * Ryzen));
|
|
4285
|
+
}, (index) * Debug('OPTIONS').interval);
|
|
4286
|
+
});
|
|
4287
|
+
}, Math.floor(Delay + Math.random() * 1000));
|
|
4288
|
+
}
|
|
4289
|
+
} else {
|
|
4290
|
+
if (Boolean(Debug('MKAUTH').module)) {
|
|
4291
|
+
if (Retorno[0].Message == "Fail" || Retorno[0].Message == false || (Retorno[0].Message == "Error") || (Retorno[0].Message == "Null") || (Retorno[0].Message == "Fatal") || (Retorno[0].Message == "False")) {
|
|
4292
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
4293
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
4294
|
+
|
|
4295
|
+
if (Retorno[0].Message == "Fail") {
|
|
4296
|
+
res.json({
|
|
4297
|
+
Status: "Fail",
|
|
4298
|
+
message: Debug('CONSOLE').unavailable
|
|
4299
|
+
});
|
|
4300
|
+
}
|
|
4301
|
+
if (Retorno[0].Message == "Error") {
|
|
4302
|
+
res.json({
|
|
4303
|
+
Status: "Fail",
|
|
4304
|
+
message: Debug('CONSOLE').request
|
|
4305
|
+
});
|
|
4306
|
+
}
|
|
4307
|
+
if (Retorno[0].Message == "Null") {
|
|
4308
|
+
res.json({
|
|
4309
|
+
Status: "Fail",
|
|
4310
|
+
message: Debug('CONSOLE').missing
|
|
4311
|
+
});
|
|
4312
|
+
}
|
|
4313
|
+
|
|
4314
|
+
if (Retorno[0].Message == "Fatal") {
|
|
4315
|
+
res.json({
|
|
4316
|
+
Status: "Fail",
|
|
4317
|
+
message: Debug('CONSOLE').mkfail
|
|
4318
|
+
});
|
|
4319
|
+
}
|
|
4320
|
+
|
|
4321
|
+
if (Retorno[0].Message == "False") {
|
|
4322
|
+
res.json({
|
|
4323
|
+
Status: "Fail",
|
|
4324
|
+
message: Debug('CONSOLE').mkunselect
|
|
4325
|
+
});
|
|
4326
|
+
}
|
|
4327
|
+
if (Retorno[0].Message == false) {
|
|
4328
|
+
var SELECTOR = false;
|
|
4329
|
+
if (Boolean(Debug('MKAUTH').bar)) {
|
|
4330
|
+
SELECTOR = true;
|
|
4331
|
+
}
|
|
4332
|
+
|
|
4333
|
+
if (Boolean(Debug('MKAUTH').pix)) {
|
|
4334
|
+
SELECTOR = true;
|
|
4335
|
+
}
|
|
4336
|
+
|
|
4337
|
+
if (Boolean(Debug('MKAUTH').qrpix)) {
|
|
4338
|
+
SELECTOR = true;
|
|
4339
|
+
}
|
|
4340
|
+
|
|
4341
|
+
if (Boolean(Debug('MKAUTH').qrlink)) {
|
|
4342
|
+
SELECTOR = true;
|
|
4343
|
+
}
|
|
4344
|
+
|
|
4345
|
+
if (Boolean(Debug('MKAUTH').pdf)) {
|
|
4346
|
+
SELECTOR = true;
|
|
4347
|
+
}
|
|
4348
|
+
Retorno[0].Message = "Fail";
|
|
4349
|
+
if (SELECTOR) {
|
|
4350
|
+
|
|
4351
|
+
return res.json({
|
|
4352
|
+
Status: "Fail",
|
|
4353
|
+
message: Debug('CONSOLE').refused
|
|
4354
|
+
});
|
|
4355
|
+
} else {
|
|
4356
|
+
return res.json({
|
|
4357
|
+
Status: "Fail",
|
|
4358
|
+
message: Debug('CONSOLE').mkunselect
|
|
4359
|
+
});
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4362
|
+
|
|
4363
|
+
db.get("SELECT * FROM target WHERE id='" + Debug('TARGET').id + "'", (err, TARGET) => {
|
|
4364
|
+
if (TARGET != undefined) {
|
|
4365
|
+
|
|
4366
|
+
if (Retorno[0].Title == "xxx") {
|
|
4367
|
+
Retorno[0].Title = Debug('TARGET').id;
|
|
4368
|
+
}
|
|
4369
|
+
if (Retorno[0].Message == undefined) {
|
|
4370
|
+
Retorno[0].Message = "Null";
|
|
4371
|
+
}
|
|
4372
|
+
if (Retorno[0].Message == "False") {
|
|
4373
|
+
Retorno[0].Message = "Fail";
|
|
4374
|
+
}
|
|
4375
|
+
|
|
4376
|
+
|
|
4377
|
+
db.serialize(() => {
|
|
4378
|
+
db.run("UPDATE target SET end=?, status=?, target=?, title=? WHERE id=?", [DateTime(), Retorno[0].Message, WhatsApp.replace(/^55+/, '').replace(/\D/g, ''), Retorno[0].Title, uID], (err) => {
|
|
4379
|
+
|
|
4380
|
+
if (err) throw err;
|
|
4381
|
+
});
|
|
4382
|
+
db.get("SELECT * FROM target WHERE id='" + uID + "'", (err, TARGET) => {
|
|
4383
|
+
isTARGET = [];
|
|
4384
|
+
if (TARGET != undefined) {
|
|
4385
|
+
Debug('TARGET', '*', 'ALL').some(function(TARGET, index) {
|
|
4386
|
+
if (TARGET.status == 'pending') {
|
|
4387
|
+
Dataset('TARGET', '*', TARGET.id, 'DELETE');
|
|
4388
|
+
Dataset('SQLITE_SEQUENCE', 'SEQ', 'TARGET', 'FLUSH');
|
|
4389
|
+
} else {
|
|
4390
|
+
if (TARGET.target == "900000000") {
|
|
4391
|
+
TARGET.target = "(00) 0 0000-0000";
|
|
4392
|
+
}
|
|
4393
|
+
GetLog = {
|
|
4394
|
+
"ID": TARGET.id,
|
|
4395
|
+
"TITLE": TARGET.title,
|
|
4396
|
+
"NAME": TARGET.client,
|
|
4397
|
+
"START": TARGET.start,
|
|
4398
|
+
"END": TARGET.end,
|
|
4399
|
+
"TARGET": TARGET.target,
|
|
4400
|
+
"STATUS": TARGET.status,
|
|
4401
|
+
};
|
|
4402
|
+
isTARGET.push(GetLog);
|
|
4403
|
+
if (Debug('TARGET', '*', 'ALL').length <= (index + 1)) {
|
|
4404
|
+
if (Boolean(Debug('OPTIONS').auth)) {
|
|
4405
|
+
global.io.emit('setlog', isTARGET);
|
|
4406
|
+
}
|
|
4407
|
+
}
|
|
4408
|
+
}
|
|
4409
|
+
|
|
4410
|
+
});
|
|
4411
|
+
}
|
|
4412
|
+
});
|
|
4413
|
+
});
|
|
4414
|
+
}
|
|
4415
|
+
});
|
|
4416
|
+
} else {
|
|
4417
|
+
if ((Debug('TARGET', '*', 'ALL')).length >= 1) {
|
|
4418
|
+
|
|
4419
|
+
db.get("SELECT * FROM target WHERE id='" + uID + "'", (err, TARGET) => {
|
|
4420
|
+
if (TARGET != undefined) {
|
|
4421
|
+
|
|
4422
|
+
if (Retorno[0].Title == "xxx") {
|
|
4423
|
+
Retorno[0].Title = uID;
|
|
4424
|
+
}
|
|
4425
|
+
if (Retorno[0].Message == undefined) {
|
|
4426
|
+
Retorno[0].Message = "Null";
|
|
4427
|
+
}
|
|
4428
|
+
if (Retorno[0].Message == "False") {
|
|
4429
|
+
Retorno[0].Message = "Fail";
|
|
4430
|
+
}
|
|
4431
|
+
|
|
4432
|
+
db.serialize(() => {
|
|
4433
|
+
db.run("UPDATE target SET end=?, status=?, target=?, title=? WHERE id=?", [DateTime(), Retorno[0].Message, WhatsApp.replace(/^55+/, '').replace(/\D/g, ''), Retorno[0].Title, uID], (err) => {
|
|
4434
|
+
|
|
4435
|
+
if (err) throw err;
|
|
4436
|
+
});
|
|
4437
|
+
db.get("SELECT * FROM target WHERE id='" + uID + "'", (err, TARGET) => {
|
|
4438
|
+
isTARGET = [];
|
|
4439
|
+
if (TARGET != undefined) {
|
|
4440
|
+
Debug('TARGET', '*', 'ALL').some(function(TARGET, index) {
|
|
4441
|
+
if (TARGET.status == 'pending') {
|
|
4442
|
+
Dataset('TARGET', '*', TARGET.id, 'DELETE');
|
|
4443
|
+
Dataset('SQLITE_SEQUENCE', 'SEQ', 'TARGET', 'FLUSH');
|
|
4444
|
+
} else {
|
|
4445
|
+
if (TARGET.target == "900000000") {
|
|
4446
|
+
TARGET.target = "(00) 0 0000-0000";
|
|
4447
|
+
}
|
|
4448
|
+
GetLog = {
|
|
4449
|
+
"ID": TARGET.id,
|
|
4450
|
+
"TITLE": TARGET.title,
|
|
4451
|
+
"NAME": TARGET.client,
|
|
4452
|
+
"START": TARGET.start,
|
|
4453
|
+
"END": TARGET.end,
|
|
4454
|
+
"TARGET": TARGET.target,
|
|
4455
|
+
"STATUS": TARGET.status,
|
|
4456
|
+
};
|
|
4457
|
+
isTARGET.push(GetLog);
|
|
4458
|
+
if (Debug('TARGET', '*', 'ALL').length <= (index + 1)) {
|
|
4459
|
+
if (Boolean(Debug('OPTIONS').auth)) {
|
|
4460
|
+
global.io.emit('setlog', isTARGET);
|
|
4461
|
+
}
|
|
4462
|
+
}
|
|
4463
|
+
}
|
|
4464
|
+
|
|
4465
|
+
});
|
|
4466
|
+
}
|
|
4467
|
+
});
|
|
4468
|
+
});
|
|
4469
|
+
}
|
|
4470
|
+
});
|
|
4471
|
+
|
|
4472
|
+
} else {
|
|
4473
|
+
global.io.emit('getlog', true);
|
|
4474
|
+
|
|
4475
|
+
}
|
|
4476
|
+
|
|
4477
|
+
return res.json({
|
|
4478
|
+
Status: "Fail",
|
|
4479
|
+
message: Debug('CONSOLE').mkunselect
|
|
4480
|
+
});
|
|
4481
|
+
}
|
|
4482
|
+
} else {
|
|
4483
|
+
|
|
4484
|
+
if (!Boolean(Debug('MKAUTH').module)) {
|
|
4485
|
+
Retorno[0].Message = "Fail";
|
|
4486
|
+
return res.json({
|
|
4487
|
+
Status: "Fail",
|
|
4488
|
+
message: Debug('CONSOLE').mkfail
|
|
4489
|
+
});
|
|
4490
|
+
|
|
4491
|
+
} else {
|
|
4492
|
+
return res.json({
|
|
4493
|
+
Status: "Fail",
|
|
4494
|
+
message: Debug('CONSOLE').unnamed
|
|
4495
|
+
});
|
|
4496
|
+
}
|
|
4497
|
+
|
|
4498
|
+
if ((Debug('TARGET', '*', 'ALL')).length >= 1) {
|
|
4499
|
+
db.get("SELECT * FROM target WHERE id='" + uID + "'", (err, TARGET) => {
|
|
4500
|
+
if (TARGET != undefined) {
|
|
4501
|
+
|
|
4502
|
+
if (Retorno[0].Title == "xxx") {
|
|
4503
|
+
Retorno[0].Title = Debug('TARGET').id;
|
|
4504
|
+
}
|
|
4505
|
+
|
|
4506
|
+
if (Retorno[0].Message == undefined) {
|
|
4507
|
+
Retorno[0].Message = "Null";
|
|
4508
|
+
}
|
|
4509
|
+
|
|
4510
|
+
if (Retorno[0].Message == "False") {
|
|
4511
|
+
Retorno[0].Message = "Fail";
|
|
4512
|
+
}
|
|
4513
|
+
|
|
4514
|
+
db.serialize(() => {
|
|
4515
|
+
db.run("UPDATE target SET end=?, status=?, target=?, title=? WHERE id=?", [DateTime(), Retorno[0].Message, WhatsApp.replace(/^55+/, '').replace(/\D/g, ''), Retorno[0].Title, uID], (err) => {
|
|
4516
|
+
|
|
4517
|
+
if (err) throw err;
|
|
4518
|
+
});
|
|
4519
|
+
db.get("SELECT * FROM target WHERE id='" + uID + "'", (err, TARGET) => {
|
|
4520
|
+
isTARGET = [];
|
|
4521
|
+
if (TARGET != undefined) {
|
|
4522
|
+
Debug('TARGET', '*', 'ALL').some(function(TARGET, index) {
|
|
4523
|
+
if (TARGET.status == 'pending') {
|
|
4524
|
+
Dataset('TARGET', '*', TARGET.id, 'DELETE');
|
|
4525
|
+
Dataset('SQLITE_SEQUENCE', 'SEQ', 'TARGET', 'FLUSH');
|
|
4526
|
+
} else {
|
|
4527
|
+
if (TARGET.target == "900000000") {
|
|
4528
|
+
TARGET.target = "(00) 0 0000-0000";
|
|
4529
|
+
}
|
|
4530
|
+
GetLog = {
|
|
4531
|
+
"ID": TARGET.id,
|
|
4532
|
+
"TITLE": TARGET.title,
|
|
4533
|
+
"NAME": TARGET.client,
|
|
4534
|
+
"START": TARGET.start,
|
|
4535
|
+
"END": TARGET.end,
|
|
4536
|
+
"TARGET": TARGET.target,
|
|
4537
|
+
"STATUS": TARGET.status,
|
|
4538
|
+
};
|
|
4539
|
+
isTARGET.push(GetLog);
|
|
4540
|
+
if (Debug('TARGET', '*', 'ALL').length <= (index + 1)) {
|
|
4541
|
+
if (Boolean(Debug('OPTIONS').auth)) {
|
|
4542
|
+
global.io.emit('setlog', isTARGET);
|
|
4543
|
+
}
|
|
4544
|
+
}
|
|
4545
|
+
}
|
|
4546
|
+
|
|
4547
|
+
});
|
|
4548
|
+
}
|
|
4549
|
+
});
|
|
4550
|
+
});
|
|
4551
|
+
}
|
|
4552
|
+
});
|
|
4553
|
+
|
|
4554
|
+
} else {
|
|
4555
|
+
global.io.emit('getlog', true);
|
|
4556
|
+
|
|
4557
|
+
}
|
|
4558
|
+
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
});
|
|
4562
|
+
});
|
|
4563
|
+
} else {
|
|
4564
|
+
console.log("Mensagem Agendada");
|
|
4565
|
+
}
|
|
4566
|
+
} else if (Boolean(Simulator)) {
|
|
4567
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
4568
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
4569
|
+
|
|
4570
|
+
return res.json({
|
|
4571
|
+
Status: "Fail",
|
|
4572
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
4573
|
+
});
|
|
4574
|
+
|
|
4575
|
+
} else if (Boolean(Debug('MKAUTH').aimbot)) {
|
|
4576
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').trigger);
|
|
4577
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').trigger);
|
|
4578
|
+
|
|
4579
|
+
return res.status(500).json({
|
|
4580
|
+
Status: "Fail",
|
|
4581
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').trigger
|
|
4582
|
+
});
|
|
4583
|
+
} else {
|
|
4584
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
4585
|
+
console.error('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error);
|
|
4586
|
+
|
|
4587
|
+
return res.status(500).json({
|
|
4588
|
+
Status: "Fail",
|
|
4589
|
+
message: Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').error
|
|
4590
|
+
});
|
|
4591
|
+
}
|
|
4592
|
+
});
|
|
4593
|
+
|
|
4594
|
+
// Html to PDF
|
|
4595
|
+
app.get('/build', [
|
|
4596
|
+
body('uid').notEmpty()
|
|
4597
|
+
], async (req, res) => {
|
|
4598
|
+
const errors = validationResult(req).formatWith(({
|
|
4599
|
+
uid
|
|
4600
|
+
}) => {
|
|
4601
|
+
return uid;
|
|
4602
|
+
});
|
|
4603
|
+
if (!errors.isEmpty()) {
|
|
4604
|
+
return res.status(422).json({
|
|
4605
|
+
status: false,
|
|
4606
|
+
message: errors.mapped()
|
|
4607
|
+
});
|
|
4608
|
+
}
|
|
4609
|
+
const GET = req.body.uid;
|
|
4610
|
+
const UID = GET.split('=')[1];
|
|
4611
|
+
const URL = ([GET]);
|
|
4612
|
+
URL.someAsync(async (Send) => {
|
|
4613
|
+
htmlPDF.setOptions({
|
|
4614
|
+
format: "A4",
|
|
4615
|
+
timeout: 5000
|
|
4616
|
+
});
|
|
4617
|
+
htmlPDF.setAutoCloseBrowser(false);
|
|
4618
|
+
const Buffer = await htmlPDF.create(Send);
|
|
4619
|
+
const Patch = `${__dirname}/${UID}.pdf`;
|
|
4620
|
+
await htmlPDF.writeFile(Buffer, Patch);
|
|
4621
|
+
return res.json({
|
|
4622
|
+
Return: "http://" + ip.address() + ":" + Debug('OPTIONS').access + "/" + UID + ".pdf"
|
|
4623
|
+
});
|
|
4624
|
+
await htmlPDF.closeBrowser();
|
|
4625
|
+
});
|
|
4626
|
+
});
|
|
4627
|
+
|
|
4628
|
+
const Build = async (SET) => {
|
|
4629
|
+
const PDFGet = await axios.get("http://" + ip.address() + ":" + Debug('OPTIONS').access + "/build", {
|
|
4630
|
+
data: {
|
|
4631
|
+
uid: SET,
|
|
4632
|
+
}
|
|
4633
|
+
}).then(response => {
|
|
4634
|
+
return response.data;
|
|
4635
|
+
}).catch(err => {
|
|
4636
|
+
return false;
|
|
4637
|
+
});
|
|
4638
|
+
return await PDFGet['Return'];
|
|
4639
|
+
};
|
|
4640
|
+
|
|
4641
|
+
|
|
4642
|
+
// WhatsApp Bot
|
|
4643
|
+
client.on('message', async msg => {
|
|
4644
|
+
|
|
4645
|
+
// ==================================================
|
|
4646
|
+
// 🤖 Bot Menu e Controle Inteligente de IA
|
|
4647
|
+
// ==================================================
|
|
4648
|
+
const lastRequestTimes = new Map();
|
|
4649
|
+
let lastGlobalRequest = 0;
|
|
4650
|
+
let globalQueue = Promise.resolve();
|
|
4651
|
+
|
|
4652
|
+
if (activeMenus.has(msg.from)) {
|
|
4653
|
+
if (activeSupportIA.has(msg.from)) {
|
|
4654
|
+
try {
|
|
4655
|
+
const _iaExit = (msg.body || '').toString().trim().toLowerCase();
|
|
4656
|
+
|
|
4657
|
+
// 🔹 Encerrar atendimento
|
|
4658
|
+
if (["0", "sair", "tchau", "tchal"].includes(_iaExit)) {
|
|
4659
|
+
activeSupportIA.delete(msg.from);
|
|
4660
|
+
activeMenus.delete(msg.from);
|
|
4661
|
+
await client.sendMessage(msg.from, "✅ Atendimento encerrado. Obrigado pelo contato!");
|
|
4662
|
+
return;
|
|
4663
|
+
}
|
|
4664
|
+
|
|
4665
|
+
// 🔹 Voltar ao menu principal
|
|
4666
|
+
if (_iaExit === "menu") {
|
|
4667
|
+
activeSupportIA.delete(msg.from);
|
|
4668
|
+
activeMenus.set(msg.from, true);
|
|
4669
|
+
await client.sendMessage(
|
|
4670
|
+
msg.from,
|
|
4671
|
+
'📋 *Menu Principal*\n\n' +
|
|
4672
|
+
'1️⃣ Boleto\n' +
|
|
4673
|
+
'2️⃣ Suporte\n' +
|
|
4674
|
+
'0️⃣ Encerrar\n\n' +
|
|
4675
|
+
'👉 Responda com o número da opção desejada.'
|
|
4676
|
+
);
|
|
4677
|
+
return;
|
|
4678
|
+
}
|
|
4679
|
+
} catch (e) {
|
|
4680
|
+
console.error('IA exit handler error:', e?.message || e);
|
|
4681
|
+
}
|
|
4682
|
+
|
|
4683
|
+
try {
|
|
4684
|
+
const chat = await msg.getChat();
|
|
4685
|
+
const Engine = Debug('OPTIONS').engine;
|
|
4686
|
+
const Level = parseInt(Debug("ENGINE", "*", "DIRECT", Engine).level || 0);
|
|
4687
|
+
const perUserDelay = parseInt(Debug('OPTIONS').airequestdelay) || 3000;
|
|
4688
|
+
const globalDelay = parseInt(Debug('OPTIONS').aiglobaldelay) || 1000;
|
|
4689
|
+
|
|
4690
|
+
const now = Date.now();
|
|
4691
|
+
const lastUser = lastRequestTimes.get(msg.from) || 0;
|
|
4692
|
+
const sinceUser = now - lastUser;
|
|
4693
|
+
const sinceGlobal = now - lastGlobalRequest;
|
|
4694
|
+
const waitUser = Math.max(0, perUserDelay - sinceUser);
|
|
4695
|
+
const waitGlobal = Math.max(0, globalDelay - sinceGlobal);
|
|
4696
|
+
const totalWait = Math.max(waitUser, waitGlobal);
|
|
4697
|
+
|
|
4698
|
+
// ==================================================
|
|
4699
|
+
// 🔹 Modo Free — com fila e controle global
|
|
4700
|
+
// ==================================================
|
|
4701
|
+
if (Level === 0) {
|
|
4702
|
+
globalQueue = globalQueue.then(async () => {
|
|
4703
|
+
try {
|
|
4704
|
+
if (totalWait > 0) {
|
|
4705
|
+
const typingInterval = setInterval(async () => {
|
|
4706
|
+
try { await chat.sendStateTyping(); } catch {}
|
|
4707
|
+
}, 4000);
|
|
4708
|
+
|
|
4709
|
+
await new Promise(r => setTimeout(r, totalWait));
|
|
4710
|
+
clearInterval(typingInterval);
|
|
4711
|
+
try { await chat.clearState(); } catch {}
|
|
4712
|
+
}
|
|
4713
|
+
|
|
4714
|
+
lastRequestTimes.set(msg.from, Date.now());
|
|
4715
|
+
lastGlobalRequest = Date.now();
|
|
4716
|
+
|
|
4717
|
+
const tLevel = parseInt(Debug('OPTIONS').typingspeed);
|
|
4718
|
+
const multiplier = 1 + (5 - tLevel) * 0.25;
|
|
4719
|
+
const baseTime = 800 * multiplier;
|
|
4720
|
+
const extraPerChar = 25 * multiplier;
|
|
4721
|
+
const maxTime = 4000 * multiplier;
|
|
4722
|
+
const estimatedDelay = Math.min(baseTime + msg.body.length * extraPerChar, maxTime);
|
|
4723
|
+
|
|
4724
|
+
await chat.sendStateTyping();
|
|
4725
|
+
await new Promise(resolve => setTimeout(resolve, estimatedDelay));
|
|
4726
|
+
await chat.clearState();
|
|
4727
|
+
|
|
4728
|
+
const reply = await askAI(msg.body);
|
|
4729
|
+
await client.sendMessage(msg.from, reply);
|
|
4730
|
+
} catch (err) {
|
|
4731
|
+
console.error("Erro ao processar IA (free):", err.message);
|
|
4732
|
+
try {
|
|
4733
|
+
const reply = await askAI(msg.body);
|
|
4734
|
+
await client.sendMessage(msg.from, reply);
|
|
4735
|
+
} catch (e2) {
|
|
4736
|
+
console.error("Erro secundário:", e2.message);
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
}).catch(e => console.error("Erro na fila global:", e.message));
|
|
4740
|
+
}
|
|
4741
|
+
|
|
4742
|
+
// ==================================================
|
|
4743
|
+
// 🔹 Modo Premium — Resposta direta (sem fila)
|
|
4744
|
+
// ==================================================
|
|
4745
|
+
else {
|
|
4746
|
+
const tLevel = parseInt(Debug('OPTIONS').typingspeed);
|
|
4747
|
+
const multiplier = 1 + (5 - tLevel) * 0.25;
|
|
4748
|
+
const baseTime = 800 * multiplier;
|
|
4749
|
+
const extraPerChar = 25 * multiplier;
|
|
4750
|
+
const maxTime = 4000 * multiplier;
|
|
4751
|
+
const estimatedDelay = Math.min(baseTime + msg.body.length * extraPerChar, maxTime);
|
|
4752
|
+
|
|
4753
|
+
await chat.sendStateTyping();
|
|
4754
|
+
await new Promise(r => setTimeout(r, estimatedDelay));
|
|
4755
|
+
await chat.clearState();
|
|
4756
|
+
|
|
4757
|
+
const reply = await askAI(msg.body);
|
|
4758
|
+
await client.sendMessage(msg.from, reply);
|
|
4759
|
+
}
|
|
4760
|
+
|
|
4761
|
+
} catch (err) {
|
|
4762
|
+
console.error("Erro ao simular digitando:", err.message);
|
|
4763
|
+
try {
|
|
4764
|
+
const reply = await askAI(msg.body);
|
|
4765
|
+
await client.sendMessage(msg.from, reply);
|
|
4766
|
+
} catch (e2) {
|
|
4767
|
+
console.error("Erro no fallback de IA:", e2.message);
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4770
|
+
return;
|
|
4771
|
+
}
|
|
4772
|
+
|
|
4773
|
+
// ==================================================
|
|
4774
|
+
// 📋 Menu principal
|
|
4775
|
+
// ==================================================
|
|
4776
|
+
if (msg.body.startsWith('1')) {
|
|
4777
|
+
await client.sendMessage(msg.from, '🔗 Aqui está o link do seu boleto: https://seudominio.com/boleto');
|
|
4778
|
+
return;
|
|
4779
|
+
}
|
|
4780
|
+
|
|
4781
|
+
if (msg.body.startsWith('2')) {
|
|
4782
|
+
await client.sendMessage(msg.from, '🤖 Você está agora em atendimento de suporte com IA. Envie sua dúvida.');
|
|
4783
|
+
activeSupportIA.set(msg.from, true);
|
|
4784
|
+
return;
|
|
4785
|
+
}
|
|
4786
|
+
|
|
4787
|
+
if (msg.body.startsWith('0')) {
|
|
4788
|
+
await client.sendMessage(msg.from, '✅ Atendimento encerrado. Obrigado pelo contato!');
|
|
4789
|
+
activeMenus.delete(msg.from);
|
|
4790
|
+
return;
|
|
4791
|
+
}
|
|
4792
|
+
}
|
|
4793
|
+
|
|
4794
|
+
if (msg.body.toLowerCase() === 'menu') {
|
|
4795
|
+
activeMenus.set(msg.from, true);
|
|
4796
|
+
await client.sendMessage(msg.from,
|
|
4797
|
+
'📋 *Menu Principal*\n\n' +
|
|
4798
|
+
'1️⃣ Boleto\n' +
|
|
4799
|
+
'2️⃣ Suporte\n' +
|
|
4800
|
+
'0️⃣ Encerrar\n\n' +
|
|
4801
|
+
'👉 Responda com o número da opção desejada.'
|
|
4802
|
+
);
|
|
4803
|
+
return;
|
|
4804
|
+
}
|
|
4805
|
+
|
|
4806
|
+
const nomeContato = msg._data.notifyName;
|
|
4807
|
+
let groupChat = await msg.getChat();
|
|
4808
|
+
|
|
4809
|
+
if (msg.type.toLowerCase() == "e2e_notification") return null;
|
|
4810
|
+
if (msg.body == "") return null;
|
|
4811
|
+
if (msg.from.includes("@g.us")) return null;
|
|
4812
|
+
const NULLED = [undefined, "XXX", null, ""];
|
|
4813
|
+
var isWid = msg.from;
|
|
4814
|
+
const RegEx = new Set("!@#:$%^&*()_");
|
|
4815
|
+
for (let Return of isWid) {
|
|
4816
|
+
if (RegEx.has(Return)) {
|
|
4817
|
+
isWid = isWid.replace(Return, '%');
|
|
4818
|
+
}
|
|
4819
|
+
}
|
|
4820
|
+
isWid = isWid.split("%")[0];
|
|
4821
|
+
const isDDI = isWid.substr(0, 2);
|
|
4822
|
+
const isDDD = isWid.substr(2, 2);
|
|
4823
|
+
const isCall = isWid.slice(-8);
|
|
4824
|
+
var WhatsApp = isWid + '@c.us';
|
|
4825
|
+
if ((isDDI == '55') && (parseInt(isDDD) <= 30)) {
|
|
4826
|
+
WhatsApp = isWid.substr(0, 4) + '9' + isCall + '@c.us';
|
|
4827
|
+
} else if ((isDDI == '55') && (parseInt(isDDD) > 30)) {
|
|
4828
|
+
WhatsApp = isWid.substr(0, 4) + isCall + '@c.us';
|
|
4829
|
+
}
|
|
4830
|
+
const isWhatsApp = WhatsApp.split("@")[0];
|
|
4831
|
+
if (msg.body.toUpperCase().includes("TOKEN") && NULLED.includes(Debug('OPTIONS').token)) {
|
|
4832
|
+
if (msg.body.includes(":") && (msg.body.split(":")[1].length == 7)) {
|
|
4833
|
+
db.run("UPDATE options SET token=?", [msg.body.split(":")[1]], (err) => {
|
|
4834
|
+
if (err) throw err;
|
|
4835
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').saved);
|
|
4836
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').saved);
|
|
4837
|
+
msg.reply(Debug('CONSOLE').saved);
|
|
4838
|
+
});
|
|
4839
|
+
} else {
|
|
4840
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').wrong);
|
|
4841
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').wrong);
|
|
4842
|
+
msg.reply(Debug('CONSOLE').wrong);
|
|
4843
|
+
}
|
|
4844
|
+
} else {
|
|
4845
|
+
db.serialize(() => {
|
|
4846
|
+
db.get("SELECT * FROM replies WHERE whats='" + isWhatsApp + "'", (err, REPLIES) => {
|
|
4847
|
+
if (REPLIES == undefined) {
|
|
4848
|
+
db.run("INSERT INTO replies(whats,date,count) VALUES(?, ?, ?)", [isWhatsApp, register, 1], (err) => {
|
|
4849
|
+
if (err) {
|
|
4850
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + err)
|
|
4851
|
+
}
|
|
4852
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').inserted);
|
|
4853
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').inserted);
|
|
4854
|
+
MsgBox = true;
|
|
4855
|
+
});
|
|
4856
|
+
|
|
4857
|
+
} else {
|
|
4858
|
+
|
|
4859
|
+
if (register.toString() > REPLIES.date) {
|
|
4860
|
+
db.run("UPDATE replies SET date=?, count=? WHERE whats=?", [register, 1, isWhatsApp], (err) => {
|
|
4861
|
+
if (err) {
|
|
4862
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + err)
|
|
4863
|
+
}
|
|
4864
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').updated);
|
|
4865
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').updated);
|
|
4866
|
+
MsgBox = true;
|
|
4867
|
+
});
|
|
4868
|
+
} else {
|
|
4869
|
+
if (Debug('OPTIONS').count > REPLIES.count) {
|
|
4870
|
+
COUNT = REPLIES.count + 1;
|
|
4871
|
+
db.run("UPDATE replies SET count=? WHERE whats=?", [COUNT, isWhatsApp], (err) => {
|
|
4872
|
+
if (err) throw err;
|
|
4873
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').updated);
|
|
4874
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').updated);
|
|
4875
|
+
MsgBox = true;
|
|
4876
|
+
});
|
|
4877
|
+
} else {
|
|
4878
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').found);
|
|
4879
|
+
global.io.emit('message', '> ' + Debug('OPTIONS').appname + ' : ' + Debug('CONSOLE').found);
|
|
4880
|
+
MsgBox = false;
|
|
4881
|
+
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
}
|
|
4885
|
+
});
|
|
4886
|
+
|
|
4887
|
+
db.get("SELECT * FROM replies WHERE whats='" + msg.from.replaceAll('@c.us', '') + "'", (err, REPLIES) => {
|
|
4888
|
+
if (err) {
|
|
4889
|
+
console.log('> ' + Debug('OPTIONS').appname + ' : ' + err)
|
|
4890
|
+
}
|
|
4891
|
+
if (REPLIES != undefined) {
|
|
4892
|
+
if (MsgBox && Boolean(Debug('OPTIONS').onbot) && (msg.body != null || msg.body == "0" || msg.type == 'ptt' || msg.hasMedia)) {
|
|
4893
|
+
if (Boolean(Debug('OPTIONS').replyes)) {
|
|
4894
|
+
msg.reply(Debug('OPTIONS').response);
|
|
4895
|
+
} else {
|
|
4896
|
+
const Mensagem = (Debug('OPTIONS').response).replaceAll("\\n", "\r\n").split("##");
|
|
4897
|
+
Mensagem.some(function(Send, index) {
|
|
4898
|
+
setTimeout(function() {
|
|
4899
|
+
client.sendMessage(WhatsApp, isEmoji(Send)).then().catch(err => {
|
|
4900
|
+
console.log(err);
|
|
4901
|
+
WwjsVersion(false);
|
|
4902
|
+
});
|
|
4903
|
+
|
|
4904
|
+
}, Math.floor(Delay + Math.random() * 1000));
|
|
4905
|
+
|
|
4906
|
+
});
|
|
4907
|
+
|
|
4908
|
+
}
|
|
4909
|
+
}
|
|
4910
|
+
}
|
|
4911
|
+
});
|
|
4912
|
+
|
|
4913
|
+
});
|
|
4914
|
+
}
|
|
4915
|
+
});
|
|
4916
|
+
|
|
4917
|
+
client.on('call', async (call) => {
|
|
4918
|
+
var isWid = call.from;
|
|
4919
|
+
const RegEx = new Set("!@#:$%^&*()_");
|
|
4920
|
+
for (let Return of isWid) {
|
|
4921
|
+
if (RegEx.has(Return)) {
|
|
4922
|
+
isWid = isWid.replace(Return, '%');
|
|
4923
|
+
}
|
|
4924
|
+
}
|
|
4925
|
+
isWid = isWid.split("%")[0];
|
|
4926
|
+
const isDDI = isWid.substr(0, 2);
|
|
4927
|
+
const isDDD = isWid.substr(2, 2);
|
|
4928
|
+
const isCall = isWid.slice(-8);
|
|
4929
|
+
var WhatsApp = isWid + '@c.us';
|
|
4930
|
+
if ((isDDI == '55') && (parseInt(isDDD) <= 30)) {
|
|
4931
|
+
WhatsApp = isWid.substr(0, 4) + '9' + isCall + '@c.us';
|
|
4932
|
+
} else if ((isDDI == '55') && (parseInt(isDDD) > 30)) {
|
|
4933
|
+
WhatsApp = isWid.substr(0, 4) + isCall + '@c.us';
|
|
4934
|
+
}
|
|
4935
|
+
const Mensagem = (Debug('OPTIONS').call).replaceAll("\\n", "\r\n").split("##");
|
|
4936
|
+
|
|
4937
|
+
if (Boolean(Debug('OPTIONS').reject)) {
|
|
4938
|
+
setTimeout(function() {
|
|
4939
|
+
call.reject().then(() => {
|
|
4940
|
+
if (Boolean(Debug('OPTIONS').alert)) {
|
|
4941
|
+
Mensagem.some(function(Send, index) {
|
|
4942
|
+
setTimeout(function() {
|
|
4943
|
+
client.sendMessage(WhatsApp, isEmoji(Send)).then().catch(err => {
|
|
4944
|
+
console.log(err);
|
|
4945
|
+
WwjsVersion(false);
|
|
4946
|
+
});
|
|
4947
|
+
|
|
4948
|
+
}, Math.floor(Delay + Math.random() * 1000));
|
|
4949
|
+
});
|
|
4950
|
+
}
|
|
4951
|
+
}).catch(err => {
|
|
4952
|
+
console.log(err);
|
|
4953
|
+
});
|
|
4954
|
+
}, Math.floor(Debug('OPTIONS').sleep + Math.random() * 1000));
|
|
4955
|
+
}
|
|
4956
|
+
});
|
|
4957
|
+
|
|
4958
|
+
client.initialize();
|
|
4959
|
+
console.log("\nAPI is Ready!\n");
|
|
4960
|
+
const Port = process.env.PORT || Debug('OPTIONS').access;
|
|
4961
|
+
server.listen(Port, ip.address(), function() {
|
|
4962
|
+
console.log('Server Running on *' + ip.address() + ':' + Port);
|
|
4963
|
+
});
|
|
4964
|
+
|
|
4965
|
+
|
|
4966
|
+
// ----------------------------------------------------
|
|
4967
|
+
// Reusable helpers
|
|
4968
|
+
// ----------------------------------------------------
|
|
4969
|
+
function showElement(sel) {
|
|
4970
|
+
if (typeof sel === "string") $(sel).fadeIn();
|
|
4971
|
+
}
|
|
4972
|
+
|
|
4973
|
+
function hideElement(sel) {
|
|
4974
|
+
if (typeof sel === "string") $(sel).fadeOut();
|
|
4975
|
+
}
|
|
4976
|
+
|
|
4977
|
+
function setText(sel, txt) {
|
|
4978
|
+
if (typeof sel === "string") $(sel).text(txt);
|
|
4979
|
+
}
|