use of com.sx4.bot.entities.webhook.ReadonlyMessage in project Sx4 by sx4-discord-bot.
the class YouTubeManager method sendYouTubeNotification.
public CompletableFuture<ReadonlyMessage> sendYouTubeNotification(TextChannel channel, Document webhookData, WebhookMessage message) {
long channelId = channel.getIdLong();
WebhookClient webhook;
if (this.webhooks.containsKey(channelId)) {
webhook = this.webhooks.get(channelId);
} else if (!webhookData.containsKey("id")) {
return this.createWebhook(channel, message);
} else {
webhook = new WebhookClient(webhookData.getLong("id"), webhookData.getString("token"), this.scheduledExecutor, this.client);
this.webhooks.put(channelId, webhook);
}
return webhook.send(message).thenApply(webhookMessage -> new ReadonlyMessage(webhookMessage, webhook.getId(), webhook.getToken())).exceptionallyCompose(exception -> {
Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception;
if (cause instanceof HttpException && ((HttpException) cause).getCode() == 404) {
this.webhooks.remove(channelId);
return this.createWebhook(channel, message);
}
return CompletableFuture.failedFuture(exception);
});
}
Aggregations