Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit e8539fb

Browse files
committed
Правки в оформлении
1 parent dca8854 commit e8539fb

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

apps/api/src/models/Subscribe/model.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { IModelPrototypeNoId } from '../types'
88
export type SubscribeModelType = {
99
diaryUserId: bigint
1010
tgId: bigint
11+
preActionsIsSuccess: boolean
1112
}
1213

1314
export type ISubscribeModelType = IModelPrototypeNoId<SubscribeModelType>
@@ -26,6 +27,12 @@ const subscribeModel = sequelize.define<ISubscribeModelType>('subscribe', {
2627
primaryKey: true,
2728
allowNull: false,
2829
unique: true
30+
},
31+
preActionsIsSuccess: {
32+
type: DataTypes.BOOLEAN,
33+
primaryKey: false,
34+
allowNull: false,
35+
unique: true
2936
}
3037
})
3138

apps/api/src/worker/notificator/bot/botLogic/registerLogic.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getCookieFromToken } from '@helpers'
22
import type TelegramBot from 'node-telegram-bot-api'
33
import { DiaryUserModel } from '../../../../models/DiaryUser'
44
import { SubscribeModel } from '../../../../models/Subscribe'
5+
import {INTERVAL_RUN} from "../../config";
56

67
export const registerLogic = (bot: TelegramBot | null) => {
78
if (!bot) return
@@ -46,7 +47,8 @@ export const registerLogic = (bot: TelegramBot | null) => {
4647

4748
await SubscribeModel.create({
4849
diaryUserId: auth.localUserId,
49-
tgId: BigInt(chatId)
50+
tgId: BigInt(chatId),
51+
preActionsIsSuccess: false
5052
})
5153

5254
const user = await DiaryUserModel.findOne({
@@ -57,7 +59,11 @@ export const registerLogic = (bot: TelegramBot | null) => {
5759

5860
bot.sendMessage(
5961
chatId,
60-
`Вы подписались на аккаунт c ФИО => ${user?.firstName} ${user?.lastName} ${user?.middleName}`
62+
`<b><i>${user?.firstName} ${user?.lastName}!</i></b> Вы успешно подписались на уведомления.`
63+
+ `\nПрежде чем Вы начнёте получать уведомления, нам нужно извлечь все ваши оценки (это просиходит примерно каждые <b>${INTERVAL_RUN} секунд</b>).`
64+
+ `\nПо окончанию подготовительных процедур, мы уведомим Вас о готовности принимать уведомления.`
65+
+ `\nСпасибо, что выбираете нас!`,
66+
{parse_mode: 'HTML'}
6167
)
6268
break
6369
}
@@ -73,7 +79,12 @@ export const registerLogic = (bot: TelegramBot | null) => {
7379
)
7480
break
7581
default:
76-
bot.sendMessage(chatId, 'Такой команды нету')
82+
bot.sendMessage(chatId,
83+
`Этой команды нету, но есть такие:`
84+
+ `\n/subscribe <code>[token]</code> — подписаться на уведомления по токену`
85+
+ `\n/unsubscribe — отписаться от уведомлений`,
86+
{parse_mode:"HTML"}
87+
)
7788
break
7889
}
7990
})

apps/api/src/worker/notificator/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getCurrPerformance } from '../../routes/performance.current/service'
55
import { checkInterval } from '../utils/checkInterval'
66
import { logger } from '../utils/logger'
77
import { INTERVAL_RUN } from './config'
8+
import {bot} from "./bot";
89

910
let lastRunning: Date | null = null
1011
const log = logger('notificator')
@@ -32,6 +33,18 @@ export const notificatorChecker = async (): Promise<void> => {
3233

3334
const cacheData = await getCookieFromToken(auth.token)
3435

36+
if (!subscribe.preActionsIsSuccess) {
37+
getCurrPerformance(cacheData, false).then(() => {
38+
if (!bot)
39+
return
40+
subscribe.preActionsIsSuccess = true
41+
subscribe.save()
42+
bot.sendMessage(String(subscribe.tgId), `Мы загрузили ваши оценки. Теперь вы будете получать уведомления!`)
43+
})
44+
continue
45+
}
46+
3547
await getCurrPerformance(cacheData, true)
3648
}
49+
log(`Проход завершён. Следующий через ${INTERVAL_RUN} секунд`)
3750
}

0 commit comments

Comments
 (0)