@Override public boolean canProcess(IncomeMessage message) { return acceptedChannels.contains(message.channel().id()); }
@Override public String message() { return String.format("[%s@%s] %s", incomeMessage.sender(), incomeMessage.channel().id(), cause.getMessage()); }
/** * Returns a predicate that allows channels that have the given id. * * @param channelId the channel id * @return a predicate that allows channels that have the given id. */ public static Predicate<IncomeMessage> channel(String channelId) { return new AcceptedValuePredicate<>(channelId, m -> m.channel().id()); }
public LinkRequest(IncomeMessage message, String user) { this.user = user; this.channel = message.channel().id(); this.target = message.sender().id(); }
/** * Returns a message location based on this message. If you send a message to this * location, the sender will receive it. * * @return the message location for sending messages to the sender */ default MessageLocation location() { return Destination.channel(channel().id()).to(target()); }
channel = message.channel().id();
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."); } }