Search in sources :

Example 1 with BaseAtomAndConnectionSpecificEvent

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;
}
Also used : BaseAtomAndConnectionSpecificEvent(won.bot.framework.eventbot.event.BaseAtomAndConnectionSpecificEvent) URI(java.net.URI)

Example 2 with BaseAtomAndConnectionSpecificEvent

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()));
            }
        }
    }
}
Also used : StartsWithTextMessageCommand(won.bot.framework.extensions.textmessagecommand.command.StartsWithTextMessageCommand) EqualsTextMessageCommand(won.bot.framework.extensions.textmessagecommand.command.EqualsTextMessageCommand) PatternMatcherTextMessageCommand(won.bot.framework.extensions.textmessagecommand.command.PatternMatcherTextMessageCommand) TextMessageCommand(won.bot.framework.extensions.textmessagecommand.command.TextMessageCommand) EventListenerContext(won.bot.framework.eventbot.EventListenerContext) MessageEvent(won.bot.framework.eventbot.event.MessageEvent) Connection(won.protocol.model.Connection) EventBus(won.bot.framework.eventbot.bus.EventBus) StartsWithTextMessageCommand(won.bot.framework.extensions.textmessagecommand.command.StartsWithTextMessageCommand) ConnectionSpecificEvent(won.bot.framework.eventbot.event.ConnectionSpecificEvent) BaseAtomAndConnectionSpecificEvent(won.bot.framework.eventbot.event.BaseAtomAndConnectionSpecificEvent) EqualsTextMessageCommand(won.bot.framework.extensions.textmessagecommand.command.EqualsTextMessageCommand) WonMessage(won.protocol.message.WonMessage) PatternMatcherTextMessageCommand(won.bot.framework.extensions.textmessagecommand.command.PatternMatcherTextMessageCommand) BaseAtomAndConnectionSpecificEvent(won.bot.framework.eventbot.event.BaseAtomAndConnectionSpecificEvent) ConnectionMessageCommandEvent(won.bot.framework.eventbot.event.impl.command.connectionmessage.ConnectionMessageCommandEvent)

Aggregations

BaseAtomAndConnectionSpecificEvent (won.bot.framework.eventbot.event.BaseAtomAndConnectionSpecificEvent)2 URI (java.net.URI)1 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)1 EventBus (won.bot.framework.eventbot.bus.EventBus)1 ConnectionSpecificEvent (won.bot.framework.eventbot.event.ConnectionSpecificEvent)1 MessageEvent (won.bot.framework.eventbot.event.MessageEvent)1 ConnectionMessageCommandEvent (won.bot.framework.eventbot.event.impl.command.connectionmessage.ConnectionMessageCommandEvent)1 EqualsTextMessageCommand (won.bot.framework.extensions.textmessagecommand.command.EqualsTextMessageCommand)1 PatternMatcherTextMessageCommand (won.bot.framework.extensions.textmessagecommand.command.PatternMatcherTextMessageCommand)1 StartsWithTextMessageCommand (won.bot.framework.extensions.textmessagecommand.command.StartsWithTextMessageCommand)1 TextMessageCommand (won.bot.framework.extensions.textmessagecommand.command.TextMessageCommand)1 WonMessage (won.protocol.message.WonMessage)1 Connection (won.protocol.model.Connection)1