use of won.bot.framework.eventbot.event.BaseAtomAndConnectionSpecificEvent in project webofneeds by researchstudio-sat.
the class SocketTypeFilter method accept.
@Override
public boolean accept(Event event) {
if (event instanceof BaseAtomAndConnectionSpecificEvent) {
BaseAtomAndConnectionSpecificEvent msgEvent = (BaseAtomAndConnectionSpecificEvent) event;
URI atomUri = msgEvent.getAtomURI();
URI socketUri = msgEvent.getSocketURI();
logger.debug("SocketTypeFilter check for atomUri: " + atomUri + " socketUri: " + socketUri);
Optional<URI> socketType = WonLinkedDataUtils.getTypeOfSocket(socketUri, getContext().getLinkedDataSource());
if (socketType.isPresent()) {
return allowedSocketTypes.contains(socketType.get());
}
}
return false;
}
use of won.bot.framework.eventbot.event.BaseAtomAndConnectionSpecificEvent in project webofneeds by researchstudio-sat.
the class TextMessageCommandExecutor method doRun.
@Override
protected void doRun(final Event event, EventListener executingListener) throws Exception {
if (event instanceof BaseAtomAndConnectionSpecificEvent) {
ConnectionSpecificEvent messageEvent = (ConnectionSpecificEvent) event;
if (messageEvent instanceof MessageEvent) {
EventListenerContext ctx = getEventListenerContext();
EventBus bus = ctx.getEventBus();
Connection con = ((BaseAtomAndConnectionSpecificEvent) messageEvent).getCon();
WonMessage msg = ((MessageEvent) messageEvent).getWonMessage();
String message = extractTextMessageFromWonMessage(msg);
try {
if (message != null) {
// Ignore anything that does not contain a textmessage
for (TextMessageCommand textMessageCommand : textMessageCommands) {
if (textMessageCommand.matchesCommand(message)) {
try {
if (textMessageCommand instanceof PatternMatcherTextMessageCommand) {
((PatternMatcherTextMessageCommand) textMessageCommand).execute(con, ((PatternMatcherTextMessageCommand) textMessageCommand).getMatcher(message));
} else if (textMessageCommand instanceof EqualsTextMessageCommand) {
((EqualsTextMessageCommand) textMessageCommand).execute(con);
} else if (textMessageCommand instanceof StartsWithTextMessageCommand) {
((StartsWithTextMessageCommand) textMessageCommand).execute(con, message);
}
break;
} catch (UnsupportedOperationException e) {
logger.warn("TextMessageCommand cant be executed due to: {}", e.getMessage());
}
}
}
}
} catch (Exception e) {
// error: send an error message
bus.publish(new ConnectionMessageCommandEvent(con, "Did not understand your command '" + message + "': " + e.getClass().getSimpleName() + ":" + e.getMessage()));
}
}
}
}
Aggregations