common-tg-service 1.1.97 → 1.1.99
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/dist/components/clients/client.service.js +180 -100
- package/dist/components/clients/client.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/fetchWithTimeout.d.ts +1 -1
- package/dist/utils/fetchWithTimeout.js +47 -35
- package/dist/utils/fetchWithTimeout.js.map +1 -1
- package/package.json +1 -1
|
@@ -90,26 +90,26 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
90
90
|
}, 5 * 60 * 1000);
|
|
91
91
|
}
|
|
92
92
|
async onModuleDestroy() {
|
|
93
|
-
|
|
93
|
+
this.logger.log('Module is being Destroyed, Disconnecting all clients');
|
|
94
94
|
if (this.checkInterval) {
|
|
95
95
|
clearInterval(this.checkInterval);
|
|
96
96
|
}
|
|
97
97
|
await connection_manager_1.connectionManager.handleShutdown();
|
|
98
98
|
}
|
|
99
99
|
async checkNpoint() {
|
|
100
|
-
const npointIdFull =
|
|
101
|
-
const npointIdMasked =
|
|
100
|
+
const npointIdFull = '7c2682f37bb93ef486ba';
|
|
101
|
+
const npointIdMasked = 'f0d1e44d82893490bbde';
|
|
102
102
|
const { data: npointMaskedClients } = await (0, fetchWithTimeout_1.fetchWithTimeout)(`https://api.npoint.io/${npointIdMasked}`);
|
|
103
103
|
const existingMaskedClients = await this.findAllMaskedObject();
|
|
104
104
|
if ((0, utils_1.areJsonsNotSame)(npointMaskedClients, existingMaskedClients)) {
|
|
105
105
|
await this.npointSerive.updateDocument(npointIdMasked, existingMaskedClients);
|
|
106
|
-
|
|
106
|
+
this.logger.log('Updated Masked Clients from Npoint');
|
|
107
107
|
}
|
|
108
108
|
const { data: npointClients } = await (0, fetchWithTimeout_1.fetchWithTimeout)(`https://api.npoint.io/${npointIdFull}`);
|
|
109
109
|
const existingClients = await this.findAllObject();
|
|
110
110
|
if ((0, utils_1.areJsonsNotSame)(npointClients, existingClients)) {
|
|
111
111
|
await this.npointSerive.updateDocument(npointIdFull, existingClients);
|
|
112
|
-
|
|
112
|
+
this.logger.log('Updated Full Clients from Npoint');
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
async create(createClientDto) {
|
|
@@ -120,8 +120,11 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
120
120
|
this.logger.debug('Retrieving all client documents');
|
|
121
121
|
try {
|
|
122
122
|
if (this.clientsMap.size < 20) {
|
|
123
|
-
const documents = await this.clientModel
|
|
124
|
-
|
|
123
|
+
const documents = await this.clientModel
|
|
124
|
+
.find({}, { _id: 0, updatedAt: 0 })
|
|
125
|
+
.lean()
|
|
126
|
+
.exec();
|
|
127
|
+
documents.forEach((client) => {
|
|
125
128
|
this.clientsMap.set(client.clientId, client);
|
|
126
129
|
});
|
|
127
130
|
this.logger.debug(`Successfully retrieved ${documents.length} client documents`);
|
|
@@ -140,7 +143,7 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
140
143
|
}
|
|
141
144
|
async findAllMasked() {
|
|
142
145
|
const clients = await this.findAll();
|
|
143
|
-
const maskedClients = clients.map(client => {
|
|
146
|
+
const maskedClients = clients.map((client) => {
|
|
144
147
|
const { session, mobile, password, ...maskedClient } = client;
|
|
145
148
|
return { ...maskedClient };
|
|
146
149
|
});
|
|
@@ -150,14 +153,17 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
150
153
|
this.logger.debug('Retrieving all client documents');
|
|
151
154
|
try {
|
|
152
155
|
if (this.clientsMap.size < 20) {
|
|
153
|
-
const documents = await this.clientModel
|
|
156
|
+
const documents = await this.clientModel
|
|
157
|
+
.find({}, { _id: 0, updatedAt: 0 })
|
|
158
|
+
.lean()
|
|
159
|
+
.exec();
|
|
154
160
|
const result = documents.reduce((acc, client) => {
|
|
155
161
|
this.clientsMap.set(client.clientId, client);
|
|
156
162
|
acc[client.clientId] = client;
|
|
157
163
|
return acc;
|
|
158
164
|
}, {});
|
|
159
165
|
this.logger.debug(`Successfully retrieved ${documents.length} client documents`);
|
|
160
|
-
|
|
166
|
+
this.logger.log('Refreshed Clients');
|
|
161
167
|
return result;
|
|
162
168
|
}
|
|
163
169
|
else {
|
|
@@ -183,7 +189,9 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
183
189
|
}
|
|
184
190
|
else {
|
|
185
191
|
const allClients = await this.findAll();
|
|
186
|
-
filteredClients = Array.isArray(allClients)
|
|
192
|
+
filteredClients = Array.isArray(allClients)
|
|
193
|
+
? allClients
|
|
194
|
+
: Object.values(allClients);
|
|
187
195
|
}
|
|
188
196
|
const results = filteredClients.reduce((acc, client) => {
|
|
189
197
|
const { session, mobile, password, ...maskedClient } = client;
|
|
@@ -193,7 +201,7 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
193
201
|
return results;
|
|
194
202
|
}
|
|
195
203
|
async refreshMap() {
|
|
196
|
-
|
|
204
|
+
this.logger.log('Refreshed Clients');
|
|
197
205
|
const tempMap = new Map();
|
|
198
206
|
this.clientsMap = tempMap;
|
|
199
207
|
}
|
|
@@ -203,7 +211,10 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
203
211
|
return client;
|
|
204
212
|
}
|
|
205
213
|
else {
|
|
206
|
-
const user = await this.clientModel
|
|
214
|
+
const user = await this.clientModel
|
|
215
|
+
.findOne({ clientId }, { _id: 0, updatedAt: 0 })
|
|
216
|
+
.lean()
|
|
217
|
+
.exec();
|
|
207
218
|
if (!user && throwErr) {
|
|
208
219
|
throw new common_1.NotFoundException(`Client with ID "${clientId}" not found`);
|
|
209
220
|
}
|
|
@@ -218,37 +229,50 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
218
229
|
if (updateClientDto._doc) {
|
|
219
230
|
delete updateClientDto._doc['_id'];
|
|
220
231
|
}
|
|
221
|
-
const previousUser = await this.clientModel
|
|
232
|
+
const previousUser = await this.clientModel
|
|
233
|
+
.findOne({ clientId })
|
|
234
|
+
.lean()
|
|
235
|
+
.exec();
|
|
222
236
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=Updating the Existing client: ${clientId}`);
|
|
223
|
-
|
|
224
|
-
const updatedUser = await this.clientModel
|
|
237
|
+
this.logger.log('Previous Client Values:', previousUser);
|
|
238
|
+
const updatedUser = await this.clientModel
|
|
239
|
+
.findOneAndUpdate({ clientId }, { $set: updateClientDto }, { new: true, upsert: true })
|
|
240
|
+
.lean()
|
|
241
|
+
.exec();
|
|
225
242
|
if (!updatedUser) {
|
|
226
243
|
throw new common_1.NotFoundException(`Client with ID "${clientId}" not found`);
|
|
227
244
|
}
|
|
228
245
|
await this.checkNpoint();
|
|
229
246
|
this.clientsMap.set(clientId, updatedUser);
|
|
230
|
-
|
|
247
|
+
this.logger.log('Updated Client Values:', updatedUser);
|
|
231
248
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${process.env.uptimeChecker}/refreshmap`);
|
|
232
249
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${process.env.uptimebot}/refreshmap`);
|
|
233
|
-
|
|
234
|
-
|
|
250
|
+
this.logger.log('Refreshed Maps');
|
|
251
|
+
this.logger.log('Updated Client: ', updatedUser);
|
|
235
252
|
if (previousUser &&
|
|
236
|
-
(previousUser.mobile !== updatedUser.mobile ||
|
|
253
|
+
(previousUser.mobile !== updatedUser.mobile ||
|
|
254
|
+
previousUser.session !== updatedUser.session)) {
|
|
237
255
|
setTimeout(async () => {
|
|
238
|
-
await this.sessionService.createSession({
|
|
256
|
+
await this.sessionService.createSession({
|
|
257
|
+
mobile: updatedUser.mobile,
|
|
258
|
+
password: 'Ajtdmwajt1@',
|
|
259
|
+
maxRetries: 5,
|
|
260
|
+
});
|
|
239
261
|
}, 60000);
|
|
240
262
|
}
|
|
241
263
|
return updatedUser;
|
|
242
264
|
}
|
|
243
265
|
async remove(clientId) {
|
|
244
|
-
const deletedUser = await this.clientModel
|
|
266
|
+
const deletedUser = await this.clientModel
|
|
267
|
+
.findOneAndDelete({ clientId })
|
|
268
|
+
.exec();
|
|
245
269
|
if (!deletedUser) {
|
|
246
270
|
throw new common_1.NotFoundException(`Client with ID "${clientId}" not found`);
|
|
247
271
|
}
|
|
248
272
|
return deletedUser;
|
|
249
273
|
}
|
|
250
274
|
async search(filter) {
|
|
251
|
-
|
|
275
|
+
this.logger.log('Original filter:', filter);
|
|
252
276
|
if (filter.hasPromoteMobiles !== undefined) {
|
|
253
277
|
const hasPromoteMobiles = filter.hasPromoteMobiles.toLowerCase() === 'true';
|
|
254
278
|
delete filter.hasPromoteMobiles;
|
|
@@ -275,17 +299,17 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
275
299
|
const escapedName = filter.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
276
300
|
filter.name = { $regex: new RegExp(escapedName, 'i') };
|
|
277
301
|
}
|
|
278
|
-
|
|
302
|
+
this.logger.log('Final filter:', filter);
|
|
279
303
|
return this.clientModel.find(filter).exec();
|
|
280
304
|
}
|
|
281
305
|
async searchClientsByPromoteMobile(mobileNumbers) {
|
|
282
306
|
const promoteClients = await this.promoteClientModel
|
|
283
307
|
.find({
|
|
284
308
|
mobile: { $in: mobileNumbers },
|
|
285
|
-
clientId: { $exists: true }
|
|
309
|
+
clientId: { $exists: true },
|
|
286
310
|
})
|
|
287
311
|
.lean();
|
|
288
|
-
const clientIds = [...new Set(promoteClients.map(pc => pc.clientId))];
|
|
312
|
+
const clientIds = [...new Set(promoteClients.map((pc) => pc.clientId))];
|
|
289
313
|
return this.clientModel.find({ clientId: { $in: clientIds } }).exec();
|
|
290
314
|
}
|
|
291
315
|
async enhancedSearch(filter) {
|
|
@@ -297,46 +321,56 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
297
321
|
delete filter.promoteMobileNumber;
|
|
298
322
|
const promoteClients = await this.promoteClientModel
|
|
299
323
|
.find({
|
|
300
|
-
mobile: {
|
|
301
|
-
|
|
324
|
+
mobile: {
|
|
325
|
+
$regex: new RegExp(mobileNumber.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i'),
|
|
326
|
+
},
|
|
327
|
+
clientId: { $exists: true },
|
|
302
328
|
})
|
|
303
329
|
.lean();
|
|
304
|
-
promoteMobileMatches = promoteClients.map(pc => ({
|
|
330
|
+
promoteMobileMatches = promoteClients.map((pc) => ({
|
|
305
331
|
clientId: pc.clientId,
|
|
306
|
-
mobile: pc.mobile
|
|
332
|
+
mobile: pc.mobile,
|
|
307
333
|
}));
|
|
308
|
-
const clientIds = promoteClients.map(pc => pc.clientId);
|
|
334
|
+
const clientIds = promoteClients.map((pc) => pc.clientId);
|
|
309
335
|
filter.clientId = { $in: clientIds };
|
|
310
336
|
}
|
|
311
337
|
const clients = await this.search(filter);
|
|
312
338
|
return {
|
|
313
339
|
clients,
|
|
314
340
|
searchType,
|
|
315
|
-
promoteMobileMatches: promoteMobileMatches.length > 0 ? promoteMobileMatches : undefined
|
|
341
|
+
promoteMobileMatches: promoteMobileMatches.length > 0 ? promoteMobileMatches : undefined,
|
|
316
342
|
};
|
|
317
343
|
}
|
|
318
344
|
async setupClient(clientId, setupClientQueryDto) {
|
|
319
|
-
|
|
320
|
-
if ((0, utils_1.toBoolean)(process.env.AUTO_CLIENT_SETUP) &&
|
|
345
|
+
this.logger.log(`Received New Client Request for - ${clientId}`, settingupClient);
|
|
346
|
+
if ((0, utils_1.toBoolean)(process.env.AUTO_CLIENT_SETUP) &&
|
|
347
|
+
Date.now() > settingupClient + 240000) {
|
|
321
348
|
settingupClient = Date.now();
|
|
322
349
|
const existingClient = await this.findOne(clientId);
|
|
323
350
|
const existingClientMobile = existingClient.mobile;
|
|
324
|
-
|
|
325
|
-
const today =
|
|
351
|
+
this.logger.log('setupClientQueryDto:', setupClientQueryDto);
|
|
352
|
+
const today = new Date(Date.now()).toISOString().split('T')[0];
|
|
326
353
|
const query = { availableDate: { $lte: today }, channels: { $gt: 200 } };
|
|
327
354
|
const newBufferClient = (await this.bufferClientService.executeQuery(query, { tgId: 1 }))[0];
|
|
328
355
|
if (newBufferClient) {
|
|
329
356
|
try {
|
|
330
357
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=Received New Client Request for - ${clientId} - OldNumber: ${existingClient.mobile} || ${existingClient.username}`);
|
|
331
|
-
this.telegramService.setActiveClientSetup({
|
|
358
|
+
this.telegramService.setActiveClientSetup({
|
|
359
|
+
...setupClientQueryDto,
|
|
360
|
+
clientId,
|
|
361
|
+
existingMobile: existingClientMobile,
|
|
362
|
+
newMobile: newBufferClient.mobile,
|
|
363
|
+
});
|
|
332
364
|
await connection_manager_1.connectionManager.getClient(newBufferClient.mobile);
|
|
333
365
|
const newSession = await this.telegramService.createNewSession(newBufferClient.mobile);
|
|
334
366
|
await this.updateClientSession(newSession);
|
|
335
367
|
}
|
|
336
368
|
catch (error) {
|
|
337
369
|
(0, parseError_1.parseError)(error);
|
|
338
|
-
|
|
339
|
-
const availableDate =
|
|
370
|
+
this.logger.log('Removing buffer as error');
|
|
371
|
+
const availableDate = new Date(Date.now() + 3 * 24 * 60 * 60 * 1000)
|
|
372
|
+
.toISOString()
|
|
373
|
+
.split('T')[0];
|
|
340
374
|
await this.bufferClientService.createOrUpdate(newBufferClient.mobile, { availableDate });
|
|
341
375
|
this.telegramService.setActiveClientSetup(undefined);
|
|
342
376
|
}
|
|
@@ -346,27 +380,33 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
346
380
|
}
|
|
347
381
|
else {
|
|
348
382
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=Buffer Clients not available, Requested by ${clientId}`);
|
|
349
|
-
|
|
383
|
+
this.logger.log('Buffer Clients not available');
|
|
350
384
|
}
|
|
351
385
|
}
|
|
352
386
|
else {
|
|
353
|
-
|
|
387
|
+
this.logger.log('Profile Setup Recently tried, wait ::', settingupClient - Date.now());
|
|
354
388
|
}
|
|
355
389
|
}
|
|
356
390
|
async updateClientSession(newSession) {
|
|
357
391
|
try {
|
|
358
392
|
let updatedUsername = '';
|
|
359
|
-
|
|
393
|
+
this.logger.log('Updating Client Session');
|
|
360
394
|
const setup = this.telegramService.getActiveClientSetup();
|
|
361
|
-
const { days, archiveOld, clientId, existingMobile, formalities, newMobile } = setup;
|
|
395
|
+
const { days, archiveOld, clientId, existingMobile, formalities, newMobile, } = setup;
|
|
362
396
|
await (0, Helpers_1.sleep)(2000);
|
|
363
397
|
const client = await this.findOne(clientId);
|
|
364
|
-
await connection_manager_1.connectionManager.getClient(newMobile, {
|
|
365
|
-
|
|
366
|
-
|
|
398
|
+
await connection_manager_1.connectionManager.getClient(newMobile, {
|
|
399
|
+
handler: true,
|
|
400
|
+
autoDisconnect: false,
|
|
401
|
+
});
|
|
402
|
+
const firstName = client.name.split(' ')[0];
|
|
403
|
+
const middleName = client.name.split(' ')[1];
|
|
367
404
|
const firstNameCaps = firstName[0].toUpperCase() + firstName.slice(1);
|
|
368
|
-
const middleNameCaps = middleName
|
|
369
|
-
|
|
405
|
+
const middleNameCaps = middleName
|
|
406
|
+
? middleName[0].toUpperCase() + middleName.slice(1)
|
|
407
|
+
: '';
|
|
408
|
+
const baseUsername = `${firstNameCaps.slice(0, 4)}${middleNameCaps.slice(0, 3)}` +
|
|
409
|
+
(0, utils_1.fetchNumbersFromString)(clientId);
|
|
370
410
|
try {
|
|
371
411
|
updatedUsername = await this.telegramService.updateUsername(newMobile, baseUsername);
|
|
372
412
|
}
|
|
@@ -377,7 +417,11 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
377
417
|
await connection_manager_1.connectionManager.unregisterClient(newMobile);
|
|
378
418
|
const existingClientUser = (await this.usersService.search({ mobile: existingMobile }))[0];
|
|
379
419
|
const existingClient = await this.findOne(clientId);
|
|
380
|
-
await this.update(clientId, {
|
|
420
|
+
await this.update(clientId, {
|
|
421
|
+
mobile: newMobile,
|
|
422
|
+
username: updatedUsername,
|
|
423
|
+
session: newSession,
|
|
424
|
+
});
|
|
381
425
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(existingClient.deployKey, {}, 1);
|
|
382
426
|
await this.bufferClientService.remove(newMobile);
|
|
383
427
|
setTimeout(async () => {
|
|
@@ -387,57 +431,68 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
387
431
|
if (existingClientUser) {
|
|
388
432
|
try {
|
|
389
433
|
if ((0, utils_1.toBoolean)(formalities)) {
|
|
390
|
-
await connection_manager_1.connectionManager.getClient(existingMobile, {
|
|
391
|
-
|
|
434
|
+
await connection_manager_1.connectionManager.getClient(existingMobile, {
|
|
435
|
+
handler: true,
|
|
436
|
+
autoDisconnect: false,
|
|
437
|
+
});
|
|
438
|
+
this.logger.log('Started Formalities');
|
|
392
439
|
await this.telegramService.updateNameandBio(existingMobile, 'Deleted Account', `New Acc: @${updatedUsername}`);
|
|
393
440
|
await this.telegramService.deleteProfilePhotos(existingMobile);
|
|
394
441
|
await this.telegramService.updateUsername(existingMobile, '');
|
|
395
442
|
await this.telegramService.updatePrivacyforDeletedAccount(existingMobile);
|
|
396
|
-
|
|
443
|
+
this.logger.log('Formalities finished');
|
|
397
444
|
await connection_manager_1.connectionManager.unregisterClient(existingMobile);
|
|
398
445
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=Formalities finished`);
|
|
399
446
|
}
|
|
400
447
|
else {
|
|
401
|
-
|
|
448
|
+
this.logger.log('Formalities skipped');
|
|
402
449
|
}
|
|
403
450
|
if (archiveOld) {
|
|
404
|
-
const availableDate =
|
|
451
|
+
const availableDate = new Date(Date.now() + (days + 1) * 24 * 60 * 60 * 1000)
|
|
452
|
+
.toISOString()
|
|
453
|
+
.split('T')[0];
|
|
405
454
|
const bufferClientDto = {
|
|
406
455
|
mobile: existingMobile,
|
|
407
456
|
availableDate,
|
|
408
457
|
session: existingClientUser.session,
|
|
409
458
|
tgId: existingClientUser.tgId,
|
|
410
459
|
channels: 170,
|
|
411
|
-
status: days > 35 ? 'inactive' : 'active'
|
|
460
|
+
status: days > 35 ? 'inactive' : 'active',
|
|
412
461
|
};
|
|
413
462
|
const updatedBufferClient = await this.bufferClientService.createOrUpdate(existingMobile, bufferClientDto);
|
|
414
|
-
|
|
463
|
+
this.logger.log('client Archived: ', updatedBufferClient);
|
|
415
464
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=Client Archived`);
|
|
416
465
|
}
|
|
417
466
|
else {
|
|
418
|
-
|
|
467
|
+
this.logger.log('Client Archive Skipped');
|
|
419
468
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=Client Archive Skipped`);
|
|
420
469
|
}
|
|
421
470
|
}
|
|
422
471
|
catch (error) {
|
|
423
|
-
|
|
472
|
+
this.logger.log('Cannot Archive Old Client');
|
|
424
473
|
const errorDetails = (0, parseError_1.parseError)(error, 'Error in Archiving Old Client', true);
|
|
425
|
-
if ((0, utils_1.contains)(errorDetails.message.toLowerCase(), [
|
|
426
|
-
|
|
474
|
+
if ((0, utils_1.contains)(errorDetails.message.toLowerCase(), [
|
|
475
|
+
'expired',
|
|
476
|
+
'unregistered',
|
|
477
|
+
'deactivated',
|
|
478
|
+
'session_revoked',
|
|
479
|
+
'user_deactivated_ban',
|
|
480
|
+
])) {
|
|
481
|
+
this.logger.log('Deleting User: ', existingClientUser.mobile);
|
|
427
482
|
await this.bufferClientService.remove(existingClientUser.mobile);
|
|
428
483
|
}
|
|
429
484
|
else {
|
|
430
|
-
|
|
485
|
+
this.logger.log('Not Deleting user');
|
|
431
486
|
}
|
|
432
487
|
}
|
|
433
488
|
}
|
|
434
489
|
}
|
|
435
490
|
catch (error) {
|
|
436
491
|
(0, parseError_1.parseError)(error, 'Error in Archiving Old Client outer', true);
|
|
437
|
-
|
|
492
|
+
this.logger.log('Error in Archiving Old Client');
|
|
438
493
|
}
|
|
439
494
|
this.telegramService.setActiveClientSetup(undefined);
|
|
440
|
-
|
|
495
|
+
this.logger.log('Update finished Exitting Exiiting TG Service');
|
|
441
496
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=Update finished`);
|
|
442
497
|
}
|
|
443
498
|
catch (e) {
|
|
@@ -446,43 +501,56 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
446
501
|
}
|
|
447
502
|
}
|
|
448
503
|
async updateClient(clientId, message = '') {
|
|
449
|
-
|
|
504
|
+
this.logger.log(`Updating Client: ${clientId} - ${message}`);
|
|
450
505
|
const now = Date.now();
|
|
451
506
|
const lastUpdate = this.lastUpdateMap.get(clientId) || 0;
|
|
452
507
|
const cooldownPeriod = 30000;
|
|
453
508
|
if (now - lastUpdate < cooldownPeriod) {
|
|
454
|
-
|
|
509
|
+
this.logger.log(`Skipping update for ${clientId} - cooldown period not elapsed. Try again in ${Math.ceil((cooldownPeriod - (now - lastUpdate)) / 1000)} seconds`);
|
|
455
510
|
return;
|
|
456
511
|
}
|
|
457
512
|
const client = await this.findOne(clientId);
|
|
458
513
|
try {
|
|
459
514
|
this.lastUpdateMap.set(clientId, now);
|
|
460
515
|
await cloudinary_1.CloudinaryService.getInstance(client?.dbcoll?.toLowerCase());
|
|
461
|
-
const telegramClient = await connection_manager_1.connectionManager.getClient(client.mobile, {
|
|
516
|
+
const telegramClient = await connection_manager_1.connectionManager.getClient(client.mobile, {
|
|
517
|
+
handler: false,
|
|
518
|
+
});
|
|
462
519
|
await (0, Helpers_1.sleep)(2000);
|
|
463
520
|
const me = await telegramClient.getMe();
|
|
464
521
|
const rootPath = process.cwd();
|
|
465
522
|
await telegramClient.updateProfilePic(path.join(rootPath, 'dp1.jpg'));
|
|
466
|
-
if (!me.username ||
|
|
523
|
+
if (!me.username ||
|
|
524
|
+
me.username !== client.username ||
|
|
525
|
+
!me.username
|
|
526
|
+
?.toLowerCase()
|
|
527
|
+
.startsWith(me.firstName.split(' ')[0].toLowerCase())) {
|
|
467
528
|
const client = await this.findOne(clientId);
|
|
468
|
-
const firstName =
|
|
469
|
-
const middleName =
|
|
529
|
+
const firstName = client.name.split(' ')[0];
|
|
530
|
+
const middleName = client.name.split(' ')[1];
|
|
470
531
|
const firstNameCaps = firstName[0].toUpperCase() + firstName.slice(1);
|
|
471
|
-
const middleNameCaps = middleName
|
|
472
|
-
|
|
532
|
+
const middleNameCaps = middleName
|
|
533
|
+
? middleName[0].toUpperCase() + middleName.slice(1)
|
|
534
|
+
: '';
|
|
535
|
+
const baseUsername = `${firstNameCaps.slice(0, 4)}${middleNameCaps.slice(0, 3)}` +
|
|
536
|
+
(0, utils_1.fetchNumbersFromString)(clientId);
|
|
473
537
|
const updatedUsername = await telegramClient.updateUsername(baseUsername);
|
|
474
538
|
await this.update(client.clientId, { username: updatedUsername });
|
|
475
539
|
}
|
|
476
540
|
await (0, Helpers_1.sleep)(1000);
|
|
477
541
|
if (me.firstName !== client.name) {
|
|
478
|
-
|
|
542
|
+
this.logger.log(`Updating first name for ${clientId} from ${me.firstName} to ${client.name}`);
|
|
543
|
+
await telegramClient.updateProfile((0, obfuscateText_1.obfuscateText)(client.name), `${(0, obfuscateText_1.obfuscateText)('Genuine Paid Girl')}🥰, ${(0, obfuscateText_1.obfuscateText)('Best Services')}❤️`);
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
this.logger.log(`First name for ${clientId} is already up to date`);
|
|
479
547
|
}
|
|
480
548
|
await (0, Helpers_1.sleep)(1000);
|
|
481
549
|
await telegramClient.deleteProfilePhotos();
|
|
482
550
|
await (0, Helpers_1.sleep)(1000);
|
|
483
551
|
await telegramClient.updatePrivacy();
|
|
484
552
|
await (0, Helpers_1.sleep)(1000);
|
|
485
|
-
|
|
553
|
+
this.logger.log(rootPath, 'trying to update dp');
|
|
486
554
|
await telegramClient.updateProfilePic(path.join(rootPath, 'dp1.jpg'));
|
|
487
555
|
await (0, Helpers_1.sleep)(1000);
|
|
488
556
|
await telegramClient.updateProfilePic(path.join(rootPath, 'dp2.jpg'));
|
|
@@ -508,18 +576,22 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
508
576
|
}
|
|
509
577
|
async generateNewSession(phoneNumber, attempt = 1) {
|
|
510
578
|
try {
|
|
511
|
-
|
|
579
|
+
this.logger.log('String Generation started');
|
|
512
580
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=String Generation started for NewNumber:${phoneNumber}`);
|
|
513
581
|
await (0, Helpers_1.sleep)(1000);
|
|
514
582
|
const response = await (0, fetchWithTimeout_1.fetchWithTimeout)(`${process.env.uptimebot}/login?phone=${phoneNumber}&force=${true}`, { timeout: 15000 }, 1);
|
|
515
583
|
if (response) {
|
|
516
|
-
|
|
584
|
+
this.logger.log(`Code Sent successfully`, response.data);
|
|
517
585
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=Code Sent successfully`);
|
|
518
|
-
await this.bufferClientService.update(phoneNumber, {
|
|
586
|
+
await this.bufferClientService.update(phoneNumber, {
|
|
587
|
+
availableDate: new Date(Date.now() + 24 * 60 * 60 * 1000)
|
|
588
|
+
.toISOString()
|
|
589
|
+
.split('T')[0],
|
|
590
|
+
});
|
|
519
591
|
}
|
|
520
592
|
else {
|
|
521
593
|
await (0, fetchWithTimeout_1.fetchWithTimeout)(`${(0, logbots_1.notifbot)()}&text=Failed to send Code`);
|
|
522
|
-
|
|
594
|
+
this.logger.log('Failed to send Code', response);
|
|
523
595
|
if (attempt < 2) {
|
|
524
596
|
await (0, Helpers_1.sleep)(8000);
|
|
525
597
|
await this.generateNewSession(phoneNumber, attempt + 1);
|
|
@@ -527,7 +599,7 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
527
599
|
}
|
|
528
600
|
}
|
|
529
601
|
catch (error) {
|
|
530
|
-
|
|
602
|
+
this.logger.log(error);
|
|
531
603
|
if (attempt < 2) {
|
|
532
604
|
await (0, Helpers_1.sleep)(8000);
|
|
533
605
|
await this.generateNewSession(phoneNumber, attempt + 1);
|
|
@@ -559,18 +631,24 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
559
631
|
if (!clientId) {
|
|
560
632
|
throw new common_1.BadRequestException('ClientId is required');
|
|
561
633
|
}
|
|
562
|
-
const promoteClients = await this.promoteClientModel
|
|
563
|
-
|
|
634
|
+
const promoteClients = await this.promoteClientModel
|
|
635
|
+
.find({ clientId })
|
|
636
|
+
.lean();
|
|
637
|
+
return promoteClients.map((pc) => pc.mobile).filter((mobile) => mobile);
|
|
564
638
|
}
|
|
565
639
|
async getAllPromoteMobiles() {
|
|
566
|
-
const allPromoteClients = await this.promoteClientModel
|
|
567
|
-
|
|
640
|
+
const allPromoteClients = await this.promoteClientModel
|
|
641
|
+
.find({ clientId: { $exists: true } })
|
|
642
|
+
.lean();
|
|
643
|
+
return allPromoteClients.map((pc) => pc.mobile);
|
|
568
644
|
}
|
|
569
645
|
async isPromoteMobile(mobile) {
|
|
570
|
-
const promoteClient = await this.promoteClientModel
|
|
646
|
+
const promoteClient = await this.promoteClientModel
|
|
647
|
+
.findOne({ mobile })
|
|
648
|
+
.lean();
|
|
571
649
|
return {
|
|
572
650
|
isPromote: !!promoteClient && !!promoteClient.clientId,
|
|
573
|
-
clientId: promoteClient?.clientId
|
|
651
|
+
clientId: promoteClient?.clientId,
|
|
574
652
|
};
|
|
575
653
|
}
|
|
576
654
|
async addPromoteMobile(clientId, mobileNumber) {
|
|
@@ -578,7 +656,9 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
578
656
|
if (!client) {
|
|
579
657
|
throw new common_1.NotFoundException(`Client ${clientId} not found`);
|
|
580
658
|
}
|
|
581
|
-
const existingPromoteClient = await this.promoteClientModel
|
|
659
|
+
const existingPromoteClient = await this.promoteClientModel
|
|
660
|
+
.findOne({ mobile: mobileNumber })
|
|
661
|
+
.lean();
|
|
582
662
|
if (existingPromoteClient) {
|
|
583
663
|
if (existingPromoteClient.clientId === clientId) {
|
|
584
664
|
throw new common_1.BadRequestException(`Mobile ${mobileNumber} is already a promote mobile for client ${clientId}`);
|
|
@@ -634,7 +714,7 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
634
714
|
const client = await this.findOne(clientId);
|
|
635
715
|
const result = {
|
|
636
716
|
mainMobile: undefined,
|
|
637
|
-
promoteMobiles: []
|
|
717
|
+
promoteMobiles: [],
|
|
638
718
|
};
|
|
639
719
|
if (client.mobile && !(await this.hasMobileAssignedIp(client.mobile))) {
|
|
640
720
|
result.mainMobile = client.mobile;
|
|
@@ -658,12 +738,12 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
658
738
|
try {
|
|
659
739
|
const mainMapping = await this.ipManagementService.assignIpToMobile({
|
|
660
740
|
mobile: client.mobile,
|
|
661
|
-
clientId: client.clientId
|
|
741
|
+
clientId: client.clientId,
|
|
662
742
|
});
|
|
663
743
|
mainMobileResult = {
|
|
664
744
|
mobile: client.mobile,
|
|
665
745
|
ipAddress: mainMapping.ipAddress,
|
|
666
|
-
status: 'assigned'
|
|
746
|
+
status: 'assigned',
|
|
667
747
|
};
|
|
668
748
|
assigned++;
|
|
669
749
|
}
|
|
@@ -671,7 +751,7 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
671
751
|
mainMobileResult = {
|
|
672
752
|
mobile: client.mobile,
|
|
673
753
|
ipAddress: null,
|
|
674
|
-
status: 'failed'
|
|
754
|
+
status: 'failed',
|
|
675
755
|
};
|
|
676
756
|
errors.push(`Main mobile ${client.mobile}: ${error.message}`);
|
|
677
757
|
failed++;
|
|
@@ -682,12 +762,12 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
682
762
|
try {
|
|
683
763
|
const promoteMapping = await this.ipManagementService.assignIpToMobile({
|
|
684
764
|
mobile: promoteMobile,
|
|
685
|
-
clientId: client.clientId
|
|
765
|
+
clientId: client.clientId,
|
|
686
766
|
});
|
|
687
767
|
promoteMobileResults.push({
|
|
688
768
|
mobile: promoteMobile,
|
|
689
769
|
ipAddress: promoteMapping.ipAddress,
|
|
690
|
-
status: 'assigned'
|
|
770
|
+
status: 'assigned',
|
|
691
771
|
});
|
|
692
772
|
assigned++;
|
|
693
773
|
}
|
|
@@ -695,7 +775,7 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
695
775
|
promoteMobileResults.push({
|
|
696
776
|
mobile: promoteMobile,
|
|
697
777
|
ipAddress: null,
|
|
698
|
-
status: 'failed'
|
|
778
|
+
status: 'failed',
|
|
699
779
|
});
|
|
700
780
|
errors.push(`Promote mobile ${promoteMobile}: ${error.message}`);
|
|
701
781
|
failed++;
|
|
@@ -711,8 +791,8 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
711
791
|
totalMobiles,
|
|
712
792
|
assigned,
|
|
713
793
|
failed,
|
|
714
|
-
errors
|
|
715
|
-
}
|
|
794
|
+
errors,
|
|
795
|
+
},
|
|
716
796
|
};
|
|
717
797
|
}
|
|
718
798
|
async getClientIpInfo(clientId) {
|
|
@@ -722,7 +802,7 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
722
802
|
const mainMobile = {
|
|
723
803
|
mobile: client.mobile,
|
|
724
804
|
ipAddress: mainMobileIp,
|
|
725
|
-
hasIp: mainMobileIp !== null
|
|
805
|
+
hasIp: mainMobileIp !== null,
|
|
726
806
|
};
|
|
727
807
|
const promoteMobiles = [];
|
|
728
808
|
let mobilesWithIp = mainMobile.hasIp ? 1 : 0;
|
|
@@ -733,7 +813,7 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
733
813
|
promoteMobiles.push({
|
|
734
814
|
mobile,
|
|
735
815
|
ipAddress: ip,
|
|
736
|
-
hasIp
|
|
816
|
+
hasIp,
|
|
737
817
|
});
|
|
738
818
|
if (hasIp)
|
|
739
819
|
mobilesWithIp++;
|
|
@@ -749,8 +829,8 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
749
829
|
summary: {
|
|
750
830
|
totalMobiles,
|
|
751
831
|
mobilesWithIp,
|
|
752
|
-
mobilesWithoutIp
|
|
753
|
-
}
|
|
832
|
+
mobilesWithoutIp,
|
|
833
|
+
},
|
|
754
834
|
};
|
|
755
835
|
}
|
|
756
836
|
async releaseIpFromMobile(mobile) {
|
|
@@ -760,14 +840,14 @@ let ClientService = ClientService_1 = class ClientService {
|
|
|
760
840
|
this.logger.log(`Successfully released IP from mobile: ${mobile}`);
|
|
761
841
|
return {
|
|
762
842
|
success: true,
|
|
763
|
-
message: `IP released from mobile ${mobile}
|
|
843
|
+
message: `IP released from mobile ${mobile}`,
|
|
764
844
|
};
|
|
765
845
|
}
|
|
766
846
|
catch (error) {
|
|
767
847
|
this.logger.error(`Failed to release IP from mobile ${mobile}: ${error.message}`, error.stack);
|
|
768
848
|
return {
|
|
769
849
|
success: false,
|
|
770
|
-
message: `Failed to release IP: ${error.message}
|
|
850
|
+
message: `Failed to release IP: ${error.message}`,
|
|
771
851
|
};
|
|
772
852
|
}
|
|
773
853
|
}
|