File size: 13,127 Bytes
03a92a9
3f354c6
03a92a9
925da1c
03a92a9
 
 
32d6468
3f354c6
d85e9c2
 
 
056939b
d85e9c2
 
 
 
 
 
 
 
 
 
 
 
 
ff308cf
35c7074
 
 
 
ff308cf
35c7074
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f2f5ae
35c7074
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f87cf87
 
9f2f5ae
35c7074
 
 
f87cf87
35c7074
 
 
 
 
 
 
d85e9c2
 
 
 
 
 
 
 
 
 
 
 
e57de41
d85e9c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8788832
 
 
 
 
90fae10
8788832
 
 
 
 
 
caa8423
8788832
 
 
 
 
 
 
 
 
 
a9746de
a379ce0
 
 
 
 
 
 
 
 
caa8423
 
 
90fae10
caa8423
90fae10
caa8423
 
 
 
 
 
 
90fae10
caa8423
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9d9e44
03a92a9
 
d9d9e44
03a92a9
d9d9e44
03a92a9
d9d9e44
03a92a9
 
d9d9e44
 
 
03a92a9
 
 
 
d9d9e44
 
 
 
 
d584fea
 
 
 
 
 
bbec6d3
 
 
 
 
 
 
 
 
 
 
 
 
d584fea
 
 
 
 
 
 
39000f4
 
 
03a92a9
d9d9e44
39000f4
 
 
 
 
 
 
 
 
2b87901
 
 
 
90fae10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33f3e99
2b87901
 
 
0d15ce1
2b87901
 
 
0d15ce1
2b87901
0d15ce1
2b87901
 
 
0d15ce1
 
 
2b87901
 
 
0d15ce1
2b87901
0d15ce1
2b87901
 
 
0d15ce1
2b87901
 
0d15ce1
 
2b87901
 
 
90fae10
 
 
 
 
 
 
0d15ce1
 
 
 
 
 
 
2b87901
 
 
0d15ce1
 
 
 
 
 
 
 
 
2b87901
 
0d15ce1
2b87901
 
 
33f3e99
 
 
 
90fae10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33f3e99
 
 
 
 
 
 
 
 
 
 
 
1565850
33f3e99
 
 
 
 
 
 
 
39000f4
 
 
 
90fae10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39000f4
 
 
 
 
 
 
d9d9e44
39000f4
 
03a92a9
d9d9e44
39000f4
 
 
 
 
 
 
d9d9e44
03a92a9
d9d9e44
03a92a9
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
import express from 'express';
import axios from 'axios';
import { Database } from '../database/database.js';
import { predictCreationDate } from '../lib/create-date.js';
import { authenticateApiKey, apiLimiter } from '../middleware/midware.js';
const AntibanRoutes = express.Router();

const protectedUsers = [6477856957, 1191668125, 1448273246, 1054295664, 6444305696]; 

const TelegramUser = async (user_id) => {
  const options = {
    method: 'GET',
    url: 'https://randydev-meta-ai.hf.space/user/get_user',
    params: {
      user_id: user_id
    }
  };
  try {
    const response = await axios.request(options);
    return response.data;
  } catch (error) {
    console.error(error);
    return null;
  }
}

const TelegramUserStoryDL = async (link) => {
  const options = {
    method: 'GET',
    url: 'https://randydev-meta-ai.hf.space/user/get_story',
    params: {
      link: link
    }
  };
  try {
    const response = await axios.request(options);
    return response.data;
  } catch (error) {
    console.error(error);
    return null;
  }
}

/**
 * @swagger
 * /api/v1/user/story-dl:
 *   get:
 *     summary: Telegram User Story Downloader
 *     tags: [User]
 *     parameters:
 *       - in: query
 *         name: link
 *         required: true
 *         description: null
 *         schema:
 *           type: string
 *       - in: header
 *         name: x-api-key
 *         required: true
 *         description: API key for authentication
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: Success
 */
AntibanRoutes.get("/api/v1/user/story-dl", authenticateApiKey, apiLimiter, async (req, res) => {
    const Links = req.query.link;
    if (!Links) {
        return res.status(400).json({ error: "Invalid or missing link" });
    }

    try {
        const result = await TelegramUserStoryDL(Links);
        res.json(result);
    } catch (error) {
        res.status(500).json({ error: "Failed to fetch user info" });
    }
});


/**
 * @swagger
 * /api/v1/user/info:
 *   get:
 *     summary: Telegram User Info
 *     tags: [User]
 *     parameters:
 *       - in: query
 *         name: user_id
 *         required: true
 *         description: null
 *         schema:
 *           type: string
 *       - in: header
 *         name: x-api-key
 *         required: true
 *         description: API key for authentication
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: Success
 */
