use of me.retrodaredevil.solarthing.commands.packets.open.ImmutableRequestFlagPacket in project solarthing by wildmountainfarms.
the class FlagCommandChatBotHandler method setFlag.
private void setFlag(MessageSender messageSender, String flagName) {
TimeRange timeRange = TimeRange.createAfter(Instant.now());
FlagData data = new FlagData(flagName, new TimeRangeActivePeriod(timeRange));
RequestFlagPacket requestFlagPacket = new ImmutableRequestFlagPacket(data);
PacketCollectionCreator creator = commandHelper.getCommandManager().makeCreator(sourceId, zoneId, null, requestFlagPacket, PacketCollectionIdGenerator.Defaults.UNIQUE_GENERATOR);
// TODO We should check if the flag being requested is already active.
executorService.execute(() -> {
PacketCollection packetCollection = creator.create(Instant.now());
boolean success = false;
try {
database.getOpenDatabase().uploadPacketCollection(packetCollection, null);
success = true;
} catch (SolarThingDatabaseException e) {
LOGGER.error("Could not upload request flag packet", e);
}
if (success) {
messageSender.sendMessage("Successfully requested flag: '" + flagName + "' to be set.");
} else {
messageSender.sendMessage("Was unable to request flag set. See logs for details or try again.");
}
});
}
Aggregations