Skip to content

Commit 9a8859d

Browse files
committed
send data about live flights
1 parent 4c03cdd commit 9a8859d

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

telegram-bot/src/main/java/project/vilsoncake/telegrambot/bot/ScheduleSender.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ public void checkNewFlightAndSendsThem() throws TelegramApiException {
124124
flight.getAirport(), flight.getCode(), flight.getAirlineName(), user.getAirport()
125125
));
126126

127-
try {
128-
absSender.execute(message);
129-
} catch (TelegramApiException e) {
130-
throw new RuntimeException(e);
131-
}
127+
absSender.execute(message);
128+
} else if (flightService.existsByUserAndFlightId(user, flight.getId()) && flight.isLive() && !flightService.findByUserAndFlightId(user, flight.getId()).isActive()) {
129+
flightService.changeFlightActive(flightService.findByUserAndFlightId(user, flight.getId()), true);
130+
SendMessage message = new SendMessage();
131+
message.setChatId(user.getChatId());
132+
message.setText(String.format(MessageConst.LIVE_FLIGHT_TEXT, flight.getAirport(), flight.getCode(), flight.getAirlineName(), flight.getCallsign(), flight.getId()));
133+
134+
absSender.execute(message);
132135
}
133136
}
134137
}

telegram-bot/src/main/java/project/vilsoncake/telegrambot/constant/MessageConst.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,38 @@ public class MessageConst {
1717
Flight to your airport from %s.
1818
Aircraft: %s
1919
Airline: %s
20-
View there:
20+
View here:
2121
https://www.flightradar24.com/airport/%s/arrivals
2222
""";
23+
public static final String LIVE_FLIGHT_TEXT = """
24+
Flight now to your airport from %s.
25+
Aircraft: %s
26+
Airline: %s
27+
View here:
28+
https://www.flightradar24.com/%s/%s
29+
""";
2330
public static final String AN_124_FLIGHT_TEXT = """
2431
An-124 in the air right now.
2532
Altitude: %sm:
2633
Ground speed: %skm/h
2734
Distance from your airport: %skm
28-
View there:
35+
View here:
2936
https://www.flightradar24.com/%s/%s
3037
""";
3138
public static final String AN_124_NEARLY_CLOSE_TO_YOUR_AIRPORT_TEXT = """
3239
An-124 NEARLY CLOSE TO YOUR AIRPORT right now.
3340
Altitude: %sm:
3441
Ground speed: %skm/h
3542
Distance from your airport: %skm
36-
View there:
43+
View here:
3744
https://www.flightradar24.com/%s/%s
3845
""";
3946
public static final String AN_124_IN_YOUR_AIRPORT_NOW_TEXT = """
4047
An-124 IN YOUR AIRPORT RIGHT NOW.
4148
Altitude: %sm:
4249
Ground speed: %skm/h
4350
Distance from your airport: %skm
44-
View there:
51+
View here:
4552
https://www.flightradar24.com/%s/%s
4653
""";
4754
public static final String AN_124_CODE = "A124";

telegram-bot/src/main/java/project/vilsoncake/telegrambot/dto/FlightDataDto.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@ public class FlightDataDto {
1717

1818
@JsonAlias("airport")
1919
private String airport;
20+
21+
@JsonAlias("callsign")
22+
private String callsign;
23+
24+
@JsonAlias("live")
25+
private boolean live;
26+
27+
@JsonAlias("text")
28+
private String text;
2029
}

0 commit comments

Comments
 (0)