Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redo PR #435 #5

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions app.js → app.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require('dotenv').config();
const { SocksProxyAgent } = require('socks-proxy-agent');
const { start } = require('./bot');
const mongoConnect = require('./db_connect');
import * as dotenv from "dotenv";
dotenv.config()
import { SocksProxyAgent } from "socks-proxy-agent";
import { MainContext, start } from "./bot/start";
import { connect as mongoConnect } from './db_connect'
const { resubscribeInvoices } = require('./ln');
const logger = require('./logger');
const { delay } = require('./util');
import { logger } from "./logger";
import { Telegraf } from "telegraf";
import { delay } from './util';

(async () => {
process.on('unhandledRejection', e => {
Expand All @@ -23,7 +25,7 @@ const { delay } = require('./util');
mongoose.connection
.once('open', async () => {
logger.info('Connected to Mongo instance.');
let options = { handlerTimeout: 60000 };
let options: Partial<Telegraf.Options<MainContext>> = { handlerTimeout: 60000 };
if (process.env.SOCKS_PROXY_HOST) {
const agent = new SocksProxyAgent(process.env.SOCKS_PROXY_HOST);
options = {
Expand All @@ -32,10 +34,11 @@ const { delay } = require('./util');
},
};
}
const bot = start(process.env.BOT_TOKEN, options);
const bot = start(String(process.env.BOT_TOKEN), options);
// Wait 1 seconds before try to resubscribe hold invoices
await delay(1000);
await resubscribeInvoices(bot);
})
.on('error', error => logger.error(`Error connecting to Mongo: ${error}`));
.on('error', (error: Error) => logger.error(`Error connecting to Mongo: ${error}`));
})();

2 changes: 1 addition & 1 deletion bot/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const {
const ordersActions = require('./ordersActions');

const { resolvLightningAddress } = require('../lnurl/lnurl-pay');
const logger = require('../logger');
const { logger } = require('../logger');

const waitPayment = async (ctx, bot, buyer, seller, order, buyerInvoice) => {
try {
Expand Down
14 changes: 7 additions & 7 deletions bot/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { TelegramError } = require('telegraf');
const QR = require('qrcode');
import { TelegramError } from 'telegraf'
import QR from 'qrcode';
const {
getCurrency,
numberFormat,
Expand All @@ -12,7 +12,7 @@ const {
decimalRound,
getUserAge,
} = require('../util');
const logger = require('../logger');
import { logger } from "../logger";
import { MainContext } from './start';
import { UserDocument } from '../models/user'
import { IOrder } from '../models/order'
Expand Down Expand Up @@ -109,7 +109,7 @@ const invoicePaymentRequestMessage = async (
}
};

const pendingSellMessage = async (ctx: MainContext, user: UserDocument, order: IOrder, channel: string, i18n: I18nContext) => {
const pendingSellMessage = async (ctx: Telegraf<MainContext>, user: UserDocument, order: IOrder, channel: string, i18n: I18nContext) => {
try {
const orderExpirationWindow =
Number(process.env.ORDER_PUBLISHED_EXPIRATION_WINDOW) / 60 / 60;
Expand Down Expand Up @@ -618,7 +618,7 @@ const publishBuyOrderMessage = async (
};

const publishSellOrderMessage = async (
ctx: MainContext,
ctx: Telegraf<MainContext>,
user: UserDocument,
order: IOrder,
i18n: I18nContext,
Expand Down Expand Up @@ -1549,7 +1549,7 @@ const currencyNotSupportedMessage = async (ctx: MainContext, currencies: Array<s
}
};

const notAuthorized = async (ctx: MainContext, tgId: string) => {
const notAuthorized = async (ctx: MainContext, tgId?: string) => {
try {
if (tgId) {
await ctx.telegram.sendMessage(tgId, ctx.i18n.t('not_authorized'));
Expand Down Expand Up @@ -1606,7 +1606,7 @@ const showConfirmationButtons = async (ctx: MainContext, orders: Array<IOrder>,
}
};

module.exports = {
export {
startMessage,
initBotErrorMessage,
invoicePaymentRequestMessage,
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/community/commands.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-underscore-dangle */
// @ts-check
const logger = require('../../../logger');
const { logger } = require('../../../logger');
const { showUserCommunitiesMessage } = require('./messages');
const { Community, Order } = require('../../../models');
const { validateParams, validateObjectId } = require('../../validations');
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/community/messages.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logger = require('../../../logger');
const { logger } = require('../../../logger');
const { Community, PendingPayment } = require('../../../models');

exports.createCommunityWizardStatus = (i18n, state) => {
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/community/scenes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Scenes } = require('telegraf');
const logger = require('../../../logger');
const { logger } = require('../../../logger');
const { Community, User, PendingPayment } = require('../../../models');
const { isPendingPayment } = require('../../../ln');
const { isGroupAdmin, itemsFromMessage } = require('../../../util');
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/dispute/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
} = require('../../validations');
const messages = require('./messages');
const globalMessages = require('../../messages');
const logger = require('../../../logger');
const { logger } = require('../../../logger');

const dispute = async ctx => {
try {
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/dispute/messages.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { getDisputeChannel, getDetailedOrder } = require('../../../util');
const logger = require('../../../logger');
const { logger } = require('../../../logger');

exports.beginDispute = async (ctx, initiator, order, buyer, seller) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/language/commands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const fs = require('fs');
const { getLanguageFlag } = require('../../../util');
const logger = require('../../../logger');
const { logger } = require('../../../logger');
const { showFlagsMessage } = require('./messages');

exports.setlang = async ctx => {
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/language/messages.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logger = require('../../../logger');
const { logger } = require('../../../logger');

exports.showFlagsMessage = async (ctx, flags, code) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/nostr/commands.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Nostr = require('nostr-tools');
const logger = require('../../../logger');
const { logger } = require('../../../logger');
const Config = require('./config');

exports.info = async ctx => {
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/nostr/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
require('websocket-polyfill');
const logger = require('../../../logger');
const { logger } = require('../../../logger');
const Config = require('./config');
const { orderCreated } = require('./events');
const Commands = require('./commands');
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/orders/commands.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
const logger = require('../../../logger');
const { logger } = require('../../../logger');
const { Community, Order } = require('../../../models');
const { isFloat } = require('../../../util');
const {
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/orders/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
const { userMiddleware } = require('../../middleware/user');
const logger = require('../../../logger');
const { logger } = require('../../../logger');
const ordersActions = require('../../ordersActions');

const commands = require('./commands');
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/orders/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {
sanitizeMD,
getTimeToExpirationOrder,
} = require('../../../util');
const logger = require('../../../logger');
const { logger } = require('../../../logger');

exports.listOrdersResponse = async (orders, i18n) => {
const tasks = orders.map(async order => {
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/orders/scenes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Scenes, Markup } = require('telegraf');
const logger = require('../../../logger');
const { logger } = require('../../../logger');
const { getCurrency } = require('../../../util');
const ordersActions = require('../../ordersActions');
const {
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/orders/takeOrder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
const logger = require('../../../logger');
const { logger } = require('../../../logger');
const { Order } = require('../../../models');
const { deleteOrderFromChannel } = require('../../../util');
const messages = require('../../messages');
Expand Down
2 changes: 1 addition & 1 deletion bot/ordersActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
getFee,
getUserAge,
} = require('../util');
const logger = require('../logger');
const { logger } = require('../logger');

const OrderEvents = require('./modules/events/orders');

Expand Down
2 changes: 1 addition & 1 deletion bot/scenes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { waitPayment, addInvoice, showHoldInvoice } = require('./commands');
const { getCurrency, getUserI18nContext } = require('../util');
const messages = require('./messages');
const { isPendingPayment } = require('../ln');
const logger = require('../logger');
const { logger } = require('../logger');

const addInvoiceWizard = new Scenes.WizardScene(
'ADD_INVOICE_WIZARD_SCENE_ID',
Expand Down
Loading
Loading