@Override public boolean accept(MessageProcessor messageProcessor, IncomeMessage message) { return messageProcessor.getClass().isAnnotationPresent(AlwaysActive.class) || activator.isEnabled(messageProcessor.name(), message.location()); }
@Override public void process(IncomeMessage message) { message.command() .on("enabled", String.class, (name) -> { boolean active = activator.isEnabled(name, message.location()); if (active) { message.reply("[p]Yes, the plugin is enabled for this channel[/p]"); } else { message.reply("[n]No, the plugin is disabled for this channel[/n]"); } }) .on("disable", List.class, (plugins) -> { plugins.forEach(name -> activator.disable(name.toString(), message.location())); message.reply("Plugin(s) disabled successfully!"); }) .on("enable", List.class, (plugins) -> { plugins.forEach(name -> activator.enable(name.toString(), message.location())); message.reply("Plugin(s) enabled successfully!"); }).execute(); }
message.command() .on("new", userId -> { userManager.create(userId, message.location()); message.reply("User created"); })
private <T> T convert(String string, Class<T> type) { try { return new ParameterBinder<>(type) .context(context -> { OsgiServiceRegistry registry = new OsgiServiceRegistry(); OsgiParameterResolver osgiResolver = new OsgiParameterResolver(registry); context.use(this.incomeMessage) .when(type(IncomeMessage.class)) .use(this.incomeMessage.channel()) .when(type(Channel.class)) .use(this.incomeMessage.sender()) .when(type(Sender.class)) .use(this.incomeMessage.location()) .when(type(MessageLocation.class)) .use(registry) .when(type(ServiceRegistry.class)) // try to lookup implementations by default using the osgi registry .use(osgiResolver) .byDefault(); if (this.incomeMessage.user() != null) { context.use(parameter -> this.incomeMessage.user()) .when(type(User.class)); } }).apply(string); } catch (Exception e) { throw new MessageProcessingException("Invalid command parameters."); } }