yahyaali77824 commited on
Commit
bf635ca
·
verified ·
1 Parent(s): a1c453c
Files changed (3) hide show
  1. data.js +14 -0
  2. package.json +22 -0
  3. server.js +88 -0
data.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports = {
2
+ adminId: 2080396578,
3
+ welcomeMessage: "مرحبًا بك في البوت الذكي! 🚀\nيمكنك طرح أي سؤال وسأجيب عليه فورًا.",
4
+ users: new Set(),
5
+ aimlapiKey: "d63d9b2f8c194c6d98191855644e2f29",
6
+
7
+ saveWelcomeMessage: function() {
8
+ const fs = require('fs');
9
+ fs.writeFileSync('./data.js', `module.exports = ${JSON.stringify(this, (key, value) => {
10
+ if (value instanceof Set) return [...value];
11
+ return value;
12
+ }, 4)}`);
13
+ }
14
+ };
package.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "taem7782",
3
+ "version": "1.0.0",
4
+ "description": "بوت ذكاء اصطناعي متقدم",
5
+ "main": "server.js",
6
+ "engines": {
7
+ "node": "16.13.2"
8
+ },
9
+ "scripts": {
10
+ "start": "node server.js",
11
+ "dev": "nodemon server.js"
12
+ },
13
+ "keywords": ["AI", "Telegram Bot"],
14
+ "author": "@Haker77teme",
15
+ "license": "ISC",
16
+ "dependencies": {
17
+ "axios": "^0.26.1",
18
+ "express": "^4.18.2",
19
+ "node-telegram-bot-api": "^0.61.0",
20
+ "uuid": "^8.3.2"
21
+ }
22
+ }
server.js ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const TelegramBot = require('node-telegram-bot-api');
2
+ const express = require('express');
3
+ const axios = require('axios');
4
+ const data = require('./data');
5
+ const app = express();
6
+ const port = process.env.PORT || 3000;
7
+
8
+ // إعداد البوت
9
+ const bot = new TelegramBot('7330777255:AAHDypo5Jno6YH_BSmwQ90UtPDMWhNap68o', {
10
+ polling: true,
11
+ request: { timeout: 30000 }
12
+ });
13
+
14
+ // تحقق من صلاحية الأدمن
15
+ function isAdmin(userId) {
16
+ return userId === data.adminId;
17
+ }
18
+
19
+ // تشغيل السيرفر
20
+ app.get('/', (req, res) => res.send('🤖 البوت يعمل بشكل صحيح'));
21
+ app.listen(port, () => console.log(`السيرفر يعمل على البورت ${port}`));
22
+
23
+ // معالجة أمر /start
24
+ bot.onText(/\/start/, (msg) => {
25
+ const chatId = msg.chat.id;
26
+ if (!data.users.has(chatId)) {
27
+ data.users.add(chatId);
28
+ }
29
+ bot.sendMessage(chatId, data.welcomeMessage);
30
+ });
31
+
32
+ // معالجة الأسئلة العادية
33
+ bot.on('message', async (msg) => {
34
+ const chatId = msg.chat.id;
35
+ const userId = msg.from.id;
36
+
37
+ if (msg.text && !msg.text.startsWith('/')) {
38
+ try {
39
+ const aiResponse = await axios.post('https://api.aimlapi.com/predict', {
40
+ model: "gpt-4-turbo",
41
+ messages: [{ role: "user", content: msg.text }],
42
+ max_tokens: 1500,
43
+ temperature: 0.7
44
+ }, {
45
+ headers: {
46
+ 'Authorization': `Bearer ${data.aimlapiKey}`,
47
+ 'Content-Type': 'application/json'
48
+ },
49
+ timeout: 20000
50
+ });
51
+
52
+ const answer = aiResponse.data.choices[0].message.content;
53
+ bot.sendMessage(chatId, answer, { parse_mode: 'Markdown' });
54
+
55
+ } catch (error) {
56
+ console.error('خطأ في API:', error.response?.data || error.message);
57
+ bot.sendMessage(chatId, '⚠️ حدث خطأ أثناء معالجة سؤالك، يرجى المحاولة لاحقًا.');
58
+ }
59
+ }
60
+ });
61
+
62
+ // أوامر الأدمن
63
+ bot.onText(/\/setwelcome (.+)/, (msg, match) => {
64
+ const userId = msg.from.id;
65
+ if (isAdmin(userId)) {
66
+ data.welcomeMessage = match[1];
67
+ data.saveWelcomeMessage();
68
+ bot.sendMessage(msg.chat.id, '✅ تم تحديث رسالة الترحيب بنجاح!');
69
+ }
70
+ });
71
+
72
+ bot.onText(/\/broadcast (.+)/, (msg, match) => {
73
+ const userId = msg.from.id;
74
+ if (isAdmin(userId)) {
75
+ const message = match[1];
76
+ data.users.forEach(user => {
77
+ bot.sendMessage(user, `📢 إشعار عام:\n${message}`);
78
+ });
79
+ bot.sendMessage(msg.chat.id, `✔️ تم الإرسال لـ ${data.users.size} مستخدم`);
80
+ }
81
+ });
82
+
83
+ // الحفاظ على البوت نشطًا
84
+ setInterval(() => {
85
+ axios.get(`https://${process.env.PROJECT_DOMAIN}.glitch.me/`)
86
+ .then(() => console.log('تم تجنب السكون ✅'))
87
+ .catch(err => console.error('خطأ في الحفاظ على النشاط:', err));
88
+ }, 280000);