Commit 351334d6fc24f7ab93c19c4cdafa0f60c6768188
1 parent
e991e3f9
Added cycle sensitive reply (e.g. "ich werde dich täglich informieren")
Showing
2 changed files
with
24 additions
and
17 deletions
services/MainBot/src/main/java/de/bht/beuthbot/scheduler/SchedulerBean.java
| @@ -132,7 +132,7 @@ public class SchedulerBean { | @@ -132,7 +132,7 @@ public class SchedulerBean { | ||
| 132 | //Extract the Date from the message | 132 | //Extract the Date from the message |
| 133 | String messageDay = message.getEntities().getOrDefault("date", "TODAY"); | 133 | String messageDay = message.getEntities().getOrDefault("date", "TODAY"); |
| 134 | //If the date retrieved from the message contains a cycling parameter (e.g. "daily"), set the reminderCycle | 134 | //If the date retrieved from the message contains a cycling parameter (e.g. "daily"), set the reminderCycle |
| 135 | - switch(messageDay) { | 135 | + switch(message.getEntities().getOrDefault("cycle", "ONCE")) { |
| 136 | case "DAILY": | 136 | case "DAILY": |
| 137 | cycle = ReminderCycle.DAILY; | 137 | cycle = ReminderCycle.DAILY; |
| 138 | break; | 138 | break; |
| @@ -142,6 +142,9 @@ public class SchedulerBean { | @@ -142,6 +142,9 @@ public class SchedulerBean { | ||
| 142 | case "MONTHLY": | 142 | case "MONTHLY": |
| 143 | cycle = ReminderCycle.MONTHLY; | 143 | cycle = ReminderCycle.MONTHLY; |
| 144 | break; | 144 | break; |
| 145 | + default: | ||
| 146 | + cycle = ReminderCycle.ONCE; | ||
| 147 | + break; | ||
| 145 | } | 148 | } |
| 146 | 149 | ||
| 147 | LocalDate cycleDay = DateStringExtractor.getLocalDateFromString(messageDay); | 150 | LocalDate cycleDay = DateStringExtractor.getLocalDateFromString(messageDay); |
| @@ -210,21 +213,9 @@ public class SchedulerBean { | @@ -210,21 +213,9 @@ public class SchedulerBean { | ||
| 210 | 213 | ||
| 211 | 214 | ||
| 212 | Map<String, String> entities = new HashMap<>(); | 215 | Map<String, String> entities = new HashMap<>(); |
| 213 | - switch(intent) { | ||
| 214 | - case "showFood": | ||
| 215 | - intent = Intent.SHOW_FOOD.getText(); | ||
| 216 | - logger.debug("Intent is show food"); | ||
| 217 | - entities.put(EntityName.DATE.getText(), cycleDate.toLocalDate().toString()); | ||
| 218 | - entities.put(EntityName.TIME.getText(), cycleTime.toString()); | ||
| 219 | - logger.debug("Entities added: " + entities); | ||
| 220 | - break; | ||
| 221 | - case "showCourses": | ||
| 222 | - //TODO: add Courses functionality | ||
| 223 | - break; | ||
| 224 | - default: | ||
| 225 | - intent = "FALLBACK"; | ||
| 226 | - break; | ||
| 227 | - } | 216 | + entities.put(EntityName.DATE.getText(), cycleDate.toLocalDate().toString()); |
| 217 | + entities.put(EntityName.TIME.getText(), cycleTime.toString()); | ||
| 218 | + entities.put(EntityName.REMINDER_CYCLE.getText(), cycle.toString()); | ||
| 228 | 219 | ||
| 229 | logger.debug("Creating reminder with date " + cycleDate.toString() + " and time " + cycleTime.minusHours(1).toString()); //For some reason the server time is off by an hour, so we need to subtract it from the cycleTime | 220 | logger.debug("Creating reminder with date " + cycleDate.toString() + " and time " + cycleTime.minusHours(1).toString()); //For some reason the server time is off by an hour, so we need to subtract it from the cycleTime |
| 230 | 221 |
services/MainBot/src/main/resources/de/bht/beuthbot/drools/Canteen.drl
| @@ -42,6 +42,7 @@ import java.time.LocalDate; | @@ -42,6 +42,7 @@ import java.time.LocalDate; | ||
| 42 | import de.bht.beuthbot.utils.DateStringExtractor; | 42 | import de.bht.beuthbot.utils.DateStringExtractor; |
| 43 | import java.time.format.DateTimeFormatter | 43 | import java.time.format.DateTimeFormatter |
| 44 | import de.bht.beuthbot.model.entities.Reminder; | 44 | import de.bht.beuthbot.model.entities.Reminder; |
| 45 | +import de.bht.beuthbot.model.enumeration.ReminderCycle; | ||
| 45 | 46 | ||
| 46 | global de.bht.beuthbot.canteen.model.CanteenData canteenData; | 47 | global de.bht.beuthbot.canteen.model.CanteenData canteenData; |
| 47 | global de.bht.beuthbot.model.entities.AppUser user; | 48 | global de.bht.beuthbot.model.entities.AppUser user; |
| @@ -138,8 +139,23 @@ rule "Create reminder" | @@ -138,8 +139,23 @@ rule "Create reminder" | ||
| 138 | TaskMessage message = new TaskMessage(m); | 139 | TaskMessage message = new TaskMessage(m); |
| 139 | Reminder reminder = schedulerBean.createReminder(message, user); | 140 | Reminder reminder = schedulerBean.createReminder(message, user); |
| 140 | String messageText = ""; | 141 | String messageText = ""; |
| 142 | + String outputDate = DateStringExtractor.getGermanWeekDayFromLocalDate(reminder.getCycleDate().toLocalDate(), false); | ||
| 143 | + switch(reminder.getReminderCycle().toString()) { | ||
| 144 | + case "DAILY": | ||
| 145 | + outputDate = "täglich"; | ||
| 146 | + break; | ||
| 147 | + case "WEEKLY": | ||
| 148 | + outputDate += "s"; //if its weekly, just take the weekday and add an "s" | ||
| 149 | + break; | ||
| 150 | + case "MONTHLY": | ||
| 151 | + outputDate = "ein mal im Monat"; | ||
| 152 | + break; | ||
| 153 | + case "ONCE": | ||
| 154 | + outputDate = DateStringExtractor.getGermanWeekDayFromLocalDate(reminder.getCycleDate().toLocalDate(), true); | ||
| 155 | + break; | ||
| 156 | + } | ||
| 141 | if(reminder.getIntent().equals(Intent.SHOW_FOOD.getText())) { | 157 | if(reminder.getIntent().equals(Intent.SHOW_FOOD.getText())) { |
| 142 | - messageText = "Ich werde dir " + DateStringExtractor.getGermanWeekDayFromLocalDate(reminder.getCycleDate().toLocalDate(), true) + " um " + reminder.getCycleDate().toLocalTime().format(DateTimeFormatter.ofPattern("HH:mm")) + " Uhr den Mensaplan mitteilen!"; | 158 | + messageText = "Ich werde dir " + outputDate + " um " + reminder.getCycleDate().toLocalTime().format(DateTimeFormatter.ofPattern("HH:mm")) + " Uhr den Mensaplan mitteilen!"; |
| 143 | } else { | 159 | } else { |
| 144 | messageText = "Es war mir leider nicht möglich eine Erinnerung für dich anzulegen. Versuche es bitte noch einmal."; | 160 | messageText = "Es war mir leider nicht möglich eine Erinnerung für dich anzulegen. Versuche es bitte noch einmal."; |
| 145 | } //TODO: Add other intents | 161 | } //TODO: Add other intents |