File size: 1,556 Bytes
66e3a81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
 * Bot Action Handlers
 * Handles specific bot commands and logic to keep bot.js clean.
 */

const { getUserSession, setAwaitingEdit } = require('./userSession');

/**
 * Handles the /edit_story command.
 * @param {Object} ctx - Telegram context.
 */
async function handleEditCommand(ctx) {
    const userId = ctx.from.id;
    const session = getUserSession(userId);

    if (!session.lastPrompt || !session.lastStory) {
        console.log(`[Actions] User ${userId} tried to edit without history.`);
        return ctx.reply("Сначала сгенерируйте историю. Просто отправьте мне тему для поста.");
    }

    // Set state: user is now expected to send edit instructions
    setAwaitingEdit(userId, true);

    await ctx.reply("Что исправить?");
}

/**
 * Handles the /edit_image command.
 * @param {Object} ctx - Telegram context.
 */
async function handleEditImageCommand(ctx) {
    const userId = ctx.from.id;
    const session = getUserSession(userId);

    // Check if we have a last image to edit
    if (!session.lastImage) {
        console.log(`[Actions] User ${userId} tried to edit image without history.`);
        return ctx.reply("Сначала сгенерируйте изображение.");
    }

    const { setAwaitingImageEdit } = require('./userSession');
    setAwaitingImageEdit(userId, true);

    await ctx.reply("Опишите, как изменить изображение?");
}

module.exports = {
    handleEditCommand,
    handleEditImageCommand
};