<commit_before>/*
 * music.js - Music streaming commands
 * 
 * Contributed by Ovyerus
 */

const MusicHandler = require(`${__dirname}/musicHandler`);
const got = require('got');
var handler;

exports.loadAsSubcommands = true;
exports.commands = [
    'play',
    'queue',
    'leave',
    'join',
    'nowplaying',
    'sources',
    'skip'
];

exports.init = bot => {
    if (!bot.config.soundCloudKey) {
        got('https://raw.githubusercontent.com/rg3/youtube-dl/master/youtube_dl/extractor/soundcloud.py').then(r => {
            bot.config.soundCloudKey = r.body.match(/_CLIENT_ID = '([A-Z0-9]+)'/i)[1];
            logger.info('SoundCloud key has been automatically scraped from Youtube-DL. If you do not wish for this to happen, please insert a key into the config.json manually.');
            handler = new MusicHandler(bot);
        }).catch(logger.error);
    } else {
        handler = new MusicHandler(bot);
    }
};

exports.main = {
    desc: 'Music commands'
};

exports.play = {
    desc: 'Play or queue a song.',
    usage: '[url|search terms]',
    main(bot, ctx) {
        return new Promise((resolve, reject) => {
            if (!ctx.suffix && !bot.music.queues.get(ctx.guild.id)) {
                ctx.createMessage('Please tell me something to play.').then(resolve).catch(reject);
            } else if (!ctx.member.voiceState.channelID) {
                ctx.createMessage('You are not in a voice channel.').then(resolve).catch(reject);
            } else {
                if (ctx.suffix) {
                    if (!urlRegex.test(ctx.suffix) && bot.config.ytSearchKey) {
                        handler.search(ctx, ctx.suffix).then(res => {
                            return handler.prePlay(ctx, res);
                        }).then(resolve).catch(err => {
                            if (err.message && err.message === 'Invalid selection (Number too high or not a number).') {
                                return ctx.createMessage(err.message);
                            } else {
                                reject(err);
                            }
                        }).then(resolve);
                    } else if (!urlRegex.test(ctx.suffix) && !bot.config.ytSearchKey) {
                        ctx.createMessage('Search token appears to be missing. Please queue songs via direct links.').then(resolve).catch(reject);
                    } else {
                        handler.prePlay(ctx, ctx.suffix).then(resolve).catch(reject);
                    }
                } else if (bot.music.queues.get(ctx.guild.id).queue.length > 0) {
                    let item = bot.music.queues.get(ctx.guild.id).queue[0];
                    handler.prePlay(item.ctx, item.url).then(resolve).catch(reject);
                } else {
                    ctx.createMessage('Please tell me something to play.').then(resolve).catch(reject);
                }
            }
        });
    }
};

exports.queue = {
    desc: 'View the current queue.',
    usage: '[page number]',
    main(bot, ctx) {
        return new Promise((resolve, reject) => {
            let embed = {
                title: 'Music Queue'
            };

            if (!bot.music.queues.get(ctx.guild.id) || bot.music.queues.get(ctx.guild.id).queue.length === 0) {
                embed.description = 'Queue is more empty than my will to live. I mean... :eyes:';
                ctx.createMessage({embed}).then(resolve).catch(reject);
            } else {
                let q = bot.music.queues.get(ctx.guild.id).queue;

                let page = !Number(ctx.suffix) || Number(ctx.suffix) === 0 ? 0 : Number(ctx.suffix) - 1;
                let pageAmt = 10;
                let pages = Math.ceil(q.length / pageAmt);
                let thisPage = [];

                if (page <= pages) {
                    queuePaginate(q, page, pageAmt, thisPage);
                } else {
                    queuePaginate(q, 0, pageAmt, thisPage);
                }

                if (pages > 1) {
                    embed.footer = {text: `Page ${page + 1}/${pages}`};
                    embed.fields = [{
                        name: `${q.length} items in queue`, value: thisPage.join('\n')
                    }];
                } else {
                    embed.description = thisPage.join('\n');
                }

                ctx.createMessage({embed}).then(resolve).catch(reject);
            }
        });
    }
};

