Skip to content

Commit

Permalink
renamed RedTelBot.java
Browse files Browse the repository at this point in the history
  • Loading branch information
yvasyliev committed Nov 8, 2023
1 parent ac7014a commit ed60277
Show file tree
Hide file tree
Showing 29 changed files with 61 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import java.util.concurrent.CompletableFuture;

@Component
public class RedTelBot extends TelegramLongPollingBot {
private static final Logger LOGGER = LoggerFactory.getLogger(RedTelBot.class);
public class RedditTelegramForwarderBot extends TelegramLongPollingBot {
private static final Logger LOGGER = LoggerFactory.getLogger(RedditTelegramForwarderBot.class);

@Autowired
private ApplicationContext context;
Expand Down Expand Up @@ -68,7 +68,7 @@ public class RedTelBot extends TelegramLongPollingBot {
@Value("${telegram.bot.username}")
private String botUsername;

public RedTelBot(@Value("${telegram.bot.token}") String botToken) {
public RedditTelegramForwarderBot(@Value("${telegram.bot.token}") String botToken) {
super(botToken);
}

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

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.yvasyliev.bots.telegram.RedTelBot;
import com.github.yvasyliev.bots.telegram.RedditTelegramForwarderBot;
import com.github.yvasyliev.model.dto.RedditPostDecisionData;
import com.github.yvasyliev.model.dto.post.Post;
import com.github.yvasyliev.model.events.NewChannelPostEvent;
Expand Down Expand Up @@ -30,7 +30,7 @@ public class PostManager {
private static final Logger LOGGER = LoggerFactory.getLogger(PostManager.class);

@Autowired
private RedTelBot redTelBot;
private RedditTelegramForwarderBot redditTelegramForwarderBot;

@Autowired
private ApplicationContext context;
Expand Down Expand Up @@ -64,7 +64,7 @@ public <T extends Post> void publishPost(T post) {

public <T extends Post> void publishPost(T post, String postServiceName) throws Exception {
@SuppressWarnings("unchecked") var postService = (PostService<T, ?>) context.getBean(postServiceName);
var chatId = post.isApproved() ? redTelBot.getChannelId() : redTelBot.getAdminId();
var chatId = post.isApproved() ? redditTelegramForwarderBot.getChannelId() : redditTelegramForwarderBot.getAdminId();
var sentMessage = postService.applyWithException(chatId, post);
if (sentMessage.isPresent() && !post.isApproved()) {
try {
Expand Down Expand Up @@ -122,6 +122,6 @@ private Message askApprove(String chatId, int created) throws TelegramApiExcepti
denyButton
))))
.build();
return redTelBot.execute(sendMessage);
return redditTelegramForwarderBot.execute(sendMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public void acceptWithException(CallbackQuery callbackQuery) throws TelegramApiE
var chatId = message.getChatId();
var messageId = message.getMessageId();
var messageData = objectMapper.readValue(callbackQuery.getData(), ExternalMessageData.class);
redTelBot.execute(new ForwardMessage(
redTelBot.getChannelId(),
redditTelegramForwarderBot.execute(new ForwardMessage(
redditTelegramForwarderBot.getChannelId(),
messageData.fromChatId(),
messageData.messageId()
));
redTelBot.execute(new EditMessageReplyMarkup(
redditTelegramForwarderBot.execute(new EditMessageReplyMarkup(
chatId.toString(),
messageId,
callbackQuery.getInlineMessageId(),
Expand All @@ -37,6 +37,6 @@ public void acceptWithException(CallbackQuery callbackQuery) throws TelegramApiE
.text(format("responses/approvepost.md", message.getText()))
.parseMode(ParseMode.MARKDOWNV2)
.build();
redTelBot.execute(editMessageText);
redditTelegramForwarderBot.execute(editMessageText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void acceptWithException(CallbackQuery callbackQuery) throws IOException,
var messageId = message.getMessageId();
var data = objectMapper.readValue(callbackQuery.getData(), RedditPostDecisionData.class);
postManager.publishPostCandidate(data.created());
redTelBot.execute(new EditMessageReplyMarkup(
redditTelegramForwarderBot.execute(new EditMessageReplyMarkup(
chatId.toString(),
messageId,
callbackQuery.getInlineMessageId(),
Expand All @@ -37,6 +37,6 @@ public void acceptWithException(CallbackQuery callbackQuery) throws IOException,
.text(format("responses/approvepost.md", message.getText()))
.parseMode(ParseMode.MARKDOWNV2)
.build();
redTelBot.execute(editMessageText);
redditTelegramForwarderBot.execute(editMessageText);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.yvasyliev.service.telegram.callbacks;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.yvasyliev.bots.telegram.RedTelBot;
import com.github.yvasyliev.bots.telegram.RedditTelegramForwarderBot;
import com.github.yvasyliev.service.telegram.readers.BotResponseReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.function.ThrowingConsumer;
Expand All @@ -12,7 +12,7 @@

public abstract class Callback implements ThrowingConsumer<CallbackQuery> {
@Autowired
protected RedTelBot redTelBot;
protected RedditTelegramForwarderBot redditTelegramForwarderBot;

@Autowired
protected BotResponseReader responseReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void acceptWithException(CallbackQuery callbackQuery) throws Exception {
var message = callbackQuery.getMessage();
var chatId = message.getChatId();
var messageId = message.getMessageId();
redTelBot.execute(new EditMessageReplyMarkup(
redditTelegramForwarderBot.execute(new EditMessageReplyMarkup(
chatId.toString(),
messageId,
callbackQuery.getInlineMessageId(),
Expand All @@ -25,6 +25,6 @@ public void acceptWithException(CallbackQuery callbackQuery) throws Exception {
.text(format("responses/rejectpost.md", message.getText()))
.parseMode(ParseMode.MARKDOWNV2)
.build();
redTelBot.execute(editMessageText);
redditTelegramForwarderBot.execute(editMessageText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void acceptWithException(CallbackQuery callbackQuery) throws Exception {
var messageId = message.getMessageId();
var data = objectMapper.readValue(callbackQuery.getData(), RedditPostDecisionData.class);
postManager.rejectPostCandidate(data.created());
redTelBot.execute(new EditMessageReplyMarkup(
redditTelegramForwarderBot.execute(new EditMessageReplyMarkup(
chatId.toString(),
messageId,
callbackQuery.getInlineMessageId(),
Expand All @@ -33,6 +33,6 @@ public void acceptWithException(CallbackQuery callbackQuery) throws Exception {
.text(format("responses/rejectpost.md", message.getText()))
.parseMode(ParseMode.MARKDOWNV2)
.build();
redTelBot.execute(editMessageText);
redditTelegramForwarderBot.execute(editMessageText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public class Reply extends Callback {
public void acceptWithException(CallbackQuery callbackQuery) throws IOException, URISyntaxException, TelegramApiException {
var messageData = objectMapper.readValue(callbackQuery.getData(), ExternalMessageData.class);
var userId = callbackQuery.getFrom().getId();
redTelBot.addUserCommand(userId, "/replysent");
redTelBot.addAwaitingReply(userId, messageData);
redditTelegramForwarderBot.addUserCommand(userId, "/replysent");
redditTelegramForwarderBot.addAwaitingReply(userId, messageData);
var sendMessage = SendMessage.builder()
.chatId(userId)
.text(responseReader.applyWithException("responses/reply.md"))
.parseMode(ParseMode.MARKDOWNV2)
.build();
redTelBot.execute(sendMessage);
redditTelegramForwarderBot.execute(sendMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
public abstract class AdminCommand extends Command {
@Override
protected boolean hasPermission(Message message) {
return redTelBot.isAdmin(message.getFrom());
return redditTelegramForwarderBot.isAdmin(message.getFrom());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class BlockAuthor extends AdminCommand {
@Override
public void execute(Message message) throws URISyntaxException, IOException, TelegramApiException {
redTelBot.addUserCommand(message.getFrom().getId(), "/addblockedauthor");
redditTelegramForwarderBot.addUserCommand(message.getFrom().getId(), "/addblockedauthor");
reply(message, "responses/blockauthor.md");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class Cancel extends Command {
@Override
public void execute(Message message) throws TelegramApiException, URISyntaxException, IOException {
redTelBot.removeUserCommand(message.getFrom().getId());
redditTelegramForwarderBot.removeUserCommand(message.getFrom().getId());
reply(message, "responses/cancel.md");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.yvasyliev.service.telegram.commands;

import com.github.yvasyliev.bots.telegram.RedTelBot;
import com.github.yvasyliev.bots.telegram.RedditTelegramForwarderBot;
import com.github.yvasyliev.service.telegram.readers.BotResponseReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.function.ThrowingConsumer;
Expand All @@ -14,7 +14,7 @@

public abstract class Command implements ThrowingConsumer<Message> {
@Autowired
protected RedTelBot redTelBot;
protected RedditTelegramForwarderBot redditTelegramForwarderBot;

@Autowired
protected BotResponseReader responseReader;
Expand All @@ -39,6 +39,6 @@ protected Message reply(Message to, String template, Object... args) throws URIS
.disableWebPagePreview(true)
.parseMode(ParseMode.MARKDOWNV2)
.build();
return redTelBot.execute(sendMessage);
return redditTelegramForwarderBot.execute(sendMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class ContactAdmin extends Command {
@Override
public void execute(Message message) throws Exception {
redTelBot.addUserCommand(message.getFrom().getId(), "/textadmin");
redditTelegramForwarderBot.addUserCommand(message.getFrom().getId(), "/textadmin");
reply(message, "responses/contactadmin.md");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PausePublishing extends AdminCommand {
@Override
public void execute(Message message) throws TelegramApiException, URISyntaxException, IOException {
postManager.pausePosting();
redTelBot.execute(new SendMessage(
redditTelegramForwarderBot.execute(new SendMessage(
message.getChatId().toString(),
responseReader.applyWithException("responses/pausepublishing.md")
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public void execute(Message message) throws TelegramApiException, IOException, U
var sourceChatId = message.getChatId().toString();
var sourceMessageId = message.getMessageId();

redTelBot.execute(new ForwardMessage(
redTelBot.getAdminId(),
redditTelegramForwarderBot.execute(new ForwardMessage(
redditTelegramForwarderBot.getAdminId(),
sourceChatId,
sourceMessageId
));
Expand Down Expand Up @@ -56,15 +56,15 @@ public void execute(Message message) throws TelegramApiException, IOException, U
.build();

var sendMessage = SendMessage.builder()
.chatId(redTelBot.getAdminId())
.chatId(redditTelegramForwarderBot.getAdminId())
.text(responseReader.applyWithException("responses/postsuggested/suggest_post.md"))
.replyMarkup(new InlineKeyboardMarkup(List.of(List.of(
approveButton,
denyButton,
replyButton
))))
.build();
redTelBot.execute(sendMessage);
redditTelegramForwarderBot.execute(sendMessage);

reply(message, "responses/postsuggested/post_suggested.md");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public class ReplySent extends AdminCommand {
public void execute(Message message) throws URISyntaxException, IOException, TelegramApiException {
if (message.hasText()) {
var userId = message.getFrom().getId();
redTelBot.removeUserCommand(userId);
var awaitingReply = redTelBot.getAwaitingReply(userId);
redditTelegramForwarderBot.removeUserCommand(userId);
var awaitingReply = redditTelegramForwarderBot.getAwaitingReply(userId);
var replyMessage = SendMessage.builder()
.chatId(awaitingReply.fromChatId())
.replyToMessageId(awaitingReply.messageId())
.text(responseReader.applyWithException("responses/replysent/reply_template.md").formatted(markdownV2Escaper.apply(message.getText())))
.parseMode(ParseMode.MARKDOWNV2)
.build();
redTelBot.execute(replyMessage);
redditTelegramForwarderBot.execute(replyMessage);
reply(message, "responses/replysent/reply_sent.md");
} else {
reply(message, "responses/replysent/empty_reply.md");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ResumePublishing extends AdminCommand {
@Override
public void execute(Message message) throws TelegramApiException, URISyntaxException, IOException {
postManager.resumePosting();
redTelBot.execute(new SendMessage(
redditTelegramForwarderBot.execute(new SendMessage(
message.getChatId().toString(),
responseReader.applyWithException("responses/resumepublishing.md")
));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.yvasyliev.service.telegram.commands;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.objects.Message;
Expand All @@ -16,12 +15,12 @@ public class Start extends Command {

@Override
public void execute(Message message) throws TelegramApiException, URISyntaxException, IOException {
if (redTelBot.isAdmin(message.getFrom())) {
if (redditTelegramForwarderBot.isAdmin(message.getFrom())) {
reply(
message,
"responses/admin/start.md",
telegramChannelName,
redTelBot.getMe().getFirstName()
redditTelegramForwarderBot.getMe().getFirstName()
);
} else {
reply(message, "responses/start.md", telegramChannelName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class Stop extends AdminCommand {
@Override
public void execute(Message message) throws TelegramApiException, URISyntaxException, IOException {
context.close();
reply(message, "responses/stop.md", redTelBot.getBotUsername());
reply(message, "responses/stop.md", redditTelegramForwarderBot.getBotUsername());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class SuggestPost extends Command {
@Override
public void execute(Message message) throws TelegramApiException, URISyntaxException, IOException {
redTelBot.addUserCommand(message.getFrom().getId(), "/postsuggested");
redditTelegramForwarderBot.addUserCommand(message.getFrom().getId(), "/postsuggested");
reply(message, "responses/suggestpost.md");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public class TextAdmin extends Command {

@Override
public void execute(Message message) throws TelegramApiException, IOException, URISyntaxException {
redTelBot.removeUserCommand(message.getFrom().getId());
redditTelegramForwarderBot.removeUserCommand(message.getFrom().getId());
var sourceChatId = message.getChatId();
var sourceMessageId = message.getMessageId();
var forwardMessage = ForwardMessage.builder()
.chatId(redTelBot.getAdminId())
.chatId(redditTelegramForwarderBot.getAdminId())
.fromChatId(sourceChatId)
.messageId(sourceMessageId)
.build();
redTelBot.execute(forwardMessage);
redditTelegramForwarderBot.execute(forwardMessage);
var replyButton = InlineKeyboardButton.builder()
.text("🔙 Reply")
.callbackData(objectMapper.writeValueAsString(new ExternalMessageData(
Expand All @@ -40,11 +40,11 @@ public void execute(Message message) throws TelegramApiException, IOException, U
)))
.build();
var sendMessage = SendMessage.builder()
.chatId(redTelBot.getAdminId())
.chatId(redditTelegramForwarderBot.getAdminId())
.text(responseReader.applyWithException("responses/textadmin/message_to_admin.md"))
.replyMarkup(new InlineKeyboardMarkup(List.of(List.of(replyButton))))
.build();
redTelBot.execute(sendMessage);
redditTelegramForwarderBot.execute(sendMessage);
reply(message, "responses/textadmin/message_sent.md");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class UnblockAuthor extends AdminCommand {
@Override
public void execute(Message message) throws TelegramApiException, URISyntaxException, IOException {
redTelBot.addUserCommand(message.getFrom().getId(), "/removeblockedauthor");
redditTelegramForwarderBot.addUserCommand(message.getFrom().getId(), "/removeblockedauthor");
reply(message, "responses/unblockauthor.md");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Optional<Message> applyWithException(@NonNull String chatId, @NonNull Gif
.hasSpoiler(post.isHasSpoiler())
.build();

return redTelBot.execute(sendAnimation);
return redditTelegramForwarderBot.execute(sendAnimation);
}, post));
}

Expand Down
Loading

0 comments on commit ed60277

Please sign in to comment.