|
1 | 1 | import { Midjourney } from 'midjourney' |
2 | 2 | import { saveAndSendPhoto, saveAndSendPreloaderPhoto } from '../../utils/saveAndSendPhoto.js' |
3 | 3 | import { loaderOn } from '../../utils/loader.js' |
4 | | -import { TYPE_RESPONSE_MJ } from '../../constants/index.js' |
| 4 | +import { REQUEST_TYPES_COST, TYPE_RESPONSE_MJ } from '../../constants/index.js' |
5 | 5 | import { upscale } from './midjourney/upscale.js' |
6 | 6 | import events from 'events' |
7 | 7 | import { variation } from './midjourney/variation.js' |
8 | 8 | import dotenv from 'dotenv' |
| 9 | +import { calculationOfNumberOfTokens } from '../../utils/checkTokens.js' |
| 10 | +import { db } from '../../db/index.js' |
| 11 | +import { Sequelize } from 'sequelize' |
9 | 12 |
|
10 | 13 | dotenv.config() |
11 | 14 |
|
@@ -84,6 +87,13 @@ export const modeMidjourney = async (bot, sudoUser, msg, match) => { |
84 | 87 |
|
85 | 88 | const prevMessage = await saveAndSendPhoto(imgUrl, imgDir, filePath, chatID, bot, options, TYPE_RESPONSE_MJ.PHOTO, waiting) |
86 | 89 |
|
| 90 | + const tokenCounts = await calculationOfNumberOfTokens(' ', REQUEST_TYPES_COST.MIDJOURNEY) |
| 91 | + |
| 92 | + await db.subscriber.update( |
| 93 | + { tokens: Sequelize.literal(`tokens - ${tokenCounts}`) }, |
| 94 | + { where: { chat_id: chatID } } |
| 95 | + ) |
| 96 | + |
87 | 97 | for (let i = 1; i < 5; i++) { |
88 | 98 | eventEmitter.on(`V${i}++${waiting.message_id}`, async function(query) { |
89 | 99 | await variation(prompt, Imagine, client, query, bot, chatID, prevMessage.message_id, userMessageId) |
|
0 commit comments