улучшение ui
This commit is contained in:
@@ -23,8 +23,8 @@ type AddCreative struct {
|
||||
WaitingForTextEdit bool // Ждем редактирования текста креатива
|
||||
}
|
||||
|
||||
func (s *AddCreative) Enter(b *bot.Bot, mode bot.RenderMode) {
|
||||
text := `<i>… › Креативы › Добавление</i>
|
||||
const msgWaitCreative = `
|
||||
<i>… › Креативы › Добавление</i>
|
||||
|
||||
<b>+ Добавить креатив</b>
|
||||
|
||||
@@ -32,15 +32,13 @@ func (s *AddCreative) Enter(b *bot.Bot, mode bot.RenderMode) {
|
||||
|
||||
• Обрабатываем любое сообщение Telegram
|
||||
• Отправляйте сразу оформленный пост
|
||||
• На следующем шаге можно добавить кнопки или изменить контент`
|
||||
• На следующем шаге можно добавить кнопки или изменить контент
|
||||
`
|
||||
|
||||
buttons := [][]echotron.InlineKeyboardButton{
|
||||
bot.Row(bot.Button("« Отмена", "cancel")),
|
||||
}
|
||||
|
||||
keyboard := bot.Keyboard(buttons...)
|
||||
func (s *AddCreative) Enter(b *bot.Bot, mode bot.RenderMode) {
|
||||
kb := Keyboard(Row(Button("« Отмена", "cancel")))
|
||||
s.WaitingForCreative = true
|
||||
b.Render(text, keyboard, mode)
|
||||
b.Render(msgWaitCreative, kb, mode)
|
||||
}
|
||||
|
||||
func (s *AddCreative) HandleCallback(b *bot.Bot, u *echotron.Update) {
|
||||
@@ -69,7 +67,7 @@ func (s *AddCreative) HandleCallback(b *bot.Bot, u *echotron.Update) {
|
||||
<b>Пример:</b>
|
||||
<i>Присоединяйтесь к нашему каналу!
|
||||
https://t.me/+AbCdEfGhIjKlMn</i>`, [][]echotron.InlineKeyboardButton{
|
||||
bot.Row(bot.Button("« Отмена", "cancel_edit")),
|
||||
Row(Button("« Отмена", "cancel_edit")),
|
||||
})
|
||||
|
||||
case data == "add_button":
|
||||
@@ -86,11 +84,11 @@ https://t.me/+AbCdEfGhIjKlMn</i>`, [][]echotron.InlineKeyboardButton{
|
||||
• Написать нам
|
||||
|
||||
<i>Ссылка на канал подставится автоматически при создании закупа.</i>`, [][]echotron.InlineKeyboardButton{
|
||||
bot.Row(
|
||||
bot.Button("✓ Ссылка на канал", "button_type_invite"),
|
||||
bot.Button("Своя ссылка", "button_type_custom"),
|
||||
Row(
|
||||
Button("✓ Ссылка на канал", "button_type_invite"),
|
||||
Button("Своя ссылка", "button_type_custom"),
|
||||
),
|
||||
bot.Row(bot.Button("« Отмена", "cancel_add_button")),
|
||||
Row(Button("« Отмена", "cancel_add_button")),
|
||||
})
|
||||
|
||||
case data == "add_media":
|
||||
@@ -102,7 +100,7 @@ https://t.me/+AbCdEfGhIjKlMn</i>`, [][]echotron.InlineKeyboardButton{
|
||||
Отправьте <b>фото, видео или GIF</b>
|
||||
|
||||
<i>Это медиа будет отображаться в креативе вместе с текстом</i>`, [][]echotron.InlineKeyboardButton{
|
||||
bot.Row(bot.Button("« Отмена", "cancel_media")),
|
||||
Row(Button("« Отмена", "cancel_media")),
|
||||
})
|
||||
|
||||
case data == "delete_media":
|
||||
@@ -150,11 +148,11 @@ https://t.me/+AbCdEfGhIjKlMn</i>`, [][]echotron.InlineKeyboardButton{
|
||||
• Написать нам
|
||||
|
||||
<i>Ссылка на канал подставится автоматически при создании закупа.</i>`, [][]echotron.InlineKeyboardButton{
|
||||
bot.Row(
|
||||
bot.Button("✓ Ссылка на канал", "button_type_invite"),
|
||||
bot.Button("Своя ссылка", "button_type_custom"),
|
||||
Row(
|
||||
Button("✓ Ссылка на канал", "button_type_invite"),
|
||||
Button("Своя ссылка", "button_type_custom"),
|
||||
),
|
||||
bot.Row(bot.Button("« Отмена", "cancel_add_button")),
|
||||
Row(Button("« Отмена", "cancel_add_button")),
|
||||
})
|
||||
|
||||
case data == "button_type_custom":
|
||||
@@ -168,11 +166,11 @@ https://t.me/+AbCdEfGhIjKlMn</i>`, [][]echotron.InlineKeyboardButton{
|
||||
• Написать нам
|
||||
|
||||
<i>Ссылка на канал подставится автоматически при создании закупа.</i>`, [][]echotron.InlineKeyboardButton{
|
||||
bot.Row(
|
||||
bot.Button("Ссылка на канал", "button_type_invite"),
|
||||
bot.Button("✓ Своя ссылка", "button_type_custom"),
|
||||
Row(
|
||||
Button("Ссылка на канал", "button_type_invite"),
|
||||
Button("✓ Своя ссылка", "button_type_custom"),
|
||||
),
|
||||
bot.Row(bot.Button("« Отмена", "cancel_add_button")),
|
||||
Row(Button("« Отмена", "cancel_add_button")),
|
||||
})
|
||||
|
||||
case data == "cancel_edit":
|
||||
@@ -321,7 +319,7 @@ URL должен начинаться с <code>https://</code>
|
||||
<i>Например:</i>
|
||||
<code>https://example.com</code>
|
||||
<code>https://t.me/yourchannel</code>`, [][]echotron.InlineKeyboardButton{
|
||||
bot.Row(bot.Button("« Отмена", "cancel_add_button")),
|
||||
Row(Button("« Отмена", "cancel_add_button")),
|
||||
})
|
||||
} else {
|
||||
s.Buttons = append(s.Buttons, InlineButton{
|
||||
@@ -359,7 +357,7 @@ URL должен начинаться с <code>https://</code>
|
||||
URL должен начинаться с <code>https://</code>
|
||||
|
||||
Попробуйте ещё раз.`, [][]echotron.InlineKeyboardButton{
|
||||
bot.Row(bot.Button("« Отмена", "cancel_add_button")),
|
||||
Row(Button("« Отмена", "cancel_add_button")),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -472,23 +470,20 @@ func (s *AddCreative) extractCreativeFromMessage(message *echotron.Message) {
|
||||
|
||||
// generateCreativeName генерирует название из текста или дефолтное
|
||||
func (s *AddCreative) generateCreativeName() string {
|
||||
// Если есть текст, берем первые слова
|
||||
if s.Text != nil && *s.Text != "" {
|
||||
// Удаляем ВСЕ HTML теги с помощью regex
|
||||
re := regexp.MustCompile(`<[^>]*>`)
|
||||
cleanText := re.ReplaceAllString(*s.Text, "")
|
||||
|
||||
// Берем первые 50 символов
|
||||
runes := []rune(strings.TrimSpace(cleanText))
|
||||
if len(runes) > 50 {
|
||||
return string(runes[:50]) + "..."
|
||||
if len(runes) > 10 {
|
||||
return string(runes[:10]) + "..."
|
||||
}
|
||||
if len(runes) > 0 {
|
||||
return string(runes)
|
||||
}
|
||||
}
|
||||
|
||||
// Дефолтное название
|
||||
return "Новый креатив"
|
||||
}
|
||||
|
||||
@@ -505,16 +500,16 @@ func (s *AddCreative) buildEditorButtons(confirmText, cancelCallback string) [][
|
||||
var buttons [][]echotron.InlineKeyboardButton
|
||||
|
||||
// Кнопки редактирования
|
||||
buttons = append(buttons, bot.Row(
|
||||
bot.Button("✎ Текст", "edit_text"),
|
||||
bot.Button("+ Медиа", "add_media"),
|
||||
buttons = append(buttons, Row(
|
||||
Button("✎ Текст", "edit_text"),
|
||||
Button("+ Медиа", "add_media"),
|
||||
))
|
||||
buttons = append(buttons, bot.Row(bot.Button("+ Добавить кнопку", "add_button")))
|
||||
buttons = append(buttons, Row(Button("+ Добавить кнопку", "add_button")))
|
||||
|
||||
// Кнопка удаления медиа (если медиа добавлено)
|
||||
if s.MediaFileID != "" {
|
||||
buttons = append(buttons, bot.Row(
|
||||
bot.Button("⌫ Убрать медиа", "delete_media"),
|
||||
buttons = append(buttons, Row(
|
||||
Button("⌫ Убрать медиа", "delete_media"),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -522,7 +517,7 @@ func (s *AddCreative) buildEditorButtons(confirmText, cancelCallback string) [][
|
||||
if len(s.Buttons) > 0 {
|
||||
var row []echotron.InlineKeyboardButton
|
||||
for i, btn := range s.Buttons {
|
||||
row = append(row, bot.Button(
|
||||
row = append(row, Button(
|
||||
fmt.Sprintf(`⌫ Убрать «%s»`, btn.Text),
|
||||
fmt.Sprintf("delete_button:%d", i),
|
||||
))
|
||||
@@ -540,13 +535,13 @@ func (s *AddCreative) buildEditorButtons(confirmText, cancelCallback string) [][
|
||||
|
||||
// Финальные кнопки
|
||||
if s.Text != nil {
|
||||
buttons = append(buttons, bot.Row(
|
||||
bot.Button("← "+cancelCallback, "cancel"),
|
||||
bot.Button(confirmText, "confirm_create"),
|
||||
buttons = append(buttons, Row(
|
||||
Button("← "+cancelCallback, "cancel"),
|
||||
Button(confirmText, "confirm_create"),
|
||||
))
|
||||
} else {
|
||||
buttons = append(buttons, bot.Row(
|
||||
bot.Button("← "+cancelCallback, "cancel"),
|
||||
buttons = append(buttons, Row(
|
||||
Button("← "+cancelCallback, "cancel"),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -592,7 +587,7 @@ func (s *AddCreative) createCreative(b *bot.Bot) {
|
||||
jwt := b.Session.JWT
|
||||
if jwt == "" {
|
||||
log.Error().Msg("JWT is empty in session")
|
||||
b.SendNew("<b>❌ Ошибка авторизации</b>\n\nПопробуйте /start login", bot.Keyboard())
|
||||
b.SendNew("<b>❌ Ошибка авторизации</b>\n\nПопробуйте /start login", Keyboard())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -692,7 +687,7 @@ https://t.me/+AbCdEfGhIjKlMn</i>
|
||||
🔘 <b>Кнопок добавлено:</b> %d`, len(s.Buttons))
|
||||
}
|
||||
|
||||
b.SendNew(successText, bot.Keyboard())
|
||||
b.SendNew(successText, Keyboard())
|
||||
|
||||
// Возвращаемся на экран креативов
|
||||
if s.BackState != nil {
|
||||
|
||||
Reference in New Issue
Block a user