Add comments
This commit is contained in:
parent
a77be4b768
commit
d8a74d6c9e
9
index.js
9
index.js
@ -6,11 +6,16 @@ const namesMap = {gems:"Салоцветы",money:"Самородки",balance:"
|
||||
let exchangeClient = new HilSu.ExchangeClient(process.env.HILTOKEN);
|
||||
let bot = new Telegraf(process.env.BOTTOKEN);
|
||||
|
||||
/**
|
||||
* rates - Новое значение курса
|
||||
* oldRates - Предыдущее значение курса
|
||||
*/
|
||||
exchangeClient.on("ratesUpdate", (rates,oldRates) => {
|
||||
if(oldRates===rates) return;
|
||||
if(oldRates===undefined) return;
|
||||
if(oldRates===rates) return; //пропускаем если ничего не изменилось
|
||||
if(oldRates===undefined) return; //и пропускаем если это первое получение данных (при старте)
|
||||
let message = "Обновление курса:\n";
|
||||
for (let rate of rates.rates) {
|
||||
//получаем старый курс для этого обмена
|
||||
let old = oldRates.rates.find(r => r.to===rate.to&&r.from===rate.from);
|
||||
message+=`${namesMap[rate.from]} -> ${namesMap[rate.to]}: ${rate.value.toFixed(3)} (${getPercentageChange(old.value, rate.value).toFixed(2)}%)\n`;
|
||||
}
|
||||
|
Reference in New Issue
Block a user