-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
728 lines (631 loc) · 26.7 KB
/
index.js
File metadata and controls
728 lines (631 loc) · 26.7 KB
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
import Binance from 'binance-api-node'
import TelegramBot from 'node-telegram-bot-api'
import CoinMarketCap from 'coinmarketcap-api'
import dotenv from 'dotenv'
import translate from "translate";
import schedule from "node-schedule";
import mongo from "mongodb";
import mongoose from 'mongoose';
import rp from 'request-promise';
import cheerio from 'cheerio';
import fs from 'fs';
import CronJob from 'node-cron';
import moment from 'moment';
import Request from 'request';
import axios from 'axios';
import { formatMoney } from './utils/money.js'
dotenv.config()
// API keys can be generated here https://www.binance.com/en/my/settings/api-management
const binanceClient = Binance.default({
apiKey: process.env.BINANCE_API_KEY,
apiSecret: process.env.BINANCE_API_SECRET,
})
// API CoinMarketCap
const CoinMarketCapClient = new CoinMarketCap(process.env.COINMARKETCAP_API_KEY)
// The bot token can be obtained from BotFather https://core.telegram.org/bots#3-how-do-i-create-a-bot
const bot = new TelegramBot(process.env.TELEGRAMM_BOT_TOKEN, { polling: true })
getWhaleCrypto()
function getIDChannel() {
return new Promise(resolve => {
bot.getChat(process.env.TELEGRAMM_CHANNEL).then(
(channel) => {
resolve(channel['id'])
}
)
});
}
function getIDChannel2() {
return new Promise(resolve => {
bot.getChat(process.env.TELEGRAMM_CHANNEL_2).then(
(channel) => {
resolve(channel['id'])
}
)
});
}
// Connect to the db
var ObjectID = mongo.ObjectID;
mongoose.connect(process.env.MONGODB_URL, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => {
//don't show the log when it is test
if(process.env.NODE_ENV !== "test") {
console.log("\nConnected to %s", process.env.MONGODB_URL);
console.log("App is running ... \n");
console.log("Press CTRL + C to stop the process. \n");
(async () => {
const idChannel = await getIDChannel();
bot.sendMessage(idChannel, 'Bảo trì hệ thống Bot tiền ảo hoàn tất!');
})();
}
}).catch(err => {
console.error("App starting error:", err.message);
process.exit(1);
});
var db = mongoose.connection;
//check Ctrl + C
if(process.env.NODE_ENV !== "test") {
process.on('SIGINT', function() {
(async () => {
const idChannel = await getIDChannel();
bot.sendMessage(idChannel, 'Bắt đầu bảo trì hệ thống Bot tiền ảo sau 3 giây nữa!');
})();
setTimeout(function () {
process.exit(1);
}, 3000)
});
}
CronJob.schedule('00 00 19 * * *', () => {
getNews()
}, {
scheduled: true,
timezone: "Asia/Ho_Chi_Minh"
});
CronJob.schedule('00 00 1 * * *', () => {
getSummingUpWhaleCryptoToday()
}, {
scheduled: true,
timezone: "Asia/Ho_Chi_Minh"
});
CronJob.schedule('30 * * * * *', () => {
getWhaleCrypto()
}, {
scheduled: true,
timezone: "Asia/Ho_Chi_Minh"
});
CronJob.schedule('50 59 23 31 01 *', () => {
happyNewYear()
}, {
scheduled: true,
timezone: "Asia/Ho_Chi_Minh"
});
CronJob.schedule('00 00 00 01 02 *', () => {
happyNewYear2()
}, {
scheduled: true,
timezone: "Asia/Ho_Chi_Minh"
});
function happyNewYear() {
(async () => {
const idChannel = await getIDChannel();
bot.sendMessage(idChannel, `\u{1F386}\u{1F386}\u{1F386}\u{1F386}\n\nVậy là chỉ còn 10s nữa thôi là bước qua năm mới, Năm Nhâm Dần.`);
})();
(async () => {
const idChannel2 = await getIDChannel2();
bot.sendMessage(idChannel2, `\u{1F386}\u{1F386}\u{1F386}\u{1F386}\n\nVậy là chỉ còn 10s nữa thôi là bước qua năm mới, Năm Nhâm Dần.`);
})();
}
function happyNewYear2() {
(async () => {
const idChannel = await getIDChannel();
bot.sendMessage(idChannel, `\u{1F386}\u{1F386}\u{1F386}\u{1F386}\n\nNăm mới Nhâm Dần, Bot Crypto VIP kính chúc mọi người đón xuân sum vầy, ấm áp, an vui và vạn sự như ý, thành công rực rỡ! Happy new year!`);
bot.sendVideo(idChannel, './images/happynewyear.mp4')
})();
(async () => {
const idChannel2 = await getIDChannel2();
bot.sendMessage(idChannel2, `\u{1F386}\u{1F386}\u{1F386}\u{1F386}\n\nNăm mới Nhâm Dần, Bot Crypto VIP kính chúc mọi người đón xuân sum vầy, ấm áp, an vui và vạn sự như ý, thành công rực rỡ! Happy new year!`);
bot.sendVideo(idChannel2, './images/happynewyear.mp4')
})();
}
function getToday() {
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
return today
}
async function getNews() {
var options = {
method: 'GET',
uri: 'https://tapchibitcoin.io/',
headers: {
json: true,
gzip: true,
'User-Agent': 'Discordbot/2.0'
},
transform: function (body) {
return cheerio.load(body);
}
};
rp(options)
.then(function ($) {
var news = []
var today = moment(new Date()).format("DD/MM/YYYY")
$('.td-block-span12').each((index, el) => { // lặp từng phần tử có class là job__list-item
if ($(el).find('.td-post-date').text() == today) {
news.push("- "+$(el).find('.entry-title').text());
}
})
setTimeout(function(){
(async () => {
const idChannel = await getIDChannel();
bot.sendMessage(idChannel, '\u{1F4E3}\u{1F4E3} Tin tức tiền ảo ngày '+today+'\u{1F4E3}\u{1F4E3}\n\n'+news.join('\n\n'));
})();
}, 3000);
})
.catch(function (err) {
console.log(err)
});
}
// Matches "/price [symbol]"
// bot.onText(/\/price -b (.+)/, (msg, data) => {
// const chatId = msg.chat.id
// // data[1] can be single token (i.e. "BTC") or pair ("ETH BTC")
// const [cryptoToken1, cryptoToken2 = 'USDT'] = data[1].split(' ')
// binanceClient
// .avgPrice({ symbol: `${cryptoToken1}${cryptoToken2}`.toUpperCase() }) // example, { symbol: "BTCUSTD" }
// .then((avgPrice) => {
// bot.sendMessage(chatId, formatMoney(avgPrice['price']))
// })
// .catch((error) =>
// bot.sendMessage(
// chatId,
// `Lỗi cuốn pháp! Vui lòng kiểm tra lại ${cryptoToken1}${cryptoToken2}: ${error}`
// )
// )
// })
//priceCrypto(chatId,cryptoToken1)
//schedule Job
bot.on('message', (msg) => {
schedule.scheduleJob('* * * * * *', function(fireDate){
//bot.sendMessage(msg.from.id, "Hello " + msg.from.first_name+msg.from.last_name);
//find_schedule_price(msg.from.id)
find_price_quote(msg.from.id,msg.chat.id)
});
})
function apiSimSimi(chatId,msg) {
var urlEncode = encodeURI(`https://simsimi.info/api/?text=${msg}&lc=vn`)
axios.get(urlEncode)
.then(function (response) {
var data = JSON.parse(JSON.stringify(response['data']));
bot.sendMessage(chatId, data['success'])
})
.catch(function (error) {
console.log(error);
})
}
function getWhaleCrypto() {
axios.get('https://api.whale-alert.io/feed.csv')
.then(function (response) {
var data = response['data'].split("\n")
for (const dataWhale of data) {
var item = dataWhale.split(",");
let ts = Date.now();
let date_ob = new Date(ts);
let today = date_ob.getDate()+"/"+date_ob.getMonth() + 1+"/"+ date_ob.getFullYear();
var data_whale = {
_id: new ObjectID(),
id: item[0],
time: item[1],
symbol: item[2],
priceusdt: item[3],
priceusd: item[4],
from: item[6],
to: item[8],
timestamp: today
};
filter_whale(item[0],data_whale,parseFloat(item[4]),item[6],item[8],item[3],item[2],item[1])
}
})
.catch(function (error) {
console.log(error);
})
}
function filter_whale(id,data_whale,total,from,to,price,symbol,time) {
var query = {
"id": id
};
var quote = db.collection('data_whale').findOne(query);
quote.then(function(result) {
var fromExchange,toExchange;
var formatMoney = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(total)
var coverTime = new Date(time*1000).toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1")
if (result == null) {
db.collection('data_whale').insert(data_whale);
// if (total > 10000000 && symbol == 'btc') {
// if (from == "") {
// fromExchange = "(Chưa rõ nguồn)"
// }else{
// fromExchange = from.toUpperCase()
// }
// if (to == "") {
// toExchange = "(Chưa rõ nguồn)"
// }else{
// toExchange = to.toUpperCase()
// }
// (async () => {
// const idChannel = await getIDChannel();
// bot.sendMessage(idChannel, '\u{1F51E}\u{1F51E} \n'+price+''+symbol.toUpperCase()+' ('+formatMoney+')'+'\nVừa được giao dịch từ '+fromExchange+' đến '+toExchange+'\nTime:'+coverTime);
// })();
// }
}
})
}
function getSummingUpWhaleCryptoToday() {
let ts = Date.now();
let date_ob = new Date(ts);
let yesterday = date_ob.getDate()-1+"/"+date_ob.getMonth() + 1+"/"+ date_ob.getFullYear();
let dayBefore = date_ob.getDate()-2+"/"+date_ob.getMonth() + 1+"/"+ date_ob.getFullYear();
var query = {
"timestamp": yesterday
};
var query2 = {
"timestamp": dayBefore
};
mongo.MongoClient.connect(process.env.MONGODB_URL_TWO, function(err, db) {
if (err) throw err;
var dbo = db.db("botcrypto");
dbo.collection("data_whale").find().toArray(function(err, result) {
if (err) throw err;
var sumVolume = 0;
var sumVolumeBTC = 0;
var sumVolumeUSDT = 0;
var totalVolumeBTC = 0;
var totalVolumeUSDT = 0;
var totalVolume = result.length;
for (let i = 0; i < result.length; i++) {
sumVolume += parseFloat(result[i].priceusd)
if (result[i].symbol == 'usdt') {
sumVolumeUSDT += parseFloat(result[i].priceusd)
totalVolumeUSDT += 1;
}
if (result[i].symbol == 'btc') {
sumVolumeBTC += parseFloat(result[i].priceusd)
totalVolumeBTC += 1;
}
}
insert_total_volume(sumVolume,sumVolumeBTC,sumVolumeUSDT,totalVolume,totalVolumeBTC,totalVolumeUSDT,yesterday)
dbo.collection("total_volume").find(query2).toArray(function(err2, result2) {
if (err2) throw err2;
var sumVolumePercent = 0;
var sumVolumeBTCPercent = 0;
var sumVolumeUSDTPercent = 0;
var totalVolumePercent = 0;
var totalVolumeBTCPercent = 0;
var totalVolumeUSDTPercent = 0;
for (let i = 0; i < result2.length; i++) {
sumVolumePercent = ((sumVolume - parseFloat(result2.sumVolume))/100)*100;
sumVolumeBTCPercent = ((sumVolumeBTC - parseFloat(result2.sumVolumeBTC))/100)*100;
sumVolumeUSDTPercent = ((sumVolumeUSDT - parseFloat(result2.sumVolumeUSDT))/100)*100;
totalVolumePercent = ((totalVolume - parseFloat(result2.totalVolume))/100)*100;
totalVolumeBTCPercent = ((totalVolumeBTC - parseFloat(result2.totalVolumeBTC))/100)*100;
totalVolumeUSDTPercent = ((totalVolumeUSDT - parseFloat(result2.totalVolumeUSDT))/100)*100;
}
(async () => {
const idChannel = await getIDChannel();
bot.sendMessage(idChannel, 'Thống kê giao dịch ngày '+yesterday+'\n\nTổng số giao dịch :'+totalVolume+' ('+totalVolumePercent+')\n\nTổng số giao dịch Bitcoin:'+totalVolumeBTC+' ('+totalVolumeBTCPercent+')\n\nTổng số giao dịch USDT: '+totalVolumeUSDT+' ('+totalVolumeUSDTPercent+')\n\nTổng lượng giao dịch: '+new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(sumVolume)+' ('+sumVolumePercent+')\n\nTổng lượng giao dịch Bitcoin: '+new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(sumVolumeBTC)+' ('+sumVolumeBTCPercent+')\n\nTổng lượng giao dịch USDT: '+new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(sumVolumeUSDT)+' ('+sumVolumeUSDTPercent+')');
})();
});
});
});
}
function insert_total_volume(sumVolume,sumVolumeBTC,sumVolumeUSDT,totalVolume,totalVolumeBTC,totalVolumeUSDT,today) {
var total_volume = {
_id: new ObjectID(),
sumVolume: sumVolume,
sumVolumeBTC: sumVolumeBTC,
sumVolumeUSDT: sumVolumeUSDT,
totalVolume: totalVolume,
totalVolumeBTC: totalVolumeBTC,
totalVolumeUSDT: totalVolumeUSDT,
timestamp: today
};
db.collection('total_volume').insert(total_volume);
}
function insert_schedule_price(msg,time,crypto) {
var schedule_prices = {
_id: new ObjectID(),
id: msg.from.id,
username: msg.from.username,
time: time,
crypto: crypto,
status: true,
timestamp: msg.date
};
db.collection('schedule_prices').insert(schedule_prices);
}
function insert_price_quote(msg,price,crypto) {
CoinMarketCapClient.getQuotes({symbol: `${crypto}`.toUpperCase()}).then(
(avgPrice) => {
var slug = avgPrice['data'][crypto.toUpperCase()]['slug']
var name = avgPrice['data'][crypto.toUpperCase()]['name']
var price_now = avgPrice['data'][crypto.toUpperCase()]['quote']['USD']['price']
var price_quote = {
_id: new ObjectID(),
id: msg.from.id,
username: msg.from.username,
price: price,
pricen: price_now,
crypto: crypto,
name: name,
slug: slug,
status: true,
timestamp: msg.date
};
db.collection('price_quote').insert(price_quote);
}
).catch((error) =>
console.log(error)
)
}
function update_status_price_quote(msg,price,crypto) {
var myquery = {
"id": msg.from.id,
"price": price,
"crypto": crypto
};
var newvalues = { $set: {status: "false" } };
db.collection('price_quote').updateOne(myquery, newvalues)
}
function find_price_quote_exist(msg,price,crypto) {
var query = {
"id": msg.from.id,
"price": price,
"crypto": crypto
};
var quote = db.collection('price_quote').findOne(query);
quote.then(function(result) {
if (result == null) {
insert_price_quote(msg,price,crypto)
bot.sendMessage(msg.chat.id, 'Đặt lệnh báo giá thành công!\nCoin: '+crypto+'\nGiá target: '+price+'\nChúc bạn sớm đạt được target mong muốn \u{2708}')
}else {
bot.sendMessage(msg.chat.id, 'Vui lòng không đặt lệnh trùng nhau!')
}
})
}
function find_price_quote_exist_off(msg,price,crypto) {
var query = {
"id": msg.from.id,
"price": price,
"crypto": crypto
};
var quote = db.collection('price_quote').findOne(query);
quote.then(function(result) {
if (result == null) {
bot.sendMessage(msg.chat.id, 'Không tìm thấy lệnh báo giá!')
}else {
update_status_price_quote(msg,price,crypto)
bot.sendMessage(msg.chat.id, 'Tắt lệnh báo giá thành công!\nTên: '+crypto+'\nGiá: '+price)
}
})
}
function find_price_quote(id,chatId) {
var query = {
"id": id,
};
var quote = db.collection('price_quote').find(query);
quote.forEach(
function(doc) {
if (doc.status == "true") {
priceQuote(doc.crypto,chatId,doc.price,doc.slug,doc.name,doc.pricen)
}
},
function(err) {
if (err) {
console.log("Error: "+err)
}
})
}
function find_schedule_price(id) {
var query = {
"id": id
};
var prices = db.collection('schedule_prices').find(query);
prices.forEach(
function(doc) {
console.log(doc);
},
function(err) {
console.log(err)
}
)
}
async function translateVN(msg) {
return await translate(msg,"vi")
}
function priceQuote(cryptoToken1,chatId,priceQuote,slug,name,pricen) {
var options = {
method: 'GET',
uri: 'https://coinmarketcap.com/currencies/'+slug,
headers: {
json: true,
gzip: true,
'User-Agent': 'Discordbot/2.0'
},
transform: function (body) {
return cheerio.load(body);
}
};
rp(options)
.then(function ($) {
var cPrice = $(".priceValue").text().trim();
var price = cPrice.replace("$", "")
if (price == priceQuote) {
var percentage_t = percentage(price,pricen).toString()
const percentage_emoji = percentage_t.charAt(0) == "-" ? '\u{1F4C9}':'\u{1F4C8}'
bot.sendMessage(chatId, '\u{1F4B0} '+name+' đã đạt đến giá: $'+price+'\nGiá trị '+percentage_emoji+' '+percentage_t+'% so với giá lúc đặt target ('+pricen+')\n\u{1F4E2}\u{1F4E2}\u{1F4E2}')
}
})
.catch(function (err) {
console.log(err)
});
}
function percentage(a,b) {
var t = (b-a)
return t/a*100
}
function percentage_price(chatId,price_f,price_s) {
var percentage_t = percentage(price_f,price_s).toString()
const percentage_emoji = percentage_t.charAt(0) == "-" ? '\u{1F4C9}':'\u{1F4C8}'
bot.sendMessage(chatId, 'Giá trị '+percentage_emoji+' '+percentage_t+'% so với giá lúc ban đầu ('+price_f+')\n\u{1F4E2}\u{1F4E2}\u{1F4E2}')
}
function topToken(chatId, count) {
CoinMarketCapClient.getIdMap({sort: 'cmc_rank', limit: `${count}`.toUpperCase()}).then(
(infoToken) =>{
for (const token of infoToken['data']) {
const date = new Date(token['first_historical_data']);
const datecover = date.toISOString().substring(0, 10);
bot.sendMessage(chatId, '\u{1F4B0}TOP '+token['rank']+'\n\nTên: '+token['name']+'('+token['symbol']+')\n\nNgày ra mắt: '+datecover)
}
}
).catch(console.error)
}
function infoCrypto(chatId, cryptoToken1) {
CoinMarketCapClient.getMetadata({symbol: `${cryptoToken1}`.toUpperCase()}).then(
(infoToken) => {
const description = infoToken['data'][cryptoToken1.toUpperCase()]['description']
const name = infoToken['data'][cryptoToken1.toUpperCase()]['name']
const symbol = infoToken['data'][cryptoToken1.toUpperCase()]['symbol']
const logo = infoToken['data'][cryptoToken1.toUpperCase()]['logo']
const tags = infoToken['data'][cryptoToken1.toUpperCase()]['tags']
const platformName = infoToken['data'][cryptoToken1.toUpperCase()]['platform']['name']
const tokenAddress = infoToken['data'][cryptoToken1.toUpperCase()]['platform']['token_address']
const selfreportedtags = infoToken['data'][cryptoToken1.toUpperCase()]['self_reported_tags']
const website = infoToken['data'][cryptoToken1.toUpperCase()]['urls']['website']
const twitter = infoToken['data'][cryptoToken1.toUpperCase()]['urls']['twitter']
const message_board = infoToken['data'][cryptoToken1.toUpperCase()]['urls']['message_board']
const chat = infoToken['data'][cryptoToken1.toUpperCase()]['urls']['chat']
const facebook = infoToken['data'][cryptoToken1.toUpperCase()]['urls']['facebook']
const explorer = infoToken['data'][cryptoToken1.toUpperCase()]['urls']['explorer']
const reddit = infoToken['data'][cryptoToken1.toUpperCase()]['urls']['reddit']
const technical_doc = infoToken['data'][cryptoToken1.toUpperCase()]['urls']['technical_doc']
const source_code = infoToken['data'][cryptoToken1.toUpperCase()]['urls']['source_code']
const announcement = infoToken['data'][cryptoToken1.toUpperCase()]['urls']['announcement']
bot.sendPhoto(chatId, logo);
translateVN(description).then(data => {
bot.sendMessage(chatId, 'Tên: '+name+'('+symbol+') \n\nMô tả: '+data+'\n\ntags: '+tags+'\n\nNền tảng: '+platformName+'\n\nContract Adress: '+tokenAddress+'\n\nTừ khóa: '+selfreportedtags+'\n\nWebsite: '+website+'\n\nTwitter: '+twitter+'\n\nBản tin : '+message_board+'\n\nChat: '+chat+'\n\nFacebook: '+facebook+'\n\nExplorer: '+explorer+'\n\nReddit: '+reddit+'\n\nSách trắng: '+technical_doc+'\n\nMã nguồn: '+source_code+'\n\nAnnouncement: '+announcement)
})
}
).catch(console.error)
}
function priceCrypto(chatId, cryptoToken1) {
CoinMarketCapClient.getQuotes({symbol: `${cryptoToken1}`.toUpperCase()}).then(
(avgPrice) => {
const price = avgPrice['data'][cryptoToken1.toUpperCase()]['quote']['USD']['price']
const volume_24h = formatMoney(avgPrice['data'][cryptoToken1.toUpperCase()]['quote']['USD']['volume_24h'])
const market_cap = formatMoney(avgPrice['data'][cryptoToken1.toUpperCase()]['quote']['USD']['market_cap'])
const percent_change_1h = avgPrice['data'][cryptoToken1.toUpperCase()]['quote']['USD']['percent_change_1h'].toString()
const percent_change_24h = avgPrice['data'][cryptoToken1.toUpperCase()]['quote']['USD']['percent_change_24h'].toString()
const percent_change_7d = avgPrice['data'][cryptoToken1.toUpperCase()]['quote']['USD']['percent_change_7d'].toString()
const percent_change_30d = avgPrice['data'][cryptoToken1.toUpperCase()]['quote']['USD']['percent_change_30d'].toString()
const percent_change_60d = avgPrice['data'][cryptoToken1.toUpperCase()]['quote']['USD']['percent_change_60d'].toString()
const percent_change_90d = avgPrice['data'][cryptoToken1.toUpperCase()]['quote']['USD']['percent_change_90d'].toString()
const percent_change_1h_emoji = percent_change_1h.charAt(0) == "-" ? '\u{1F4C9}':'\u{1F4C8}'
const percent_change_24h_emoji = percent_change_24h.charAt(0) == "-" ? '\u{1F4C9}':'\u{1F4C8}'
const percent_change_7d_emoji = percent_change_7d.charAt(0) == "-" ? '\u{1F4C9}':'\u{1F4C8}'
const percent_change_30d_emoji = percent_change_30d.charAt(0) == "-" ? '\u{1F4C9}':'\u{1F4C8}'
const percent_change_60d_emoji = percent_change_60d.charAt(0) == "-" ? '\u{1F4C9}':'\u{1F4C8}'
const percent_change_90d_emoji = percent_change_90d.charAt(0) == "-" ? '\u{1F4C9}':'\u{1F4C8}'
bot.sendMessage(chatId, '\u{1F4B0}Giá: <pre>$'+price+'</pre>\n\n\u{1F4B0}Khối lượng giao dịch(24h): <pre>'+volume_24h+'</pre>\n\n\u{1F4B0}Vốn hóa thị trường : <pre>'+market_cap+'</pre>\n\nThay đổi giá sau 1h:'+percent_change_1h_emoji.concat('<pre>',percent_change_1h,'%','</pre>')+'\n\nThay đổi giá sau 24h:'+percent_change_24h_emoji.concat('<pre>',percent_change_24h,'%','</pre>')+'\n\nThay đổi giá sau 1 ngày:'+percent_change_24h_emoji.concat('<pre>',percent_change_24h,'%','</pre>')+'\n\nThay đổi giá sau 1 tháng:'+percent_change_30d_emoji.concat('<pre>',percent_change_30d,'%','</pre>')+'\n\nThay đổi giá sau 2 tháng:'+percent_change_60d_emoji.concat('<pre>',percent_change_60d,'%','</pre>')+'\n\nThay đổi giá sau 3 tháng:'+percent_change_90d_emoji.concat('<pre>',percent_change_90d,'%','</pre>')+'\n' ,{parse_mode : "HTML"})
}
).catch((error) =>
bot.sendMessage(
chatId,
`Lỗi cuốn pháp! Vui lòng kiểm tra lại ${cryptoToken1}: ${error}`
)
)
}
function checkImgChart(chatId,urlChart) {
const path = './images/image.png';
Request
.get(urlChart)
.on('response', function(response) {
if (response.statusCode == 200) {
bot.sendMessage(chatId, "Vui lòng đợi trong giây lát!");
download(urlChart, path, () => {
console.log('✅ Done. Download Crypto Chart!')
bot.sendPhoto(chatId, path);
})
}else{
bot.sendMessage(chatId, "Hệ thống chưa hỗ trợ đồng tiền ảo này!");
}
})
}
const download = (url, path, callback) => {
Request.head(url, (err, res, body) => {
Request(url)
.pipe(fs.createWriteStream(path))
.on('close', callback)
})
}
bot.onText(/\/top (.+)/, (msg, data) => {
const chatId = msg.chat.id
const [count] = data[1].split(' ')
topToken(chatId,count);
})
bot.onText(/\/info (.+)/, (msg, data) => {
const chatId = msg.chat.id
const [cryptoToken1] = data[1].split(' ')
infoCrypto(chatId,cryptoToken1)
})
bot.onText(/\/price (.+)/, (msg, data) => {
const chatId = msg.chat.id
const [cryptoToken1] = data[1].split(' ')
priceCrypto(chatId,cryptoToken1)
})
bot.onText(/\/schedule -t (.+)/, (msg, data) => {
const chatId = msg.chat.id
// const cryptoToken1 = data[1].split(' ')
// insert_schedule_price(msg,cryptoToken1[0],cryptoToken1[1])
bot.sendMessage(chatId, 'Hệ thống bảo trì chức năng hẹn lịch báo giá.')
})
bot.onText(/\/quote -p (.+)/, (msg, data) => {
const chatId = msg.chat.id
const cryptoToken1 = data[1].split(' ')
if (cryptoToken1[2] == 'off') {
find_price_quote_exist_off(msg,cryptoToken1[0],cryptoToken1[1])
}else{
find_price_quote_exist(msg,cryptoToken1[0],cryptoToken1[1])
}
})
bot.onText(/\/percentage (.+)/, (msg, data) => {
const chatId = msg.chat.id
const price = data[1].split(' ')
percentage_price(chatId,price[0],price[1])
})
bot.onText(/\/c (.+)/, (msg, data) => {
const chatId = msg.chat.id
const crypto = data[1].split(' ')
var symbol = crypto['0'].toUpperCase()+"USDT"
var urlChart = "https://api.chart-img.com/v1/tradingview/advanced-chart?height=400&symbol="+symbol
checkImgChart(chatId, urlChart)
})
bot.onText(/\/s (.+)/, (msg, data) => {
const chatId = msg.chat.id
apiSimSimi(chatId,data[1])
})
bot.on('message', (msg) => {
const chatId = msg.chat.id
switch (msg.text) {
case 'Bắt đầu':
bot.sendMessage(chatId, 'Hệ thống BOT báo giá tiền điện tử. Đang trong quá trình phát triển')
break
case 'Trợ giúp':
bot.sendMessage(chatId, 'Xem giá: /price (Tên tiền ảo) VD: /price DOGE\n\nXem thông tin: /info (Tên tiền ảo) VD: /info DOGE\n\nXem top: /top (số top) VD: /top 10\n\nLên lịch báo giá: /quote -p (giá cần báo) (Tên tiền ảo) VD: /quote -p 0.3 DOGE\n Tắt lịch báo giá:/quote -p (giá cần báo) (Tên tiền ảo) off VD: /quote -p 0.3 DOGE off\n\nTính giá trị gia tăng hoặc giảm: /percentage (giá ban đầu) (giá sau khi tăng hoặc giảm) VD: /percentage 0.2 0.3\n\nXem biểu đồ tiền ảo : /c tên đồng tiền ảo . VD: /c btc', {"reply_markup": {"keyboard": [["Bắt đầu"], ["Trợ giúp"], ["About"]]}})
break
case 'About':
bot.sendMessage(chatId, 'Develop by KenDzz\n<a href="https://www.facebook.com/Rin.Boss.Rin/">Facebook</a>\n<a href="https://github.com/KenDzz">Github</a>',{parse_mode : "HTML"})
break
default:
break
}
})