-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (58 loc) · 1.62 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
const TeleBot = require("telebot");
const bot = new TeleBot("464437322:AAHL4K-FyOtglauma0rYy6RBUMC1nic6_rc");
const request = require("request");
const _ = require('lodash');
const r = require('./r');
class Bot {
getName() {
if (this.last_name) {
return `${this.first_name} ${this.last_name}`;
} else {
return `${this.first_name}`;
}
}
getCoins() {
const opt = {
url: 'https://api.coinmarketcap.com/v1/ticker/?limit=10'
}
return r.get(opt);
}
listCoins(msg, coins) {
let text;
_.forEach(coins, (coin) => {
text += `${coin.rank} ${coin.symbol} - $${coin.price_usd} - vol ${coin.market_cap_usd} \n`;
});
console.log(text);
return msg.reply.text(text);
}
introduceYourself() {
console.log(
`Hello, my name is ${this.getName()}. You can talk to me through my username: @${
this.username
}`
);
}
}
TOKEN = '464437322:AAHL4K-FyOtglauma0rYy6RBUMC1nic6_rc';
// const b = new Bot()
// b.init(TOKEN).then(() => {
// b.introduceYourself()
// })
bot.on(["/start", "/hello"], msg => msg.reply.text("Welcome!"));
bot.on(["/top"], msg => {
const b = new Bot();
return b.getCoins().then((coins) => {
// console.log("Got here");
// return b.listCoins(msg, coins);
let text = '';
const c = JSON.parse(coins);
for(let i = 0; i < c.length; i++) {
const coin = c[i];
text += `${coin.rank} ${coin.symbol} - $${coin.price_usd} - vol ${coin.market_cap_usd} \n`;
}
text += '\n \n';
text += 'Source: https://coinmarketcap.com';
return msg.reply.text(text);
}, err => console.log(err));
});
bot.start();