-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
69 lines (58 loc) · 1.6 KB
/
utils.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
import { sendMessage } from './service.js';
const MAX_MESSAGE_LENGTH = 4096;
export const sendLongMessage = async (chatId, messageId, longMessage, etc = {}) => {
while (longMessage.length > 0) {
const messageChunk = longMessage.slice(0, MAX_MESSAGE_LENGTH);
try {
await sendMessage(chatId, messageChunk, {
parse_mode: 'HTML',
disable_web_page_preview: true,
reply_to_message_id: messageId,
...etc,
});
return 'success';
} catch (error) {
sendMessage(chatId, 'oops, something went wrong');
return 'error';
}
}
};
export const createInlineKeyboard = (chainId, address) => {
let buttons = [];
if (chainId === 'eth') {
buttons.push([
{
text: '👥 Holders',
url: `https://etherscan.io/token/${address}#balances`,
},
{
text: '📈 Chart',
url: `https://www.dextools.io/app/en/ether/pair-explorer/${address}`,
},
]);
} else if (chainId === 'bsc') {
buttons.push([
{
text: '👥 Holders',
url: `https://bscscan.com/token/${address}#balances`,
},
{
text: '📈 Chart',
url: `https://www.dextools.io/app/en/bnb/pair-explorer/${address}`,
},
]);
}
const secondRow = [];
secondRow.push({
text: '🟣🔵 Bubblemaps',
url: `https://app.bubblemaps.io/${chainId}/token/${address}`,
});
buttons.push(secondRow);
return { reply_markup: { inline_keyboard: buttons } };
};
export const extractAddressFromMessage = (message) => {
const regex = /^0x[a-fA-F0-9]{40}$/;
const result = message?.match(regex);
return result ? result[0] : null;
};
export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));