use of me.retrodaredevil.solarthing.AlterPacketsProvider in project solarthing by wildmountainfarms.
the class AlterManagerActionNode method createAction.
@Override
public Action createAction(ActionEnvironment actionEnvironment) {
SolarThingDatabaseEnvironment solarThingDatabaseEnvironment = actionEnvironment.getInjectEnvironment().get(SolarThingDatabaseEnvironment.class);
OpenDatabaseCacheEnvironment openDatabaseCacheEnvironment = actionEnvironment.getInjectEnvironment().get(OpenDatabaseCacheEnvironment.class);
AuthorizationEnvironment authorizationEnvironment = actionEnvironment.getInjectEnvironment().get(AuthorizationEnvironment.class);
AlterPacketsEnvironment alterPacketsEnvironment = actionEnvironment.getInjectEnvironment().get(AlterPacketsEnvironment.class);
SourceIdEnvironment sourceIdEnvironment = actionEnvironment.getInjectEnvironment().get(SourceIdEnvironment.class);
TimeZoneEnvironment timeZoneEnvironment = actionEnvironment.getInjectEnvironment().get(TimeZoneEnvironment.class);
SolarThingDatabase database = solarThingDatabaseEnvironment.getSolarThingDatabase();
DatabaseCache openDatabaseCache = openDatabaseCacheEnvironment.getOpenDatabaseCache();
String sourceId = sourceIdEnvironment.getSourceId();
AlterPacketsProvider alterPacketsProvider = alterPacketsEnvironment.getAlterPacketsProvider();
return new AlterManagerAction(new CommandManager(keyDirectory, sender), authorizationEnvironment.getPublicKeyLookUp(), database, openDatabaseCache, alterPacketsProvider, sourceId, timeZoneEnvironment.getZoneId(), fragmentId);
}
use of me.retrodaredevil.solarthing.AlterPacketsProvider in project solarthing by wildmountainfarms.
the class FlagActionNode method createAction.
@Override
public Action createAction(ActionEnvironment actionEnvironment) {
AlterPacketsEnvironment alterPacketsEnvironment = actionEnvironment.getInjectEnvironment().get(AlterPacketsEnvironment.class);
AlterPacketsProvider provider = alterPacketsEnvironment.getAlterPacketsProvider();
return new SimpleAction(false) {
@Override
protected void onUpdate() {
super.onUpdate();
List<VersionedPacket<StoredAlterPacket>> packets = provider.getPackets();
if (packets != null) {
Instant now = Instant.now();
if (FlagUtil.isFlagActive(now, flagName, packets.stream().map(VersionedPacket::getPacket)) != not) {
setDone(true);
}
}
}
};
}
use of me.retrodaredevil.solarthing.AlterPacketsProvider in project solarthing by wildmountainfarms.
the class SlackChatBotActionNode method createAction.
@Override
public Action createAction(ActionEnvironment actionEnvironment) {
LatestFragmentedPacketGroupEnvironment latestPacketGroupEnvironment = actionEnvironment.getInjectEnvironment().get(LatestFragmentedPacketGroupEnvironment.class);
AlterPacketsEnvironment alterPacketsEnvironment = actionEnvironment.getInjectEnvironment().get(AlterPacketsEnvironment.class);
SolarThingDatabaseEnvironment solarThingDatabaseEnvironment = actionEnvironment.getInjectEnvironment().get(SolarThingDatabaseEnvironment.class);
SourceIdEnvironment sourceIdEnvironment = actionEnvironment.getInjectEnvironment().get(SourceIdEnvironment.class);
TimeZoneEnvironment timeZoneEnvironment = actionEnvironment.getInjectEnvironment().get(TimeZoneEnvironment.class);
EventDatabaseCacheEnvironment eventDatabaseCacheEnvironment = actionEnvironment.getInjectEnvironment().get(EventDatabaseCacheEnvironment.class);
// Note that all objects listed here must be thread safe, as data will be accessed from them on a separate thread
FragmentedPacketGroupProvider packetGroupProvider = latestPacketGroupEnvironment.getFragmentedPacketGroupProvider();
AlterPacketsProvider alterPacketsProvider = alterPacketsEnvironment.getAlterPacketsProvider();
SolarThingDatabase database = solarThingDatabaseEnvironment.getSolarThingDatabase();
String sourceId = sourceIdEnvironment.getSourceId();
ZoneId zoneId = timeZoneEnvironment.getZoneId();
ResourceManager<? extends DatabaseCache> eventDatabaseCacheManager = eventDatabaseCacheEnvironment.getEventDatabaseCacheManager();
Slack slack = Slack.getInstance(new SlackConfig(), new SlackHttpClient(new OkHttpClient.Builder().callTimeout(Duration.ofSeconds(10)).connectTimeout(Duration.ofSeconds(4)).build()));
ChatBotCommandHelper commandHelper = new ChatBotCommandHelper(permissionMap, packetGroupProvider, new CommandManager(keyDirectory, sender));
return new SlackChatBotAction(appToken, new SlackMessageSender(authToken, channelId, slack), slack, new HelpChatBotHandler(new ChatBotHandlerMultiplexer(Arrays.asList(// note: this isn't applied to "help" commands
new StaleMessageHandler(), new ScheduleCommandChatBotHandler(commandHelper, database, sourceId, zoneId), new CancelCommandChatBotHandler(commandHelper, database, sourceId, zoneId, alterPacketsProvider), new FlagCommandChatBotHandler(commandHelper, database, sourceId, zoneId, alterPacketsProvider), new CommandChatBotHandler(commandHelper, database, sourceId, zoneId), new StatusChatBotHandler(packetGroupProvider, alterPacketsProvider), new HeartbeatCommandChatBotHandler(eventDatabaseCacheManager), (message, messageSender) -> {
messageSender.sendMessage("Unknown command!");
return true;
}))));
}
Aggregations