<commit_before>const { parseFormString } = require('./util/parse');
const slack = require('./slack');
const {
    convertLinkToUri,
    extractFromUri
} = require('./spotify');
const radio = require('./spotify/radio');
const track = require('./spotify/track');


function handler(event, context, callback) {

    const { body = '' } = event;
    const {
        SPOTIFY_USER_ACCESS_TOKEN,
        SPOTIFY_LOCAL_URL,
        SLACK_TOKEN,
        SPOTIFY_RADIO_PLAYLIST
    } = process.env;

    const {
        text,
        token,
        response_url
    } = parseFormString(body);

    //console.log('PROCESSING SLACK COMMAND', text, response_url, SPOTIFY_RADIO_PLAYLIST)

    if (token !== SLACK_TOKEN) {
        return callback(null,
            slack.slackResp(
                slack.INVALID_TOKEN,
                401,
                slack.TYPE_PRIVATE
            )
        );
    }

    const trackUri = convertLinkToUri(text);
    track
        .getTrackInfo(
            extractFromUri(trackUri, 'track'),
            SPOTIFY_USER_ACCESS_TOKEN
        )
        .then((trackInfo) => {
            slack.notify(
                response_url,
                radio.SLACK_PENDING_MESSAGE(trackInfo),
                slack.TYPE_PRIVATE
            );
            radio
                .playBasedOnTrack(
                    SPOTIFY_RADIO_PLAYLIST,
                    trackInfo,
                    SPOTIFY_USER_ACCESS_TOKEN,
                    SPOTIFY_LOCAL_URL
                )
                .then((msg) => {
                    //console.log('notify success', response_url, msg);
                    slack.notify(
                        response_url,
                        msg
                    );
                })
                .catch(({ message }) => {
                    //console.log('notify error', response_url, message);
                    slack.notify(
                        response_url,
                        `Error creating playlist: ${message}`,
                        slack.TYPE_PRIVATE
                    );
                });
        })
        .catch((error) => {
            slack.notify(
                response_url,
                error.message,
                slack.TYPE_PRIVATE
            );
        });

    return callback(null, slack.slackResp(''));

}

module.exports = {
    handler
};<commit_msg>setting wait for empty event loop to false to try and fix slack timeout error<commit_after>const { parseFormString } = require('./util/parse');
const slack = require('./slack');
const {
    convertLinkToUri,
    extractFromUri
} = require('./spotify');
const radio = require('./spotify/radio');
const track = require('./spotify/track');


function handler(event, context, callback) {

    const { body = '' } = event;
    const {
        SPOTIFY_USER_ACCESS_TOKEN,
        SPOTIFY_LOCAL_URL,
        SLACK_TOKEN,
        SPOTIFY_RADIO_PLAYLIST
    } = process.env;

    const {
        text,
        token,
        response_url
    } = parseFormString(body);

    //console.log('PROCESSING SLACK COMMAND', text, response_url, SPOTIFY_RADIO_PLAYLIST)

    if (token !== SLACK_TOKEN) {
        return callback(null,
            slack.slackResp(
                slack.INVALID_TOKEN,
                401,
                slack.TYPE_PRIVATE
            )
        );
    }

    const trackUri = convertLinkToUri(text);
    track
        .getTrackInfo(
            extractFromUri(trackUri, 'track'),
            SPOTIFY_USER_ACCESS_TOKEN
        )
        .then((trackInfo) => {
            slack.notify(
                response_url,
                radio.SLACK_PENDING_MESSAGE(trackInfo),
                slack.TYPE_PRIVATE
            );
            radio
                .playBasedOnTrack(
                    SPOTIFY_RADIO_PLAYLIST,
                    trackInfo,
                    SPOTIFY_USER_ACCESS_TOKEN,
                    SPOTIFY_LOCAL_URL
                )
                .then((msg) => {
                    //console.log('notify success', response_url, msg);
                    slack.notify(
                        response_url,
                        msg
                    );
                })
                .catch(({ message }) => {
                    //console.log('notify error', response_url, message);
                    slack.notify(
                        response_url,
                        `Error creating playlist: ${message}`,
                        slack.TYPE_PRIVATE
                    );
                });
        })
        .catch((error) => {
            slack.notify(
                response_url,
                error.message,
                slack.TYPE_PRIVATE
            );
        });
    // eslint-disable-next-line no-param-reassign
    context.callbackWaitsForEmptyEventLoop = false;
    return callback(null, slack.slackResp(''));

}

module.exports = {
    handler
};
{'fraction_non_alphanumeric': 0.0991193938152775, 'fraction_numerical': 0.0012287528158918697, 'mean_word_length': 1.297271872060207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1719374', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1269, 'n_words': 216}