-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
147 lines (110 loc) · 3.42 KB
/
index.ts
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
import dotenv from 'dotenv';
dotenv.config();
import fetch from 'node-fetch';
import TelegramBot from 'node-telegram-bot-api';
import { aveta } from 'aveta';
const token = process.env.BOT_TOKEN!;
const bot = new TelegramBot(token, {
polling: true
});
bot.onText(/\/start/, (msg) => {
const chatId = msg.chat.id;
bot.sendMessage(chatId, '👾 Welcome to the MOTO price Telegram bot! 👾\n\nWhat would you like to do? Use /price to get real time statistics about the MOTO token, or /scan to get complete analysis about any other token', {
reply_markup: {
inline_keyboard: [
[
{
text: '📈 Price',
callback_data: 'price'
},
{
text: '🔍 Scan',
callback_data: 'scan'
}
]
]
}
});
});
const fetchMarketData = (token: string) => {
return fetch(`https://dapp.herokuapp.com/token-market-data?contract=${token}`)
.then((data) => data.json());
}
const getMOTOMessage = async () => {
const data = await fetchMarketData(process.env.MOTO_TOKEN_ADDRESS!) as {
price_eth: number;
price_usd: number;
liquidity: number;
liquidity_usd: number;
holder_count: number;
circSupply: number;
volume_24h_usd: number;
};
const marketCap = aveta(data.circSupply * data.price_usd, {
digits: 5
});
const usdPrice = aveta(data.price_usd, {
digits: 5
});
const ethPrice = aveta(data.price_eth, {
digits: 5
});
const holderCount = aveta(data.holder_count, {
digits: 2
});
const liquidity = aveta(data.liquidity_usd, {
digits: 4
});
const lastDayVolume = aveta(data.volume_24h_usd, {
digits: 5
});
const circSupply = aveta(data.circSupply, {
digits: 5
});
const message = `
$MOTO Token Stats
🛒 *Total Supply:* $10bn
🏦 *Circ. Supply:* $${circSupply}
💰 *Marketcap:* $${marketCap}
💸 *Price:* $${usdPrice}
📊 *Volume:* $${lastDayVolume}
🔐 *Liquidity:* $${liquidity}
👥 *Holders:* ${holderCount}
app.miyamotoproject.org
`.trim();
return message;
}
bot.on('callback_query', async (query) => {
const chatId = query.message!.chat.id;
const data = query.data;
if (data === 'price') {
const message = await bot.sendMessage(chatId, 'Loading...');
const content = await getMOTOMessage();
await bot.editMessageText(content, {
parse_mode: 'Markdown',
message_id: message.message_id,
chat_id: chatId
});
}
if (data === 'scan') {
bot.sendMessage(chatId, '🔍 This feature is not available yet!');
}
});
bot.onText(/\/price/, async (msg, match) => {
const chatId = msg.chat.id;
const message = await bot.sendMessage(chatId, 'Loading...');
const content = await getMOTOMessage();
await bot.editMessageText(content, {
parse_mode: 'Markdown',
message_id: message.message_id,
chat_id: chatId
});
});
bot.onText(/\/scan/, async (msg, match) => {
const chatId = msg.chat.id;
await bot.sendMessage(chatId, '🔍 This feature is not available yet!');
});
bot.on('message', (msg) => {
const chatId = msg.chat.id;
});
console.log(`🤖 Miyamoto Price bot is started!`);