<commit_before>/**
 * Created by Julian/Wolke on 07.11.2016.
 */
let Command = require('../../structures/command');
let winston = require('winston');
let Selector = require('../../structures/selector');
let _ = require("lodash");
let track_error = !require('../../config/main.json').no_error_tracking;
/**
 * The play command
 * plays a song duh.
 * @extends Command
 *
 */
class Play extends Command {
    /**
     * Create the command
     * @param {Function} t - the translation module
     * @param {Object} v - the voice manager
     * @param mod The module manager
     */
    constructor({t, v, mod}) {
        super();
        this.cmd = "play";
        this.cat = "music";
        this.needGuild = true;
        this.t = t;
        this.v = v;
        this.r = mod.getMod('raven');
        this.accessLevel = 0;
    }

    run(msg) {
        let msgSplit = msg.content.split(' ').splice(1);
        let uwu = this.checkNext(msgSplit);
        let next = uwu.next;
        msgSplit = uwu.msgSplit;
        msg.content = msgSplit.join(' ');
        this.v.addToQueue(msg, !next, next).then(result => {
            switch (result.type) {
                case "added":
                    if (next) return msg.channel.createMessage(this.t('play.next', {
                        song: result.data.title,
                        lngs: msg.lang
                    }));
                    msg.channel.createMessage(this.t('play.success', {song: result.data.title, lngs: msg.lang}));
                    return;
                case "search_result":
                    this.searchResult(msg, result.data);
                    return;

            }
        }).catch(err => {
            console.error(err);
            if (track_error) {
                if (typeof(err) === 'object') {
                    err = err.err;
                }
                this.r.captureException(err, {
                    extra: {
                        userId: msg.author.id,
                        guildId: msg.channel.guild.id,
                        msg: msg.content,
                        msgId: msg.id
                    }
                });
            }
            msg.channel.createMessage(this.t('generic.error', {lngs: msg.lang}));
        });
    }

    checkNext(msgSplit) {
        let next = false;
        let index = _.indexOf(msgSplit, '-next');
        if (index > -1) {
            _.pull(msgSplit, '-next');
            next = true;
        }
        return {next, msgSplit};
    }

    searchResult(msg, results) {
        let selector = new Selector(msg, results, this.t, (err, number) => {
            if (err) {
                return msg.channel.createMessage(this.t(err, {lngs: msg.lang}));
            }
            msg.content = `https://youtube.com/watch?v=${results[number - 1].id}`;
            this.run(msg);
        });
    }
}
module.exports = Play;<commit_msg>tfw. when you change the msg content and accidentally rip it<commit_after>/**
 * Created by Julian/Wolke on 07.11.2016.
 */
let Command = require('../../structures/command');
let winston = require('winston');
let Selector = require('../../structures/selector');
let _ = require("lodash");
let track_error = !require('../../config/main.json').no_error_tracking;
/**
 * The play command
 * plays a song duh.
 * @extends Command
 *
 */
class Play extends Command {
    /**
     * Create the command
     * @param {Function} t - the translation module
     * @param {Object} v - the voice manager
     * @param mod The module manager
     */
    constructor({t, v, mod}) {
        super();
        this.cmd = "play";
        this.cat = "music";
        this.needGuild = true;
        this.t = t;
        this.v = v;
        this.r = mod.getMod('raven');
        this.accessLevel = 0;
    }

    run(msg) {
        let msgSplit = msg.content.split(' ').splice(1);
        if (msgSplit.length === 0) return msg.channel.createMessage(this.t('qa.empty-search', {lngs: msg.lang}));
        let uwu = this.checkNext(msgSplit);
        let next = uwu.next;
        msgSplit = uwu.msgSplit;
        msg.content = msgSplit.join(' ');
        this.v.addToQueue(msg, !next, next).then(result => {
            switch (result.type) {
                case "added":
                    if (next) return msg.channel.createMessage(this.t('play.next', {
                        song: result.data.title,
                        lngs: msg.lang
                    }));
                    msg.channel.createMessage(this.t('play.success', {song: result.data.title, lngs: msg.lang}));
                    return;
                case "search_result":
                    this.searchResult(msg, result.data);
                    return;

            }
        }).catch(err => {
            console.error(err);
            if (track_error) {
                if (typeof(err) === 'object') {
                    err = err.err;
                }
                this.r.captureException(err, {
                    extra: {
                        userId: msg.author.id,
                        guildId: msg.channel.guild.id,
                        msg: msg.content,
                        msgId: msg.id
                    }
                });
            }
            msg.channel.createMessage(this.t('generic.error', {lngs: msg.lang}));
        });
    }

    checkNext(msgSplit) {
        let next = false;
        let index = _.indexOf(msgSplit, '-next');
        if (index > -1) {
            _.pull(msgSplit, '-next');
            next = true;
        }
        return {next, msgSplit};
    }

    searchResult(msg, results) {
        let selector = new Selector(msg, results, this.t, (err, number) => {
            if (err) {
                return msg.channel.createMessage(this.t(err, {lngs: msg.lang}));
            }
            msg.content = `!w.play https://youtube.com/watch?v=${results[number - 1].id}`;
            this.run(msg);
        });
    }
}
module.exports = Play;
{'fraction_non_alphanumeric': 0.14451352713829607, 'fraction_numerical': 0.004200974626113258, 'mean_word_length': 1.4503911074516262, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '4768185', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1692, 'n_words': 365}