aboutsummaryrefslogtreecommitdiff
path: root/input_msg.py
blob: d034f5ff1f6ccb1992fb5e7569387c95a8f536d7 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import string

from random import choices

from vars import *
from config import *
from helpers import get_user_config, set_user_setting

from aiogram.types import (
    InlineKeyboardButton,
    InlineKeyboardMarkup,
    InlineQueryResultArticle,
    InputTextMessageContent,
    Message,
)

async def da(bot, message, user_id):
    config = get_user_config(user_id)
    if user_id in alo_command:
        if message.chat.id == alo_command[user_id]["chat_id"]:
            if alo_command[user_id]["action"] == "p_name":
                alo_command[user_id]["action"] = "p_prompt"
                alo_command[user_id]["name"] = message.text[:16]
                return await bot.edit_message_text(
                    text=f"установи промпт для `{alo_command[user_id]['name']}`:",
                    chat_id=alo_command[user_id]["chat_id"],
                    message_id=alo_command[user_id]["message_id"],
                    reply_markup=InlineKeyboardMarkup(
                        inline_keyboard=[
                            [
                                InlineKeyboardButton(
                                    text=f"❌ отменить", callback_data=f"p_cancel%{user_id}"
                                ),
                            ],
                        ]
                    )
                )
            elif alo_command[user_id]["action"] == "p_prompt":
                alo_command[user_id]["action"] = None
                alo_command[user_id]["prompt"] = message.text

                if len(config["prompts"]) >= MAX_PROMPTS:
                    return await bot.edit_message_text(
                        text=f"невозможно создать новый промпт так как ты превысил лимит промптов da.",
                        chat_id=alo_command[user_id]["chat_id"],
                        message_id=alo_command[user_id]["message_id"],
                        reply_markup=InlineKeyboardMarkup(
                            inline_keyboard=[
                                [
                                    InlineKeyboardButton(
                                        text=f"ок", callback_data=f"user_prompts%{user_id}"
                                    ),
                                ],
                            ]
                        )
                    )
                
                while 1:
                    alo_command[user_id]["id"] = ''.join(choices(string.ascii_letters, k=10))
                    if alo_command[user_id]["id"] not in config["prompts"]: 
                        break

                config["prompts"] = config["prompts"] | {
                    alo_command[user_id]["id"]: {
                        "name": alo_command[user_id]["name"],
                        "text": alo_command[user_id]["prompt"],
                        "filer": False,
                        "public": False
                    }
                }

                set_user_setting(
                    user_id, 
                    prompts=config["prompts"]
                )
                
                return await bot.edit_message_text(
                    text=f"промпт `{alo_command[user_id]['name']}` создан!",
                    chat_id=alo_command[user_id]["chat_id"],
                    message_id=alo_command[user_id]["message_id"],
                    reply_markup=InlineKeyboardMarkup(
                        inline_keyboard=[
                            [
                                InlineKeyboardButton(
                                    text=f"✅ посмотреть", callback_data=f"vp%{user_id}%{alo_command[user_id]['id']}"
                                ),
                            ],
                        ]
                    )
                )
            elif alo_command[user_id]["action"] == "p_e_name":
                alo_command[user_id]["action"] = None
                alo_command[user_id]["name"] = message.text[:16]
                
                config["prompts"] = config["prompts"] | {
                    alo_command[user_id]["prompt_id"]: {
                        "name": alo_command[user_id]["name"],
                        "text": config["prompts"][alo_command[user_id]["prompt_id"]]["text"],
                        "filer": config["prompts"][alo_command[user_id]["prompt_id"]]["filer"],
                        "public": config["prompts"][alo_command[user_id]["prompt_id"]]["public"],
                    }
                }

                set_user_setting(
                    user_id, 
                    prompts = config["prompts"]
                )
                
                return await bot.edit_message_text(
                    text=f"имя промпта было изменено на `{alo_command[user_id]['name']}`.",
                    chat_id=alo_command[user_id]["chat_id"],
                    message_id=alo_command[user_id]["message_id"],
                    reply_markup=InlineKeyboardMarkup(
                        inline_keyboard=[
                            [
                                InlineKeyboardButton(
                                    text=f"✅ посмотреть", callback_data=f"vp%{user_id}%{alo_command[user_id]['prompt_id']}"
                                ),
                            ],
                        ]
                    )
                )
            elif alo_command[user_id]["action"] == "p_e_prompt":
                alo_command[user_id]["action"] = None
                alo_command[user_id]["prompt"] = message.text
                
                config["prompts"] = config["prompts"] | {
                    alo_command[user_id]["prompt_id"]: {
                        "name": config["prompts"][alo_command[user_id]["prompt_id"]]["name"],
                        "text": alo_command[user_id]["prompt"],
                        "filer": config["prompts"][alo_command[user_id]["prompt_id"]]["filer"],
                        "public": config["prompts"][alo_command[user_id]["prompt_id"]]["public"],
                    }
                }

                set_user_setting(
                    user_id, 
                    prompts=config["prompts"]
                )

                return await bot.edit_message_text(
                    text=f"текст промпта был изменён.",
                    chat_id=alo_command[user_id]["chat_id"],
                    message_id=alo_command[user_id]["message_id"],
                    reply_markup=InlineKeyboardMarkup(
                        inline_keyboard=[
                            [
                                InlineKeyboardButton(
                                    text=f"✅ посмотреть", callback_data=f"vp%{user_id}%{alo_command[user_id]['prompt_id']}"
                                ),
                            ],
                        ]
                    )
                )
    return None