<commit_before>
module.exports = function(RED) {
    "use strict";

    function SenseEvent(n) {
        RED.nodes.createNode(this,n);
        var senseId = n.senseid,
            eventType = n.eventtype,
            eventName = n.eventname,
            node = this;

        RED.comms.subscribe(senseId, function(data) {
            try {
                var event;
                if (typeof data === 'string') {
                    event = JSON.parse(data);
                } else {
                    event = data;
                }
                
                if (event.eventType === eventType && event.eventName === eventName) {
                    node.send({
                        payload: event.message
                    });
                }
            } catch (e) {
                node.error('Error: '+e);
            }
        });
    }
    RED.nodes.registerType("sense event", SenseEvent);

    function SenseCommand(n) {
        RED.nodes.createNode(this,n);
        var senseId = n.senseid,
            commandType = n.commandtype,
            commandName = n.commandname,
            node = this;

        node.on('input', function(msg) {
            if (!msg.payload) {
                node.error('Missing property: msg.payload');
                return;
            }

            var message = {
                header: {
                    type: 'modules'<commit_msg>unsubscribe event after node has been modified<commit_after>
module.exports = function(RED) {
    "use strict";

    function SenseEvent(n) {
        RED.nodes.createNode(this,n);
        var node = this,
            senseId = n.senseid,
            eventType = n.eventtype,
            eventName = n.eventname;

        var eventHandler = function(data) {
            try {
                var event;
                if (typeof data === 'string') {
                    event = JSON.parse(data);
                } else {
                    event = data;
                }

                if (event.eventType === eventType && event.eventName === eventName) {
                    node.send({
                        payload: event.message
                    });
                }
            } catch (e) {
                node.error('Error: '+e);
            }
        };

        RED.comms.subscribe(senseId, eventHandler);

        node.on('close', function() {
            RED.comms.unsubscribe(senseId, eventHandler);
        });
    }
    RED.nodes.registerType("sense event", SenseEvent);

    function SenseCommand(n) {
        RED.nodes.createNode(this,n);
        var senseId = n.senseid,
            commandType = n.commandtype,
            commandName = n.commandname,
            node = this;

        node.on('input', function(msg) {
            if (!msg.payload) {
                node.error('Missing property: msg.payload');
                return;
            }

            var message = {
                header: {
                    type: 'modules'
{'fraction_non_alphanumeric': 0.11077441077441078, 'fraction_numerical': 0.0, 'mean_word_length': 1.1845588235294118, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1748658', 'n_tokens_mistral': 812, 'n_tokens_neox': 740, 'n_words': 154}