Skip to content

Commit

Permalink
removed AbstractRedTelBot.java
Browse files Browse the repository at this point in the history
  • Loading branch information
yvasyliev committed Nov 8, 2023
1 parent 9629779 commit 46cdc7c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 53 deletions.

This file was deleted.

40 changes: 32 additions & 8 deletions src/main/java/com/github/yvasyliev/bots/telegram/RedTelBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.methods.send.SendMediaGroup;
import org.telegram.telegrambots.meta.api.methods.send.SendPhoto;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.generics.BotSession;
import org.telegram.telegrambots.starter.AfterBotRegistration;

Expand All @@ -34,7 +33,7 @@
import java.util.concurrent.CompletableFuture;

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

@Autowired
Expand All @@ -57,6 +56,18 @@ public class RedTelBot extends AbstractRedTelBot {
@Autowired
private DelayedBlockingExecutor delayedBlockingExecutor;

@Value("${telegram.chat.id}")
private String chatId;

@Value("${telegram.channel.id}")
private String channelId;

@Value("${telegram.admin.id}")
private String adminId;

@Value("${telegram.bot.username}")
private String botUsername;

public RedTelBot(@Value("${telegram.bot.token}") String botToken) {
super(botToken);
}
Expand All @@ -67,11 +78,6 @@ public void setBotSession(BotSession botSession) {
LOGGER.info("{} started long polling.", getBotUsername());
}

public void startPolling() throws TelegramApiException {
botSession = context.getBean(TelegramBotsApi.class).registerBot(this);
LOGGER.info("{} started long polling.", getBotUsername());
}

@PreDestroy
public void stopPolling() {
botSession.stop();
Expand Down Expand Up @@ -156,6 +162,7 @@ public CompletableFuture<Message> executeDelayed(SendPhoto sendPhoto) {
return delayedBlockingExecutor.submit(() -> execute(sendPhoto));
}

// TODO: 11/8/2023 message.isCommand
private Optional<String> getCommand(Message message) {
long userId = message.getFrom().getId();
if (message.hasText()) {
Expand All @@ -172,4 +179,21 @@ private Optional<String> getCommand(Message message) {
private boolean looksLikeCommand(String text) {
return text.matches("/\\w+");
}

public String getChatId() {
return chatId;
}

public String getChannelId() {
return channelId;
}

public String getAdminId() {
return adminId;
}

@Override
public String getBotUsername() {
return botUsername;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Optional<List<Message>> applyWithException(@NonNull String chatId, PhotoG
public List<Message> sendExtraPhotos(int replyToMessageId, int forwardMessageId) throws ExecutionException, InterruptedException {
var post = extraPhotos.remove(forwardMessageId);
return post != null
? sendDelayed(redTelBot.getGroupId(), replyToMessageId, post)
? sendDelayed(redTelBot.getChatId(), replyToMessageId, post)
: List.of();
}

Expand Down

0 comments on commit 46cdc7c

Please sign in to comment.