forked from Sanders/TelegaBot
Small fixes
This commit is contained in:
@@ -2,7 +2,9 @@ package ru.cathub.telegabot.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.cathub.telegabot.model.Book;
|
||||
import ru.cathub.telegabot.model.BookCreationCache;
|
||||
import ru.cathub.telegabot.model.TextRole;
|
||||
@@ -42,6 +44,7 @@ public class BookCreationServiceImpl implements BookCreationService {
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void handleExistingAddCache(BotUser user, String text) {
|
||||
BookCreationCache cache = bookCacheService.getCache(user.getId());
|
||||
@@ -91,9 +94,28 @@ public class BookCreationServiceImpl implements BookCreationService {
|
||||
bookCacheService.clearCache(user.getId());
|
||||
|
||||
// Отправляем подтверждение
|
||||
String message = String.format("✅ Книга успешно добавлена!\n\n%s",
|
||||
String message = String.format("✅ Книга успешно добавлена\\!\n\n%s",
|
||||
bookCommonService.formatBookDetails(book));
|
||||
telegramClientService.sendMessageWithMarkdown(user, message);
|
||||
// Формируем статистику
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate endOfYear = LocalDate.of(today.getYear(), 12, 31);
|
||||
long weeksLeft = ChronoUnit.WEEKS.between(today, endOfYear);
|
||||
|
||||
int target = user.getBooksToRead() != null ? user.getBooksToRead() : 0;
|
||||
int read = user.getBooks() != null ? user.getBooks().size() : 0;
|
||||
int left = target - read;
|
||||
|
||||
String stats = String.format(
|
||||
"\n\n📊 *Статистика:*\n" +
|
||||
"⏳ До конца года: %d недель\n" +
|
||||
"🎯 Цель: %d книг\n" +
|
||||
"✅ Прочитано: %d\n" +
|
||||
"📖 Осталось: %d",
|
||||
weeksLeft, target, read, left > 0 ? left : 0
|
||||
);
|
||||
|
||||
telegramClientService.sendMessageWithMarkdown(user, message + stats);
|
||||
|
||||
|
||||
// Генерируем и отправляем поздравление
|
||||
try {
|
||||
@@ -106,25 +128,9 @@ public class BookCreationServiceImpl implements BookCreationService {
|
||||
TextRole.DEFAULT
|
||||
);
|
||||
|
||||
// Формируем статистику
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate endOfYear = LocalDate.of(today.getYear(), 12, 31);
|
||||
long weeksLeft = ChronoUnit.WEEKS.between(today, endOfYear);
|
||||
|
||||
|
||||
int target = user.getBooksToRead() != null ? user.getBooksToRead() : 0;
|
||||
int read = user.getBooks() != null ? user.getBooks().size() : 0;
|
||||
int left = target - read;
|
||||
|
||||
String stats = String.format(
|
||||
"\n\n📊 *Статистика:*\n" +
|
||||
"⏳ До конца года: %d недель\n" +
|
||||
"🎯 Цель: %d книг\n" +
|
||||
"✅ Прочитано: %d\n" +
|
||||
"📖 Осталось: %d",
|
||||
weeksLeft, target, read, left > 0 ? left : 0
|
||||
);
|
||||
|
||||
telegramClientService.sendMessageWithMarkdown(user, "🎉 *Поздравляю с прочтением!*\n\n" + congrat + stats);
|
||||
telegramClientService.sendMessageWithMarkdown(user, "🎉 *Поздравляю с прочтением!*\n\n" + congrat);
|
||||
} catch (Exception e) {
|
||||
log.error("Error generating congratulation for user {}", user.getId(), e);
|
||||
telegramClientService.sendMessage(user, "📚 Спасибо за добавление книги!");
|
||||
|
||||
@@ -77,7 +77,7 @@ public class TelegramClientServiceImps implements TelegramClientService {
|
||||
return telegramClient.execute(message);
|
||||
} catch (TelegramApiException e) {
|
||||
//logger.error("Ошибка отправки сообщения", e);
|
||||
throw new RuntimeException(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user