exports.nowplaying = {<commit_msg>sorten nowplaying statement to np because maymays<commit_after>/*
 * music.js - Music streaming commands
 * 
 * Contributed by Ovyerus
 */

const MusicHandler = require(`${__dirname}/musicHandler`);
const got = require('got');
var handler;

exports.loadAsSubcommands = true;
exports.commands = [
    'play',
    'queue',
    'leave',
    'join',
    'np',
    'sources',
    'skip'
];

exports.init = bot => {
    if (!bot.config.soundCloudKey) {
        got('https://raw.githubusercontent.com/rg3/youtube-dl/master/youtube_dl/extractor/soundcloud.py').then(r => {
            bot.config.soundCloudKey = r.body.match(/_CLIENT_ID = '([A-Z0-9]+)'/i)[1];
            logger.info('SoundCloud key has been automatically scraped from Youtube-DL. If you do not wish for this to happen, please insert a key into the config.json manually.');
            handler = new MusicHandler(bot);
        }).catch(logger.error);
    } else {
        handler = new MusicHandler(bot);
    }
};

exports.main = {
    desc: 'Music commands'
};

exports.play = {
    desc: 'Play or queue a song.',
    usage: '[url|search terms]',
    main(bot, ctx) {
        return new Promise((resolve, reject) => {
            if (!ctx.suffix && !bot.music.queues.get(ctx.guild.id)) {
                ctx.createMessage('Please tell me something to play.').then(resolve).catch(reject);
            } else if (!ctx.member.voiceState.channelID) {
                ctx.createMessage('You are not in a voice channel.').then(resolve).catch(reject);
            } else {
                if (ctx.suffix) {
                    if (!urlRegex.test(ctx.suffix) && bot.config.ytSearchKey) {
                        handler.search(ctx, ctx.suffix).then(res => {
                            return handler.prePlay(ctx, res);
                        }).then(resolve).catch(err => {
                            if (err.message && err.message === 'Invalid selection (Number too high or not a number).') {
                                return ctx.createMessage(err.message);
                            } else {
                                reject(err);
                            }
                        }).then(resolve);
                    } else if (!urlRegex.test(ctx.suffix) && !bot.config.ytSearchKey) {
                        ctx.createMessage('Search token appears to be missing. Please queue songs via direct links.').then(resolve).catch(reject);
                    } else {
                        handler.prePlay(ctx, ctx.suffix).then(resolve).catch(reject);
                    }
                } else if (bot.music.queues.get(ctx.guild.id).queue.length > 0) {
                    let item = bot.music.queues.get(ctx.guild.id).queue[0];
                    handler.prePlay(item.ctx, item.url).then(resolve).catch(reject);
                } else {
                    ctx.createMessage('Please tell me something to play.').then(resolve).catch(reject);
                }
            }
        });
    }
};

exports.queue = {
    desc: 'View the current queue.',
    usage: '[page number]',
    main(bot, ctx) {
        return new Promise((resolve, reject) => {
            let embed = {
                title: 'Music Queue'
            };

            if (!bot.music.queues.get(ctx.guild.id) || bot.music.queues.get(ctx.guild.id).queue.length === 0) {
                embed.description = 'Queue is more empty than my will to live. I mean... :eyes:';
                ctx.createMessage({embed}).then(resolve).catch(reject);
            } else {
                let q = bot.music.queues.get(ctx.guild.id).queue;

                let page = !Number(ctx.suffix) || Number(ctx.suffix) === 0 ? 0 : Number(ctx.suffix) - 1;
                let pageAmt = 10;
                let pages = Math.ceil(q.length / pageAmt);
                let thisPage = [];

                if (page <= pages) {
                    queuePaginate(q, page, pageAmt, thisPage);
                } else {
                    queuePaginate(q, 0, pageAmt, thisPage);
                }

                if (pages > 1) {
                    embed.footer = {text: `Page ${page + 1}/${pages}`};
                    embed.fields = [{
                        name: `${q.length} items in queue`, value: thisPage.join('\n')
                    }];
                } else {
                    embed.description = thisPage.join('\n');
                }

                ctx.createMessage({embed}).then(resolve).catch(reject);
            }
        });
    }
};

exports.np = {
{'fraction_non_alphanumeric': 0.13983050847457626, 'fraction_numerical': 0.003345227475468332, 'mean_word_length': 1.5647698026880184, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '4093017', 'n_tokens_mistral': 2582, 'n_tokens_neox': 2444, 'n_words': 530}