AntibanRoutes.get("/api/v1/user/info", authenticateApiKey, apiLimiter, async (req, res) => {
    const userId = req.query.user_id;
    if (!userId) {
        return res.status(400).json({ error: "Invalid or missing user_id" });
    }

    try {
        const result = await TelegramUser(userId);
        res.json(result);
    } catch (error) {
        res.status(500).json({ error: "Failed to fetch user info" });
    }
});


/**
 * @swagger
 * /api/v1/user/creation-date:
 *   get:
 *     summary: Telegram creation date User
 *     tags: [User]
 *     parameters:
 *       - in: query
 *         name: user_id
 *         required: true
 *         description: null
 *         schema:
 *           type: number
 *       - in: header
 *         name: x-api-key
 *         required: true
 *         description: API key for authentication
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: Success
 */
AntibanRoutes.get("/api/v1/user/creation-date", authenticateApiKey, apiLimiter, (req, res) => {
    const userId = Number(req.query.user_id);
    if (!userId || isNaN(userId)) {
        return res.status(400).json({ error: "Invalid or missing user_id" });
    }

    const result = predictCreationDate(userId);
    res.json({ user_id: userId, estimated_creation: result });
});

/**
 * @swagger
 * /api/v1/user/ban-user:
 *   post:
 *     summary: Telegram Ban User
 *     tags: [User]
 *     parameters:
 *       - in: query
 *         name: user_id
 *         required: true
 *         description: null
 *         schema:
 *           type: number
 *       - in: query
 *         name: reason
 *         required: false
 *         description: null
 *         schema:
 *           type: string
 *       - in: header
 *         name: x-api-key
 *         required: true
 *         description: API key for authentication
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: Success
 */
AntibanRoutes.post("/api/v1/user/ban-user", authenticateApiKey, apiLimiter, async (req, res) => {
    const dbClient = new Database("AkenoXJs");
    const collection = dbClient.collection("ban_users");
    const collectionKey = dbClient.collection("api_keys");
    try {
        const apiKey = req.headers["x-api-key"];
        const userIdString = req.query.user_id;
        const reasonString = req.query.reason;
        const userIdNumber = Number(userIdString);

        if (!apiKey) {
            return res.status(400).json({ error: "Missing API key in headers" });
        }
        if (isNaN(userIdNumber)) {
            return res.status(400).json({ error: "Invalid or missing user_id" });
        }

        const existingUserKey = await collectionKey.findOne({ key: apiKey });
        if (!existingUserKey) {
            return res.status(401).json({ message: "API key not found" });
        }

        if (existingUserKey.owner === userIdNumber) {
            return res.status(200).json({ 
              message: `User ${userIdNumber} cannot be banned because they created the API key`,
              is_ban: false
            });
        }
        const result = await collectionKey.find({}).toArray();
        let userIds = [];
        for (const data of result) {
          if (data.owner !== undefined) {
            userIds.push(data.owner);
          }
        }
        if (userIds.includes(userIdNumber)) {
            return res.status(403).json({ 
              message: `User ${userIdNumber} cannot be banned because they created the API key`,
              is_ban: false 
            });
        }
        if (protectedUsers.includes(userIdNumber)) {
            return res.status(403).json({ 
              message: `User ${userIdNumber} is a protected admin and cannot be banned`,
              is_ban: false 
            });
        }

        const existingBan = await collection.findOne({ user_ban: userIdNumber });
        if (existingBan) {
            return res.status(200).json({ message: `User ${userIdNumber} is already banned`, is_ban: true });
        }

        await collection.updateOne(
            { key: existingUserKey.key },
            { $addToSet: { user_ban: userIdNumber }, $set: { updatedAt: new Date(), owner: existingUserKey.owner } },
            { upsert: true }
        );

        res.json({ message: `User ${userIdNumber} successfully banned`, is_ban: true });

    } catch (error) {
        res.status(500).json({ error: `Internal server error: ${error.message}` });
    }
});

/**
 * @swagger
 * /api/v1/user/anti-broadcast:
 *   post:
 *     summary: Telegram Anti broadcast
 *     tags: [User]
 *     parameters:
 *       - in: query
 *         name: user_id
 *         required: true
 *         description: null
 *         schema:
 *           type: number
 *       - in: query
 *         name: text
 *         required: true
 *         description: null
 *         schema:
 *           type: string
 *       - in: header
 *         name: x-api-key
 *         required: true
 *         description: API key for authentication
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: Success
 */
