From 4f41f4c6cca881f0fc90cc253d8d6eaa15a50c43 Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Tue, 13 Dec 2022 15:57:43 +0330 Subject: [PATCH 1/3] fix(telegram-notifier): prevent duplicate register --- services/telegram-notifier/src/bot/command/start.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/telegram-notifier/src/bot/command/start.ts b/services/telegram-notifier/src/bot/command/start.ts index 0f23b6702..1843a953c 100644 --- a/services/telegram-notifier/src/bot/command/start.ts +++ b/services/telegram-notifier/src/bot/command/start.ts @@ -9,7 +9,7 @@ bot.command('start', async (ctx): Promise => { logger.logMethodArgs('command/start', {chatId, token}); if (token == null) { - ctx.reply('You don\'t have permission!'); + ctx.reply('این یک بات خصوصی هستش! لطفا مزاحم نشوید.'); return; } @@ -18,8 +18,13 @@ bot.command('start', async (ctx): Promise => { memberList: [], }; + if (target.memberList.indexOf(chatId) !== -1) { + ctx.reply('شما درحال حاضر عضو این لیست هستید!'); + return; + } + target.memberList.push(chatId); storage.set(target, true); - await ctx.reply('You are registered to notify list!'); + await ctx.reply('شما با موفقیت در لیست ثبت شدید.'); }); From 10a203e10d66ba1073834fa4d473d2b9664649e6 Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Tue, 13 Dec 2022 16:31:43 +0330 Subject: [PATCH 2/3] refactor(flight-crawler): notify template --- services/flight-crawler/src/crawl.ts | 29 +++++++++++++++++-------- services/flight-crawler/src/lib/type.ts | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/services/flight-crawler/src/crawl.ts b/services/flight-crawler/src/crawl.ts index 2cf2d598e..4162eb22a 100644 --- a/services/flight-crawler/src/crawl.ts +++ b/services/flight-crawler/src/crawl.ts @@ -17,7 +17,7 @@ export async function crawlAllJobs(): Promise { const oldResultList = job.resultList; const resultList = await crawl(job.detail); job.resultList = resultList; - if (job.resultList.length > 0 && differentObject(job.resultList, oldResultList)) { + if (differentObject(job.resultList, oldResultList)) { const message = makeMessage(job); await notify(config.notifier.to, message); logger.logOther(`Notified to ${config.notifier.to}!`); @@ -57,7 +57,7 @@ function makeRequestOption(detail: JobDetail): Partial & {url: str pageSize: 20, pageNumber: 0, originAirportIataCode: detail.origin, - destinationAirportIataCode: detail.dest, + destinationAirportIataCode: detail.destination, departureDate: detail.date, sort: 1, }, @@ -135,16 +135,27 @@ function extraFilterResult(jobResultList: Array, detail: JobDetail): function makeMessage(job: Job): string { logger.logMethod('makeMessage'); - let message = `پرواز از ${cityList[job.detail.origin]} به ${cityList[job.detail.dest]} در تاریخ ${job.detail.date}`; + // prettier-ignore + const resultListStr = job.resultList.length === 0 ? 'هیچ پروازی یافت نشد!' + : job.resultList.map((jobResult) => ` + قیمت: ${jobResult.price} + ساعت: ${jobResult.time} + هواپیمایی ${jobResult.airline} + `).join(''); - // add description if exists - job.detail.description ? (message += '\nتوضیحات:' + job.detail.description) : null; + return ` + تغییرات جدید در جستجوی ${job.id}: - job.resultList.forEach((jobResult) => { - message += '\n\n' + `قیمت: ${jobResult.price}\n ساعت: ${jobResult.time}\nتعداد صندلی: ${jobResult.seatCount}`; - }); + ${job.detail.description} + + ${cityList[job.detail.origin]} ✈️ ${cityList[job.detail.destination]} + + تاریخ: ${job.detail.date} + حداکثر قیمت: ${job.detail.maxPrice} + تعداد صندلی: ${job.detail.seatCount} - return message; + ${resultListStr} + `.replaceAll(' ', ''); } async function notify(to: string, message: string): Promise { diff --git a/services/flight-crawler/src/lib/type.ts b/services/flight-crawler/src/lib/type.ts index 6e2df29c6..9c42753ad 100644 --- a/services/flight-crawler/src/lib/type.ts +++ b/services/flight-crawler/src/lib/type.ts @@ -7,7 +7,7 @@ export interface Job extends AlwatrDocumentObject { export interface JobDetail extends Record { origin: string; - dest: string; + destination: string; date: string; seatCount: number; maxPrice: number | null; From ad983f7960da79c44e3c3b565e640be659c0fc43 Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Tue, 13 Dec 2022 16:34:18 +0330 Subject: [PATCH 3/3] fix(ff-pwa): JobDetail destination --- uniquely/flight-finder-pwa/src/component/job-item.ts | 2 +- uniquely/flight-finder-pwa/src/component/page-flight-finder.ts | 2 +- uniquely/flight-finder-pwa/src/type.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/uniquely/flight-finder-pwa/src/component/job-item.ts b/uniquely/flight-finder-pwa/src/component/job-item.ts index 16ade60b5..c12b1cf9e 100644 --- a/uniquely/flight-finder-pwa/src/component/job-item.ts +++ b/uniquely/flight-finder-pwa/src/component/job-item.ts @@ -108,7 +108,7 @@ export class JobItem extends AlwatrElement { - ${this.__renderTitle(i18nCityList[this.job.detail.origin], i18nCityList[this.job.detail.dest])} + ${this.__renderTitle(i18nCityList[this.job.detail.origin], i18nCityList[this.job.detail.destination])} ${this.__renderSubtitle( this.job.detail.date, this.job.detail.dayPart.map((part) => i18nDayPartList[part]).join(' - '), diff --git a/uniquely/flight-finder-pwa/src/component/page-flight-finder.ts b/uniquely/flight-finder-pwa/src/component/page-flight-finder.ts index cb9405973..f9206a543 100644 --- a/uniquely/flight-finder-pwa/src/component/page-flight-finder.ts +++ b/uniquely/flight-finder-pwa/src/component/page-flight-finder.ts @@ -238,7 +238,7 @@ export class PageFlightFinder extends AlwatrElement { PageFlightFinder.jobAddSignal.dispatch({ detail: { - dest: this.__newJob.dest as string, + destination: this.__newJob.destination as string, origin: this.__newJob.origin as string, dayPart: (this.__newJob.dayPart as dayParts[]) ?? [], maxPrice: this.__newJob.maxPrice ?? null, diff --git a/uniquely/flight-finder-pwa/src/type.ts b/uniquely/flight-finder-pwa/src/type.ts index cb3c7a27a..8dab6a1e7 100644 --- a/uniquely/flight-finder-pwa/src/type.ts +++ b/uniquely/flight-finder-pwa/src/type.ts @@ -25,7 +25,7 @@ export interface Job extends AlwatrDocumentObject { export interface JobDetail { origin: string; - dest: string; + destination: string; date: string; seatCount: number; maxPrice: number | null;