Skip to content

Commit f9e9a33

Browse files
committed
update deprecated api usages
1 parent bedec4a commit f9e9a33

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/main/java/vc/live/LiveFeed.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
import discord4j.discordjson.json.MessageCreateRequest;
1111
import discord4j.rest.entity.RestChannel;
1212
import discord4j.rest.http.client.ClientException;
13+
import discord4j.rest.util.MultipartRequest;
1314
import org.redisson.api.RBoundedBlockingQueue;
1415
import org.slf4j.Logger;
16+
import reactor.core.Exceptions;
1517
import reactor.core.publisher.Flux;
1618
import reactor.core.publisher.Mono;
1719
import reactor.core.scheduler.Schedulers;
18-
import reactor.retry.RetryExhaustedException;
1920
import reactor.util.retry.Retry;
2021
import vc.config.GuildConfigManager;
2122
import vc.config.GuildConfigRecord;
@@ -91,7 +92,7 @@ record InputQueue<T>(
9192
record Message(EmbedData embedData, long timestamp) implements Comparable<Message> {
9293
@Override
9394
public int compareTo(final Message o) {
94-
return (timestamp() < o.timestamp()) ? -1 : ((timestamp() == o.timestamp()) ? 0 : 1);
95+
return Long.compare(timestamp(), o.timestamp());
9596
}
9697
}
9798

@@ -206,35 +207,34 @@ protected void processMessageQueue() {
206207
}
207208
}
208209
if (embeds.isEmpty()) return;
210+
final MultipartRequest<MessageCreateRequest> request = MultipartRequest.ofRequest(MessageCreateRequest.builder()
211+
.embeds(embeds)
212+
.build());
209213
// todo: test if we need to use a rate limiter between sending messages to different guilds
210214
Flux.fromIterable(liveChannels.entrySet())
211215
.parallel()
212216
.runOn(Schedulers.parallel())
213-
.flatMap(entry -> processSend(entry, embeds))
217+
.flatMap(entry -> processSend(entry.getKey(), entry.getValue(), request))
214218
.sequential()
215219
.blockLast(Duration.ofSeconds(20));
216220
} catch (final Throwable e) {
217221
LOGGER.error("Error processing message queue", e);
218222
}
219223
}
220224

221-
private Mono<?> processSend(final Map.Entry<String, RestChannel> entry, final List<EmbedData> embeds) {
222-
final RestChannel channel = entry.getValue();
223-
final String guildId = entry.getKey();
224-
return channel.createMessage(
225-
MessageCreateRequest.builder()
226-
.embeds(embeds)
227-
.build())
225+
private Mono<?> processSend(String guildId, RestChannel channel, MultipartRequest<MessageCreateRequest> request) {
226+
return channel.createMessage(request)
228227
.timeout(Duration.ofSeconds(3))
229228
// retry only on TimeoutException
230229
.retryWhen(Retry.fixedDelay(1, Duration.ofSeconds(1))
231230
.filter(error -> error instanceof TimeoutException)
232-
.onRetryExhaustedThrow((spec, signal) ->
233-
new RetryExhaustedException("Retries exhausted sending message to guild: " + guildId + ", channelId: " + channel.getId().asString(), signal.failure())))
231+
.onRetryExhaustedThrow((spec, signal) -> Exceptions.retryExhausted(
232+
"Retries exhausted sending message to guild: " + guildId + ", channelId: " + channel.getId().asString(),
233+
signal.failure())))
234234
.onErrorResume(error -> {
235-
if (error instanceof RetryExhaustedException e) {
236-
handleBroadcastError(e.getCause(), guildId, channel);
237-
} else
235+
if (Exceptions.isRetryExhausted(error))
236+
handleBroadcastError(error.getCause(), guildId, channel);
237+
else
238238
handleBroadcastError(error, guildId, channel);
239239
return Mono.empty();
240240
});

0 commit comments

Comments
 (0)