-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeFiMonitorBotImpl.java
More file actions
80 lines (66 loc) · 2.47 KB
/
DeFiMonitorBotImpl.java
File metadata and controls
80 lines (66 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package ivan.solscanbot.bot;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
@Component
public class DeFiMonitorBotImpl extends TelegramLongPollingBot {
private final String token;
private final String username;
public DeFiMonitorBotImpl(
@Value("${telegram.bot.token}") String token,
@Value("${telegram.bot.username}") String username
) {
this.token = token;
this.username = username;
}
@Override
public String getBotUsername() {
return username;
}
@Override
public String getBotToken() {
return token;
}
@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage() && update.getMessage().hasText()) {
String messageText = update.getMessage().getText();
long chatId = update.getMessage().getChatId();
if (messageText.startsWith("/add")) {
handleAddAddress(chatId, messageText);
} else if (messageText.startsWith("/list")) {
handleListAddresses(chatId);
} else if (messageText.startsWith("/remove")) {
handleRemoveAddress(chatId, messageText);
} else {
sendMessage(chatId, "Unknown command. Use /add, /list, or /remove");
}
}
}
private void handleAddAddress(long chatId, String message) {
sendMessage(chatId, "Address added to monitoring");
}
private void handleListAddresses(long chatId) {
sendMessage(chatId, "List of monitored addresses...");
}
private void handleRemoveAddress(long chatId, String message) {
sendMessage(chatId, "Address removed from monitoring");
}
public void sendNotification(long chatId, String notification) {
sendMessage(chatId, notification);
}
private void sendMessage(long chatId, String text) {
SendMessage message = new SendMessage();
message.setChatId(String.valueOf(chatId));
message.setText(text);
try {
execute(message);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}