-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a83794e
commit 4cc091b
Showing
5 changed files
with
80 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { INITIAL_SESSION } from '../../constants/index.js' | ||
|
||
export const resetQuiz = bot => { | ||
bot.onText(/\/rq/, async msg => { | ||
if (msg?.chat?.id == process.env.NOTIF_GROUP) { | ||
const { id: chatId } = msg.chat | ||
const msgId = msg.message_id | ||
const { id } = msg.from | ||
const options = { | ||
parse_mode: 'HTML', | ||
reply_to_message_id: msgId | ||
} | ||
|
||
try { | ||
лучше созданять дату и время, когда у человека будет доступна следубщая игра | ||
позже при открытии этим пользователем викторины я должен буду проверить эту дату | ||
если эта дата будет | ||
} catch (error) { | ||
await bot.sendMessage(chatId, `${error.message}`, options) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,53 @@ | ||
export const createNewQuizKeyboard = (res, chatId, t) => { | ||
import { db } from '../../db/index.js' | ||
|
||
export const createNewQuizKeyboard = async (res, msgId, t, chatId) => { | ||
const keyboard = [] | ||
const keyboard2 = [] | ||
// проверить, если с даты блокировки прошло ровно 7 дней - обнулить | ||
const dateFreezeQuiz = res.dataValues?.quiz_reboot_date | ||
const today = new Date() | ||
const daysHavePassed = (today - dateFreezeQuiz) / 1000 / 60 / 60 / 24 | ||
const VALUES = 5; | ||
const { dataValues } = await db.settings.findOne({ where: { user_id: 0 } }) | ||
|
||
if ((res?.dataValues?.quiz_subs_available === 0 && res.dataValues?.quiz_token_available === 0) | ||
&& (dataValues['days_freez'] - daysHavePassed) <= 0) { | ||
db.subscriber.findOne( | ||
{ where: { chat_id: chatId } } | ||
).then(() => { | ||
|
||
if (res?.dataValues?.quiz_subs_available === 0 && res.dataValues?.quiz_token_available === 0) { | ||
db.subscriber.update( | ||
{ | ||
quiz_reboot_date: null, | ||
quiz_subs_available: VALUES, | ||
quiz_token_available: VALUES | ||
}, | ||
{ where: { chat_id: chatId } } | ||
).then(() => { | ||
keyboard.push({ | ||
text: `${t('btn_win_subs')} (${VALUES})`, | ||
callback_data: `WIN_SUBS_${msgId}` | ||
}) | ||
keyboard2.push({ | ||
text: `${t('btn_win_tokens')} (${VALUES})`, | ||
callback_data: `WIN_REQ_${msgId}` | ||
}) | ||
}) | ||
}) | ||
} else if ((dataValues['days_freez'] - daysHavePassed) >= 0) { | ||
keyboard.push({ text: t('new_quiz_after_week'), callback_data: `NO_ATTEMPTS` }) | ||
} else { | ||
if (res?.dataValues?.quiz_subs_available !== 0) | ||
keyboard.push({ | ||
text: `${t('btn_win_subs')} (${res.dataValues.quiz_subs_available})`, | ||
callback_data: `WIN_SUBS_${chatId}` | ||
callback_data: `WIN_SUBS_${msgId}` | ||
}) | ||
if (res?.dataValues?.quiz_token_available !== 0) | ||
keyboard2.push({ | ||
text: `${t('btn_win_tokens')} (${res.dataValues.quiz_token_available})`, | ||
callback_data: `WIN_REQ_${chatId}` | ||
callback_data: `WIN_REQ_${msgId}` | ||
}) | ||
} | ||
|
||
return [ | ||
keyboard, | ||
keyboard2 | ||
] | ||
return [keyboard, keyboard2] | ||
} |