added duration field to reminder and restructured remind text

added general duration formatting to freemarker (its a builtin method currently
added source channel attribute to starboard post
added exception logging to immediate reminders
This commit is contained in:
Sheldan
2020-04-21 21:54:47 +02:00
parent 7b56b89157
commit ff8817f765
11 changed files with 117 additions and 5 deletions

View File

@@ -28,9 +28,7 @@ import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
@Component
@Slf4j
@@ -80,8 +78,14 @@ public class RemindServiceBean implements ReminderService {
log.trace("Directly scheduling the reminder, because it was below the threshold.");
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.schedule(() -> {
self.executeReminder(reminder.getId());
try {
self.executeReminder(reminder.getId());
} catch (Exception exception) {
log.error("Failed to remind immediately.", exception);
}
}, remindIn.toNanos(), TimeUnit.NANOSECONDS);
} else {
log.trace("Starting scheduled job to execute reminder.");
JobDataMap parameters = new JobDataMap();
@@ -109,6 +113,7 @@ public class RemindServiceBean implements ReminderService {
.builder()
.reminder(reminderToRemindFor)
.member(memberInServer)
.duration(Duration.between(reminderToRemindFor.getReminderDate(), reminderToRemindFor.getTargetDate()))
.build();
MessageToSend messageToSend = templateService.renderEmbedTemplate("remind_reminder", build);
channelService.sendMessageToEndInTextChannel(messageToSend, channelToAnswerIn.get());

View File

@@ -2,6 +2,7 @@ package dev.sheldan.abstracto.utility.service.management;
import dev.sheldan.abstracto.core.models.AServerAChannelMessage;
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.utility.models.database.StarboardPost;
import dev.sheldan.abstracto.utility.repository.StarboardPostRepository;
@@ -32,6 +33,7 @@ public class StarboardPostManagementServiceBean implements StarboardPostManageme
.postMessageId(starredMessage.getMessageId())
.starboardMessageId(starboardPost.getMessageId())
.starboardChannel(starboardPost.getChannel())
.sourceChanel(AChannel.builder().id(starredMessage.getChannelId()).build())
.starredDate(Instant.now())
.build();
repository.save(post);

View File

@@ -8,6 +8,20 @@
"g": 0,
"b": 255
},
"description": "You wanted to be reminded of: '${reminder.text}'. Original message was [here](${messageUrl}).",
"description": "You wanted to be reminded.",
"fields": [
{
"name": "Duration",
"value": "${fmtDuration(duration)}"
},
{
"name": "Note",
"value": "${reminder.text}"
},
{
"name": "Link",
"value": "[Jump!](${messageUrl})"
}
],
"additionalMessage": "${member.asMention}"
}

View File

@@ -35,6 +35,10 @@ public class StarboardPost {
@JoinColumn(name = "channelId")
private AChannel starboardChannel;
@ManyToOne
@JoinColumn(name = "sourceChannelId")
private AChannel sourceChanel;
@Transient
private Integer reactionCount;

View File

@@ -8,12 +8,15 @@ import lombok.Setter;
import lombok.experimental.SuperBuilder;
import net.dv8tion.jda.api.entities.Member;
import java.time.Duration;
@Getter
@Setter
@SuperBuilder
public class ExecutedReminderModel extends ServerContext {
private Reminder reminder;
private Member member;
private Duration duration;
public String getMessageUrl() {
return MessageUtils.buildMessageUrl(this.reminder.getServer().getId() ,this.reminder.getChannel().getId(), this.reminder.getMessageId());