From 94a67cd412936a567d6d48db6ef706d46a64a05a Mon Sep 17 00:00:00 2001 From: Anyitechs Date: Mon, 9 Jun 2025 15:02:18 +0100 Subject: [PATCH 1/6] feat: add language to community This allows the community admin to set the language for the published message in their channel --- bot/messages.ts | 35 +++++++- bot/middleware/stage.ts | 1 + bot/modules/community/commands.ts | 6 ++ bot/modules/community/index.ts | 7 ++ bot/modules/community/messages.ts | 12 ++- .../community/scenes.communityAdmin.ts | 21 +++++ bot/modules/community/scenes.ts | 79 +++++++++++++++++++ bot/ordersActions.ts | 16 +++- locales/de.yaml | 6 ++ locales/en.yaml | 7 ++ locales/es.yaml | 6 ++ locales/fa.yaml | 6 ++ locales/fr.yaml | 6 ++ locales/it.yaml | 6 ++ locales/ko.yaml | 6 ++ locales/pt.yaml | 6 ++ locales/ru.yaml | 6 ++ locales/uk.yaml | 6 ++ models/community.ts | 2 + 19 files changed, 235 insertions(+), 5 deletions(-) diff --git a/bot/messages.ts b/bot/messages.ts index 32a7e41d..9329f60d 100644 --- a/bot/messages.ts +++ b/bot/messages.ts @@ -26,6 +26,8 @@ import { IFiat } from '../util/fiatModel'; import { CommunityContext } from './modules/community/communityContext'; import { imageCache } from '../util/imageCache'; import { ImageProcessingError } from '../util/errors'; +const { I18n } = require('@grammyjs/i18n'); +import { Community } from '../models'; const startMessage = async (ctx: MainContext) => { try { @@ -738,11 +740,25 @@ const publishBuyOrderMessage = async ( const channel = await getOrderChannel(order); if (channel === undefined) throw new Error('channel is undefined'); + + // Get the community language if available + let communityI18n = i18n; + if (order.community_id) { + const community = await Community.findOne({ _id: order.community_id }); + if (community && community.language) { + communityI18n = new I18n({ + defaultLanguageOnMissing: true, + locale: community.language, + directory: 'locales' + }).createContext(community.language); + } + } + // We send the message to the channel const message1 = await bot.telegram.sendMessage(channel, publishMessage, { reply_markup: { inline_keyboard: [ - [{ text: i18n.t('sell_sats'), callback_data: 'takebuy' }], + [{ text: communityI18n.t('sell_sats'), callback_data: 'takebuy' }], ], }, }); @@ -776,11 +792,26 @@ const publishSellOrderMessage = async ( publishMessage += `:${order._id}:`; const channel = await getOrderChannel(order); if (channel === undefined) throw new Error('channel is undefined'); + + // Get the community language if available + let communityI18n = i18n; + + if (order.community_id) { + const community = await Community.findOne({ _id: order.community_id }); + if (community && community.language) { + communityI18n = new I18n({ + defaultLanguageOnMissing: true, + locale: community.language, + directory: 'locales' + }).createContext(community.language); + } + } + // We send the message to the channel const message1 = await ctx.telegram.sendMessage(channel, publishMessage, { reply_markup: { inline_keyboard: [ - [{ text: i18n.t('buy_sats'), callback_data: 'takesell' }], + [{ text: communityI18n.t('buy_sats'), callback_data: 'takesell' }], ], }, }); diff --git a/bot/middleware/stage.ts b/bot/middleware/stage.ts index 9aa7bfd7..424eda3a 100644 --- a/bot/middleware/stage.ts +++ b/bot/middleware/stage.ts @@ -22,6 +22,7 @@ export const stageMiddleware = () => { CommunityModule.Scenes.updateSolversCommunityWizard, CommunityModule.Scenes.updateFeeCommunityWizard, CommunityModule.Scenes.updateDisputeChannelCommunityWizard, + CommunityModule.Scenes.updateLanguageCommunityWizard, CommunityModule.Scenes.addEarningsInvoiceWizard, addInvoicePHIWizard, OrdersModule.Scenes.createOrder, diff --git a/bot/modules/community/commands.ts b/bot/modules/community/commands.ts index cd49a25b..0c62c791 100644 --- a/bot/modules/community/commands.ts +++ b/bot/modules/community/commands.ts @@ -200,6 +200,12 @@ export const updateCommunity = async ( user, community, }); + } else if (field === 'language') { + ctx.scene.enter('UPDATE_LANGUAGE_COMMUNITY_WIZARD_SCENE_ID', { + id, + user, + community, + }); } } catch (error) { logger.error(error); diff --git a/bot/modules/community/index.ts b/bot/modules/community/index.ts index 79b2cee8..424700f3 100644 --- a/bot/modules/community/index.ts +++ b/bot/modules/community/index.ts @@ -54,6 +54,13 @@ export const configure = (bot: Telegraf) => { await commands.updateCommunity(ctx, ctx.match[1], 'disputeChannel', bot); }, ); + bot.action( + /^editLanguageBtn_([0-9a-f]{24})$/, + userMiddleware, + async ctx => { + await commands.updateCommunity(ctx, ctx.match[1], 'language'); + } + ); bot.command('findcomms', userMiddleware, commands.findCommunity); bot.action( diff --git a/bot/modules/community/messages.ts b/bot/modules/community/messages.ts index 9501b4d0..37be5e97 100644 --- a/bot/modules/community/messages.ts +++ b/bot/modules/community/messages.ts @@ -12,6 +12,7 @@ export const createCommunityWizardStatus = ( try { let { name, group } = state; name = state.name || '__'; + const language = state.language || '__'; let currencies = state.currencies && state.currencies.join(', '); currencies = currencies || '__'; group = state.group || '__'; @@ -27,6 +28,7 @@ export const createCommunityWizardStatus = ( solvers = solvers || '__'; const text = [ i18n.t('name') + `: ${name}`, + i18n.t('language') + `: ${language}`, i18n.t('currency') + `: ${currencies}`, i18n.t('group') + `: ${group}`, i18n.t('channels') + `: ${channels}`, @@ -94,15 +96,21 @@ export const updateCommunityMessage = async (ctx: MainContext) => { callback_data: `editDisputeChannelBtn_${id}`, }, { - text: '💰 ' + ctx.i18n.t('earnings'), - callback_data: `earningsBtn_${id}`, + text: '✏️ ' + ctx.i18n.t('language'), + callback_data: `editLanguageBtn_${id}`, }, ], [ + { + text: '💰 ' + ctx.i18n.t('earnings'), + callback_data: `earningsBtn_${id}`, + }, { text: visibilityText, callback_data: `changeVisibilityBtn_${id}`, }, + ], + [ { text: '☠️ ' + ctx.i18n.t('delete_community'), callback_data: `deleteCommunityAskBtn_${id}`, diff --git a/bot/modules/community/scenes.communityAdmin.ts b/bot/modules/community/scenes.communityAdmin.ts index 2d874c70..68ba0555 100644 --- a/bot/modules/community/scenes.communityAdmin.ts +++ b/bot/modules/community/scenes.communityAdmin.ts @@ -37,6 +37,27 @@ const communityAdmin = () => { } }); + scene.command('/setlanguage', async (ctx: CommunityContext) => { + try { + const [, language] = ctx.message!.text.trim().split(' '); + const lang = language?.toLowerCase(); + + // Check if language is valid + const validLanguages = ['en', 'es', 'fr', 'de', 'it', 'pt', 'ru', 'uk', 'ko', 'fa']; + if (!lang || !validLanguages.includes(lang)) { + return ctx.reply(ctx.i18n.t('wizard_community_invalid_language')); + } + + const { community } = ctx.scene.state as any; + community.language = lang; + await community.save(); + await ctx.reply(ctx.i18n.t('community_language_updated', { language: lang })); + CommunityEvents.communityUpdated(community); + } catch (err) { + return ctx.reply(ctx.i18n.t('generic_error')); + } + }); + return scene; }; diff --git a/bot/modules/community/scenes.ts b/bot/modules/community/scenes.ts index da1d835e..e1075778 100644 --- a/bot/modules/community/scenes.ts +++ b/bot/modules/community/scenes.ts @@ -25,6 +25,7 @@ export const communityWizard = new Scenes.WizardScene( const { name, + language, currencies, group, channels, @@ -61,6 +62,7 @@ export const communityWizard = new Scenes.WizardScene( } if (undefined === name) return createCommunitySteps.name(ctx); + if (undefined === language) return createCommunitySteps.language(ctx); if (undefined === currencies) return createCommunitySteps.currencies(ctx); if (undefined === group) return createCommunitySteps.group(ctx); if (undefined === channels) return createCommunitySteps.channels(ctx); @@ -71,6 +73,7 @@ export const communityWizard = new Scenes.WizardScene( const community = new Community({ name, + language, currencies, group, order_channels: channels, @@ -150,6 +153,38 @@ const createCommunitySteps = { return ctx.wizard.next(); }, + async language(ctx: CommunityContext) { + const prompt = await createCommunityPrompts.language(ctx); + + ctx.wizard.state.handler = async (ctx: CommunityContext) => { + const text = ctx?.message?.text; + if (!text) { + await ctx.deleteMessage(); + return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); + } + + ctx.wizard.state.error = null; + const lang = text.trim().toLowerCase(); + + // Check if language is valid + const validLanguages = ['en', 'es', 'fr', 'de', 'it', 'pt', 'ru', 'uk', 'ko', 'fa']; + if (!validLanguages.includes(lang)) { + ctx.telegram.deleteMessage(ctx.chat!.id, ctx.message!.message_id); + ctx.wizard.state.error = ctx.i18n.t('wizard_community_invalid_language'); + return await ctx.wizard.state.updateUI(); + } + + ctx.wizard.state.language = lang; + await ctx.wizard.state.updateUI(); + await ctx.telegram.deleteMessage( + ctx.message!.chat.id, + ctx.message!.message_id + ); + return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); + }; + + return ctx.wizard.next(); + }, async currencies(ctx: CommunityContext) { const prompt = await createCommunityPrompts.currencies(ctx); @@ -427,6 +462,9 @@ const createCommunityPrompts = { async name(ctx: CommunityContext) { return ctx.reply(ctx.i18n.t('wizard_community_enter_name')); }, + async language(ctx: CommunityContext) { + return ctx.reply(ctx.i18n.t('wizard_community_enter_language')); + }, async currencies(ctx: CommunityContext) { return ctx.reply(ctx.i18n.t('wizard_community_enter_currency')); }, @@ -837,6 +875,47 @@ export const updateDisputeChannelCommunityWizard = new Scenes.WizardScene( }, ); +export const updateLanguageCommunityWizard = new Scenes.WizardScene( + 'UPDATE_LANGUAGE_COMMUNITY_WIZARD_SCENE_ID', + async (ctx: CommunityContext) => { + try { + const { community } = ctx.wizard.state; + let message = ctx.i18n.t('language') + ': ' + (community.language || 'en') + '\n\n'; + message += ctx.i18n.t('wizard_community_enter_language') + '\n\n'; + message += ctx.i18n.t('wizard_to_exit'); + await ctx.reply(message); + + return ctx.wizard.next(); + } catch (error) { + logger.error(error); + ctx.scene.leave(); + } + }, + async (ctx: CommunityContext) => { + try { + if (ctx.message === undefined) return ctx.scene.leave(); + + const lang = ctx.message.text.trim().toLowerCase(); + // Check if language is valid + const validLanguages = ['en', 'es', 'fr', 'de', 'it', 'pt', 'ru', 'uk', 'ko', 'fa']; + if (!validLanguages.includes(lang)) { + ctx.deleteMessage(); + return await ctx.reply(ctx.i18n.t('wizard_community_invalid_language')); + } + + const { community } = ctx.wizard.state; + community.language = lang; + await community.save(); + await ctx.reply(ctx.i18n.t('operation_successful')); + + return ctx.scene.leave(); + } catch (error) { + logger.error(error); + ctx.scene.leave(); + } + } +); + export const addEarningsInvoiceWizard = new Scenes.WizardScene( 'ADD_EARNINGS_INVOICE_WIZARD_SCENE_ID', async (ctx: CommunityContext) => { diff --git a/bot/ordersActions.ts b/bot/ordersActions.ts index 8d632633..cf29d370 100644 --- a/bot/ordersActions.ts +++ b/bot/ordersActions.ts @@ -73,10 +73,24 @@ const createOrder = async ( try { amount = Math.floor(amount); let isPublic = true; + + // Use community language if community_id is provided + let descriptionI18n = i18n; + if (community_id) { const community = await Community.findById(community_id); if (community == null) throw new Error('community is null'); isPublic = community.public; + + // Get community language for description + if (community.language) { + const { I18n } = require('@grammyjs/i18n'); + descriptionI18n = new I18n({ + defaultLanguageOnMissing: true, + locale: community.language, + directory: 'locales' + }).createContext(community.language); + } } const fee = await getFee(amount, community_id || ''); if (process.env.MAX_FEE === undefined) @@ -129,7 +143,7 @@ const createOrder = async ( tg_order_message: tgOrderMessage, price_from_api: priceFromAPI, price_margin: priceMargin || 0, - description: buildDescription(i18n, { + description: buildDescription(descriptionI18n, { user, type, amount, diff --git a/locales/de.yaml b/locales/de.yaml index 1f647803..0763f016 100644 --- a/locales/de.yaml +++ b/locales/de.yaml @@ -570,6 +570,8 @@ community_admin: | ${community.fee} Earnings: ${community.earnings} + Language: + ${community.language || 'de'} npub: ${community.nostr_public_key || ''} @@ -580,7 +582,11 @@ community_admin_help: | # commands /setnpub <npub> - Configure Nostr community's public key. + /setlanguage <lang> - Configure community's language for published messages. community_npub_updated: You added the community's pubkey ${npub} successfully! +community_language_updated: You updated the community's language to ${language} successfully! +wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) +wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa # END modules/community # START modules/orders diff --git a/locales/en.yaml b/locales/en.yaml index 3d886029..565884f6 100644 --- a/locales/en.yaml +++ b/locales/en.yaml @@ -559,6 +559,8 @@ community_admin: | ${community.fee} Earnings: ${community.earnings} + Language: + ${community.language || 'en'} npub: ${community.nostr_public_key || ''} @@ -569,7 +571,12 @@ community_admin_help: | # commands /setnpub <npub> - Configure Nostr community's public key. + /setlanguage <lang> - Configure community's language for published messages. community_npub_updated: You added the community's pubkey ${npub} successfully! +community_language_updated: You updated the community's language to ${language} successfully! +wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) +wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa +language: Language # END modules/community # START modules/nostr diff --git a/locales/es.yaml b/locales/es.yaml index 02715af1..8cc0cc5d 100644 --- a/locales/es.yaml +++ b/locales/es.yaml @@ -554,6 +554,8 @@ community_admin: | ${community.fee} Ganancias: ${community.earnings} + Idioma: + ${community.language || 'es'} npub: ${community.nostr_public_key || ''} @@ -564,7 +566,11 @@ community_admin_help: | # comandos /setnpub <npub> - Configura la llave pública de Nostr de la comunidad. + /setlanguage <lang> - Configura el idioma de la comunidad para los mensajes publicados. community_npub_updated: Has configurado la pubkey ${npub} de la comunidad exitosamente! +community_language_updated: Has configurado el idioma ${language} de la comunidad exitosamente! +wizard_community_enter_language: Ingresa el idioma de la comunidad, ej: es, en, pt, fr, de, it, etc. +wizard_community_invalid_language: El idioma debe ser uno de los siguientes: es, en, pt, fr, de, it, etc. # END modules/community # START modules/nostr diff --git a/locales/fa.yaml b/locales/fa.yaml index 31530779..2e3b03ae 100644 --- a/locales/fa.yaml +++ b/locales/fa.yaml @@ -553,6 +553,8 @@ community_admin: | ${community.fee} Earnings: ${community.earnings} + Language: + ${community.language || 'fa'} npub: ${community.nostr_public_key || ''} @@ -563,6 +565,10 @@ community_admin_help: | # commands /setnpub <npub> - کلید عمومی جامعه را پیکربندی کنید. رویدادهای ناستر با این کلید عمومی برچسب‌گذاری می‌شوند. + /setlanguage <lang> - Configure community's language for published messages. +community_language_updated: You updated the community's language to ${language} successfully! +wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) +wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa community_npub_updated: شما کلیدعمومی کامیونیتی ${npub} را با موفقیت اضافه کردید! # END modules/community diff --git a/locales/fr.yaml b/locales/fr.yaml index 15b4fe88..14dfa881 100644 --- a/locales/fr.yaml +++ b/locales/fr.yaml @@ -552,6 +552,8 @@ community_admin: | ${community.fee} Earnings: ${community.earnings} + Language: + ${community.language || 'fr'} npub: ${community.nostr_public_key || ''} @@ -562,6 +564,10 @@ community_admin_help: | # commands /setnpub <npub> - Configurer la clé publique de la communauté. + /setlanguage <lang> - Configurer la langue de la communauté pour les messages publiés. +community_language_updated: Vous avez configuré la langue de la communauté en ${language} avec succès ! +wizard_community_enter_language: Entrez le code de la langue de votre communauté (en, es, fr, de, it, pt, ru, uk, ko, fa) +wizard_community_invalid_language: Code de langue invalide. Veuillez entrer l'un des suivants - en, es, fr, de, it, pt, ru, uk, ko, fa community_npub_updated: Vous avez ajouté la clé publique de la communauté ${npub} avec succès ! # END modules/community diff --git a/locales/it.yaml b/locales/it.yaml index 60043fe4..d6efb13b 100644 --- a/locales/it.yaml +++ b/locales/it.yaml @@ -567,6 +567,8 @@ community_admin: | ${community.fee} Earnings: ${community.earnings} + Language: + ${community.language || 'it'} npub: ${community.nostr_public_key || ''} @@ -577,6 +579,10 @@ community_admin_help: | # commands /setnpub <npub> - Configure community's public key. + /setlanguage <lang> - Configure community's language for published messages. +community_language_updated: You updated the community's language to ${language} successfully! +wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) +wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/locales/ko.yaml b/locales/ko.yaml index ce324ad4..adf61259 100644 --- a/locales/ko.yaml +++ b/locales/ko.yaml @@ -550,6 +550,8 @@ community_admin: | ${community.fee} 수익: ${community.earnings} + Language: + ${community.language || 'ko'} npub: ${community.nostr_public_key || ''} @@ -560,6 +562,10 @@ community_admin_help: | # 명령어 /setnpub <npub> - 커뮤니티의 Nostr npub을 등록합니다. Nostr 이벤트들은 이 npub으로 등록됩니다. + /setlanguage <lang> - 커뮤니티의 언어를 설정합니다. +community_language_updated: 성공적으로 커뮤니티의 언어를 ${language}로 설정하였습니다! +wizard_community_enter_language: 커뮤니티의 언어를 입력하세요. (en, es, fr, de, it, pt, ru, uk, ko, fa) +wizard_community_invalid_language: 유효하지 않은 언어입니다. 다음 중 하나를 입력하세요: en, es, fr, de, it, pt, ru, uk, ko, fa community_npub_updated: 성공적으로 커뮤니티의 공개키 ${npub}을 추가하였습니다! # END modules/community diff --git a/locales/pt.yaml b/locales/pt.yaml index bd3a5fa7..31271f92 100644 --- a/locales/pt.yaml +++ b/locales/pt.yaml @@ -569,6 +569,8 @@ community_admin: | ${community.fee} Earnings: ${community.earnings} + Language: + ${community.language || 'pt'} npub: ${community.nostr_public_key || ''} @@ -579,6 +581,10 @@ community_admin_help: | # commands /setnpub <npub> - Configure community's public key. + /setlanguage <lang> - Configure community's language for published messages. +community_language_updated: You updated the community's language to ${language} successfully! +wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) +wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/locales/ru.yaml b/locales/ru.yaml index dea0cd9a..8c7a33e1 100644 --- a/locales/ru.yaml +++ b/locales/ru.yaml @@ -570,6 +570,8 @@ community_admin: | ${community.fee} Earnings: ${community.earnings} + Language: + ${community.language || 'ru'} npub: ${community.nostr_public_key || ''} @@ -580,6 +582,10 @@ community_admin_help: | # commands /setnpub <npub> - Configure community's Nostr public key. + /setlanguage <lang> - Configure community's language for published messages. +community_language_updated: You updated the community's language to ${language} successfully! +wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) +wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/locales/uk.yaml b/locales/uk.yaml index 40e76f35..f2f80bc9 100644 --- a/locales/uk.yaml +++ b/locales/uk.yaml @@ -566,6 +566,8 @@ community_admin: | ${community.fee} Earnings: ${community.earnings} + Language: + ${community.language || 'uk'} npub: ${community.nostr_public_key || ''} @@ -576,6 +578,10 @@ community_admin_help: | # commands /setnpub <npub> - Configure community's Nostr public key. + /setlanguage <lang> - Configure community's language for published messages. +community_language_updated: You updated the community's language to ${language} successfully! +wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) +wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/models/community.ts b/models/community.ts index c23b75b6..f18a5720 100644 --- a/models/community.ts +++ b/models/community.ts @@ -49,6 +49,7 @@ export interface ICommunity extends Document { created_at: Date; nostr_public_key: string; warning_messages_count: number; + language: string; } const CommunitySchema = new Schema({ @@ -82,6 +83,7 @@ const CommunitySchema = new Schema({ created_at: { type: Date, default: Date.now }, nostr_public_key: { type: String }, warning_messages_count: { type: Number, default: 0 }, + language: { type: String, default: 'en' }, }); export default mongoose.model('Community', CommunitySchema); From e9ecbf5a8c3271970f0d4a1a921eff5705a1ecd8 Mon Sep 17 00:00:00 2001 From: Anyitechs Date: Tue, 26 Aug 2025 15:24:22 +0100 Subject: [PATCH 2/6] refactor: improve changes and fix CI --- bot/messages.ts | 3 ++- .../community/scenes.communityAdmin.ts | 21 +++++++++++-------- bot/modules/community/scenes.ts | 13 +++++------- bot/ordersActions.ts | 3 ++- locales/de.yaml | 4 ++-- locales/en.yaml | 4 ++-- locales/es.yaml | 4 ++-- locales/fa.yaml | 4 ++-- locales/fr.yaml | 4 ++-- locales/it.yaml | 4 ++-- locales/ko.yaml | 4 ++-- locales/pt.yaml | 4 ++-- locales/ru.yaml | 4 ++-- locales/uk.yaml | 4 ++-- models/community.ts | 12 ++++++++++- util/languages.ts | 17 +++++++++++++++ 16 files changed, 69 insertions(+), 40 deletions(-) create mode 100644 util/languages.ts diff --git a/bot/messages.ts b/bot/messages.ts index 9329f60d..ae5f375a 100644 --- a/bot/messages.ts +++ b/bot/messages.ts @@ -26,9 +26,10 @@ import { IFiat } from '../util/fiatModel'; import { CommunityContext } from './modules/community/communityContext'; import { imageCache } from '../util/imageCache'; import { ImageProcessingError } from '../util/errors'; -const { I18n } = require('@grammyjs/i18n'); import { Community } from '../models'; +const { I18n } = require('@grammyjs/i18n'); + const startMessage = async (ctx: MainContext) => { try { const holdInvoiceExpiration = holdInvoiceExpirationInSecs(); diff --git a/bot/modules/community/scenes.communityAdmin.ts b/bot/modules/community/scenes.communityAdmin.ts index 68ba0555..5c376f02 100644 --- a/bot/modules/community/scenes.communityAdmin.ts +++ b/bot/modules/community/scenes.communityAdmin.ts @@ -1,5 +1,6 @@ import { Scenes } from 'telegraf'; import { CommunityContext } from './communityContext'; +import { isValidLanguage } from '../../../util/languages'; import * as CommunityEvents from '../events/community'; @@ -39,21 +40,23 @@ const communityAdmin = () => { scene.command('/setlanguage', async (ctx: CommunityContext) => { try { - const [, language] = ctx.message!.text.trim().split(' '); - const lang = language?.toLowerCase(); - - // Check if language is valid - const validLanguages = ['en', 'es', 'fr', 'de', 'it', 'pt', 'ru', 'uk', 'ko', 'fa']; - if (!lang || !validLanguages.includes(lang)) { + const [, maybeLanguage] = ctx.message!.text.split(' '); + if (!maybeLanguage || maybeLanguage.trim() === '') { return ctx.reply(ctx.i18n.t('wizard_community_invalid_language')); } - + + const language = maybeLanguage.trim().toLowerCase(); + if (!isValidLanguage(language)) { + return ctx.reply(ctx.i18n.t('wizard_community_invalid_language')); + } + const { community } = ctx.scene.state as any; - community.language = lang; + community.language = language; await community.save(); - await ctx.reply(ctx.i18n.t('community_language_updated', { language: lang })); + await ctx.reply(ctx.i18n.t('community_language_updated', { language })); CommunityEvents.communityUpdated(community); } catch (err) { + console.error('setlanguage error:', err); return ctx.reply(ctx.i18n.t('generic_error')); } }); diff --git a/bot/modules/community/scenes.ts b/bot/modules/community/scenes.ts index e1075778..57c880f8 100644 --- a/bot/modules/community/scenes.ts +++ b/bot/modules/community/scenes.ts @@ -12,6 +12,7 @@ import { } from './messages'; import { CommunityContext } from './communityContext'; import * as commAdmin from './scenes.communityAdmin'; +import { isValidLanguage } from '../../../util/languages'; const CURRENCIES = parseInt(process.env.COMMUNITY_CURRENCIES || '10'); @@ -165,10 +166,8 @@ const createCommunitySteps = { ctx.wizard.state.error = null; const lang = text.trim().toLowerCase(); - - // Check if language is valid - const validLanguages = ['en', 'es', 'fr', 'de', 'it', 'pt', 'ru', 'uk', 'ko', 'fa']; - if (!validLanguages.includes(lang)) { + + if (!isValidLanguage(lang)) { ctx.telegram.deleteMessage(ctx.chat!.id, ctx.message!.message_id); ctx.wizard.state.error = ctx.i18n.t('wizard_community_invalid_language'); return await ctx.wizard.state.updateUI(); @@ -896,13 +895,11 @@ export const updateLanguageCommunityWizard = new Scenes.WizardScene( if (ctx.message === undefined) return ctx.scene.leave(); const lang = ctx.message.text.trim().toLowerCase(); - // Check if language is valid - const validLanguages = ['en', 'es', 'fr', 'de', 'it', 'pt', 'ru', 'uk', 'ko', 'fa']; - if (!validLanguages.includes(lang)) { + if (!isValidLanguage(lang)) { ctx.deleteMessage(); return await ctx.reply(ctx.i18n.t('wizard_community_invalid_language')); } - + const { community } = ctx.wizard.state; community.language = lang; await community.save(); diff --git a/bot/ordersActions.ts b/bot/ordersActions.ts index cf29d370..4335742a 100644 --- a/bot/ordersActions.ts +++ b/bot/ordersActions.ts @@ -15,9 +15,11 @@ import { UserDocument } from '../models/user'; import { HasTelegram, MainContext } from './start'; import { IOrder } from '../models/order'; import { IFiat } from '../util/fiatModel'; + import * as OrderEvents from './modules/events/orders'; const { ObjectId } = require('mongoose').Types; +const { I18n } = require('@grammyjs/i18n'); interface CreateOrderArguments { type: string; @@ -84,7 +86,6 @@ const createOrder = async ( // Get community language for description if (community.language) { - const { I18n } = require('@grammyjs/i18n'); descriptionI18n = new I18n({ defaultLanguageOnMissing: true, locale: community.language, diff --git a/locales/de.yaml b/locales/de.yaml index 0763f016..fc7eca4e 100644 --- a/locales/de.yaml +++ b/locales/de.yaml @@ -585,8 +585,8 @@ community_admin_help: | /setlanguage <lang> - Configure community's language for published messages. community_npub_updated: You added the community's pubkey ${npub} successfully! community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) -wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa +wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' # END modules/community # START modules/orders diff --git a/locales/en.yaml b/locales/en.yaml index 565884f6..60bb25c9 100644 --- a/locales/en.yaml +++ b/locales/en.yaml @@ -574,8 +574,8 @@ community_admin_help: | /setlanguage <lang> - Configure community's language for published messages. community_npub_updated: You added the community's pubkey ${npub} successfully! community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) -wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa +wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' language: Language # END modules/community diff --git a/locales/es.yaml b/locales/es.yaml index 8cc0cc5d..aaa05658 100644 --- a/locales/es.yaml +++ b/locales/es.yaml @@ -569,8 +569,8 @@ community_admin_help: | /setlanguage <lang> - Configura el idioma de la comunidad para los mensajes publicados. community_npub_updated: Has configurado la pubkey ${npub} de la comunidad exitosamente! community_language_updated: Has configurado el idioma ${language} de la comunidad exitosamente! -wizard_community_enter_language: Ingresa el idioma de la comunidad, ej: es, en, pt, fr, de, it, etc. -wizard_community_invalid_language: El idioma debe ser uno de los siguientes: es, en, pt, fr, de, it, etc. +wizard_community_enter_language: 'Ingresa el idioma de la comunidad, ej: es, en, pt, fr, de, it, etc.' +wizard_community_invalid_language: 'El idioma debe ser uno de los siguientes: es, en, pt, fr, de, it, etc.' # END modules/community # START modules/nostr diff --git a/locales/fa.yaml b/locales/fa.yaml index 2e3b03ae..f6a65478 100644 --- a/locales/fa.yaml +++ b/locales/fa.yaml @@ -567,8 +567,8 @@ community_admin_help: | /setnpub <npub> - کلید عمومی جامعه را پیکربندی کنید. رویدادهای ناستر با این کلید عمومی برچسب‌گذاری می‌شوند. /setlanguage <lang> - Configure community's language for published messages. community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) -wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa +wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: شما کلیدعمومی کامیونیتی ${npub} را با موفقیت اضافه کردید! # END modules/community diff --git a/locales/fr.yaml b/locales/fr.yaml index 14dfa881..7f95edef 100644 --- a/locales/fr.yaml +++ b/locales/fr.yaml @@ -566,8 +566,8 @@ community_admin_help: | /setnpub <npub> - Configurer la clé publique de la communauté. /setlanguage <lang> - Configurer la langue de la communauté pour les messages publiés. community_language_updated: Vous avez configuré la langue de la communauté en ${language} avec succès ! -wizard_community_enter_language: Entrez le code de la langue de votre communauté (en, es, fr, de, it, pt, ru, uk, ko, fa) -wizard_community_invalid_language: Code de langue invalide. Veuillez entrer l'un des suivants - en, es, fr, de, it, pt, ru, uk, ko, fa +wizard_community_enter_language: 'Entrez le code de la langue de votre communauté (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: "Code de langue invalide. Veuillez entrer l'un des suivants - en, es, fr, de, it, pt, ru, uk, ko, fa" community_npub_updated: Vous avez ajouté la clé publique de la communauté ${npub} avec succès ! # END modules/community diff --git a/locales/it.yaml b/locales/it.yaml index d6efb13b..60fdbb54 100644 --- a/locales/it.yaml +++ b/locales/it.yaml @@ -581,8 +581,8 @@ community_admin_help: | /setnpub <npub> - Configure community's public key. /setlanguage <lang> - Configure community's language for published messages. community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) -wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa +wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/locales/ko.yaml b/locales/ko.yaml index adf61259..b52cce9f 100644 --- a/locales/ko.yaml +++ b/locales/ko.yaml @@ -564,8 +564,8 @@ community_admin_help: | /setnpub <npub> - 커뮤니티의 Nostr npub을 등록합니다. Nostr 이벤트들은 이 npub으로 등록됩니다. /setlanguage <lang> - 커뮤니티의 언어를 설정합니다. community_language_updated: 성공적으로 커뮤니티의 언어를 ${language}로 설정하였습니다! -wizard_community_enter_language: 커뮤니티의 언어를 입력하세요. (en, es, fr, de, it, pt, ru, uk, ko, fa) -wizard_community_invalid_language: 유효하지 않은 언어입니다. 다음 중 하나를 입력하세요: en, es, fr, de, it, pt, ru, uk, ko, fa +wizard_community_enter_language: '커뮤니티의 언어를 입력하세요. (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: '유효하지 않은 언어입니다. 다음 중 하나를 입력하세요: en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: 성공적으로 커뮤니티의 공개키 ${npub}을 추가하였습니다! # END modules/community diff --git a/locales/pt.yaml b/locales/pt.yaml index 31271f92..eca342b5 100644 --- a/locales/pt.yaml +++ b/locales/pt.yaml @@ -583,8 +583,8 @@ community_admin_help: | /setnpub <npub> - Configure community's public key. /setlanguage <lang> - Configure community's language for published messages. community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) -wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa +wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/locales/ru.yaml b/locales/ru.yaml index 8c7a33e1..a4e320cf 100644 --- a/locales/ru.yaml +++ b/locales/ru.yaml @@ -584,8 +584,8 @@ community_admin_help: | /setnpub <npub> - Configure community's Nostr public key. /setlanguage <lang> - Configure community's language for published messages. community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) -wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa +wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/locales/uk.yaml b/locales/uk.yaml index f2f80bc9..75c835cf 100644 --- a/locales/uk.yaml +++ b/locales/uk.yaml @@ -580,8 +580,8 @@ community_admin_help: | /setnpub <npub> - Configure community's Nostr public key. /setlanguage <lang> - Configure community's language for published messages. community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa) -wizard_community_invalid_language: Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa +wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/models/community.ts b/models/community.ts index f18a5720..4d69a30b 100644 --- a/models/community.ts +++ b/models/community.ts @@ -83,7 +83,17 @@ const CommunitySchema = new Schema({ created_at: { type: Date, default: Date.now }, nostr_public_key: { type: String }, warning_messages_count: { type: Number, default: 0 }, - language: { type: String, default: 'en' }, + language: { + type: String, + default: 'en', + validate: { + validator: function(v: string) { + const supportedLanguages = ['en', 'es', 'fr', 'de', 'it', 'pt', 'ru', 'uk', 'ko', 'fa']; // Add all supported languages + return supportedLanguages.includes(v); + }, + message: 'Language code {VALUE} is not supported' + } + }, }); export default mongoose.model('Community', CommunitySchema); diff --git a/util/languages.ts b/util/languages.ts new file mode 100644 index 00000000..267d8660 --- /dev/null +++ b/util/languages.ts @@ -0,0 +1,17 @@ +export const SUPPORTED_LANGUAGES = [ + 'en', + 'es', + 'fr', + 'de', + 'it', + 'pt', + 'ru', + 'uk', + 'ko', + 'fa', +] as const; +export type SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number]; + +export const isValidLanguage = (lang: string): lang is SupportedLanguage => { + return SUPPORTED_LANGUAGES.includes(lang as SupportedLanguage); +}; From 4fa2a75f936b52e323c83a5459b68e31886c1596 Mon Sep 17 00:00:00 2001 From: Anyitechs Date: Thu, 11 Sep 2025 13:56:58 +0100 Subject: [PATCH 3/6] fix formatting and localize translation --- bot/messages.ts | 286 ++++++++++++++++---------------- bot/modules/community/index.ts | 26 ++- bot/modules/community/scenes.ts | 101 +++++------ bot/ordersActions.ts | 14 +- locales/de.yaml | 8 +- locales/fa.yaml | 8 +- locales/it.yaml | 8 +- locales/pt.yaml | 8 +- locales/ru.yaml | 8 +- locales/uk.yaml | 8 +- models/community.ts | 35 ++-- 11 files changed, 260 insertions(+), 250 deletions(-) diff --git a/bot/messages.ts b/bot/messages.ts index ae5f375a..177fd118 100644 --- a/bot/messages.ts +++ b/bot/messages.ts @@ -53,7 +53,7 @@ const startMessage = async (ctx: MainContext) => { const initBotErrorMessage = async ( ctx: MainContext, bot: MainContext, - user: UserDocument, + user: UserDocument ) => { // Correct way to handle errors: https://github.com/telegraf/telegraf/issues/1757 await bot.telegram @@ -72,7 +72,7 @@ const invoicePaymentRequestMessage = async ( user: UserDocument, order: IOrder, i18n: I18nContext, - buyer: UserDocument, + buyer: UserDocument ) => { try { const currencyObject = getCurrency(order.fiat_code); @@ -126,7 +126,7 @@ const showQRCodeMessage = async ( ctx: MainContext, order: IOrder, request: string, - user: UserDocument, + user: UserDocument ) => { try { // @@ -146,7 +146,7 @@ const showQRCodeMessage = async ( if (error instanceof ImageProcessingError) { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('image_processing_error'), + ctx.i18n.t('image_processing_error') ); } } @@ -157,7 +157,7 @@ const pendingSellMessage = async ( user: UserDocument, order: IOrder, channel: string, - i18n: I18nContext, + i18n: I18nContext ) => { try { const orderExpirationWindow = @@ -170,7 +170,7 @@ const pendingSellMessage = async ( }); const imageBase64 = await imageCache.convertImageToBase64( - order.random_image, + order.random_image ); await ctx.telegram.sendMediaGroup(user.tg_id, [ @@ -185,7 +185,7 @@ const pendingSellMessage = async ( await ctx.telegram.sendMessage( user.tg_id, i18n.t('cancel_order_cmd', { orderId: order._id }), - { parse_mode: 'Markdown' }, + { parse_mode: 'Markdown' } ); if (order.is_golden_honey_badger === true && order.type === 'sell') { @@ -196,7 +196,7 @@ const pendingSellMessage = async ( if (error instanceof ImageProcessingError) { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('image_processing_error'), + i18n.t('image_processing_error') ); } } @@ -207,7 +207,7 @@ const pendingBuyMessage = async ( user: UserDocument, order: IOrder, channel: string, - i18n: I18nContext, + i18n: I18nContext ) => { try { const orderExpirationWindow = @@ -217,12 +217,12 @@ const pendingBuyMessage = async ( i18n.t('pending_buy', { channel, orderExpirationWindow: Math.round(orderExpirationWindow), - }), + }) ); await bot.telegram.sendMessage( user.tg_id, i18n.t('cancel_order_cmd', { orderId: order._id }), - { parse_mode: 'MarkdownV2' }, + { parse_mode: 'MarkdownV2' } ); } catch (error) { logger.error(error); @@ -254,7 +254,7 @@ const minimunAmountInvoiceMessage = async (ctx: MainContext) => { await ctx.reply( ctx.i18n.t('min_invoice_amount', { minPaymentAmount: process.env.MIN_PAYMENT_AMT, - }), + }) ); } catch (error) { logger.error(error); @@ -283,14 +283,14 @@ const expiredInvoiceOnPendingMessage = async ( bot: HasTelegram, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage(user.tg_id, i18n.t('invoice_expired_long')); await bot.telegram.sendMessage( user.tg_id, i18n.t('setinvoice_cmd_order', { orderId: order._id }), - { parse_mode: 'MarkdownV2' }, + { parse_mode: 'MarkdownV2' } ); } catch (error) { logger.error(error); @@ -310,7 +310,7 @@ const invoiceMustBeLargerMessage = async (ctx: MainContext) => { await ctx.reply( ctx.i18n.t('invoice_must_be_larger_error', { minInvoice: process.env.MIN_PAYMENT_AMT, - }), + }) ); } catch (error) { logger.error(error); @@ -360,7 +360,7 @@ const invoiceInvalidMessage = async (ctx: MainContext) => { const invalidOrderMessage = async ( ctx: MainContext, bot: HasTelegram, - user: UserDocument, + user: UserDocument ) => { try { await bot.telegram.sendMessage(user.tg_id, ctx.i18n.t('order_id_invalid')); @@ -373,12 +373,12 @@ const invalidTypeOrderMessage = async ( ctx: MainContext, bot: HasTelegram, user: UserDocument, - type: IOrder['type'], + type: IOrder['type'] ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('order_invalid_type', { type }), + ctx.i18n.t('order_invalid_type', { type }) ); } catch (error) { logger.error(error); @@ -388,12 +388,12 @@ const invalidTypeOrderMessage = async ( const alreadyTakenOrderMessage = async ( ctx: MainContext, bot: HasTelegram, - user: UserDocument, + user: UserDocument ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('order_already_taken'), + ctx.i18n.t('order_already_taken') ); } catch (error) { logger.error(error); @@ -403,7 +403,7 @@ const alreadyTakenOrderMessage = async ( const invalidDataMessage = async ( ctx: MainContext, bot: HasTelegram, - user: UserDocument, + user: UserDocument ) => { try { await bot.telegram.sendMessage(user.tg_id, ctx.i18n.t('invalid_data')); @@ -415,7 +415,7 @@ const invalidDataMessage = async ( const genericErrorMessage = async ( bot: HasTelegram, user: UserDocument, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage(user.tg_id, i18n.t('generic_error')); @@ -428,7 +428,7 @@ const beginTakeBuyMessage = async ( ctx: MainContext, bot: HasTelegram, seller: UserDocument, - order: IOrder, + order: IOrder ) => { try { const expirationTime = @@ -436,7 +436,7 @@ const beginTakeBuyMessage = async ( const caption = ctx.i18n.t('begin_take_buy', { expirationTime }); const imageBase64 = await imageCache.convertImageToBase64( - order.random_image, + order.random_image ); await bot.telegram.sendMediaGroup(seller.tg_id, [ @@ -468,7 +468,7 @@ const beginTakeBuyMessage = async ( if (error instanceof ImageProcessingError) { await bot.telegram.sendMessage( seller.tg_id, - ctx.i18n.t('image_processing_error'), + ctx.i18n.t('image_processing_error') ); } } @@ -481,7 +481,7 @@ const showHoldInvoiceMessage = async ( fiatCode: IOrder['fiat_code'], fiatAmount: IOrder['fiat_amount'], randomImage: string, - isGoldenHoneyBadger: boolean = false, + isGoldenHoneyBadger: boolean = false ) => { try { const currency = getCurrency(fiatCode); @@ -495,7 +495,7 @@ const showHoldInvoiceMessage = async ( amount: numberFormat(fiatCode, amount), fiatAmount: numberFormat(fiatCode, fiatAmount!), currency: currencySymbol, - }), + }) ); if (isGoldenHoneyBadger) { @@ -527,12 +527,12 @@ const onGoingTakeBuyMessage = async ( order: IOrder, i18nBuyer: I18nContext, i18nSeller: I18nContext, - rate: string, + rate: string ) => { try { await bot.telegram.sendMessage( seller.tg_id, - i18nSeller.t('payment_received'), + i18nSeller.t('payment_received') ); const holdInvoiceExpiration = holdInvoiceExpirationInSecs(); const orderExpiration = @@ -550,7 +550,7 @@ const onGoingTakeBuyMessage = async ( expirationTime, rate, days: ageInDays, - }), + }) ); await bot.telegram.sendMessage(buyer.tg_id, order._id, { reply_markup: { @@ -568,7 +568,7 @@ const beginTakeSellMessage = async ( ctx: MainContext, bot: HasTelegram, buyer: UserDocument, - order: IOrder, + order: IOrder ) => { try { const holdInvoiceExpiration = holdInvoiceExpirationInSecs(); @@ -582,7 +582,7 @@ const beginTakeSellMessage = async ( await bot.telegram.sendMessage( buyer.tg_id, ctx.i18n.t('you_took_someone_order', { expirationTime }), - { parse_mode: 'MarkdownV2' }, + { parse_mode: 'MarkdownV2' } ); await bot.telegram.sendMessage(buyer.tg_id, order._id, { reply_markup: { @@ -608,7 +608,7 @@ const onGoingTakeSellMessage = async ( buyerUser: UserDocument, order: IOrder, i18nBuyer: I18nContext, - i18nSeller: I18nContext, + i18nSeller: I18nContext ) => { try { await bot.telegram.sendMessage( @@ -619,12 +619,12 @@ const onGoingTakeSellMessage = async ( sellerUsername: sellerUser.username, fiatAmount: numberFormat(order.fiat_code, order.fiat_amount!), paymentMethod: order.payment_method, - }), + }) ); await bot.telegram.sendMessage( buyerUser.tg_id, i18nBuyer.t('fiatsent_order_cmd'), - { parse_mode: 'MarkdownV2' }, + { parse_mode: 'MarkdownV2' } ); await bot.telegram.sendMessage( sellerUser.tg_id, @@ -634,7 +634,7 @@ const onGoingTakeSellMessage = async ( paymentMethod: order.payment_method, currency: order.fiat_code, buyerUsername: buyerUser.username, - }), + }) ); } catch (error) { logger.error(error); @@ -645,12 +645,12 @@ const takeSellWaitingSellerToPayMessage = async ( ctx: MainContext, bot: HasTelegram, buyerUser: UserDocument, - order: IOrder, + order: IOrder ) => { try { await bot.telegram.sendMessage( buyerUser.tg_id, - ctx.i18n.t('waiting_seller_to_pay', { orderId: order._id }), + ctx.i18n.t('waiting_seller_to_pay', { orderId: order._id }) ); } catch (error) { logger.error(error); @@ -662,16 +662,16 @@ const releasedSatsMessage = async ( sellerUser: UserDocument, buyerUser: UserDocument, i18nBuyer: I18nContext, - i18nSeller: I18nContext, + i18nSeller: I18nContext ) => { try { await bot.telegram.sendMessage( sellerUser.tg_id, - i18nSeller.t('sell_success', { buyerUsername: buyerUser.username }), + i18nSeller.t('sell_success', { buyerUsername: buyerUser.username }) ); await bot.telegram.sendMessage( buyerUser.tg_id, - i18nBuyer.t('funds_released', { sellerUsername: sellerUser.username }), + i18nBuyer.t('funds_released', { sellerUsername: sellerUser.username }) ); } catch (error) { logger.error(error); @@ -682,7 +682,7 @@ const rateUserMessage = async ( bot: HasTelegram, caller: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { const starButtons = []; @@ -733,7 +733,7 @@ const publishBuyOrderMessage = async ( user: UserDocument, order: IOrder, i18n: I18nContext, - messageToUser: boolean = false, + messageToUser: boolean = false ) => { try { let publishMessage = `⚡️🍊⚡️\n${order.description}\n`; @@ -750,11 +750,11 @@ const publishBuyOrderMessage = async ( communityI18n = new I18n({ defaultLanguageOnMissing: true, locale: community.language, - directory: 'locales' + directory: 'locales', }).createContext(community.language); } } - + // We send the message to the channel const message1 = await bot.telegram.sendMessage(channel, publishMessage, { reply_markup: { @@ -786,7 +786,7 @@ const publishSellOrderMessage = async ( user: UserDocument, order: IOrder, i18n: I18nContext, - messageToUser?: boolean, + messageToUser?: boolean ) => { try { let publishMessage = `⚡️🍊⚡️\n${order.description}\n`; @@ -803,11 +803,11 @@ const publishSellOrderMessage = async ( communityI18n = new I18n({ defaultLanguageOnMissing: true, locale: community.language, - directory: 'locales' + directory: 'locales', }).createContext(community.language); } } - + // We send the message to the channel const message1 = await ctx.telegram.sendMessage(channel, publishMessage, { reply_markup: { @@ -845,7 +845,7 @@ const checkOrderMessage = async ( ctx: MainContext, order: IOrder, buyer: UserDocument | null, - seller: UserDocument | null, + seller: UserDocument | null ) => { try { let message = getDetailedOrder(ctx.i18n, order, buyer, seller); @@ -861,7 +861,7 @@ const checkInvoiceMessage = async ( ctx: MainContext, isConfirmed: boolean, isCanceled: boolean, - isHeld: boolean, + isHeld: boolean ) => { try { if (isConfirmed) { @@ -931,14 +931,14 @@ const privacyMessage = async (ctx: MainContext) => { const mustBeGreatherEqThan = async ( ctx: MainContext, fieldName: string, - qty: number, + qty: number ) => { try { await ctx.reply( ctx.i18n.t('must_be_gt_or_eq', { fieldName, qty, - }), + }) ); } catch (error) { logger.error(error); @@ -949,7 +949,7 @@ const bannedUserErrorMessage = async (ctx: MainContext, user: UserDocument) => { try { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('you_have_been_banned'), + ctx.i18n.t('you_have_been_banned') ); } catch (error) { logger.error(error); @@ -958,12 +958,12 @@ const bannedUserErrorMessage = async (ctx: MainContext, user: UserDocument) => { const userOrderIsBlockedByUserTaker = async ( ctx: MainContext, - user: UserDocument, + user: UserDocument ) => { try { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('user_order_is_blocked_by_user_taker'), + ctx.i18n.t('user_order_is_blocked_by_user_taker') ); } catch (error) { logger.error(error); @@ -972,12 +972,12 @@ const userOrderIsBlockedByUserTaker = async ( const userTakerIsBlockedByUserOrder = async ( ctx: MainContext, - user: UserDocument, + user: UserDocument ) => { try { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('user_taker_is_blocked_by_user_order'), + ctx.i18n.t('user_taker_is_blocked_by_user_order') ); } catch (error) { logger.error(error); @@ -989,25 +989,25 @@ const fiatSentMessages = async ( buyer: UserDocument, seller: UserDocument, i18nBuyer: I18nContext, - i18nSeller: I18nContext, + i18nSeller: I18nContext ) => { try { await ctx.telegram.sendMessage( buyer.tg_id, i18nBuyer.t('I_told_seller_you_sent_fiat', { sellerUsername: seller.username, - }), + }) ); await ctx.telegram.sendMessage( seller.tg_id, i18nSeller.t('buyer_told_me_that_sent_fiat', { buyerUsername: buyer.username, - }), + }) ); await ctx.telegram.sendMessage( seller.tg_id, i18nSeller.t('release_order_cmd'), - { parse_mode: 'Markdown' }, + { parse_mode: 'Markdown' } ); } catch (error) { logger.error(error); @@ -1016,12 +1016,12 @@ const fiatSentMessages = async ( const orderOnfiatSentStatusMessages = async ( ctx: MainContext, - user: UserDocument, + user: UserDocument ) => { try { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('you_have_orders_waiting'), + ctx.i18n.t('you_have_orders_waiting') ); } catch (error) { logger.error(error); @@ -1073,7 +1073,7 @@ const addInvoiceMessage = async ( bot: HasTelegram, buyer: UserDocument, seller: UserDocument, - order: IOrder, + order: IOrder ) => { try { await bot.telegram.sendMessage( @@ -1084,12 +1084,12 @@ const addInvoiceMessage = async ( sellerUsername: seller.username, fiatAmount: numberFormat(order.fiat_code, order.fiat_amount!), paymentMethod: order.payment_method, - }), + }) ); await bot.telegram.sendMessage( buyer.tg_id, ctx.i18n.t('fiatsent_order_cmd'), - { parse_mode: 'MarkdownV2' }, + { parse_mode: 'MarkdownV2' } ); } catch (error) { logger.error(error); @@ -1101,7 +1101,7 @@ const sendBuyerInfo2SellerMessage = async ( buyer: UserDocument, seller: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( @@ -1112,7 +1112,7 @@ const sendBuyerInfo2SellerMessage = async ( buyerUsername: buyer.username, fiatAmount: numberFormat(order.fiat_code, order.fiat_amount!), paymentMethod: order.payment_method, - }), + }) ); } catch (error) { logger.error(error); @@ -1122,12 +1122,12 @@ const sendBuyerInfo2SellerMessage = async ( const cantTakeOwnOrderMessage = async ( ctx: MainContext, bot: HasTelegram, - user: UserDocument, + user: UserDocument ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('cant_take_own_order'), + ctx.i18n.t('cant_take_own_order') ); } catch (error) { logger.error(error); @@ -1139,7 +1139,7 @@ const notLightningInvoiceMessage = async (ctx: MainContext, order: IOrder) => { await ctx.reply(ctx.i18n.t('send_me_lninvoice', { amount: order.amount })); await ctx.reply( ctx.i18n.t('setinvoice_cmd_order', { orderId: order._id }), - { parse_mode: 'MarkdownV2' }, + { parse_mode: 'MarkdownV2' } ); } catch (error) { logger.error(error); @@ -1157,14 +1157,14 @@ const notOrdersMessage = async (ctx: MainContext) => { const notRateForCurrency = async ( bot: HasTelegram, user: UserDocument, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( user.tg_id, i18n.t('not_rate_for_currency', { fiatRateProvider: process.env.FIAT_RATE_NAME, - }), + }) ); } catch (error) { logger.error(error); @@ -1230,12 +1230,12 @@ const successCancelOrderMessage = async ( ctx: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('cancel_success', { orderId: order._id }), + i18n.t('cancel_success', { orderId: order._id }) ); } catch (error) { logger.error(error); @@ -1246,12 +1246,12 @@ const counterPartyCancelOrderMessage = async ( ctx: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('order_cancelled_by_counterparty', { orderId: order._id }), + i18n.t('order_cancelled_by_counterparty', { orderId: order._id }) ); } catch (error) { logger.error(error); @@ -1270,12 +1270,12 @@ const successCancelOrderByAdminMessage = async ( ctx: MainContext, bot: Telegraf, user: UserDocument, - order: IOrder, + order: IOrder ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('order_cancelled_by_admin', { orderId: order._id }), + ctx.i18n.t('order_cancelled_by_admin', { orderId: order._id }) ); } catch (error) { logger.error(error); @@ -1294,12 +1294,12 @@ const successCompleteOrderByAdminMessage = async ( ctx: MainContext, bot: HasTelegram, user: UserDocument, - order: IOrder, + order: IOrder ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('order_completed_by_admin', { orderId: order._id }), + ctx.i18n.t('order_completed_by_admin', { orderId: order._id }) ); } catch (error) { logger.error(error); @@ -1308,12 +1308,12 @@ const successCompleteOrderByAdminMessage = async ( const shouldWaitCooperativeCancelMessage = async ( ctx: MainContext, - user: UserDocument, + user: UserDocument ) => { try { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('have_to_wait_for_counterpart'), + ctx.i18n.t('have_to_wait_for_counterpart') ); } catch (error) { logger.error(error); @@ -1324,12 +1324,12 @@ const okCooperativeCancelMessage = async ( ctx: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('ok_cooperativecancel', { orderId: order._id }), + i18n.t('ok_cooperativecancel', { orderId: order._id }) ); } catch (error) { logger.error(error); @@ -1339,12 +1339,12 @@ const okCooperativeCancelMessage = async ( const refundCooperativeCancelMessage = async ( ctx: MainContext, user: UserDocument, - i18n: I18nContext, + i18n: I18nContext ) => { try { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('refund_cooperativecancel'), + i18n.t('refund_cooperativecancel') ); } catch (error) { logger.error(error); @@ -1353,11 +1353,11 @@ const refundCooperativeCancelMessage = async ( const initCooperativeCancelMessage = async ( ctx: MainContext, - order: IOrder, + order: IOrder ) => { try { await ctx.reply( - ctx.i18n.t('init_cooperativecancel', { orderId: order._id }), + ctx.i18n.t('init_cooperativecancel', { orderId: order._id }) ); } catch (error) { logger.error(error); @@ -1368,17 +1368,17 @@ const counterPartyWantsCooperativeCancelMessage = async ( ctx: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('counterparty_wants_cooperativecancel', { orderId: order._id }), + i18n.t('counterparty_wants_cooperativecancel', { orderId: order._id }) ); await ctx.telegram.sendMessage( user.tg_id, i18n.t('cancel_order_cmd', { orderId: order._id }), - { parse_mode: 'MarkdownV2' }, + { parse_mode: 'MarkdownV2' } ); } catch (error) { logger.error(error); @@ -1388,7 +1388,7 @@ const counterPartyWantsCooperativeCancelMessage = async ( const invoicePaymentFailedMessage = async ( bot: HasTelegram, user: UserDocument, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( @@ -1396,7 +1396,7 @@ const invoicePaymentFailedMessage = async ( i18n.t('invoice_payment_failed', { pendingPaymentWindow: process.env.PENDING_PAYMENT_WINDOW, attempts: process.env.PAYMENT_ATTEMPTS, - }), + }) ); } catch (error) { logger.error(error); @@ -1406,12 +1406,12 @@ const invoicePaymentFailedMessage = async ( const userCantTakeMoreThanOneWaitingOrderMessage = async ( ctx: MainContext, bot: MainContext, - user: UserDocument, + user: UserDocument ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('cant_take_more_orders'), + ctx.i18n.t('cant_take_more_orders') ); } catch (error) { logger.error(error); @@ -1429,7 +1429,7 @@ const sellerPaidHoldMessage = async (ctx: MainContext, user: UserDocument) => { const showInfoMessage = async ( ctx: MainContext, user: UserDocument, - config: IConfig, + config: IConfig ) => { try { // user info @@ -1466,7 +1466,7 @@ const showInfoMessage = async ( }), { parse_mode: 'MarkdownV2', - }, + } ); } catch (error) { logger.error(error); @@ -1477,14 +1477,14 @@ const buyerReceivedSatsMessage = async ( bot: HasTelegram, buyerUser: UserDocument, sellerUser: UserDocument, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( buyerUser.tg_id, i18n.t('your_purchase_is_completed', { sellerUsername: sellerUser.username, - }), + }) ); } catch (error) { logger.error(error); @@ -1493,7 +1493,7 @@ const buyerReceivedSatsMessage = async ( const listCurrenciesResponse = async ( ctx: MainContext, - currencies: Array, + currencies: Array ) => { try { let response = `Code | Name |\n`; @@ -1509,12 +1509,12 @@ const listCurrenciesResponse = async ( const priceApiFailedMessage = async ( ctx: MainContext, bot: HasTelegram, - user: UserDocument, + user: UserDocument ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('problem_getting_price'), + ctx.i18n.t('problem_getting_price') ); } catch (error) { logger.error(error); @@ -1524,14 +1524,14 @@ const priceApiFailedMessage = async ( const updateUserSettingsMessage = async ( ctx: MainContext, field: string, - newState: string, + newState: string ) => { try { await ctx.reply( ctx.i18n.t('update_user_setting', { field, newState, - }), + }) ); } catch (error) { logger.error(error); @@ -1557,7 +1557,7 @@ const invalidRangeWithAmount = async (ctx: MainContext) => { const tooManyPendingOrdersMessage = async ( ctx: MainContext, user: UserDocument, - i18n: I18nContext, + i18n: I18nContext ) => { try { ctx.telegram.sendMessage(user.tg_id, i18n.t('too_many_pending_orders')); @@ -1570,7 +1570,7 @@ const wizardAddInvoiceInitMessage = async ( ctx: MainContext, order: IOrder, currency: string, - expirationTime: number, + expirationTime: number ) => { try { await ctx.reply( @@ -1579,7 +1579,7 @@ const wizardAddInvoiceInitMessage = async ( satsAmount: numberFormat(order.fiat_code, order.amount), currency, fiatAmount: numberFormat(order.fiat_code, order.fiat_amount!), - }), + }) ); } catch (error) { logger.error(error); @@ -1593,7 +1593,7 @@ const wizardAddInvoiceExitMessage = async (ctx: MainContext, order: IOrder) => { amount: numberFormat(order.fiat_code, order.amount), orderId: order._id, }), - { parse_mode: 'MarkdownV2' }, + { parse_mode: 'MarkdownV2' } ); } catch (error) { logger.error(error); @@ -1627,7 +1627,7 @@ const cantAddInvoiceMessage = async (ctx: MainContext) => { const sendMeAnInvoiceMessage = async ( ctx: MainContext, amount: number, - i18nCtx: I18nContext, + i18nCtx: I18nContext ) => { try { await ctx.reply(i18nCtx.t('send_me_lninvoice', { amount })); @@ -1640,7 +1640,7 @@ const wizardAddFiatAmountMessage = async ( ctx: MainContext, currency: string, action: string, - order: IOrder, + order: IOrder ) => { try { await ctx.reply( @@ -1650,7 +1650,7 @@ const wizardAddFiatAmountMessage = async ( fiatAmount: numberFormat(order.fiat_code, order.fiat_amount!), minAmount: numberFormat(order.fiat_code, order.min_amount), maxAmount: numberFormat(order.fiat_code, order.max_amount), - }), + }) ); } catch (error) { logger.error(error); @@ -1659,7 +1659,7 @@ const wizardAddFiatAmountMessage = async ( const wizardAddFiatAmountWrongAmountMessage = async ( ctx: MainContext, - order: IOrder, + order: IOrder ) => { try { ctx.deleteMessage(); @@ -1667,7 +1667,7 @@ const wizardAddFiatAmountWrongAmountMessage = async ( ctx.i18n.t('wizard_add_fiat_wrong_amount', { minAmount: numberFormat(order.fiat_code, order.min_amount), maxAmount: numberFormat(order.fiat_code, order.max_amount), - }), + }) ); } catch (error) { logger.error(error); @@ -1677,14 +1677,14 @@ const wizardAddFiatAmountWrongAmountMessage = async ( const wizardAddFiatAmountCorrectMessage = async ( ctx: MainContext, currency: IFiat, - fiatAmount: number, + fiatAmount: number ) => { try { await ctx.reply( ctx.i18n.t('wizard_add_fiat_correct_amount', { currency: currency.symbol_native, fiatAmount, - }), + }) ); } catch (error) { logger.error(error); @@ -1696,7 +1696,7 @@ const expiredOrderMessage = async ( order: IOrder, buyerUser: UserDocument, sellerUser: UserDocument, - i18n: I18nContext, + i18n: I18nContext ) => { try { const detailedOrder = getDetailedOrder(i18n, order, buyerUser, sellerUser); @@ -1707,7 +1707,7 @@ const expiredOrderMessage = async ( buyerUser, sellerUser, }), - { parse_mode: 'MarkdownV2' }, + { parse_mode: 'MarkdownV2' } ); } catch (error) { logger.error(error); @@ -1717,12 +1717,12 @@ const expiredOrderMessage = async ( const toBuyerExpiredOrderMessage = async ( bot: HasTelegram, user: UserDocument, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('expired_order_to_buyer', { helpGroup: process.env.HELP_GROUP }), + i18n.t('expired_order_to_buyer', { helpGroup: process.env.HELP_GROUP }) ); } catch (error) { logger.error(error); @@ -1732,12 +1732,12 @@ const toBuyerExpiredOrderMessage = async ( const toSellerExpiredOrderMessage = async ( bot: HasTelegram, user: UserDocument, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('expired_order_to_seller', { helpGroup: process.env.HELP_GROUP }), + i18n.t('expired_order_to_seller', { helpGroup: process.env.HELP_GROUP }) ); } catch (error) { logger.error(error); @@ -1748,12 +1748,12 @@ const toBuyerDidntAddInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('didnt_add_invoice', { orderId: order._id }), + i18n.t('didnt_add_invoice', { orderId: order._id }) ); } catch (error) { logger.error(error); @@ -1764,12 +1764,12 @@ const toSellerBuyerDidntAddInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('buyer_havent_add_invoice', { orderId: order._id }), + i18n.t('buyer_havent_add_invoice', { orderId: order._id }) ); } catch (error) { logger.error(error); @@ -1780,7 +1780,7 @@ const toAdminChannelBuyerDidntAddInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( @@ -1800,12 +1800,12 @@ const toSellerDidntPayInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('havent_paid_invoice', { orderId: order._id }), + i18n.t('havent_paid_invoice', { orderId: order._id }) ); } catch (error) { logger.error(error); @@ -1816,12 +1816,12 @@ const toBuyerSellerDidntPayInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('seller_havent_paid_invoice', { orderId: order._id }), + i18n.t('seller_havent_paid_invoice', { orderId: order._id }) ); } catch (error) { logger.error(error); @@ -1832,7 +1832,7 @@ const toAdminChannelSellerDidntPayInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( @@ -1854,7 +1854,7 @@ const toAdminChannelPendingPaymentSuccessMessage = async ( order: IOrder, pending: IPendingPayment, payment: PayViaPaymentRequestResult, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( @@ -1865,7 +1865,7 @@ const toAdminChannelPendingPaymentSuccessMessage = async ( attempts: pending.attempts, amount: numberFormat(order.fiat_code, order.amount), paymentSecret: payment.secret, - }), + }) ); } catch (error) { logger.error(error); @@ -1877,7 +1877,7 @@ const toBuyerPendingPaymentSuccessMessage = async ( user: UserDocument, order: IOrder, payment: PayViaPaymentRequestResult, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( @@ -1886,7 +1886,7 @@ const toBuyerPendingPaymentSuccessMessage = async ( id: order._id, amount: numberFormat(order.fiat_code, order.amount), paymentSecret: payment.secret, - }), + }) ); } catch (error) { logger.error(error); @@ -1897,7 +1897,7 @@ const toBuyerPendingPaymentFailedMessage = async ( bot: Telegraf, user: UserDocument, order: IOrder, - i18n: I18nContext, + i18n: I18nContext ) => { try { const attempts = process.env.PAYMENT_ATTEMPTS; @@ -1905,7 +1905,7 @@ const toBuyerPendingPaymentFailedMessage = async ( user.tg_id, i18n.t('pending_payment_failed', { attempts, - }), + }) ); await bot.telegram.sendMessage(user.tg_id, i18n.t('press_to_continue'), { reply_markup: { @@ -1929,7 +1929,7 @@ const toAdminChannelPendingPaymentFailedMessage = async ( user: UserDocument, order: IOrder, pending: IPendingPayment, - i18n: I18nContext, + i18n: I18nContext ) => { try { await bot.telegram.sendMessage( @@ -1938,7 +1938,7 @@ const toAdminChannelPendingPaymentFailedMessage = async ( attempts: pending.attempts, orderId: order._id, username: user.username, - }), + }) ); } catch (error) { logger.error(error); @@ -1947,7 +1947,7 @@ const toAdminChannelPendingPaymentFailedMessage = async ( const currencyNotSupportedMessage = async ( ctx: MainContext, - currencies: Array, + currencies: Array ) => { try { const currenciesStr = currencies.join(', '); @@ -1959,7 +1959,7 @@ const currencyNotSupportedMessage = async ( const notAuthorized = async ( ctx: MainContext, - tgId?: string, + tgId?: string ): Promise => { try { if (tgId) { @@ -1983,7 +1983,7 @@ const mustBeANumber = async (ctx: MainContext) => { const showConfirmationButtons = async ( ctx: MainContext, orders: Array, - commandString: string, + commandString: string ) => { try { commandString = commandString.slice(1); diff --git a/bot/modules/community/index.ts b/bot/modules/community/index.ts index 424700f3..8fd41ba1 100644 --- a/bot/modules/community/index.ts +++ b/bot/modules/community/index.ts @@ -23,7 +23,7 @@ export const configure = (bot: Telegraf) => { bot.action( /^updateCommunity_([0-9a-f]{24})$/, userMiddleware, - updateCommunityMessage, + updateCommunityMessage ); bot.action(/^editNameBtn_([0-9a-f]{24})$/, userMiddleware, async ctx => { await commands.updateCommunity(ctx, ctx.match[1], 'name'); @@ -36,7 +36,7 @@ export const configure = (bot: Telegraf) => { userMiddleware, async ctx => { await commands.updateCommunity(ctx, ctx.match[1], 'currencies'); - }, + } ); bot.action(/^editGroupBtn_([0-9a-f]{24})$/, userMiddleware, async ctx => { await commands.updateCommunity(ctx, ctx.match[1], 'group', bot); @@ -52,26 +52,22 @@ export const configure = (bot: Telegraf) => { userMiddleware, async ctx => { await commands.updateCommunity(ctx, ctx.match[1], 'disputeChannel', bot); - }, - ); - bot.action( - /^editLanguageBtn_([0-9a-f]{24})$/, - userMiddleware, - async ctx => { - await commands.updateCommunity(ctx, ctx.match[1], 'language'); } ); + bot.action(/^editLanguageBtn_([0-9a-f]{24})$/, userMiddleware, async ctx => { + await commands.updateCommunity(ctx, ctx.match[1], 'language'); + }); bot.command('findcomms', userMiddleware, commands.findCommunity); bot.action( /^communityInfo_([0-9a-f]{24})$/, userMiddleware, - actions.onCommunityInfo, + actions.onCommunityInfo ); bot.action( /^setCommunity_([0-9a-f]{24})$/, userMiddleware, - actions.onSetCommunity, + actions.onSetCommunity ); bot.action('doNothingBtn', userMiddleware, async ctx => { await ctx.deleteMessage(); @@ -80,22 +76,22 @@ export const configure = (bot: Telegraf) => { bot.action( /^deleteCommunityAskBtn_([0-9a-f]{24})$/, userMiddleware, - sureMessage, + sureMessage ); bot.action( /^withdrawEarnings_([0-9a-f]{24})$/, userMiddleware, - actions.withdrawEarnings, + actions.withdrawEarnings ); bot.action( /^deleteCommunityBtn_([0-9a-f]{24})$/, userMiddleware, - commands.deleteCommunity, + commands.deleteCommunity ); bot.action( /^changeVisibilityBtn_([0-9a-f]{24})$/, userMiddleware, - commands.changeVisibility, + commands.changeVisibility ); }; diff --git a/bot/modules/community/scenes.ts b/bot/modules/community/scenes.ts index 57c880f8..a0c8f179 100644 --- a/bot/modules/community/scenes.ts +++ b/bot/modules/community/scenes.ts @@ -46,14 +46,14 @@ export const communityWizard = new Scenes.WizardScene( try { const status = createCommunityWizardStatus( ctx.i18n, - ctx.wizard.state, + ctx.wizard.state ); if (ctx.wizard.state.currentStatusText === status!.text) return; await ctx.telegram.editMessageText( res.chat.id, res.message_id, undefined, - status!.text, + status!.text ); ctx.wizard.state.currentStatusText = status!.text; } catch (err) { @@ -87,7 +87,7 @@ export const communityWizard = new Scenes.WizardScene( await ctx.reply( ctx.i18n.t('wizard_community_success', { days: process.env.COMMUNITY_TTL, - }), + }) ); return ctx.scene.leave(); @@ -115,7 +115,7 @@ export const communityWizard = new Scenes.WizardScene( logger.error(err); return ctx.scene.leave(); } - }, + } ); const createCommunitySteps = { @@ -147,7 +147,7 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); }; @@ -156,23 +156,25 @@ const createCommunitySteps = { }, async language(ctx: CommunityContext) { const prompt = await createCommunityPrompts.language(ctx); - + ctx.wizard.state.handler = async (ctx: CommunityContext) => { const text = ctx?.message?.text; if (!text) { await ctx.deleteMessage(); return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); } - + ctx.wizard.state.error = null; const lang = text.trim().toLowerCase(); if (!isValidLanguage(lang)) { ctx.telegram.deleteMessage(ctx.chat!.id, ctx.message!.message_id); - ctx.wizard.state.error = ctx.i18n.t('wizard_community_invalid_language'); + ctx.wizard.state.error = ctx.i18n.t( + 'wizard_community_invalid_language' + ); return await ctx.wizard.state.updateUI(); } - + ctx.wizard.state.language = lang; await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( @@ -200,7 +202,7 @@ const createCommunitySteps = { if (currencies.length > max) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); ctx.wizard.state.error = ctx.i18n.t('max_allowed', { max }); return await ctx.wizard.state.updateUI(); @@ -209,7 +211,7 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); }; @@ -234,7 +236,7 @@ const createCommunitySteps = { if (!isGroupOk.success) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); await wizardCommunityWrongPermission(ctx, group, isGroupOk.message); @@ -245,7 +247,7 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); } catch (error: any) { @@ -269,10 +271,10 @@ const createCommunitySteps = { if (chan.length > 2) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); ctx.wizard.state.error = ctx.i18n.t( - 'wizard_community_one_or_two_channels', + 'wizard_community_one_or_two_channels' ); return await ctx.wizard.state.updateUI(); } @@ -282,7 +284,7 @@ const createCommunitySteps = { if (!isGroupOk.success) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); await wizardCommunityWrongPermission(ctx, chan[0], isGroupOk.message); @@ -298,7 +300,7 @@ const createCommunitySteps = { if (!isGroupOk.success) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); await wizardCommunityWrongPermission(ctx, chan[0], isGroupOk.message); @@ -308,7 +310,7 @@ const createCommunitySteps = { if (!isGroupOk.success) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); await wizardCommunityWrongPermission(ctx, chan[1], isGroupOk.message); @@ -329,11 +331,11 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); return await ctx.telegram.deleteMessage( prompt.chat.id, - prompt.message_id, + prompt.message_id ); }; const prompt = await createCommunityPrompts.channels(ctx); @@ -350,7 +352,7 @@ const createCommunitySteps = { if (isNaN(num)) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); ctx.wizard.state.error = ctx.i18n.t('not_number'); return await ctx.wizard.state.updateUI(); @@ -358,7 +360,7 @@ const createCommunitySteps = { if (num < 0 || num > 100) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); ctx.wizard.state.error = ctx.i18n.t('wizard_community_wrong_percent'); return await ctx.wizard.state.updateUI(); @@ -367,11 +369,11 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); return await ctx.telegram.deleteMessage( prompt.chat.id, - prompt.message_id, + prompt.message_id ); }; const prompt = await createCommunityPrompts.fee(ctx); @@ -400,10 +402,10 @@ const createCommunitySteps = { } else { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); ctx.wizard.state.error = ctx.i18n.t( - 'wizard_community_must_enter_names', + 'wizard_community_must_enter_names' ); return await ctx.wizard.state.updateUI(); } @@ -412,11 +414,11 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); return await ctx.telegram.deleteMessage( prompt.chat.id, - prompt.message_id, + prompt.message_id ); }; const prompt = await createCommunityPrompts.solvers(ctx); @@ -435,7 +437,7 @@ const createCommunitySteps = { if (!isGroupOk.success) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); await wizardCommunityWrongPermission(ctx, channel, isGroupOk.message); @@ -445,11 +447,11 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id, + ctx.message!.message_id ); return await ctx.telegram.deleteMessage( prompt.chat.id, - prompt.message_id, + prompt.message_id ); }; const prompt = await createCommunityPrompts.disputeChannel(ctx); @@ -509,7 +511,7 @@ export const updateNameCommunityWizard = new Scenes.WizardScene( if (name.length > length) { ctx.deleteMessage(); return await ctx.reply( - ctx.i18n.t('wizard_community_too_long_name', { length }), + ctx.i18n.t('wizard_community_too_long_name', { length }) ); } const { community } = ctx.wizard.state; @@ -523,7 +525,7 @@ export const updateNameCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - }, + } ); export const updateGroupCommunityWizard = new Scenes.WizardScene( @@ -554,7 +556,7 @@ export const updateGroupCommunityWizard = new Scenes.WizardScene( return await wizardCommunityWrongPermission( ctx, group, - isGroupOk.message, + isGroupOk.message ); } @@ -567,7 +569,7 @@ export const updateGroupCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - }, + } ); export const updateCurrenciesCommunityWizard = new Scenes.WizardScene( @@ -609,7 +611,7 @@ export const updateCurrenciesCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - }, + } ); export const updateChannelsCommunityWizard = new Scenes.WizardScene( @@ -649,7 +651,7 @@ export const updateChannelsCommunityWizard = new Scenes.WizardScene( return await wizardCommunityWrongPermission( ctx, chan[0], - isGroupOk.message, + isGroupOk.message ); } @@ -665,7 +667,7 @@ export const updateChannelsCommunityWizard = new Scenes.WizardScene( return await wizardCommunityWrongPermission( ctx, chan[0], - isGroupOk.message, + isGroupOk.message ); } @@ -675,7 +677,7 @@ export const updateChannelsCommunityWizard = new Scenes.WizardScene( return await wizardCommunityWrongPermission( ctx, chan[1], - isGroupOk.message, + isGroupOk.message ); } @@ -705,7 +707,7 @@ export const updateChannelsCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - }, + } ); export const updateSolversCommunityWizard = new Scenes.WizardScene( @@ -759,7 +761,7 @@ export const updateSolversCommunityWizard = new Scenes.WizardScene( await ctx.reply( ctx.i18n.t('users_added', { users: botUsers.join(', '), - }), + }) ); const { community } = ctx.wizard.state; @@ -769,7 +771,7 @@ export const updateSolversCommunityWizard = new Scenes.WizardScene( if (notBotUsers.length) await ctx.reply( - ctx.i18n.t('users_not_added', { users: notBotUsers.join(', ') }), + ctx.i18n.t('users_not_added', { users: notBotUsers.join(', ') }) ); return ctx.scene.leave(); @@ -777,7 +779,7 @@ export const updateSolversCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - }, + } ); export const updateFeeCommunityWizard = new Scenes.WizardScene( @@ -822,7 +824,7 @@ export const updateFeeCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - }, + } ); export const updateDisputeChannelCommunityWizard = new Scenes.WizardScene( @@ -858,7 +860,7 @@ export const updateDisputeChannelCommunityWizard = new Scenes.WizardScene( return await wizardCommunityWrongPermission( ctx, channel, - isGroupOk.message, + isGroupOk.message ); } @@ -871,7 +873,7 @@ export const updateDisputeChannelCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - }, + } ); export const updateLanguageCommunityWizard = new Scenes.WizardScene( @@ -879,7 +881,8 @@ export const updateLanguageCommunityWizard = new Scenes.WizardScene( async (ctx: CommunityContext) => { try { const { community } = ctx.wizard.state; - let message = ctx.i18n.t('language') + ': ' + (community.language || 'en') + '\n\n'; + let message = + ctx.i18n.t('language') + ': ' + (community.language || 'en') + '\n\n'; message += ctx.i18n.t('wizard_community_enter_language') + '\n\n'; message += ctx.i18n.t('wizard_to_exit'); await ctx.reply(message); @@ -921,7 +924,7 @@ export const addEarningsInvoiceWizard = new Scenes.WizardScene( if (community.earnings === 0) return ctx.scene.leave(); await ctx.reply( - ctx.i18n.t('send_me_lninvoice', { amount: community.earnings }), + ctx.i18n.t('send_me_lninvoice', { amount: community.earnings }) ); return ctx.wizard.next(); @@ -971,5 +974,5 @@ export const addEarningsInvoiceWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - }, + } ); diff --git a/bot/ordersActions.ts b/bot/ordersActions.ts index 4335742a..b3a87ae6 100644 --- a/bot/ordersActions.ts +++ b/bot/ordersActions.ts @@ -70,26 +70,26 @@ const createOrder = async ( tgChatId, tgOrderMessage, community_id, - }: CreateOrderArguments, + }: CreateOrderArguments ) => { try { amount = Math.floor(amount); let isPublic = true; - + // Use community language if community_id is provided let descriptionI18n = i18n; - + if (community_id) { const community = await Community.findById(community_id); if (community == null) throw new Error('community is null'); isPublic = community.public; - + // Get community language for description if (community.language) { descriptionI18n = new I18n({ defaultLanguageOnMissing: true, locale: community.language, - directory: 'locales' + directory: 'locales', }).createContext(community.language); } } @@ -215,7 +215,7 @@ const buildDescription = ( priceFromAPI, currency, isGoldenHoneyBadger, - }: BuildDescriptionArguments, + }: BuildDescriptionArguments ) => { try { const action = type === 'sell' ? i18n.t('selling') : i18n.t('buying'); @@ -286,7 +286,7 @@ const buildDescription = ( const getOrder = async ( ctx: MainContext, user: UserDocument, - orderId: string, + orderId: string ) => { try { if (!ObjectId.isValid(orderId)) { diff --git a/locales/de.yaml b/locales/de.yaml index fc7eca4e..e25b112a 100644 --- a/locales/de.yaml +++ b/locales/de.yaml @@ -582,11 +582,11 @@ community_admin_help: | # commands /setnpub <npub> - Configure Nostr community's public key. - /setlanguage <lang> - Configure community's language for published messages. + /setlanguage <lang> - Konfiguriere die Sprache der Community für veröffentlichte Nachrichten. community_npub_updated: You added the community's pubkey ${npub} successfully! -community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' -wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' +community_language_updated: Du hast die Sprache der Community erfolgreich auf ${language} aktualisiert! +wizard_community_enter_language: 'Gib den Sprachcode für deine Community ein (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Ungültiger Sprachcode. Bitte gib einen der folgenden ein - en, es, fr, de, it, pt, ru, uk, ko, fa' # END modules/community # START modules/orders diff --git a/locales/fa.yaml b/locales/fa.yaml index f6a65478..88b5d03a 100644 --- a/locales/fa.yaml +++ b/locales/fa.yaml @@ -565,10 +565,10 @@ community_admin_help: | # commands /setnpub <npub> - کلید عمومی جامعه را پیکربندی کنید. رویدادهای ناستر با این کلید عمومی برچسب‌گذاری می‌شوند. - /setlanguage <lang> - Configure community's language for published messages. -community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' -wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' + /setlanguage <lang> - زبان کامیونیتی را برای پیام‌های منتشرشده پیکربندی کنید. +community_language_updated: شما زبان کامیونیتی را با موفقیت به ${language} به‌روزرسانی کردید! +wizard_community_enter_language: 'کد زبان کامیونیتی خود را وارد کنید (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'کد زبان نامعتبر است. لطفاً یکی از موارد زیر را وارد کنید - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: شما کلیدعمومی کامیونیتی ${npub} را با موفقیت اضافه کردید! # END modules/community diff --git a/locales/it.yaml b/locales/it.yaml index 60fdbb54..f4de2052 100644 --- a/locales/it.yaml +++ b/locales/it.yaml @@ -579,10 +579,10 @@ community_admin_help: | # commands /setnpub <npub> - Configure community's public key. - /setlanguage <lang> - Configure community's language for published messages. -community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' -wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' + /setlanguage <lang> - Configura la lingua della community per i messaggi pubblicati. +community_language_updated: Hai aggiornato con successo la lingua della community a ${language}! +wizard_community_enter_language: 'Inserisci il codice lingua per la tua community (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Codice lingua non valido. Inserisci uno dei seguenti - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/locales/pt.yaml b/locales/pt.yaml index eca342b5..f0611c0c 100644 --- a/locales/pt.yaml +++ b/locales/pt.yaml @@ -581,10 +581,10 @@ community_admin_help: | # commands /setnpub <npub> - Configure community's public key. - /setlanguage <lang> - Configure community's language for published messages. -community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' -wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' + /setlanguage <lang> - Configure o idioma da comunidade para mensagens publicadas. +community_language_updated: Você atualizou o idioma da comunidade para ${language} com sucesso! +wizard_community_enter_language: 'Insira o código de idioma da sua comunidade (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Código de idioma inválido. Insira um dos seguintes - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/locales/ru.yaml b/locales/ru.yaml index a4e320cf..463bbcd4 100644 --- a/locales/ru.yaml +++ b/locales/ru.yaml @@ -582,10 +582,10 @@ community_admin_help: | # commands /setnpub <npub> - Configure community's Nostr public key. - /setlanguage <lang> - Configure community's language for published messages. -community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' -wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' + /setlanguage <lang> - Настройте язык сообщества для публикуемых сообщений. +community_language_updated: Вы успешно обновили язык сообщества на ${language}! +wizard_community_enter_language: 'Введите код языка для вашего сообщества (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Недопустимый код языка. Пожалуйста, введите один из следующих - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/locales/uk.yaml b/locales/uk.yaml index 75c835cf..0b139581 100644 --- a/locales/uk.yaml +++ b/locales/uk.yaml @@ -578,10 +578,10 @@ community_admin_help: | # commands /setnpub <npub> - Configure community's Nostr public key. - /setlanguage <lang> - Configure community's language for published messages. -community_language_updated: You updated the community's language to ${language} successfully! -wizard_community_enter_language: 'Enter the language code for your community (en, es, fr, de, it, pt, ru, uk, ko, fa)' -wizard_community_invalid_language: 'Invalid language code. Please enter one of the following - en, es, fr, de, it, pt, ru, uk, ko, fa' + /setlanguage <lang> - Налаштуйте мову спільноти для опублікованих повідомлень. +community_language_updated: Ви успішно оновили мову спільноти на ${language}! +wizard_community_enter_language: 'Введіть код мови для вашої спільноти (en, es, fr, de, it, pt, ru, uk, ko, fa)' +wizard_community_invalid_language: 'Недійсний код мови. Будь ласка, введіть один із таких - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! # END modules/community diff --git a/models/community.ts b/models/community.ts index 4d69a30b..70abfe9c 100644 --- a/models/community.ts +++ b/models/community.ts @@ -49,7 +49,7 @@ export interface ICommunity extends Document { created_at: Date; nostr_public_key: string; warning_messages_count: number; - language: string; + language: string; } const CommunitySchema = new Schema({ @@ -83,17 +83,28 @@ const CommunitySchema = new Schema({ created_at: { type: Date, default: Date.now }, nostr_public_key: { type: String }, warning_messages_count: { type: Number, default: 0 }, - language: { - type: String, - default: 'en', - validate: { - validator: function(v: string) { - const supportedLanguages = ['en', 'es', 'fr', 'de', 'it', 'pt', 'ru', 'uk', 'ko', 'fa']; // Add all supported languages - return supportedLanguages.includes(v); - }, - message: 'Language code {VALUE} is not supported' - } - }, + language: { + type: String, + default: 'en', + validate: { + validator: function (v: string) { + const supportedLanguages = [ + 'en', + 'es', + 'fr', + 'de', + 'it', + 'pt', + 'ru', + 'uk', + 'ko', + 'fa', + ]; // Add all supported languages + return supportedLanguages.includes(v); + }, + message: 'Language code {VALUE} is not supported', + }, + }, }); export default mongoose.model('Community', CommunitySchema); From ade9e360b6529da238cfb30af586ae19dbee7553 Mon Sep 17 00:00:00 2001 From: Anyitechs Date: Thu, 11 Sep 2025 14:18:19 +0100 Subject: [PATCH 4/6] f fix CI errors --- bot/messages.ts | 278 ++++++++++++++++---------------- bot/modules/community/index.ts | 18 +-- bot/modules/community/scenes.ts | 94 +++++------ bot/ordersActions.ts | 6 +- 4 files changed, 198 insertions(+), 198 deletions(-) diff --git a/bot/messages.ts b/bot/messages.ts index 177fd118..19b5a692 100644 --- a/bot/messages.ts +++ b/bot/messages.ts @@ -53,7 +53,7 @@ const startMessage = async (ctx: MainContext) => { const initBotErrorMessage = async ( ctx: MainContext, bot: MainContext, - user: UserDocument + user: UserDocument, ) => { // Correct way to handle errors: https://github.com/telegraf/telegraf/issues/1757 await bot.telegram @@ -72,7 +72,7 @@ const invoicePaymentRequestMessage = async ( user: UserDocument, order: IOrder, i18n: I18nContext, - buyer: UserDocument + buyer: UserDocument, ) => { try { const currencyObject = getCurrency(order.fiat_code); @@ -126,7 +126,7 @@ const showQRCodeMessage = async ( ctx: MainContext, order: IOrder, request: string, - user: UserDocument + user: UserDocument, ) => { try { // @@ -146,7 +146,7 @@ const showQRCodeMessage = async ( if (error instanceof ImageProcessingError) { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('image_processing_error') + ctx.i18n.t('image_processing_error'), ); } } @@ -157,7 +157,7 @@ const pendingSellMessage = async ( user: UserDocument, order: IOrder, channel: string, - i18n: I18nContext + i18n: I18nContext, ) => { try { const orderExpirationWindow = @@ -170,7 +170,7 @@ const pendingSellMessage = async ( }); const imageBase64 = await imageCache.convertImageToBase64( - order.random_image + order.random_image, ); await ctx.telegram.sendMediaGroup(user.tg_id, [ @@ -185,7 +185,7 @@ const pendingSellMessage = async ( await ctx.telegram.sendMessage( user.tg_id, i18n.t('cancel_order_cmd', { orderId: order._id }), - { parse_mode: 'Markdown' } + { parse_mode: 'Markdown' }, ); if (order.is_golden_honey_badger === true && order.type === 'sell') { @@ -196,7 +196,7 @@ const pendingSellMessage = async ( if (error instanceof ImageProcessingError) { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('image_processing_error') + i18n.t('image_processing_error'), ); } } @@ -207,7 +207,7 @@ const pendingBuyMessage = async ( user: UserDocument, order: IOrder, channel: string, - i18n: I18nContext + i18n: I18nContext, ) => { try { const orderExpirationWindow = @@ -217,12 +217,12 @@ const pendingBuyMessage = async ( i18n.t('pending_buy', { channel, orderExpirationWindow: Math.round(orderExpirationWindow), - }) + }), ); await bot.telegram.sendMessage( user.tg_id, i18n.t('cancel_order_cmd', { orderId: order._id }), - { parse_mode: 'MarkdownV2' } + { parse_mode: 'MarkdownV2' }, ); } catch (error) { logger.error(error); @@ -254,7 +254,7 @@ const minimunAmountInvoiceMessage = async (ctx: MainContext) => { await ctx.reply( ctx.i18n.t('min_invoice_amount', { minPaymentAmount: process.env.MIN_PAYMENT_AMT, - }) + }), ); } catch (error) { logger.error(error); @@ -283,14 +283,14 @@ const expiredInvoiceOnPendingMessage = async ( bot: HasTelegram, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage(user.tg_id, i18n.t('invoice_expired_long')); await bot.telegram.sendMessage( user.tg_id, i18n.t('setinvoice_cmd_order', { orderId: order._id }), - { parse_mode: 'MarkdownV2' } + { parse_mode: 'MarkdownV2' }, ); } catch (error) { logger.error(error); @@ -310,7 +310,7 @@ const invoiceMustBeLargerMessage = async (ctx: MainContext) => { await ctx.reply( ctx.i18n.t('invoice_must_be_larger_error', { minInvoice: process.env.MIN_PAYMENT_AMT, - }) + }), ); } catch (error) { logger.error(error); @@ -360,7 +360,7 @@ const invoiceInvalidMessage = async (ctx: MainContext) => { const invalidOrderMessage = async ( ctx: MainContext, bot: HasTelegram, - user: UserDocument + user: UserDocument, ) => { try { await bot.telegram.sendMessage(user.tg_id, ctx.i18n.t('order_id_invalid')); @@ -373,12 +373,12 @@ const invalidTypeOrderMessage = async ( ctx: MainContext, bot: HasTelegram, user: UserDocument, - type: IOrder['type'] + type: IOrder['type'], ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('order_invalid_type', { type }) + ctx.i18n.t('order_invalid_type', { type }), ); } catch (error) { logger.error(error); @@ -388,12 +388,12 @@ const invalidTypeOrderMessage = async ( const alreadyTakenOrderMessage = async ( ctx: MainContext, bot: HasTelegram, - user: UserDocument + user: UserDocument, ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('order_already_taken') + ctx.i18n.t('order_already_taken'), ); } catch (error) { logger.error(error); @@ -403,7 +403,7 @@ const alreadyTakenOrderMessage = async ( const invalidDataMessage = async ( ctx: MainContext, bot: HasTelegram, - user: UserDocument + user: UserDocument, ) => { try { await bot.telegram.sendMessage(user.tg_id, ctx.i18n.t('invalid_data')); @@ -415,7 +415,7 @@ const invalidDataMessage = async ( const genericErrorMessage = async ( bot: HasTelegram, user: UserDocument, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage(user.tg_id, i18n.t('generic_error')); @@ -428,7 +428,7 @@ const beginTakeBuyMessage = async ( ctx: MainContext, bot: HasTelegram, seller: UserDocument, - order: IOrder + order: IOrder, ) => { try { const expirationTime = @@ -436,7 +436,7 @@ const beginTakeBuyMessage = async ( const caption = ctx.i18n.t('begin_take_buy', { expirationTime }); const imageBase64 = await imageCache.convertImageToBase64( - order.random_image + order.random_image, ); await bot.telegram.sendMediaGroup(seller.tg_id, [ @@ -468,7 +468,7 @@ const beginTakeBuyMessage = async ( if (error instanceof ImageProcessingError) { await bot.telegram.sendMessage( seller.tg_id, - ctx.i18n.t('image_processing_error') + ctx.i18n.t('image_processing_error'), ); } } @@ -481,7 +481,7 @@ const showHoldInvoiceMessage = async ( fiatCode: IOrder['fiat_code'], fiatAmount: IOrder['fiat_amount'], randomImage: string, - isGoldenHoneyBadger: boolean = false + isGoldenHoneyBadger: boolean = false, ) => { try { const currency = getCurrency(fiatCode); @@ -495,7 +495,7 @@ const showHoldInvoiceMessage = async ( amount: numberFormat(fiatCode, amount), fiatAmount: numberFormat(fiatCode, fiatAmount!), currency: currencySymbol, - }) + }), ); if (isGoldenHoneyBadger) { @@ -527,12 +527,12 @@ const onGoingTakeBuyMessage = async ( order: IOrder, i18nBuyer: I18nContext, i18nSeller: I18nContext, - rate: string + rate: string, ) => { try { await bot.telegram.sendMessage( seller.tg_id, - i18nSeller.t('payment_received') + i18nSeller.t('payment_received'), ); const holdInvoiceExpiration = holdInvoiceExpirationInSecs(); const orderExpiration = @@ -550,7 +550,7 @@ const onGoingTakeBuyMessage = async ( expirationTime, rate, days: ageInDays, - }) + }), ); await bot.telegram.sendMessage(buyer.tg_id, order._id, { reply_markup: { @@ -568,7 +568,7 @@ const beginTakeSellMessage = async ( ctx: MainContext, bot: HasTelegram, buyer: UserDocument, - order: IOrder + order: IOrder, ) => { try { const holdInvoiceExpiration = holdInvoiceExpirationInSecs(); @@ -582,7 +582,7 @@ const beginTakeSellMessage = async ( await bot.telegram.sendMessage( buyer.tg_id, ctx.i18n.t('you_took_someone_order', { expirationTime }), - { parse_mode: 'MarkdownV2' } + { parse_mode: 'MarkdownV2' }, ); await bot.telegram.sendMessage(buyer.tg_id, order._id, { reply_markup: { @@ -608,7 +608,7 @@ const onGoingTakeSellMessage = async ( buyerUser: UserDocument, order: IOrder, i18nBuyer: I18nContext, - i18nSeller: I18nContext + i18nSeller: I18nContext, ) => { try { await bot.telegram.sendMessage( @@ -619,12 +619,12 @@ const onGoingTakeSellMessage = async ( sellerUsername: sellerUser.username, fiatAmount: numberFormat(order.fiat_code, order.fiat_amount!), paymentMethod: order.payment_method, - }) + }), ); await bot.telegram.sendMessage( buyerUser.tg_id, i18nBuyer.t('fiatsent_order_cmd'), - { parse_mode: 'MarkdownV2' } + { parse_mode: 'MarkdownV2' }, ); await bot.telegram.sendMessage( sellerUser.tg_id, @@ -634,7 +634,7 @@ const onGoingTakeSellMessage = async ( paymentMethod: order.payment_method, currency: order.fiat_code, buyerUsername: buyerUser.username, - }) + }), ); } catch (error) { logger.error(error); @@ -645,12 +645,12 @@ const takeSellWaitingSellerToPayMessage = async ( ctx: MainContext, bot: HasTelegram, buyerUser: UserDocument, - order: IOrder + order: IOrder, ) => { try { await bot.telegram.sendMessage( buyerUser.tg_id, - ctx.i18n.t('waiting_seller_to_pay', { orderId: order._id }) + ctx.i18n.t('waiting_seller_to_pay', { orderId: order._id }), ); } catch (error) { logger.error(error); @@ -662,16 +662,16 @@ const releasedSatsMessage = async ( sellerUser: UserDocument, buyerUser: UserDocument, i18nBuyer: I18nContext, - i18nSeller: I18nContext + i18nSeller: I18nContext, ) => { try { await bot.telegram.sendMessage( sellerUser.tg_id, - i18nSeller.t('sell_success', { buyerUsername: buyerUser.username }) + i18nSeller.t('sell_success', { buyerUsername: buyerUser.username }), ); await bot.telegram.sendMessage( buyerUser.tg_id, - i18nBuyer.t('funds_released', { sellerUsername: sellerUser.username }) + i18nBuyer.t('funds_released', { sellerUsername: sellerUser.username }), ); } catch (error) { logger.error(error); @@ -682,7 +682,7 @@ const rateUserMessage = async ( bot: HasTelegram, caller: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { const starButtons = []; @@ -733,7 +733,7 @@ const publishBuyOrderMessage = async ( user: UserDocument, order: IOrder, i18n: I18nContext, - messageToUser: boolean = false + messageToUser: boolean = false, ) => { try { let publishMessage = `⚡️🍊⚡️\n${order.description}\n`; @@ -786,7 +786,7 @@ const publishSellOrderMessage = async ( user: UserDocument, order: IOrder, i18n: I18nContext, - messageToUser?: boolean + messageToUser?: boolean, ) => { try { let publishMessage = `⚡️🍊⚡️\n${order.description}\n`; @@ -845,7 +845,7 @@ const checkOrderMessage = async ( ctx: MainContext, order: IOrder, buyer: UserDocument | null, - seller: UserDocument | null + seller: UserDocument | null, ) => { try { let message = getDetailedOrder(ctx.i18n, order, buyer, seller); @@ -861,7 +861,7 @@ const checkInvoiceMessage = async ( ctx: MainContext, isConfirmed: boolean, isCanceled: boolean, - isHeld: boolean + isHeld: boolean, ) => { try { if (isConfirmed) { @@ -931,14 +931,14 @@ const privacyMessage = async (ctx: MainContext) => { const mustBeGreatherEqThan = async ( ctx: MainContext, fieldName: string, - qty: number + qty: number, ) => { try { await ctx.reply( ctx.i18n.t('must_be_gt_or_eq', { fieldName, qty, - }) + }), ); } catch (error) { logger.error(error); @@ -949,7 +949,7 @@ const bannedUserErrorMessage = async (ctx: MainContext, user: UserDocument) => { try { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('you_have_been_banned') + ctx.i18n.t('you_have_been_banned'), ); } catch (error) { logger.error(error); @@ -958,12 +958,12 @@ const bannedUserErrorMessage = async (ctx: MainContext, user: UserDocument) => { const userOrderIsBlockedByUserTaker = async ( ctx: MainContext, - user: UserDocument + user: UserDocument, ) => { try { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('user_order_is_blocked_by_user_taker') + ctx.i18n.t('user_order_is_blocked_by_user_taker'), ); } catch (error) { logger.error(error); @@ -972,12 +972,12 @@ const userOrderIsBlockedByUserTaker = async ( const userTakerIsBlockedByUserOrder = async ( ctx: MainContext, - user: UserDocument + user: UserDocument, ) => { try { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('user_taker_is_blocked_by_user_order') + ctx.i18n.t('user_taker_is_blocked_by_user_order'), ); } catch (error) { logger.error(error); @@ -989,25 +989,25 @@ const fiatSentMessages = async ( buyer: UserDocument, seller: UserDocument, i18nBuyer: I18nContext, - i18nSeller: I18nContext + i18nSeller: I18nContext, ) => { try { await ctx.telegram.sendMessage( buyer.tg_id, i18nBuyer.t('I_told_seller_you_sent_fiat', { sellerUsername: seller.username, - }) + }), ); await ctx.telegram.sendMessage( seller.tg_id, i18nSeller.t('buyer_told_me_that_sent_fiat', { buyerUsername: buyer.username, - }) + }), ); await ctx.telegram.sendMessage( seller.tg_id, i18nSeller.t('release_order_cmd'), - { parse_mode: 'Markdown' } + { parse_mode: 'Markdown' }, ); } catch (error) { logger.error(error); @@ -1016,12 +1016,12 @@ const fiatSentMessages = async ( const orderOnfiatSentStatusMessages = async ( ctx: MainContext, - user: UserDocument + user: UserDocument, ) => { try { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('you_have_orders_waiting') + ctx.i18n.t('you_have_orders_waiting'), ); } catch (error) { logger.error(error); @@ -1073,7 +1073,7 @@ const addInvoiceMessage = async ( bot: HasTelegram, buyer: UserDocument, seller: UserDocument, - order: IOrder + order: IOrder, ) => { try { await bot.telegram.sendMessage( @@ -1084,12 +1084,12 @@ const addInvoiceMessage = async ( sellerUsername: seller.username, fiatAmount: numberFormat(order.fiat_code, order.fiat_amount!), paymentMethod: order.payment_method, - }) + }), ); await bot.telegram.sendMessage( buyer.tg_id, ctx.i18n.t('fiatsent_order_cmd'), - { parse_mode: 'MarkdownV2' } + { parse_mode: 'MarkdownV2' }, ); } catch (error) { logger.error(error); @@ -1101,7 +1101,7 @@ const sendBuyerInfo2SellerMessage = async ( buyer: UserDocument, seller: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( @@ -1112,7 +1112,7 @@ const sendBuyerInfo2SellerMessage = async ( buyerUsername: buyer.username, fiatAmount: numberFormat(order.fiat_code, order.fiat_amount!), paymentMethod: order.payment_method, - }) + }), ); } catch (error) { logger.error(error); @@ -1122,12 +1122,12 @@ const sendBuyerInfo2SellerMessage = async ( const cantTakeOwnOrderMessage = async ( ctx: MainContext, bot: HasTelegram, - user: UserDocument + user: UserDocument, ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('cant_take_own_order') + ctx.i18n.t('cant_take_own_order'), ); } catch (error) { logger.error(error); @@ -1139,7 +1139,7 @@ const notLightningInvoiceMessage = async (ctx: MainContext, order: IOrder) => { await ctx.reply(ctx.i18n.t('send_me_lninvoice', { amount: order.amount })); await ctx.reply( ctx.i18n.t('setinvoice_cmd_order', { orderId: order._id }), - { parse_mode: 'MarkdownV2' } + { parse_mode: 'MarkdownV2' }, ); } catch (error) { logger.error(error); @@ -1157,14 +1157,14 @@ const notOrdersMessage = async (ctx: MainContext) => { const notRateForCurrency = async ( bot: HasTelegram, user: UserDocument, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( user.tg_id, i18n.t('not_rate_for_currency', { fiatRateProvider: process.env.FIAT_RATE_NAME, - }) + }), ); } catch (error) { logger.error(error); @@ -1230,12 +1230,12 @@ const successCancelOrderMessage = async ( ctx: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('cancel_success', { orderId: order._id }) + i18n.t('cancel_success', { orderId: order._id }), ); } catch (error) { logger.error(error); @@ -1246,12 +1246,12 @@ const counterPartyCancelOrderMessage = async ( ctx: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('order_cancelled_by_counterparty', { orderId: order._id }) + i18n.t('order_cancelled_by_counterparty', { orderId: order._id }), ); } catch (error) { logger.error(error); @@ -1270,12 +1270,12 @@ const successCancelOrderByAdminMessage = async ( ctx: MainContext, bot: Telegraf, user: UserDocument, - order: IOrder + order: IOrder, ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('order_cancelled_by_admin', { orderId: order._id }) + ctx.i18n.t('order_cancelled_by_admin', { orderId: order._id }), ); } catch (error) { logger.error(error); @@ -1294,12 +1294,12 @@ const successCompleteOrderByAdminMessage = async ( ctx: MainContext, bot: HasTelegram, user: UserDocument, - order: IOrder + order: IOrder, ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('order_completed_by_admin', { orderId: order._id }) + ctx.i18n.t('order_completed_by_admin', { orderId: order._id }), ); } catch (error) { logger.error(error); @@ -1308,12 +1308,12 @@ const successCompleteOrderByAdminMessage = async ( const shouldWaitCooperativeCancelMessage = async ( ctx: MainContext, - user: UserDocument + user: UserDocument, ) => { try { await ctx.telegram.sendMessage( user.tg_id, - ctx.i18n.t('have_to_wait_for_counterpart') + ctx.i18n.t('have_to_wait_for_counterpart'), ); } catch (error) { logger.error(error); @@ -1324,12 +1324,12 @@ const okCooperativeCancelMessage = async ( ctx: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('ok_cooperativecancel', { orderId: order._id }) + i18n.t('ok_cooperativecancel', { orderId: order._id }), ); } catch (error) { logger.error(error); @@ -1339,12 +1339,12 @@ const okCooperativeCancelMessage = async ( const refundCooperativeCancelMessage = async ( ctx: MainContext, user: UserDocument, - i18n: I18nContext + i18n: I18nContext, ) => { try { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('refund_cooperativecancel') + i18n.t('refund_cooperativecancel'), ); } catch (error) { logger.error(error); @@ -1353,11 +1353,11 @@ const refundCooperativeCancelMessage = async ( const initCooperativeCancelMessage = async ( ctx: MainContext, - order: IOrder + order: IOrder, ) => { try { await ctx.reply( - ctx.i18n.t('init_cooperativecancel', { orderId: order._id }) + ctx.i18n.t('init_cooperativecancel', { orderId: order._id }), ); } catch (error) { logger.error(error); @@ -1368,17 +1368,17 @@ const counterPartyWantsCooperativeCancelMessage = async ( ctx: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await ctx.telegram.sendMessage( user.tg_id, - i18n.t('counterparty_wants_cooperativecancel', { orderId: order._id }) + i18n.t('counterparty_wants_cooperativecancel', { orderId: order._id }), ); await ctx.telegram.sendMessage( user.tg_id, i18n.t('cancel_order_cmd', { orderId: order._id }), - { parse_mode: 'MarkdownV2' } + { parse_mode: 'MarkdownV2' }, ); } catch (error) { logger.error(error); @@ -1388,7 +1388,7 @@ const counterPartyWantsCooperativeCancelMessage = async ( const invoicePaymentFailedMessage = async ( bot: HasTelegram, user: UserDocument, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( @@ -1396,7 +1396,7 @@ const invoicePaymentFailedMessage = async ( i18n.t('invoice_payment_failed', { pendingPaymentWindow: process.env.PENDING_PAYMENT_WINDOW, attempts: process.env.PAYMENT_ATTEMPTS, - }) + }), ); } catch (error) { logger.error(error); @@ -1406,12 +1406,12 @@ const invoicePaymentFailedMessage = async ( const userCantTakeMoreThanOneWaitingOrderMessage = async ( ctx: MainContext, bot: MainContext, - user: UserDocument + user: UserDocument, ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('cant_take_more_orders') + ctx.i18n.t('cant_take_more_orders'), ); } catch (error) { logger.error(error); @@ -1429,7 +1429,7 @@ const sellerPaidHoldMessage = async (ctx: MainContext, user: UserDocument) => { const showInfoMessage = async ( ctx: MainContext, user: UserDocument, - config: IConfig + config: IConfig, ) => { try { // user info @@ -1466,7 +1466,7 @@ const showInfoMessage = async ( }), { parse_mode: 'MarkdownV2', - } + }, ); } catch (error) { logger.error(error); @@ -1477,14 +1477,14 @@ const buyerReceivedSatsMessage = async ( bot: HasTelegram, buyerUser: UserDocument, sellerUser: UserDocument, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( buyerUser.tg_id, i18n.t('your_purchase_is_completed', { sellerUsername: sellerUser.username, - }) + }), ); } catch (error) { logger.error(error); @@ -1493,7 +1493,7 @@ const buyerReceivedSatsMessage = async ( const listCurrenciesResponse = async ( ctx: MainContext, - currencies: Array + currencies: Array, ) => { try { let response = `Code | Name |\n`; @@ -1509,12 +1509,12 @@ const listCurrenciesResponse = async ( const priceApiFailedMessage = async ( ctx: MainContext, bot: HasTelegram, - user: UserDocument + user: UserDocument, ) => { try { await bot.telegram.sendMessage( user.tg_id, - ctx.i18n.t('problem_getting_price') + ctx.i18n.t('problem_getting_price'), ); } catch (error) { logger.error(error); @@ -1524,14 +1524,14 @@ const priceApiFailedMessage = async ( const updateUserSettingsMessage = async ( ctx: MainContext, field: string, - newState: string + newState: string, ) => { try { await ctx.reply( ctx.i18n.t('update_user_setting', { field, newState, - }) + }), ); } catch (error) { logger.error(error); @@ -1557,7 +1557,7 @@ const invalidRangeWithAmount = async (ctx: MainContext) => { const tooManyPendingOrdersMessage = async ( ctx: MainContext, user: UserDocument, - i18n: I18nContext + i18n: I18nContext, ) => { try { ctx.telegram.sendMessage(user.tg_id, i18n.t('too_many_pending_orders')); @@ -1570,7 +1570,7 @@ const wizardAddInvoiceInitMessage = async ( ctx: MainContext, order: IOrder, currency: string, - expirationTime: number + expirationTime: number, ) => { try { await ctx.reply( @@ -1579,7 +1579,7 @@ const wizardAddInvoiceInitMessage = async ( satsAmount: numberFormat(order.fiat_code, order.amount), currency, fiatAmount: numberFormat(order.fiat_code, order.fiat_amount!), - }) + }), ); } catch (error) { logger.error(error); @@ -1593,7 +1593,7 @@ const wizardAddInvoiceExitMessage = async (ctx: MainContext, order: IOrder) => { amount: numberFormat(order.fiat_code, order.amount), orderId: order._id, }), - { parse_mode: 'MarkdownV2' } + { parse_mode: 'MarkdownV2' }, ); } catch (error) { logger.error(error); @@ -1627,7 +1627,7 @@ const cantAddInvoiceMessage = async (ctx: MainContext) => { const sendMeAnInvoiceMessage = async ( ctx: MainContext, amount: number, - i18nCtx: I18nContext + i18nCtx: I18nContext, ) => { try { await ctx.reply(i18nCtx.t('send_me_lninvoice', { amount })); @@ -1640,7 +1640,7 @@ const wizardAddFiatAmountMessage = async ( ctx: MainContext, currency: string, action: string, - order: IOrder + order: IOrder, ) => { try { await ctx.reply( @@ -1650,7 +1650,7 @@ const wizardAddFiatAmountMessage = async ( fiatAmount: numberFormat(order.fiat_code, order.fiat_amount!), minAmount: numberFormat(order.fiat_code, order.min_amount), maxAmount: numberFormat(order.fiat_code, order.max_amount), - }) + }), ); } catch (error) { logger.error(error); @@ -1659,7 +1659,7 @@ const wizardAddFiatAmountMessage = async ( const wizardAddFiatAmountWrongAmountMessage = async ( ctx: MainContext, - order: IOrder + order: IOrder, ) => { try { ctx.deleteMessage(); @@ -1667,7 +1667,7 @@ const wizardAddFiatAmountWrongAmountMessage = async ( ctx.i18n.t('wizard_add_fiat_wrong_amount', { minAmount: numberFormat(order.fiat_code, order.min_amount), maxAmount: numberFormat(order.fiat_code, order.max_amount), - }) + }), ); } catch (error) { logger.error(error); @@ -1677,14 +1677,14 @@ const wizardAddFiatAmountWrongAmountMessage = async ( const wizardAddFiatAmountCorrectMessage = async ( ctx: MainContext, currency: IFiat, - fiatAmount: number + fiatAmount: number, ) => { try { await ctx.reply( ctx.i18n.t('wizard_add_fiat_correct_amount', { currency: currency.symbol_native, fiatAmount, - }) + }), ); } catch (error) { logger.error(error); @@ -1696,7 +1696,7 @@ const expiredOrderMessage = async ( order: IOrder, buyerUser: UserDocument, sellerUser: UserDocument, - i18n: I18nContext + i18n: I18nContext, ) => { try { const detailedOrder = getDetailedOrder(i18n, order, buyerUser, sellerUser); @@ -1707,7 +1707,7 @@ const expiredOrderMessage = async ( buyerUser, sellerUser, }), - { parse_mode: 'MarkdownV2' } + { parse_mode: 'MarkdownV2' }, ); } catch (error) { logger.error(error); @@ -1717,12 +1717,12 @@ const expiredOrderMessage = async ( const toBuyerExpiredOrderMessage = async ( bot: HasTelegram, user: UserDocument, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('expired_order_to_buyer', { helpGroup: process.env.HELP_GROUP }) + i18n.t('expired_order_to_buyer', { helpGroup: process.env.HELP_GROUP }), ); } catch (error) { logger.error(error); @@ -1732,12 +1732,12 @@ const toBuyerExpiredOrderMessage = async ( const toSellerExpiredOrderMessage = async ( bot: HasTelegram, user: UserDocument, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('expired_order_to_seller', { helpGroup: process.env.HELP_GROUP }) + i18n.t('expired_order_to_seller', { helpGroup: process.env.HELP_GROUP }), ); } catch (error) { logger.error(error); @@ -1748,12 +1748,12 @@ const toBuyerDidntAddInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('didnt_add_invoice', { orderId: order._id }) + i18n.t('didnt_add_invoice', { orderId: order._id }), ); } catch (error) { logger.error(error); @@ -1764,12 +1764,12 @@ const toSellerBuyerDidntAddInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('buyer_havent_add_invoice', { orderId: order._id }) + i18n.t('buyer_havent_add_invoice', { orderId: order._id }), ); } catch (error) { logger.error(error); @@ -1780,7 +1780,7 @@ const toAdminChannelBuyerDidntAddInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( @@ -1800,12 +1800,12 @@ const toSellerDidntPayInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('havent_paid_invoice', { orderId: order._id }) + i18n.t('havent_paid_invoice', { orderId: order._id }), ); } catch (error) { logger.error(error); @@ -1816,12 +1816,12 @@ const toBuyerSellerDidntPayInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( user.tg_id, - i18n.t('seller_havent_paid_invoice', { orderId: order._id }) + i18n.t('seller_havent_paid_invoice', { orderId: order._id }), ); } catch (error) { logger.error(error); @@ -1832,7 +1832,7 @@ const toAdminChannelSellerDidntPayInvoiceMessage = async ( bot: MainContext, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( @@ -1854,7 +1854,7 @@ const toAdminChannelPendingPaymentSuccessMessage = async ( order: IOrder, pending: IPendingPayment, payment: PayViaPaymentRequestResult, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( @@ -1865,7 +1865,7 @@ const toAdminChannelPendingPaymentSuccessMessage = async ( attempts: pending.attempts, amount: numberFormat(order.fiat_code, order.amount), paymentSecret: payment.secret, - }) + }), ); } catch (error) { logger.error(error); @@ -1877,7 +1877,7 @@ const toBuyerPendingPaymentSuccessMessage = async ( user: UserDocument, order: IOrder, payment: PayViaPaymentRequestResult, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( @@ -1886,7 +1886,7 @@ const toBuyerPendingPaymentSuccessMessage = async ( id: order._id, amount: numberFormat(order.fiat_code, order.amount), paymentSecret: payment.secret, - }) + }), ); } catch (error) { logger.error(error); @@ -1897,7 +1897,7 @@ const toBuyerPendingPaymentFailedMessage = async ( bot: Telegraf, user: UserDocument, order: IOrder, - i18n: I18nContext + i18n: I18nContext, ) => { try { const attempts = process.env.PAYMENT_ATTEMPTS; @@ -1905,7 +1905,7 @@ const toBuyerPendingPaymentFailedMessage = async ( user.tg_id, i18n.t('pending_payment_failed', { attempts, - }) + }), ); await bot.telegram.sendMessage(user.tg_id, i18n.t('press_to_continue'), { reply_markup: { @@ -1929,7 +1929,7 @@ const toAdminChannelPendingPaymentFailedMessage = async ( user: UserDocument, order: IOrder, pending: IPendingPayment, - i18n: I18nContext + i18n: I18nContext, ) => { try { await bot.telegram.sendMessage( @@ -1938,7 +1938,7 @@ const toAdminChannelPendingPaymentFailedMessage = async ( attempts: pending.attempts, orderId: order._id, username: user.username, - }) + }), ); } catch (error) { logger.error(error); @@ -1947,7 +1947,7 @@ const toAdminChannelPendingPaymentFailedMessage = async ( const currencyNotSupportedMessage = async ( ctx: MainContext, - currencies: Array + currencies: Array, ) => { try { const currenciesStr = currencies.join(', '); @@ -1959,7 +1959,7 @@ const currencyNotSupportedMessage = async ( const notAuthorized = async ( ctx: MainContext, - tgId?: string + tgId?: string, ): Promise => { try { if (tgId) { @@ -1983,7 +1983,7 @@ const mustBeANumber = async (ctx: MainContext) => { const showConfirmationButtons = async ( ctx: MainContext, orders: Array, - commandString: string + commandString: string, ) => { try { commandString = commandString.slice(1); diff --git a/bot/modules/community/index.ts b/bot/modules/community/index.ts index 8fd41ba1..9b9eacf9 100644 --- a/bot/modules/community/index.ts +++ b/bot/modules/community/index.ts @@ -23,7 +23,7 @@ export const configure = (bot: Telegraf) => { bot.action( /^updateCommunity_([0-9a-f]{24})$/, userMiddleware, - updateCommunityMessage + updateCommunityMessage, ); bot.action(/^editNameBtn_([0-9a-f]{24})$/, userMiddleware, async ctx => { await commands.updateCommunity(ctx, ctx.match[1], 'name'); @@ -36,7 +36,7 @@ export const configure = (bot: Telegraf) => { userMiddleware, async ctx => { await commands.updateCommunity(ctx, ctx.match[1], 'currencies'); - } + }, ); bot.action(/^editGroupBtn_([0-9a-f]{24})$/, userMiddleware, async ctx => { await commands.updateCommunity(ctx, ctx.match[1], 'group', bot); @@ -52,7 +52,7 @@ export const configure = (bot: Telegraf) => { userMiddleware, async ctx => { await commands.updateCommunity(ctx, ctx.match[1], 'disputeChannel', bot); - } + }, ); bot.action(/^editLanguageBtn_([0-9a-f]{24})$/, userMiddleware, async ctx => { await commands.updateCommunity(ctx, ctx.match[1], 'language'); @@ -62,12 +62,12 @@ export const configure = (bot: Telegraf) => { bot.action( /^communityInfo_([0-9a-f]{24})$/, userMiddleware, - actions.onCommunityInfo + actions.onCommunityInfo, ); bot.action( /^setCommunity_([0-9a-f]{24})$/, userMiddleware, - actions.onSetCommunity + actions.onSetCommunity, ); bot.action('doNothingBtn', userMiddleware, async ctx => { await ctx.deleteMessage(); @@ -76,22 +76,22 @@ export const configure = (bot: Telegraf) => { bot.action( /^deleteCommunityAskBtn_([0-9a-f]{24})$/, userMiddleware, - sureMessage + sureMessage, ); bot.action( /^withdrawEarnings_([0-9a-f]{24})$/, userMiddleware, - actions.withdrawEarnings + actions.withdrawEarnings, ); bot.action( /^deleteCommunityBtn_([0-9a-f]{24})$/, userMiddleware, - commands.deleteCommunity + commands.deleteCommunity, ); bot.action( /^changeVisibilityBtn_([0-9a-f]{24})$/, userMiddleware, - commands.changeVisibility + commands.changeVisibility, ); }; diff --git a/bot/modules/community/scenes.ts b/bot/modules/community/scenes.ts index a0c8f179..b320a13d 100644 --- a/bot/modules/community/scenes.ts +++ b/bot/modules/community/scenes.ts @@ -46,14 +46,14 @@ export const communityWizard = new Scenes.WizardScene( try { const status = createCommunityWizardStatus( ctx.i18n, - ctx.wizard.state + ctx.wizard.state, ); if (ctx.wizard.state.currentStatusText === status!.text) return; await ctx.telegram.editMessageText( res.chat.id, res.message_id, undefined, - status!.text + status!.text, ); ctx.wizard.state.currentStatusText = status!.text; } catch (err) { @@ -87,7 +87,7 @@ export const communityWizard = new Scenes.WizardScene( await ctx.reply( ctx.i18n.t('wizard_community_success', { days: process.env.COMMUNITY_TTL, - }) + }), ); return ctx.scene.leave(); @@ -115,7 +115,7 @@ export const communityWizard = new Scenes.WizardScene( logger.error(err); return ctx.scene.leave(); } - } + }, ); const createCommunitySteps = { @@ -147,7 +147,7 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); }; @@ -170,7 +170,7 @@ const createCommunitySteps = { if (!isValidLanguage(lang)) { ctx.telegram.deleteMessage(ctx.chat!.id, ctx.message!.message_id); ctx.wizard.state.error = ctx.i18n.t( - 'wizard_community_invalid_language' + 'wizard_community_invalid_language', ); return await ctx.wizard.state.updateUI(); } @@ -179,7 +179,7 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); }; @@ -202,7 +202,7 @@ const createCommunitySteps = { if (currencies.length > max) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); ctx.wizard.state.error = ctx.i18n.t('max_allowed', { max }); return await ctx.wizard.state.updateUI(); @@ -211,7 +211,7 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); }; @@ -236,7 +236,7 @@ const createCommunitySteps = { if (!isGroupOk.success) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); await wizardCommunityWrongPermission(ctx, group, isGroupOk.message); @@ -247,7 +247,7 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); return ctx.telegram.deleteMessage(prompt.chat.id, prompt.message_id); } catch (error: any) { @@ -271,10 +271,10 @@ const createCommunitySteps = { if (chan.length > 2) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); ctx.wizard.state.error = ctx.i18n.t( - 'wizard_community_one_or_two_channels' + 'wizard_community_one_or_two_channels', ); return await ctx.wizard.state.updateUI(); } @@ -284,7 +284,7 @@ const createCommunitySteps = { if (!isGroupOk.success) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); await wizardCommunityWrongPermission(ctx, chan[0], isGroupOk.message); @@ -300,7 +300,7 @@ const createCommunitySteps = { if (!isGroupOk.success) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); await wizardCommunityWrongPermission(ctx, chan[0], isGroupOk.message); @@ -310,7 +310,7 @@ const createCommunitySteps = { if (!isGroupOk.success) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); await wizardCommunityWrongPermission(ctx, chan[1], isGroupOk.message); @@ -331,11 +331,11 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); return await ctx.telegram.deleteMessage( prompt.chat.id, - prompt.message_id + prompt.message_id, ); }; const prompt = await createCommunityPrompts.channels(ctx); @@ -352,7 +352,7 @@ const createCommunitySteps = { if (isNaN(num)) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); ctx.wizard.state.error = ctx.i18n.t('not_number'); return await ctx.wizard.state.updateUI(); @@ -360,7 +360,7 @@ const createCommunitySteps = { if (num < 0 || num > 100) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); ctx.wizard.state.error = ctx.i18n.t('wizard_community_wrong_percent'); return await ctx.wizard.state.updateUI(); @@ -369,11 +369,11 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); return await ctx.telegram.deleteMessage( prompt.chat.id, - prompt.message_id + prompt.message_id, ); }; const prompt = await createCommunityPrompts.fee(ctx); @@ -402,10 +402,10 @@ const createCommunitySteps = { } else { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); ctx.wizard.state.error = ctx.i18n.t( - 'wizard_community_must_enter_names' + 'wizard_community_must_enter_names', ); return await ctx.wizard.state.updateUI(); } @@ -414,11 +414,11 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); return await ctx.telegram.deleteMessage( prompt.chat.id, - prompt.message_id + prompt.message_id, ); }; const prompt = await createCommunityPrompts.solvers(ctx); @@ -437,7 +437,7 @@ const createCommunitySteps = { if (!isGroupOk.success) { await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); await wizardCommunityWrongPermission(ctx, channel, isGroupOk.message); @@ -447,11 +447,11 @@ const createCommunitySteps = { await ctx.wizard.state.updateUI(); await ctx.telegram.deleteMessage( ctx.message!.chat.id, - ctx.message!.message_id + ctx.message!.message_id, ); return await ctx.telegram.deleteMessage( prompt.chat.id, - prompt.message_id + prompt.message_id, ); }; const prompt = await createCommunityPrompts.disputeChannel(ctx); @@ -511,7 +511,7 @@ export const updateNameCommunityWizard = new Scenes.WizardScene( if (name.length > length) { ctx.deleteMessage(); return await ctx.reply( - ctx.i18n.t('wizard_community_too_long_name', { length }) + ctx.i18n.t('wizard_community_too_long_name', { length }), ); } const { community } = ctx.wizard.state; @@ -525,7 +525,7 @@ export const updateNameCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - } + }, ); export const updateGroupCommunityWizard = new Scenes.WizardScene( @@ -556,7 +556,7 @@ export const updateGroupCommunityWizard = new Scenes.WizardScene( return await wizardCommunityWrongPermission( ctx, group, - isGroupOk.message + isGroupOk.message, ); } @@ -569,7 +569,7 @@ export const updateGroupCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - } + }, ); export const updateCurrenciesCommunityWizard = new Scenes.WizardScene( @@ -611,7 +611,7 @@ export const updateCurrenciesCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - } + }, ); export const updateChannelsCommunityWizard = new Scenes.WizardScene( @@ -651,7 +651,7 @@ export const updateChannelsCommunityWizard = new Scenes.WizardScene( return await wizardCommunityWrongPermission( ctx, chan[0], - isGroupOk.message + isGroupOk.message, ); } @@ -667,7 +667,7 @@ export const updateChannelsCommunityWizard = new Scenes.WizardScene( return await wizardCommunityWrongPermission( ctx, chan[0], - isGroupOk.message + isGroupOk.message, ); } @@ -677,7 +677,7 @@ export const updateChannelsCommunityWizard = new Scenes.WizardScene( return await wizardCommunityWrongPermission( ctx, chan[1], - isGroupOk.message + isGroupOk.message, ); } @@ -707,7 +707,7 @@ export const updateChannelsCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - } + }, ); export const updateSolversCommunityWizard = new Scenes.WizardScene( @@ -761,7 +761,7 @@ export const updateSolversCommunityWizard = new Scenes.WizardScene( await ctx.reply( ctx.i18n.t('users_added', { users: botUsers.join(', '), - }) + }), ); const { community } = ctx.wizard.state; @@ -771,7 +771,7 @@ export const updateSolversCommunityWizard = new Scenes.WizardScene( if (notBotUsers.length) await ctx.reply( - ctx.i18n.t('users_not_added', { users: notBotUsers.join(', ') }) + ctx.i18n.t('users_not_added', { users: notBotUsers.join(', ') }), ); return ctx.scene.leave(); @@ -779,7 +779,7 @@ export const updateSolversCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - } + }, ); export const updateFeeCommunityWizard = new Scenes.WizardScene( @@ -824,7 +824,7 @@ export const updateFeeCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - } + }, ); export const updateDisputeChannelCommunityWizard = new Scenes.WizardScene( @@ -860,7 +860,7 @@ export const updateDisputeChannelCommunityWizard = new Scenes.WizardScene( return await wizardCommunityWrongPermission( ctx, channel, - isGroupOk.message + isGroupOk.message, ); } @@ -873,7 +873,7 @@ export const updateDisputeChannelCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - } + }, ); export const updateLanguageCommunityWizard = new Scenes.WizardScene( @@ -913,7 +913,7 @@ export const updateLanguageCommunityWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - } + }, ); export const addEarningsInvoiceWizard = new Scenes.WizardScene( @@ -924,7 +924,7 @@ export const addEarningsInvoiceWizard = new Scenes.WizardScene( if (community.earnings === 0) return ctx.scene.leave(); await ctx.reply( - ctx.i18n.t('send_me_lninvoice', { amount: community.earnings }) + ctx.i18n.t('send_me_lninvoice', { amount: community.earnings }), ); return ctx.wizard.next(); @@ -974,5 +974,5 @@ export const addEarningsInvoiceWizard = new Scenes.WizardScene( logger.error(error); ctx.scene.leave(); } - } + }, ); diff --git a/bot/ordersActions.ts b/bot/ordersActions.ts index b3a87ae6..fa49bc3c 100644 --- a/bot/ordersActions.ts +++ b/bot/ordersActions.ts @@ -70,7 +70,7 @@ const createOrder = async ( tgChatId, tgOrderMessage, community_id, - }: CreateOrderArguments + }: CreateOrderArguments, ) => { try { amount = Math.floor(amount); @@ -215,7 +215,7 @@ const buildDescription = ( priceFromAPI, currency, isGoldenHoneyBadger, - }: BuildDescriptionArguments + }: BuildDescriptionArguments, ) => { try { const action = type === 'sell' ? i18n.t('selling') : i18n.t('buying'); @@ -286,7 +286,7 @@ const buildDescription = ( const getOrder = async ( ctx: MainContext, user: UserDocument, - orderId: string + orderId: string, ) => { try { if (!ObjectId.isValid(orderId)) { From 30ea6307a7a9c8fcdd75626415059b143da40dfa Mon Sep 17 00:00:00 2001 From: Anyitechs Date: Thu, 18 Dec 2025 14:01:27 +0100 Subject: [PATCH 5/6] improve `language` field definition in `Community` model --- models/community.ts | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/models/community.ts b/models/community.ts index 70abfe9c..dcd134c5 100644 --- a/models/community.ts +++ b/models/community.ts @@ -1,4 +1,5 @@ import mongoose, { Document, Schema, Types } from 'mongoose'; +import { isValidLanguage, SUPPORTED_LANGUAGES } from '../util/languages'; const CURRENCIES: number = parseInt(process.env.COMMUNITY_CURRENCIES || '10'); @@ -85,25 +86,11 @@ const CommunitySchema = new Schema({ warning_messages_count: { type: Number, default: 0 }, language: { type: String, + trim: true, + lowercase: true, default: 'en', - validate: { - validator: function (v: string) { - const supportedLanguages = [ - 'en', - 'es', - 'fr', - 'de', - 'it', - 'pt', - 'ru', - 'uk', - 'ko', - 'fa', - ]; // Add all supported languages - return supportedLanguages.includes(v); - }, - message: 'Language code {VALUE} is not supported', - }, + enum: SUPPORTED_LANGUAGES, + validate: [isValidLanguage, 'Language code {VALUE} is not supported'], }, }); From cff978f9a756cbdd8d11b7ea6248d58908939817 Mon Sep 17 00:00:00 2001 From: Anyitechs Date: Thu, 18 Dec 2025 14:47:28 +0100 Subject: [PATCH 6/6] add missing `language` key to locale files --- locales/de.yaml | 1 + locales/es.yaml | 5 +++-- locales/fa.yaml | 1 + locales/fr.yaml | 1 + locales/it.yaml | 1 + locales/ko.yaml | 1 + locales/pt.yaml | 1 + locales/ru.yaml | 1 + locales/uk.yaml | 1 + 9 files changed, 11 insertions(+), 2 deletions(-) diff --git a/locales/de.yaml b/locales/de.yaml index e25b112a..bc69bedf 100644 --- a/locales/de.yaml +++ b/locales/de.yaml @@ -587,6 +587,7 @@ community_npub_updated: You added the community's pubkey ${npub} successfully! community_language_updated: Du hast die Sprache der Community erfolgreich auf ${language} aktualisiert! wizard_community_enter_language: 'Gib den Sprachcode für deine Community ein (en, es, fr, de, it, pt, ru, uk, ko, fa)' wizard_community_invalid_language: 'Ungültiger Sprachcode. Bitte gib einen der folgenden ein - en, es, fr, de, it, pt, ru, uk, ko, fa' +language: "Sprache" # END modules/community # START modules/orders diff --git a/locales/es.yaml b/locales/es.yaml index aaa05658..ed44d26e 100644 --- a/locales/es.yaml +++ b/locales/es.yaml @@ -567,10 +567,11 @@ community_admin_help: | /setnpub <npub> - Configura la llave pública de Nostr de la comunidad. /setlanguage <lang> - Configura el idioma de la comunidad para los mensajes publicados. -community_npub_updated: Has configurado la pubkey ${npub} de la comunidad exitosamente! -community_language_updated: Has configurado el idioma ${language} de la comunidad exitosamente! +community_npub_updated: ¡Has configurado la pubkey ${npub} de la comunidad exitosamente! +community_language_updated: ¡Has configurado el idioma ${language} de la comunidad exitosamente! wizard_community_enter_language: 'Ingresa el idioma de la comunidad, ej: es, en, pt, fr, de, it, etc.' wizard_community_invalid_language: 'El idioma debe ser uno de los siguientes: es, en, pt, fr, de, it, etc.' +language: "Idioma" # END modules/community # START modules/nostr diff --git a/locales/fa.yaml b/locales/fa.yaml index 88b5d03a..fce42fa6 100644 --- a/locales/fa.yaml +++ b/locales/fa.yaml @@ -570,6 +570,7 @@ community_language_updated: شما زبان کامیونیتی را با موف wizard_community_enter_language: 'کد زبان کامیونیتی خود را وارد کنید (en, es, fr, de, it, pt, ru, uk, ko, fa)' wizard_community_invalid_language: 'کد زبان نامعتبر است. لطفاً یکی از موارد زیر را وارد کنید - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: شما کلیدعمومی کامیونیتی ${npub} را با موفقیت اضافه کردید! +language: "زبان" # END modules/community # START modules/nostr diff --git a/locales/fr.yaml b/locales/fr.yaml index 7f95edef..07074e51 100644 --- a/locales/fr.yaml +++ b/locales/fr.yaml @@ -569,6 +569,7 @@ community_language_updated: Vous avez configuré la langue de la communauté en wizard_community_enter_language: 'Entrez le code de la langue de votre communauté (en, es, fr, de, it, pt, ru, uk, ko, fa)' wizard_community_invalid_language: "Code de langue invalide. Veuillez entrer l'un des suivants - en, es, fr, de, it, pt, ru, uk, ko, fa" community_npub_updated: Vous avez ajouté la clé publique de la communauté ${npub} avec succès ! +language: "Langue" # END modules/community # START modules/nostr diff --git a/locales/it.yaml b/locales/it.yaml index f4de2052..fa66ebad 100644 --- a/locales/it.yaml +++ b/locales/it.yaml @@ -584,6 +584,7 @@ community_language_updated: Hai aggiornato con successo la lingua della communit wizard_community_enter_language: 'Inserisci il codice lingua per la tua community (en, es, fr, de, it, pt, ru, uk, ko, fa)' wizard_community_invalid_language: 'Codice lingua non valido. Inserisci uno dei seguenti - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! +language: "Lingua" # END modules/community # START modules/orders diff --git a/locales/ko.yaml b/locales/ko.yaml index b52cce9f..6dc3b9d3 100644 --- a/locales/ko.yaml +++ b/locales/ko.yaml @@ -567,6 +567,7 @@ community_language_updated: 성공적으로 커뮤니티의 언어를 ${language wizard_community_enter_language: '커뮤니티의 언어를 입력하세요. (en, es, fr, de, it, pt, ru, uk, ko, fa)' wizard_community_invalid_language: '유효하지 않은 언어입니다. 다음 중 하나를 입력하세요: en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: 성공적으로 커뮤니티의 공개키 ${npub}을 추가하였습니다! +language: "언어" # END modules/community # START modules/nostr diff --git a/locales/pt.yaml b/locales/pt.yaml index f0611c0c..a2bc8592 100644 --- a/locales/pt.yaml +++ b/locales/pt.yaml @@ -586,6 +586,7 @@ community_language_updated: Você atualizou o idioma da comunidade para ${langua wizard_community_enter_language: 'Insira o código de idioma da sua comunidade (en, es, fr, de, it, pt, ru, uk, ko, fa)' wizard_community_invalid_language: 'Código de idioma inválido. Insira um dos seguintes - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! +language: "Idioma" # END modules/community # START modules/orders diff --git a/locales/ru.yaml b/locales/ru.yaml index 463bbcd4..79b1a6ae 100644 --- a/locales/ru.yaml +++ b/locales/ru.yaml @@ -587,6 +587,7 @@ community_language_updated: Вы успешно обновили язык соо wizard_community_enter_language: 'Введите код языка для вашего сообщества (en, es, fr, de, it, pt, ru, uk, ko, fa)' wizard_community_invalid_language: 'Недопустимый код языка. Пожалуйста, введите один из следующих - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! +language: "Язык" # END modules/community # START modules/orders diff --git a/locales/uk.yaml b/locales/uk.yaml index 0b139581..8202ce68 100644 --- a/locales/uk.yaml +++ b/locales/uk.yaml @@ -583,6 +583,7 @@ community_language_updated: Ви успішно оновили мову спіл wizard_community_enter_language: 'Введіть код мови для вашої спільноти (en, es, fr, de, it, pt, ru, uk, ko, fa)' wizard_community_invalid_language: 'Недійсний код мови. Будь ласка, введіть один із таких - en, es, fr, de, it, pt, ru, uk, ko, fa' community_npub_updated: You added the community's pubkey ${npub} successfully! +language: "Мова" # END modules/community # START modules/orders