-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
170 lines (137 loc) · 4.4 KB
/
index.js
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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
const easyvk = require('easyvk');
const bd = require("./js/bd.js");
const g = require("./js/giftSend.js");
const vk = require("./js/vk.js");
const pl = require("./js/test.js");
const sleep = require('util').promisify(setTimeout);
var oldbody;
pl.start();
var giftSend = async function(body){
var b = JSON.parse(body);
let giftid = 10001;
let mess = "Хаха, ты впускаешь Венома в свой мозг! Удачи!";
await g.gSend(b.uid,giftid,mess);
}
var ballEdd = async function (body){
var b = JSON.parse(body);
console.log(b.uid);
var shopballs = await bd.SBallsGet(b.uid);
shopballs.balls = shopballs.balls - b.balls;
await bd.SBallsRewrite(b.uid,shopballs.balls);
console.log(shopballs.balls);
}
var by = async function (body){
var ustat = await pl.Ustat();
while (ustat.length == 0){
await sleep(100);
ustat = await pl.Ustat();
}
if (ustat.length == 0){
let resp = await vk.senditem(body.object.peer_id,"","","start_server");
console.log("Попытка покупки. Сервер не запущен");
}else{
try{
var shopballs = await bd.SBallsGet(body.object.peer_id);
let idx = await ustat.findIndex(e => e.uid == body.object.peer_id);
var line = body.object.text.indexOf('ЕБаллы: Купить за')+18;
var cost = body.object.text.slice(line);
line = cost.indexOf('ЕБ')-1;
cost = cost.slice(0,line);
if (ustat[idx].balls - shopballs.balls >= cost){
var line2 = body.object.text.indexOf('Корзина:')+9;
var item = body.object.text.slice(line2);
line2 = item.indexOf('[За Ебаллы]')-1;
item = item.slice(0,line2);
console.log(item);
var resp = await vk.senditem(body.object.peer_id,cost,ustat[idx].balls - Number(cost) - shopballs.balls ,item);
if (resp == "ok"){
shopballs.balls = shopballs.balls + Number(cost);
await bd.SBallsRewrite(body.object.peer_id,shopballs.balls);
console.log("Новая продажа");
}else{
console.log(resp);
}
}else{
let resp = await vk.senditem(body.object.peer_id,cost,ustat[idx].balls - shopballs.balls,"non_money123");
console.log("Недостаточно баллов для покупки ");//+ustat[idx].balls+" "+cost);
}
}catch(err){
if (err.message == "Cannot read property 'uid' of undefined"){
try{
let resp = await vk.senditem(body.object.peer_id,"","","non_sub123");
console.log("Не подписан");
}catch(err){
console.log(err);
}
}else{console.log(err.message); }
}
}
}
var urlencodedParser = bodyParser.urlencoded({
extended: false
});
app.use(bodyParser.json());
app.set('view engine', 'ejs');
app.use('/public', express.static('public'));
app.post('/', function (req, res) {
const {body} = req;
switch (body.type) {
case 'confirmation':
res.end('8d9c8073');
//res.end('ba2d09a1');
break;
case 'message_reply':
res.end('ok');
if ((body.object.text.indexOf('{"giftSend":"1.0.0","uid":') !== -1))
{
oldbody = body.object.body;
giftSend(body.object.text);
}else
if ((body.object.text.indexOf('{"ballEdd":"1.0.0","uid":') !== -1) &&
(body.object.text.indexOf('","balls":"') == -1)// &&
) //(body.object.body !== oldbody))
{
oldbody = body.object.body;
ballEdd(body.object.text);
}else
if ((body.object.text.indexOf("Купить за ЕБаллы:") !== -1) &&
(body.object.text.indexOf("Новый заказ") == -1) &&
(body.object.text !== oldbody))
{
oldbody = body.object.text;
by(body);
}
break;
case 'group_join':
vk.UserAdd(body.object.user_id);
res.end('ok');
break;
case 'group_leave':
bd.UserRemove(body.object.user_id);
res.end('ok');
break;
default:
res.end('ok');
vk.PostsGet();
break;
}
});
app.get('/', function (req, res) {
res.render('start',{users:pl.topuser()});
});
app.get('/rules', function (req, res) {
res.render('rules');
});
app.get('/pr70312345', function (req, res) {
vk.PostsGet();
res.render('start');
});
app.get('/ur70312345', function (req, res) {
vk.UsersGet();
res.render('start');
});
app.listen(process.env.PORT || 3000);
//http://localhost:3000/