use of won.bot.framework.extensions.textmessagecommand.command.EqualsTextMessageCommand 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