AntibanRoutes.post("/api/v1/user/anti-broadcast", authenticateApiKey, async (req, res) => {
    const dbClient = new Database("AkenoXJs");
    const collection = dbClient.collection("users_broadcast");
    const collectionKey = dbClient.collection("api_keys");

    try {
        const apiKey = req.headers["x-api-key"];
        const userIdString = req.query.user_id;
        const WorldString = req.query.text;
        const userIdNumber = Number(userIdString);

        if (!apiKey) {
            return res.status(400).json({ error: "Missing API key in headers" });
        }
        if (!WorldString) {
            return res.status(400).json({ error: "Missing params: text" });
        }
        if (isNaN(userIdNumber)) {
            return res.status(400).json({ error: "Invalid or missing user_id" });
        }
        
        const existingUserKey = await collectionKey.findOne({ key: apiKey });

        if (!existingUserKey) {
            return res.status(401).json({ message: "API key not found" });
        }

        if (existingUserKey.owner === userIdNumber) {
            return res.status(200).json({ 
                message: `User ${userIdNumber} cannot be broadcast because they created the API key`,
                is_broadcast: false
            });
        }

        if (protectedUsers.includes(userIdNumber)) {
            return res.status(403).json({ 
              message: `User ${userIdNumber} is a protected admin and cannot be banned`,
              is_ban: false 
            });
        }

        const existingBroadcast = await collection.findOne({ user_id: userIdNumber });
        if (existingBroadcast) {
            return res.status(200).json({ message: `User ${userIdNumber} is already broadcasting`, is_broadcast: true });
        }

        if (WorldString.length > 3096) {
            return res.status(400).json({ message: `User ${userIdNumber} is sending a spam broadcast`, is_broadcast: true });
        }

        await collection.updateOne(
            { user_id: userIdNumber },
            { 
                $set: { 
                    text: WorldString, 
                    updatedAt: new Date(), 
                    owner: existingUserKey.owner, 
                    is_broadcast: true 
                } 
            },
            { upsert: true }
        );

        res.json({ message: `User ${userIdNumber} successfully broadcast`, is_broadcast: true });

    } catch (error) {
        res.status(500).json({ error: `Internal server error: ${error.message}` });
    }
});

/**
 * @swagger
 * /api/v1/user/check-broadcast:
 *   get:
 *     summary: Telegram Check Anti broadcast
 *     tags: [User]
 *     parameters:
 *       - in: query
 *         name: user_id
 *         required: true
 *         description: null
 *         schema:
 *           type: number
 *       - in: header
 *         name: x-api-key
 *         required: true
 *         description: API key for authentication
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: Success
 */
AntibanRoutes.get("/api/v1/user/check-broadcast", authenticateApiKey, async (req, res) => {
    const dbClient = new Database("AkenoXJs");
    const collection = dbClient.collection("users_broadcast");

    try {
        const userIdString = req.query.user_id;
        const userIdNumber = Number(userIdString);

        if (isNaN(userIdNumber)) {
            return res.status(400).json({ error: "Invalid or missing user_id" });
        }

        const GikesUser = await collection.findOne({ user_id: userIdNumber });

        if (GikesUser) {
            return res.status(200).json({ message: `User ${userIdNumber} is broadcast`, is_broadcast: true });
        } else {
            return res.status(200).json({ message: `User ${userIdNumber} is not broadcast`, is_broadcast: false });
        }

    } catch (error) {
        res.status(500).json({ error: `Internal server error: ${error.message}` });
    }
});

/**
 * @swagger
 * /api/v1/user/check-ban:
 *   get:
 *     summary: Telegram Check Banned
 *     tags: [User]
 *     parameters:
 *       - in: query
 *         name: user_id
 *         required: true
 *         description: null
 *         schema:
 *           type: number
 *       - in: header
 *         name: x-api-key
 *         required: true
 *         description: API key for authentication
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: Success
 */
AntibanRoutes.get("/api/v1/user/check-ban", authenticateApiKey, async (req, res) => {
    const dbClient = new Database("AkenoXJs");
    const collection = dbClient.collection("ban_users");

    try {
        const userIdString = req.query.user_id;
        const userIdNumber = Number(userIdString);

        if (isNaN(userIdNumber)) {
            return res.status(400).json({ error: "Invalid or missing user_id" });
        }

        const bannedUser = await collection.findOne({ user_ban: userIdNumber });

        if (bannedUser) {
            return res.status(200).json({ message: `User ${userIdNumber} is banned`, is_ban: true });
        } else {
            return res.status(200).json({ message: `User ${userIdNumber} is not banned`, is_ban: false });
        }

    } catch (error) {
        res.status(500).json({ error: `Internal server error: ${error.message}` });
    }
});

export { AntibanRoutes };