Skip to content

Commit

Permalink
New cron job to check node status
Browse files Browse the repository at this point in the history
This PR updates /info command to show updated information
about the node status, node URI and bot fees
  • Loading branch information
grunch committed Jul 19, 2023
1 parent 11c677d commit 82169aa
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 17 deletions.
23 changes: 15 additions & 8 deletions bot/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
secondsToTime,
getOrderChannel,
holdInvoiceExpirationInSecs,
sanitizeMD,
} = require('../util');
const logger = require('../logger');

Expand Down Expand Up @@ -1087,15 +1088,21 @@ const sellerPaidHoldMessage = async (ctx, user) => {
}
};

const showInfoMessage = async (bot, user, info) => {
const showInfoMessage = async (ctx, user, config) => {
try {
// const status = !!info.public_key;
// const statusEmoji = status ? '🟢' : '🔴';
let fee = (process.env.MAX_FEE * 100).toString();
fee = fee.replace('.', '\\.');
await bot.telegram.sendMessage(user.tg_id, `*Bot fee*: ${fee}%`, {
parse_mode: 'MarkdownV2',
});
const status = config.node_status == 'up' ? '🟢' : '🔴';
const node_uri = sanitizeMD(config.node_uri);
let bot_fee = (process.env.MAX_FEE * 100).toString() + '%';
bot_fee = bot_fee.replace('.', '\\.');
let routing_fee = (process.env.MAX_ROUTING_FEE * 100).toString() + '%';
routing_fee = routing_fee.replace('.', '\\.');
await ctx.telegram.sendMessage(
user.tg_id,
ctx.i18n.t('bot_info', { bot_fee, routing_fee, status, node_uri }),
{
parse_mode: 'MarkdownV2',
}
);
// if (status) {
// await bot.telegram.sendMessage(user.tg_id, `*Node pubkey*: ${info.public_key}\n`, { parse_mode: "MarkdownV2" });
// }
Expand Down
8 changes: 7 additions & 1 deletion bot/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const {
calculateEarnings,
attemptCommunitiesPendingPayments,
deleteCommunity,
nodeInfo,
} = require('../jobs');
const logger = require('../logger');

Expand Down Expand Up @@ -156,6 +157,10 @@ const initialize = (botToken, options) => {
await deleteCommunity(bot);
});

schedule.scheduleJob(`* * * * *`, async () => {
await nodeInfo(bot);
});

bot.start(async ctx => {
try {
const tgUser = ctx.update.message.from;
Expand Down Expand Up @@ -750,7 +755,8 @@ const initialize = (botToken, options) => {

bot.command('info', userMiddleware, async ctx => {
try {
await messages.showInfoMessage(bot, ctx.user);
const config = await Config.findOne({});
await messages.showInfoMessage(ctx, ctx.user, config);
} catch (error) {
logger.error(error);
}
Expand Down
1 change: 0 additions & 1 deletion jobs/communities.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { Order, Community } = require('../models');
// const { deleteOrderFromChannel } = require('../util');
const logger = require('../logger');

const deleteCommunity = async bot => {
Expand Down
2 changes: 2 additions & 0 deletions jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const cancelOrders = require('./cancel_orders');
const deleteOrders = require('./delete_published_orders');
const calculateEarnings = require('./calculate_community_earnings');
const deleteCommunity = require('./communities');
const nodeInfo = require('./node_info');

module.exports = {
attemptPendingPayments,
Expand All @@ -14,4 +15,5 @@ module.exports = {
calculateEarnings,
attemptCommunitiesPendingPayments,
deleteCommunity,
nodeInfo,
};
20 changes: 20 additions & 0 deletions jobs/node_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { Config } = require('../models');
const { getInfo } = require('../ln');
const logger = require('../logger');

const info = async bot => {
try {
const config = await Config.findOne({});
const info = await getInfo();
if (info.is_synced_to_chain) {
config.node_status = 'up';
}
config.node_uri = info.uris[0];
await config.save();
} catch (error) {
const message = error.toString();
logger.error(`node info catch error: ${message}`);
}
};

module.exports = info;
10 changes: 9 additions & 1 deletion locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,12 @@ user_settings: |
invoice_settled: Rechnung wurde bereits niedergelassen
invoice_cancelled: Rechnung storniert
invoice_held: Rechnung festgehalten
invoice_no_info: Ich habe keine Informationen für diese Rechnung
invoice_no_info: Ich habe keine Informationen für diese Rechnung
bot_info: |
Bot fee: ${bot_fee}
Routing fee: ${routing_fee}
Node URI: ${node_uri}
Node status: ${status}
8 changes: 8 additions & 0 deletions locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,11 @@ invoice_settled: Invoice already settled
invoice_cancelled: Invoice cancelled
invoice_held: Invoice held
invoice_no_info: I don't have information for that invoice
bot_info: |
Bot fee: ${bot_fee}
Routing fee: ${routing_fee}
Node URI: ${node_uri}
Node status: ${status}
10 changes: 9 additions & 1 deletion locales/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,12 @@ user_settings: |
invoice_settled: Factura ya cobrada
invoice_cancelled: Factura cancelada
invoice_held: Factura retenida
invoice_no_info: No tengo información para esa factura
invoice_no_info: No tengo información para esa factura
bot_info: |
Bot fee: ${bot_fee}
Routing fee: ${routing_fee}
Node URI: ${node_uri}
Node status: ${status}
10 changes: 9 additions & 1 deletion locales/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,12 @@ user_settings: |
invoice_settled: Facture déjà installée
invoice_cancelled: Facture annulée
invoice_held: Facture tenue
invoice_no_info: Je n'ai pas d'informations pour cette facture
invoice_no_info: Je n'ai pas d'informations pour cette facture
bot_info: |
Bot fee: ${bot_fee}
Routing fee: ${routing_fee}
Node URI: ${node_uri}
Node status: ${status}
10 changes: 9 additions & 1 deletion locales/it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,12 @@ user_settings: |
invoice_settled: Fattura già risolta
invoice_cancelled: Fattura annullata
invoice_held: Fattura detenuta
invoice_no_info: Non ho informazioni per quella fattura
invoice_no_info: Non ho informazioni per quella fattura
bot_info: |
Bot fee: ${bot_fee}
Routing fee: ${routing_fee}
Node URI: ${node_uri}
Node status: ${status}
10 changes: 9 additions & 1 deletion locales/pt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,12 @@ user_settings: |
invoice_settled: Fatura já liquidada
invoice_cancelled: Fatura cancelada
invoice_held: Fatura mantida
invoice_no_info: Não tenho informações para essa fatura
invoice_no_info: Não tenho informações para essa fatura
bot_info: |
Bot fee: ${bot_fee}
Routing fee: ${routing_fee}
Node URI: ${node_uri}
Node status: ${status}
10 changes: 9 additions & 1 deletion locales/ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,12 @@ user_settings: |
invoice_settled: Invoice already settled
invoice_cancelled: Invoice cancelled
invoice_held: Invoice held
invoice_no_info: I don't have information for that invoice
invoice_no_info: I don't have information for that invoice
bot_info: |
Bot fee: ${bot_fee}
Routing fee: ${routing_fee}
Node URI: ${node_uri}
Node status: ${status}
10 changes: 9 additions & 1 deletion locales/uk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,12 @@ user_settings: |
invoice_settled: Invoice already settled
invoice_cancelled: Invoice cancelled
invoice_held: Invoice held
invoice_no_info: I don't have information for that invoice
invoice_no_info: I don't have information for that invoice
bot_info: |
Bot fee: ${bot_fee}
Routing fee: ${routing_fee}
Node URI: ${node_uri}
Node status: ${status}
2 changes: 2 additions & 0 deletions models/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const mongoose = require('mongoose');

const ConfigSchema = new mongoose.Schema({
maintenance: { type: Boolean, default: false },
node_status: { type: String, default: 'down' },
node_uri: { type: String },
});

module.exports = mongoose.model('Config', ConfigSchema);

0 comments on commit 82169aa

Please sign in to comment.