Skip to content

Commit

Permalink
Merge pull request #35 from BucketOnHead/dev
Browse files Browse the repository at this point in the history
fix: recover lost commits
  • Loading branch information
BucketOnHead authored Jun 30, 2023
2 parents 3176f2d + 8edb780 commit 30795e4
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.bucketonhead.dao;

import com.github.bucketonhead.entity.AppTask;
import com.github.bucketonhead.entity.task.AppTask;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.bucketonhead.dao;

import com.github.bucketonhead.entity.AppUser;
import com.github.bucketonhead.entity.user.AppUser;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.bucketonhead.entity;
package com.github.bucketonhead.entity.task;

import com.github.bucketonhead.entity.user.AppUser;
import lombok.*;

import javax.persistence.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.bucketonhead.entity;
package com.github.bucketonhead.entity.user;

import com.github.bucketonhead.entity.enums.BotState;
import com.github.bucketonhead.entity.task.AppTask;
import com.github.bucketonhead.entity.user.enums.BotState;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.bucketonhead.entity.enums;
package com.github.bucketonhead.entity.user.enums;

public enum BotState {
BASIC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ public String getBotToken() {

@Override
public void onUpdateReceived(Update update) {
log.info("Received update: id={}", update.getUpdateId());
log.debug("Received update: {}", update);
updateController.processUpdate(update);
}

public void sendBotMessageIgnoreException(SendMessage message) {
if (message != null) {
public void sendBotMessageIgnoreException(SendMessage msg) {
if (msg != null) {
try {
execute(message);
} catch (TelegramApiException e) {
log.error("Message was not sent: {}", e.getMessage());
execute(msg);
log.info("Message sent successfully: chat_id={}, text='{}'", msg.getChatId(), msg.getText());
log.debug("Message sent successfully: {}", msg);
} catch (TelegramApiException ex) {
log.error("Failed to send message: {}", ex.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.bucketonhead.controller;

import com.github.bucketonhead.consts.MessagePattern;
import com.github.bucketonhead.service.rabbitmq.UpdateProducer;
import com.github.bucketonhead.service.rabbitmq.producer.UpdateProducer;
import com.github.bucketonhead.utils.MessageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
Expand All @@ -21,40 +21,43 @@ public UpdateController(@Lazy TelegramBot telegramBot,
this.updateProducer = updateProducer;
}

public void setView(SendMessage sendMessage) {
telegramBot.sendBotMessageIgnoreException(sendMessage);
log.debug("Отправлено сообщение[text='{}'] от бота в чат[id={}]",
sendMessage.getText(), sendMessage.getChatId());
public void setView(SendMessage msg) {
log.info("View set: chat_id={}, text='{}'", msg.getChatId(), msg.getText());
log.debug("View set: {}", msg);
telegramBot.sendBotMessageIgnoreException(msg);
}

public void processUpdate(Update update) {
if (update == null) {
log.error("Received update is null");
log.warn("Received null update");
return;
}

log.info("Update processing: id={}", update.getUpdateId());
log.debug("Update processing: {}", update);
if (update.hasMessage()) {
distributeMessageByType(update);
} else {
log.error("Unsupported message type is received: " + update);
log.warn("Unsupported message type: {}", update);
}
}

private void distributeMessageByType(Update update) {
var message = update.getMessage();
if (message.hasText()) {
log.debug("Получено сообщение[text='{}'] от пользователя[id={}]",
message.getText(), message.getFrom().getId());
processTextMessage(update);
private void distributeMessageByType(Update upd) {
log.info("Update distributing: id={}", upd.getUpdateId());
log.debug("Update distributing: {}", upd);
var msg = upd.getMessage();
if (msg.hasText()) {
processTextMessage(upd);
} else {
log.error("Получен не поддерживаемый тип сообщения от пользователя[id={}]",
message.getFrom().getId());
setUnsupportedMessageTypeView(update);
setUnsupportedMessageTypeView(upd);
}
}

private void processTextMessage(Update update) {
updateProducer.produceTextMessage(update);
private void processTextMessage(Update upd) {
updateProducer.produceTextMessage(upd);
log.info("Update(TextMessage) processed: update_id={}, message_id={}",
upd.getUpdateId(), upd.getMessage().getMessageId());
log.debug("Update(TextMessage) processed: {}", upd);
}

private void setUnsupportedMessageTypeView(Update update) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.bucketonhead.service.rabbitmq;
package com.github.bucketonhead.service.rabbitmq.consumer;

import org.telegram.telegrambots.meta.api.methods.send.SendMessage;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.bucketonhead.service.rabbitmq.impl;
package com.github.bucketonhead.service.rabbitmq.consumer.impl;

import com.github.bucketonhead.consts.RabbitQueue;
import com.github.bucketonhead.controller.UpdateController;
import com.github.bucketonhead.service.rabbitmq.AnswerConsumer;
import com.github.bucketonhead.service.rabbitmq.consumer.AnswerConsumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
Expand All @@ -17,9 +17,9 @@ public class AnswerConsumerImpl implements AnswerConsumer {

@Override
@RabbitListener(queues = RabbitQueue.ANSWER_MESSAGE)
public void consume(SendMessage sendMessage) {
log.debug("Получено сообщение[text='{}'] из очереди[name='{}'] для чата[id={}]",
sendMessage.getText(), RabbitQueue.ANSWER_MESSAGE, sendMessage.getChatId());
updateController.setView(sendMessage);
public void consume(SendMessage msg) {
log.info("Received sendMessage: chat_id={}, text='{}'", msg.getChatId(), msg.getText());
log.debug("Received sendMessage: {}", msg);
updateController.setView(msg);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.bucketonhead.service.rabbitmq;
package com.github.bucketonhead.service.rabbitmq.producer;

import com.github.bucketonhead.consts.RabbitQueue;
import org.telegram.telegrambots.meta.api.objects.Update;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.bucketonhead.service.rabbitmq.impl;
package com.github.bucketonhead.service.rabbitmq.producer.impl;

import com.github.bucketonhead.service.rabbitmq.UpdateProducer;
import com.github.bucketonhead.service.rabbitmq.producer.UpdateProducer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
Expand All @@ -15,9 +15,9 @@ public class UpdateProducerImpl implements UpdateProducer {

@Override
public void produce(String rabbitQueue, Update update) {
var message = update.getMessage();
log.debug("Сообщение[text='{}'] от пользователя[id={}] добавлено в очередь[name='{}']",
message.getText(), message.getFrom().getId(), rabbitQueue);
var msg = update.getMessage();
log.info("Producing message: from_id={}, text='{}'", msg.getFrom().getId(), msg.getText());
log.debug("Producing message: {}", msg);
rabbitTemplate.convertAndSend(rabbitQueue, update);
}
}
2 changes: 1 addition & 1 deletion dispatcher/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
server.port=8084

logging.level.com.github.bucketonhead=DEBUG
logging.level.com.github.bucketonhead=info
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.bucketonhead.service.processor;

import com.github.bucketonhead.entity.AppUser;
import com.github.bucketonhead.entity.user.AppUser;
import org.telegram.telegrambots.meta.api.objects.Message;

public interface CommandProcessor {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.bucketonhead.service.processor.basic;

import com.github.bucketonhead.entity.AppUser;
import com.github.bucketonhead.entity.user.AppUser;
import com.github.bucketonhead.service.processor.CommandProcessor;
import org.telegram.telegrambots.meta.api.objects.Message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.github.bucketonhead.cache.AppCache;
import com.github.bucketonhead.dao.AppUserJpaRepository;
import com.github.bucketonhead.entity.AppUser;
import com.github.bucketonhead.entity.enums.BotState;
import com.github.bucketonhead.entity.user.AppUser;
import com.github.bucketonhead.entity.user.enums.BotState;
import com.github.bucketonhead.service.processor.basic.BasicService;
import com.github.bucketonhead.service.processor.main.enums.AppCommand;
import com.github.bucketonhead.service.sender.MessageSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.github.bucketonhead.cache.AppCache;
import com.github.bucketonhead.dao.AppUserJpaRepository;
import com.github.bucketonhead.dao.RawDataJpaRepository;
import com.github.bucketonhead.entity.AppUser;
import com.github.bucketonhead.entity.user.AppUser;
import com.github.bucketonhead.entity.RawData;
import com.github.bucketonhead.entity.enums.BotState;
import com.github.bucketonhead.entity.user.enums.BotState;
import com.github.bucketonhead.service.processor.basic.BasicService;
import com.github.bucketonhead.service.processor.main.MainService;
import com.github.bucketonhead.service.processor.main.enums.AppCommand;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.bucketonhead.service.processor.task;

import com.github.bucketonhead.entity.AppUser;
import com.github.bucketonhead.entity.user.AppUser;
import com.github.bucketonhead.service.processor.CommandProcessor;
import org.telegram.telegrambots.meta.api.objects.Message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.github.bucketonhead.cache.AppCache;
import com.github.bucketonhead.dao.AppTaskJpaRepository;
import com.github.bucketonhead.dao.AppUserJpaRepository;
import com.github.bucketonhead.entity.AppTask;
import com.github.bucketonhead.entity.AppUser;
import com.github.bucketonhead.entity.enums.BotState;
import com.github.bucketonhead.entity.task.AppTask;
import com.github.bucketonhead.entity.user.AppUser;
import com.github.bucketonhead.entity.user.enums.BotState;
import com.github.bucketonhead.service.processor.main.enums.AppCommand;
import com.github.bucketonhead.service.processor.task.TaskService;
import com.github.bucketonhead.service.sender.MessageSender;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.bucketonhead.utils;

import com.github.bucketonhead.consts.MessagePattern;
import com.github.bucketonhead.entity.AppUser;
import com.github.bucketonhead.entity.user.AppUser;
import com.github.bucketonhead.service.processor.main.enums.AppCommand;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;
Expand Down

0 comments on commit 30795e4

Please sign in to comment.