-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclaimFaucet.js
70 lines (67 loc) · 1.99 KB
/
claimFaucet.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
const axios = require('axios');
const colors = require('colors');
const { CronJob } = require('cron');
const { SendTelegram } = require('./sendTelegram');
const claimFaucet = async (address) => {
try {
const { data } = await axios({
method: 'GET',
url: `https://api.expedition.mitosis.org/v1/faucet/${address}`,
});
if (data.result && data.result.message === 'ok') {
console.log(
colors.green('Claim successful. Will try again in 24 hours.')
);
if (process.env.TELEGRAM_BOT_TOKEN) {
SendTelegram(
`Claim successful with address ${address}. Will try again in 24 hours.`
);
}
const job = new CronJob(
'0 0 * * *',
() => {
console.log(colors.blue('Retrying claim...'));
claimFaucet(address);
},
null,
true,
''
);
job.start();
}
} catch (error) {
let errorMessage = 'An unknown error occurred';
if (
error.response &&
error.response.data &&
typeof error.response.data.message === 'string'
) {
errorMessage = error.response.data.message;
} else if (typeof error.message === 'string') {
errorMessage = error.message;
}
console.log(colors.red('Error:'), errorMessage);
if (process.env.TELEGRAM_BOT_TOKEN) {
SendTelegram(`Claim failed with address ${address}: ${errorMessage}`);
}
if (errorMessage === 'Already received asset today') {
console.log(colors.yellow('Will try again in 1 hour.'));
const retryJob = new CronJob(
'0 * * * *',
() => {
console.log(colors.blue('Retrying now...'));
claimFaucet(address);
},
null,
true,
''
);
retryJob.start();
} else if (errorMessage.includes('is not integrated to the address')) {
console.log(colors.cyan('Please link your Twitter account.'));
} else {
console.log(colors.magenta('Unknown error.'));
}
}
};
module.exports = claimFaucet;