isite 2024.8.23 → 2024.9.2
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/apps/client-side/site_files/css/bootstrap5-addon.css +3 -0
- package/apps/client-side/site_files/css/dropdown.css +1 -1
- package/apps/client-side/site_files/css/theme.css +1 -1
- package/apps/client-side/site_files/css/theme_dark.css +1 -1
- package/apps/client-side/site_files/css/theme_paper.css +1 -1
- package/apps/client-side/site_files/html/directive/i-list.html +1 -1
- package/apps/client-side/site_files/js/bootstrap-5-directive.js +8 -0
- package/apps/client-side/site_files/js/site.js +49 -1
- package/apps/client-side/site_files/js/site.min.js +1 -1
- package/apps/security/app.js +181 -175
- package/apps/security/site_files/js/login.js +33 -33
- package/index.js +2 -5
- package/lib/collection.js +1 -0
- package/lib/collectionFile.js +3 -2
- package/lib/integrated.js +85 -5
- package/lib/mongodb.js +2 -2
- package/lib/parser.js +3 -0
- package/lib/routing.js +32 -22
- package/lib/security.js +3 -38
- package/lib/ws.js +30 -12
- package/lib/wsClient.js +7 -3
- package/package.json +2 -2
package/apps/security/app.js
CHANGED
|
@@ -1,289 +1,295 @@
|
|
|
1
1
|
module.exports = function init(site) {
|
|
2
|
-
|
|
3
2
|
site.post('/api/security/permissions', (req, res) => {
|
|
4
|
-
|
|
5
3
|
let response = {
|
|
6
|
-
done: !1
|
|
7
|
-
}
|
|
4
|
+
done: !1,
|
|
5
|
+
};
|
|
8
6
|
|
|
9
7
|
if (!req.session.user) {
|
|
10
|
-
response.error = 'You Are Not Login'
|
|
11
|
-
res.json(response)
|
|
12
|
-
return
|
|
8
|
+
response.error = 'You Are Not Login';
|
|
9
|
+
res.json(response);
|
|
10
|
+
return;
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
response.done = !0;
|
|
16
|
-
response.permissions = site.security.permissions
|
|
17
|
-
res.json(response)
|
|
18
|
-
})
|
|
14
|
+
response.permissions = site.security.permissions;
|
|
15
|
+
res.json(response);
|
|
16
|
+
});
|
|
19
17
|
|
|
20
18
|
site.post('/api/security/roles', (req, res) => {
|
|
21
|
-
|
|
22
19
|
let response = {
|
|
23
|
-
done: !1
|
|
24
|
-
}
|
|
20
|
+
done: !1,
|
|
21
|
+
};
|
|
25
22
|
|
|
26
23
|
if (!req.session.user) {
|
|
27
|
-
response.error = 'You Are Not Login'
|
|
28
|
-
res.json(response)
|
|
29
|
-
return
|
|
24
|
+
response.error = 'You Are Not Login';
|
|
25
|
+
res.json(response);
|
|
26
|
+
return;
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
response.done = !0;
|
|
33
|
-
response.roles = site.security.roles
|
|
34
|
-
res.json(response)
|
|
35
|
-
})
|
|
30
|
+
response.roles = site.security.roles;
|
|
31
|
+
res.json(response);
|
|
32
|
+
});
|
|
36
33
|
|
|
37
34
|
site.get({
|
|
38
|
-
name: [
|
|
39
|
-
path: __dirname +
|
|
40
|
-
parser:
|
|
41
|
-
compress: !1
|
|
42
|
-
})
|
|
35
|
+
name: ['security', 'security/users'],
|
|
36
|
+
path: __dirname + '/site_files/html/index.html',
|
|
37
|
+
parser: 'html css js',
|
|
38
|
+
compress: !1,
|
|
39
|
+
});
|
|
43
40
|
|
|
44
41
|
site.get({
|
|
45
42
|
name: '/images',
|
|
46
|
-
path: __dirname + '/site_files/images'
|
|
47
|
-
})
|
|
48
|
-
|
|
43
|
+
path: __dirname + '/site_files/images',
|
|
44
|
+
});
|
|
49
45
|
|
|
50
46
|
site.post('/api/users/all', (req, res) => {
|
|
51
|
-
|
|
52
47
|
let response = {
|
|
53
|
-
done: !1
|
|
54
|
-
}
|
|
48
|
+
done: !1,
|
|
49
|
+
};
|
|
55
50
|
|
|
56
51
|
if (!req.session.user) {
|
|
57
|
-
response.error = 'You Are Not Login'
|
|
58
|
-
res.json(response)
|
|
59
|
-
return
|
|
52
|
+
response.error = 'You Are Not Login';
|
|
53
|
+
res.json(response);
|
|
54
|
+
return;
|
|
60
55
|
}
|
|
61
56
|
|
|
62
|
-
site.security.getUsers(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
site.security.getUsers(
|
|
58
|
+
{
|
|
59
|
+
limit: 1000,
|
|
60
|
+
},
|
|
61
|
+
(err, docs, count) => {
|
|
62
|
+
if (!err) {
|
|
63
|
+
response.done = !0;
|
|
64
|
+
for (let i = 0; i < docs.length; i++) {
|
|
65
|
+
let u = docs[i];
|
|
66
|
+
u.profile = u.profile || {};
|
|
67
|
+
u.profile.image_url = u.profile.image_url || '/images/user.png';
|
|
68
|
+
}
|
|
69
|
+
response.users = docs;
|
|
70
|
+
response.count = count;
|
|
71
71
|
}
|
|
72
|
-
response
|
|
73
|
-
response.count = count
|
|
72
|
+
res.json(response);
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
site.post("/api/user/add", (req, res) => {
|
|
74
|
+
);
|
|
75
|
+
});
|
|
80
76
|
|
|
77
|
+
site.post('/api/user/add', (req, res) => {
|
|
81
78
|
let response = {
|
|
82
|
-
done: !1
|
|
83
|
-
}
|
|
79
|
+
done: !1,
|
|
80
|
+
};
|
|
84
81
|
|
|
85
82
|
if (!req.session.user) {
|
|
86
|
-
response.error = 'You Are Not Login'
|
|
87
|
-
res.json(response)
|
|
88
|
-
return
|
|
83
|
+
response.error = 'You Are Not Login';
|
|
84
|
+
res.json(response);
|
|
85
|
+
return;
|
|
89
86
|
}
|
|
90
87
|
|
|
91
|
-
let user = req.body
|
|
92
|
-
user.$req = req
|
|
93
|
-
user.$res = res
|
|
88
|
+
let user = req.body;
|
|
89
|
+
user.$req = req;
|
|
90
|
+
user.$res = res;
|
|
94
91
|
site.security.addUser(user, (err, _id) => {
|
|
95
92
|
if (!err) {
|
|
96
|
-
response.done = !0
|
|
93
|
+
response.done = !0;
|
|
97
94
|
} else {
|
|
98
|
-
response.error = err.message
|
|
95
|
+
response.error = err.message;
|
|
99
96
|
}
|
|
100
|
-
res.json(response)
|
|
101
|
-
})
|
|
102
|
-
})
|
|
97
|
+
res.json(response);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
103
100
|
|
|
104
|
-
site.post(
|
|
101
|
+
site.post('/api/user/update', (req, res) => {
|
|
105
102
|
let response = {
|
|
106
|
-
done: !1
|
|
107
|
-
}
|
|
103
|
+
done: !1,
|
|
104
|
+
};
|
|
108
105
|
|
|
109
106
|
if (!req.session.user) {
|
|
110
|
-
response.error = 'You Are Not Login'
|
|
111
|
-
res.json(response)
|
|
112
|
-
return
|
|
107
|
+
response.error = 'You Are Not Login';
|
|
108
|
+
res.json(response);
|
|
109
|
+
return;
|
|
113
110
|
}
|
|
114
111
|
|
|
115
|
-
let user = req.body
|
|
116
|
-
user.$req = req
|
|
117
|
-
user.$res = res
|
|
118
|
-
delete user.$$hashKey
|
|
112
|
+
let user = req.body;
|
|
113
|
+
user.$req = req;
|
|
114
|
+
user.$res = res;
|
|
115
|
+
delete user.$$hashKey;
|
|
119
116
|
|
|
120
|
-
site.security.updateUser(user, err => {
|
|
117
|
+
site.security.updateUser(user, (err) => {
|
|
121
118
|
if (!err) {
|
|
122
|
-
response.done = !0
|
|
119
|
+
response.done = !0;
|
|
123
120
|
} else {
|
|
124
|
-
response.error = err.message
|
|
121
|
+
response.error = err.message;
|
|
125
122
|
}
|
|
126
|
-
res.json(response)
|
|
127
|
-
})
|
|
123
|
+
res.json(response);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
128
126
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
site.post("/api/user/delete", (req, res) => {
|
|
127
|
+
site.post('/api/user/delete', (req, res) => {
|
|
132
128
|
let response = {
|
|
133
|
-
done: !1
|
|
134
|
-
}
|
|
129
|
+
done: !1,
|
|
130
|
+
};
|
|
135
131
|
|
|
136
132
|
if (!req.session.user) {
|
|
137
|
-
response.error = 'You Are Not Login'
|
|
138
|
-
res.json(response)
|
|
139
|
-
return
|
|
133
|
+
response.error = 'You Are Not Login';
|
|
134
|
+
res.json(response);
|
|
135
|
+
return;
|
|
140
136
|
}
|
|
141
137
|
|
|
142
|
-
let id = req.body.id
|
|
138
|
+
let id = req.body.id;
|
|
143
139
|
if (id) {
|
|
144
|
-
site.security.deleteUser(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
140
|
+
site.security.deleteUser(
|
|
141
|
+
{
|
|
142
|
+
id: id,
|
|
143
|
+
$req: req,
|
|
144
|
+
$res: res,
|
|
145
|
+
},
|
|
146
|
+
(err, result) => {
|
|
147
|
+
if (!err) {
|
|
148
|
+
response.done = !0;
|
|
149
|
+
} else {
|
|
150
|
+
response.error = err.message;
|
|
151
|
+
}
|
|
152
|
+
res.json(response);
|
|
153
153
|
}
|
|
154
|
-
|
|
155
|
-
})
|
|
154
|
+
);
|
|
156
155
|
} else {
|
|
157
|
-
response.error = 'No ID Requested'
|
|
158
|
-
res.json(response)
|
|
156
|
+
response.error = 'No ID Requested';
|
|
157
|
+
res.json(response);
|
|
159
158
|
}
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
site.post("/api/user/view", (req, res) => {
|
|
159
|
+
});
|
|
163
160
|
|
|
161
|
+
site.post('/api/user/view', (req, res) => {
|
|
164
162
|
let response = {
|
|
165
|
-
done: !1
|
|
166
|
-
}
|
|
163
|
+
done: !1,
|
|
164
|
+
};
|
|
167
165
|
|
|
168
166
|
if (!req.session.user) {
|
|
169
|
-
response.error = 'You Are Not Login'
|
|
170
|
-
res.json(response)
|
|
171
|
-
return
|
|
167
|
+
response.error = 'You Are Not Login';
|
|
168
|
+
res.json(response);
|
|
169
|
+
return;
|
|
172
170
|
}
|
|
173
171
|
|
|
174
|
-
site.security.getUser(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
172
|
+
site.security.getUser(
|
|
173
|
+
{
|
|
174
|
+
id: req.body.id,
|
|
175
|
+
},
|
|
176
|
+
(err, doc) => {
|
|
177
|
+
if (!err) {
|
|
178
|
+
response.done = !0;
|
|
179
|
+
response.doc = doc;
|
|
180
|
+
} else {
|
|
181
|
+
response.error = err.message;
|
|
182
|
+
}
|
|
183
|
+
res.json(response);
|
|
182
184
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
})
|
|
185
|
+
);
|
|
186
|
+
});
|
|
186
187
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
let response = {}
|
|
188
|
+
site.post('/api/user/register', (req, res) => {
|
|
189
|
+
let response = {};
|
|
190
190
|
|
|
191
191
|
if (req.body.$encript) {
|
|
192
|
-
if (req.body.$encript ===
|
|
193
|
-
req.body.email = site.fromBase64(req.body.email)
|
|
194
|
-
req.body.password = site.fromBase64(req.body.password)
|
|
195
|
-
} else if (req.body.$encript ===
|
|
196
|
-
req.body.email = site.from123(req.body.email)
|
|
197
|
-
req.body.password = site.from123(req.body.password)
|
|
192
|
+
if (req.body.$encript === '64') {
|
|
193
|
+
req.body.email = site.fromBase64(req.body.email);
|
|
194
|
+
req.body.password = site.fromBase64(req.body.password);
|
|
195
|
+
} else if (req.body.$encript === '123') {
|
|
196
|
+
req.body.email = site.from123(req.body.email);
|
|
197
|
+
req.body.password = site.from123(req.body.password);
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
site.security.register(
|
|
201
|
+
site.security.register(
|
|
202
|
+
{
|
|
202
203
|
email: req.body.email,
|
|
203
204
|
password: req.body.password,
|
|
204
205
|
ip: req.ip,
|
|
205
|
-
permissions: [
|
|
206
|
+
permissions: ['user'],
|
|
206
207
|
profile: {
|
|
207
208
|
files: [],
|
|
208
|
-
name: req.body.email
|
|
209
|
+
name: req.body.email,
|
|
209
210
|
},
|
|
210
211
|
$req: req,
|
|
211
|
-
$res: res
|
|
212
|
+
$res: res,
|
|
212
213
|
},
|
|
213
214
|
function (err, doc) {
|
|
214
215
|
if (!err) {
|
|
215
|
-
response.user = doc
|
|
216
|
-
response.done = !0
|
|
216
|
+
response.user = doc;
|
|
217
|
+
response.done = !0;
|
|
217
218
|
} else {
|
|
218
|
-
response.error = err.message
|
|
219
|
+
response.error = err.message;
|
|
219
220
|
}
|
|
220
|
-
res.json(response)
|
|
221
|
+
res.json(response);
|
|
221
222
|
}
|
|
222
|
-
)
|
|
223
|
-
})
|
|
224
|
-
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
225
|
|
|
226
|
-
site.post(
|
|
226
|
+
site.post('/api/user/login', function (req, res) {
|
|
227
227
|
let response = {
|
|
228
|
-
accessToken: req.session.accessToken
|
|
229
|
-
}
|
|
228
|
+
accessToken: req.session.accessToken,
|
|
229
|
+
};
|
|
230
230
|
|
|
231
231
|
if (req.body.$encript) {
|
|
232
|
-
if (req.body.$encript ===
|
|
233
|
-
req.body.email = site.fromBase64(req.body.email)
|
|
234
|
-
req.body.
|
|
235
|
-
|
|
236
|
-
req.body.
|
|
237
|
-
req.body.
|
|
232
|
+
if (req.body.$encript === '64') {
|
|
233
|
+
req.body.email = site.fromBase64(req.body.email);
|
|
234
|
+
req.body.mobile = site.fromBase64(req.body.mobile);
|
|
235
|
+
req.body.username = site.fromBase64(req.body.username);
|
|
236
|
+
req.body.password = site.fromBase64(req.body.password);
|
|
237
|
+
req.body.key = site.fromBase64(req.body.key);
|
|
238
|
+
} else if (req.body.$encript === '123') {
|
|
239
|
+
req.body.email = site.from123(req.body.email);
|
|
240
|
+
req.body.mobile = site.from123(req.body.mobile);
|
|
241
|
+
req.body.username = site.from123(req.body.username);
|
|
242
|
+
req.body.password = site.from123(req.body.password);
|
|
243
|
+
req.body.key = site.from123(req.body.key);
|
|
238
244
|
}
|
|
239
245
|
}
|
|
240
246
|
|
|
241
247
|
if (site.security.isUserLogin(req, res)) {
|
|
242
|
-
response.error =
|
|
243
|
-
response.done = !0
|
|
244
|
-
res.json(response)
|
|
245
|
-
return
|
|
248
|
+
response.error = 'Login Error , You Are Loged ';
|
|
249
|
+
response.done = !0;
|
|
250
|
+
res.json(response);
|
|
251
|
+
return;
|
|
246
252
|
}
|
|
247
253
|
|
|
248
|
-
site.security.login(
|
|
254
|
+
site.security.login(
|
|
255
|
+
{
|
|
249
256
|
email: req.body.email,
|
|
257
|
+
username: req.body.username,
|
|
258
|
+
mobile: req.body.mobile,
|
|
250
259
|
password: req.body.password,
|
|
260
|
+
key: req.body.key,
|
|
251
261
|
$req: req,
|
|
252
|
-
$res: res
|
|
262
|
+
$res: res,
|
|
253
263
|
},
|
|
254
264
|
function (err, user) {
|
|
255
265
|
if (!err) {
|
|
266
|
+
response.user = user;
|
|
256
267
|
|
|
257
|
-
response.
|
|
258
|
-
|
|
259
|
-
response.done = !0
|
|
260
|
-
|
|
268
|
+
response.done = !0;
|
|
261
269
|
} else {
|
|
262
|
-
response.error = err.message
|
|
270
|
+
response.error = err.message;
|
|
263
271
|
}
|
|
264
272
|
|
|
265
|
-
res.json(response)
|
|
273
|
+
res.json(response);
|
|
266
274
|
}
|
|
267
|
-
)
|
|
268
|
-
})
|
|
275
|
+
);
|
|
276
|
+
});
|
|
269
277
|
|
|
270
|
-
site.post(
|
|
278
|
+
site.post('/api/user/logout', function (req, res) {
|
|
271
279
|
let response = {
|
|
272
|
-
done: !0
|
|
273
|
-
}
|
|
280
|
+
done: !0,
|
|
281
|
+
};
|
|
274
282
|
|
|
275
283
|
site.security.logout(req, res, (err, ok) => {
|
|
276
|
-
response.accessToken = req.session.accessToken
|
|
284
|
+
response.accessToken = req.session.accessToken;
|
|
277
285
|
if (ok) {
|
|
278
|
-
response.done = !0
|
|
279
|
-
res.json(response)
|
|
286
|
+
response.done = !0;
|
|
287
|
+
res.json(response);
|
|
280
288
|
} else {
|
|
281
|
-
response.error =
|
|
282
|
-
response.done = !0
|
|
283
|
-
res.json(response)
|
|
289
|
+
response.error = 'You Are Not Loged';
|
|
290
|
+
response.done = !0;
|
|
291
|
+
res.json(response);
|
|
284
292
|
}
|
|
285
|
-
})
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
};
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
app.controller('login', function ($scope, $http) {
|
|
2
|
+
$scope.busy = !1;
|
|
3
|
+
$scope.tryLogin = function (ev) {
|
|
4
|
+
if (ev.which == 13) {
|
|
5
|
+
$scope.login();
|
|
6
|
+
}
|
|
7
|
+
};
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
$scope.
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
$scope.login = function () {
|
|
10
|
+
$scope.error = '';
|
|
11
|
+
$scope.busy = !0;
|
|
12
|
+
$http({
|
|
13
|
+
method: 'POST',
|
|
14
|
+
url: '/api/user/login',
|
|
15
|
+
data: {
|
|
16
|
+
$encript: '123',
|
|
17
|
+
email: site.to123($scope.userEmail),
|
|
18
|
+
password: site.to123($scope.userPassword),
|
|
19
|
+
},
|
|
20
|
+
}).then(
|
|
21
|
+
function (response) {
|
|
22
|
+
if (response.data.error) {
|
|
23
|
+
$scope.error = response.data.error;
|
|
7
24
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
$scope.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
}).then(function (response) {
|
|
22
|
-
|
|
23
|
-
if (response.data.error) {
|
|
24
|
-
$scope.error = response.data.error;
|
|
25
|
-
}
|
|
26
|
-
if (response.data.done) {
|
|
27
|
-
window.location.reload(!0);
|
|
28
|
-
}
|
|
29
|
-
$scope.busy = !1;
|
|
30
|
-
} , function(err){
|
|
31
|
-
$scope.busy = !1;
|
|
32
|
-
$scope.error = err;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
});
|
|
25
|
+
if (response.data.done) {
|
|
26
|
+
window.location.reload(!0);
|
|
27
|
+
}
|
|
28
|
+
$scope.busy = !1;
|
|
29
|
+
},
|
|
30
|
+
function (err) {
|
|
31
|
+
$scope.busy = !1;
|
|
32
|
+
$scope.error = err;
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
});
|
package/index.js
CHANGED
|
@@ -114,11 +114,8 @@ module.exports = function init(options) {
|
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
setTimeout(() => {
|
|
117
|
-
console.log('Closing
|
|
118
|
-
|
|
119
|
-
console.log('Closing Process');
|
|
120
|
-
process.exit(0);
|
|
121
|
-
});
|
|
117
|
+
console.log('Closing Process');
|
|
118
|
+
process.exit(0);
|
|
122
119
|
}, 1000 * wait);
|
|
123
120
|
};
|
|
124
121
|
____0.options = {};
|
package/lib/collection.js
CHANGED
package/lib/collectionFile.js
CHANGED
|
@@ -9,13 +9,14 @@ module.exports = function init(____0, options, db) {
|
|
|
9
9
|
createIndexs: function () {},
|
|
10
10
|
dropIndex: function () {},
|
|
11
11
|
dropIndexes: function () {},
|
|
12
|
+
find: function () {},
|
|
13
|
+
get: function () {},
|
|
12
14
|
findOne: function () {},
|
|
13
15
|
findAll: function () {},
|
|
14
16
|
findMany: function () {},
|
|
15
|
-
get: function () {},
|
|
16
17
|
getAll: function () {},
|
|
17
|
-
find: function () {},
|
|
18
18
|
add: function () {},
|
|
19
|
+
insert: function () {},
|
|
19
20
|
update: function () {},
|
|
20
21
|
delete: function () {},
|
|
21
22
|
};
|
package/lib/integrated.js
CHANGED
|
@@ -15,14 +15,94 @@ module.exports = function init(____0) {
|
|
|
15
15
|
____0.telegramInit = function (_token, onNewMessage) {
|
|
16
16
|
const token = _token || ____0.from123('28151274267416752654127427546213313647493756417147542323361941814637625228172373327862183774477626168234323932434158325736319191');
|
|
17
17
|
const bot = new ____0.telegramBotApi(token, { polling: true });
|
|
18
|
-
|
|
18
|
+
let botManager = {
|
|
19
|
+
token: _token,
|
|
20
|
+
bot: bot,
|
|
21
|
+
messageList: [],
|
|
22
|
+
userMessageList: [],
|
|
23
|
+
sendMessage: function (...args) {
|
|
24
|
+
botManager.messageList.push(args);
|
|
25
|
+
bot.sendMessage(...args);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
19
28
|
bot.on('message', function (msg) {
|
|
20
|
-
if (
|
|
21
|
-
|
|
29
|
+
if (msg.text.toString().like('json')) {
|
|
30
|
+
bot.sendMessage(msg.chat.id, JSON.stringify(msg.chat));
|
|
31
|
+
} else if (msg.text.toString().like('id')) {
|
|
32
|
+
bot.sendMessage(msg.chat.id, 'Your ID : ' + msg.chat.id);
|
|
33
|
+
} else if (onNewMessage) {
|
|
34
|
+
onNewMessage(msg, botManager);
|
|
22
35
|
} else {
|
|
23
|
-
|
|
36
|
+
botManager.sendMessage(msg.chat.id, 'This Bot Not Implement Yet. \n For Help Call \n whats up: +966568118373 ');
|
|
24
37
|
}
|
|
25
38
|
});
|
|
26
|
-
return
|
|
39
|
+
return botManager;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
____0.newTelegramBot = function (data, onNewMessage) {
|
|
43
|
+
if (typeof data === 'string') {
|
|
44
|
+
data = { token: data };
|
|
45
|
+
}
|
|
46
|
+
let botManager = ____0.telegramBotList.find((b) => b.token == data.token);
|
|
47
|
+
if (!botManager) {
|
|
48
|
+
botManager = ____0.telegramInit(data.token, onNewMessage);
|
|
49
|
+
if (Array.isArray(data.userMessageList)) {
|
|
50
|
+
botManager.userMessageList = data.userMessageList;
|
|
51
|
+
}
|
|
52
|
+
____0.telegramBotList.push(botManager);
|
|
53
|
+
}
|
|
54
|
+
return botManager;
|
|
27
55
|
};
|
|
56
|
+
|
|
57
|
+
____0.telegramBotList = [];
|
|
58
|
+
|
|
59
|
+
____0.onPOST('/telegram/connect', (req, res) => {
|
|
60
|
+
let response = {
|
|
61
|
+
done: false,
|
|
62
|
+
data: req.data,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
if (req.data.token) {
|
|
66
|
+
____0.newTelegramBot(req.data, (msg, botManager) => {
|
|
67
|
+
botManager.sendMessage(msg.chat.id, 'This Bot is hosting on https://social-browser.com');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
response.done = true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
res.json(response);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
____0.onPOST('/telegram/disconnect', (req, res) => {
|
|
77
|
+
let response = {
|
|
78
|
+
done: false,
|
|
79
|
+
data: req.data,
|
|
80
|
+
};
|
|
81
|
+
if (req.data.token) {
|
|
82
|
+
let index = ____0.telegramBotList.findIndex((b) => b.token == req.data.token);
|
|
83
|
+
if (index !== -1) {
|
|
84
|
+
____0.telegramBotList = ____0.telegramBotList.filter((b) => b.token !== req.data.token);
|
|
85
|
+
response.done = true;
|
|
86
|
+
response.index = index;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
res.json(response);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
____0.onPOST('/telegram/send-message', (req, res) => {
|
|
94
|
+
let response = {
|
|
95
|
+
done: false,
|
|
96
|
+
data: req.data,
|
|
97
|
+
};
|
|
98
|
+
if (req.data.token) {
|
|
99
|
+
let bot = ____0.newTelegramBot(req.data.token, (msg, botManager) => {
|
|
100
|
+
botManager.sendMessage(msg.chat.id, 'This Bot is hosting on https://social-browser.com');
|
|
101
|
+
});
|
|
102
|
+
bot.sendMessage(req.data.chatID, req.data.message);
|
|
103
|
+
response.done = true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
res.json(response);
|
|
107
|
+
});
|
|
28
108
|
};
|