From c411bfe96d62cca99a4f159c2e226348fa651c5d Mon Sep 17 00:00:00 2001 From: Mehrshad Date: Mon, 23 Oct 2023 17:09:07 +0330 Subject: [PATCH] fix: logger.ts imports After porting logger.js to typescript, the logger type became a "named export", this changes the syntax for importing it. Additionally, there are a few mistakes in imports that we weren't noticed of. --- bot/commands.js | 2 +- bot/modules/community/commands.js | 2 +- bot/modules/community/messages.js | 2 +- bot/modules/community/scenes.js | 2 +- bot/modules/dispute/commands.js | 2 +- bot/modules/dispute/messages.js | 2 +- bot/modules/language/commands.js | 2 +- bot/modules/language/messages.js | 2 +- bot/modules/nostr/commands.js | 2 +- bot/modules/nostr/index.js | 2 +- bot/modules/orders/commands.js | 2 +- bot/modules/orders/index.js | 2 +- bot/modules/orders/messages.js | 2 +- bot/modules/orders/scenes.js | 2 +- bot/modules/orders/takeOrder.js | 2 +- bot/ordersActions.js | 2 +- bot/scenes.js | 2 +- bot/start.ts | 21 ++++++++++----------- bot/validations.ts | 2 +- ln/connect.ts | 8 ++++---- ln/hold_invoice.ts | 6 +++--- ln/info.ts | 6 +++--- ln/pay_request.js | 2 +- ln/subscribe_invoice.ts | 2 +- ln/subscribe_probe.js | 2 +- util/index.ts | 5 +++-- 26 files changed, 44 insertions(+), 44 deletions(-) diff --git a/bot/commands.js b/bot/commands.js index acfe66e7..175eae1a 100644 --- a/bot/commands.js +++ b/bot/commands.js @@ -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 { diff --git a/bot/modules/community/commands.js b/bot/modules/community/commands.js index 83e29a68..1876914b 100644 --- a/bot/modules/community/commands.js +++ b/bot/modules/community/commands.js @@ -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'); diff --git a/bot/modules/community/messages.js b/bot/modules/community/messages.js index 61b398f9..85d3bfc4 100644 --- a/bot/modules/community/messages.js +++ b/bot/modules/community/messages.js @@ -1,4 +1,4 @@ -const logger = require('../../../logger'); +const { logger } = require('../../../logger'); const { Community, PendingPayment } = require('../../../models'); exports.createCommunityWizardStatus = (i18n, state) => { diff --git a/bot/modules/community/scenes.js b/bot/modules/community/scenes.js index 612d2b86..81eb5f6b 100644 --- a/bot/modules/community/scenes.js +++ b/bot/modules/community/scenes.js @@ -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'); diff --git a/bot/modules/dispute/commands.js b/bot/modules/dispute/commands.js index 01ec8a6b..54b8cefd 100644 --- a/bot/modules/dispute/commands.js +++ b/bot/modules/dispute/commands.js @@ -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 { diff --git a/bot/modules/dispute/messages.js b/bot/modules/dispute/messages.js index 7999eb5b..40dc36bf 100644 --- a/bot/modules/dispute/messages.js +++ b/bot/modules/dispute/messages.js @@ -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 { diff --git a/bot/modules/language/commands.js b/bot/modules/language/commands.js index c58e403c..0ce55db1 100644 --- a/bot/modules/language/commands.js +++ b/bot/modules/language/commands.js @@ -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 => { diff --git a/bot/modules/language/messages.js b/bot/modules/language/messages.js index a0a10c4b..870abade 100644 --- a/bot/modules/language/messages.js +++ b/bot/modules/language/messages.js @@ -1,4 +1,4 @@ -const logger = require('../../../logger'); +const { logger } = require('../../../logger'); exports.showFlagsMessage = async (ctx, flags, code) => { try { diff --git a/bot/modules/nostr/commands.js b/bot/modules/nostr/commands.js index 0f3d8db7..0861bdf5 100644 --- a/bot/modules/nostr/commands.js +++ b/bot/modules/nostr/commands.js @@ -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 => { diff --git a/bot/modules/nostr/index.js b/bot/modules/nostr/index.js index d1fac01b..d3bad273 100644 --- a/bot/modules/nostr/index.js +++ b/bot/modules/nostr/index.js @@ -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'); diff --git a/bot/modules/orders/commands.js b/bot/modules/orders/commands.js index c04b4c82..1e9f4c63 100644 --- a/bot/modules/orders/commands.js +++ b/bot/modules/orders/commands.js @@ -1,5 +1,5 @@ // @ts-check -const logger = require('../../../logger'); +const { logger } = require('../../../logger'); const { Community, Order } = require('../../../models'); const { isFloat } = require('../../../util'); const { diff --git a/bot/modules/orders/index.js b/bot/modules/orders/index.js index 42dabe52..bdf75edd 100644 --- a/bot/modules/orders/index.js +++ b/bot/modules/orders/index.js @@ -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'); diff --git a/bot/modules/orders/messages.js b/bot/modules/orders/messages.js index e113b149..908eb6ec 100644 --- a/bot/modules/orders/messages.js +++ b/bot/modules/orders/messages.js @@ -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 => { diff --git a/bot/modules/orders/scenes.js b/bot/modules/orders/scenes.js index 7e4e9065..a5ea0245 100644 --- a/bot/modules/orders/scenes.js +++ b/bot/modules/orders/scenes.js @@ -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 { diff --git a/bot/modules/orders/takeOrder.js b/bot/modules/orders/takeOrder.js index 5e73a746..23c47b9d 100644 --- a/bot/modules/orders/takeOrder.js +++ b/bot/modules/orders/takeOrder.js @@ -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'); diff --git a/bot/ordersActions.js b/bot/ordersActions.js index 28360123..d36ebab5 100644 --- a/bot/ordersActions.js +++ b/bot/ordersActions.js @@ -10,7 +10,7 @@ const { getFee, getUserAge, } = require('../util'); -const logger = require('../logger'); +const { logger } = require('../logger'); const OrderEvents = require('./modules/events/orders'); diff --git a/bot/scenes.js b/bot/scenes.js index a4eb7559..86c1c6ce 100644 --- a/bot/scenes.js +++ b/bot/scenes.js @@ -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', diff --git a/bot/start.ts b/bot/start.ts index 7546081a..77b28ac1 100644 --- a/bot/start.ts +++ b/bot/start.ts @@ -56,17 +56,16 @@ const { validateLightningAddress, } = require('./validations'); import * as messages from './messages'; -const { - attemptPendingPayments, - cancelOrders, - deleteOrders, - calculateEarnings, - attemptCommunitiesPendingPayments, - deleteCommunity, - nodeInfo, -} = require('../jobs'); -import logger from "../logger"; -import { ICommunity, IUsernameId } from '../models/community'; +import { attemptPendingPayments, + cancelOrders, + deleteOrders, + calculateEarnings, + attemptCommunitiesPendingPayments, + deleteCommunity, + nodeInfo +} from '../jobs'; +import { logger } from '../logger'; +import { IUsernameId } from '../models/community'; export interface MainContext extends Context { match: Array | null; diff --git a/bot/validations.ts b/bot/validations.ts index e6ce3881..408acce2 100644 --- a/bot/validations.ts +++ b/bot/validations.ts @@ -11,7 +11,7 @@ import * as messages from './messages'; import { Order, User, Community } from '../models'; const { isIso4217, isDisputeSolver } = require('../util'); const { existLightningAddress } = require('../lnurl/lnurl-pay'); -const logger = require('../logger'); +import { logger } from '../logger'; // We look in database if the telegram user exists, // if not, it creates a new user diff --git a/ln/connect.ts b/ln/connect.ts index f82b5c04..19c5e7df 100644 --- a/ln/connect.ts +++ b/ln/connect.ts @@ -1,7 +1,7 @@ -import * as fs from 'fs'; -import * as path from 'path'; -import * as lightning from "lightning"; -import logger from "../logger"; +import fs from 'fs'; +import path from 'path'; +import lightning from 'lightning'; +import { logger } from '../logger'; const { authenticatedLndGrpc } = lightning; diff --git a/ln/hold_invoice.ts b/ln/hold_invoice.ts index 201d644c..82aea0eb 100644 --- a/ln/hold_invoice.ts +++ b/ln/hold_invoice.ts @@ -1,7 +1,7 @@ import { randomBytes, createHash } from 'crypto'; -import * as lightning from "lightning"; -import { lnd } from './connect' -import logger from "../logger"; +import lightning from 'lightning'; +import { lnd } from './connect'; +import { logger } from '../logger'; const createHoldInvoice = async (description: string, amount: number ) => { try { diff --git a/ln/info.ts b/ln/info.ts index 179fb82e..14ea89c8 100644 --- a/ln/info.ts +++ b/ln/info.ts @@ -1,6 +1,6 @@ -import * as lightning from "lightning"; -import { lnd } from './connect' -import logger from "../logger"; +import lightning from 'lightning'; +import { lnd } from './connect'; +import { logger } from '../logger'; export const getInfo = async () => { try { diff --git a/ln/pay_request.js b/ln/pay_request.js index 59fe6d38..df0b00f6 100644 --- a/ln/pay_request.js +++ b/ln/pay_request.js @@ -8,7 +8,7 @@ const { User, PendingPayment } = require('../models'); const lnd = require('./connect'); const { handleReputationItems, getUserI18nContext } = require('../util'); const messages = require('../bot/messages'); -const logger = require('../logger'); +const { logger } = require('../logger'); const payRequest = async ({ request, amount }) => { try { diff --git a/ln/subscribe_invoice.ts b/ln/subscribe_invoice.ts index 7700a479..30420b67 100644 --- a/ln/subscribe_invoice.ts +++ b/ln/subscribe_invoice.ts @@ -7,7 +7,7 @@ import { lnd } from "./connect"; import * as messages from '../bot/messages'; const ordersActions = require('../bot/ordersActions'); const { getUserI18nContext, getEmojiRate, decimalRound } = require('../util'); -import logger from "../logger"; +import { logger } from '../logger'; const subscribeInvoice = async (bot: Telegraf, id: string, resub: boolean) => { try { diff --git a/ln/subscribe_probe.js b/ln/subscribe_probe.js index 3bdc8fe7..4dc798bb 100644 --- a/ln/subscribe_probe.js +++ b/ln/subscribe_probe.js @@ -1,6 +1,6 @@ const { subscribeToProbeForRoute } = require('lightning'); const lnd = require('./connect'); -const logger = require('../logger'); +const { logger } = require('../logger'); const subscribeProbe = async (destination, tokens) => { try { diff --git a/util/index.ts b/util/index.ts index a9165729..6d617c4d 100644 --- a/util/index.ts +++ b/util/index.ts @@ -8,8 +8,9 @@ import { Telegram } from "telegraf/typings/core/types/typegram"; import axios from "axios"; import fiatJson from './fiat.json'; import languagesJson from './languages.json'; -import { Order, Community } from "../models"; -import logger from "../logger"; +import { Order, Community } from '../models'; +import { logger } from '../logger'; +import { MainContext } from '../bot/start'; const { I18n } = require('@grammyjs/i18n'); const languages: ILanguages = languagesJson;