{"size": 604, "ext": "js", "max_stars_repo_path": "src/commands/Utility/image.js", "max_stars_repo_name": "hbashdbhiasbdhabsdhasbdhbas/tgarobbot1", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/commands/Utility/image.js", "max_issues_repo_name": "hbashdbhiasbdhabsdhasbdhbas/tgarobbot1", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/commands/Utility/image.js", "max_forks_repo_name": "hbashdbhiasbdhabsdhasbdhbas/tgarobbot1", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 18.875, "max_line_length": 53, "alphanum_fraction": 0.4801324503}
const IMAGE_NAME = /\.(jpe?g|png|gif|webp)$/i;

exports.run = (bot, msg, args) => {
    if (args.length < 1) {
        throw 'Please provide an image URL to send.';
    }

    const url = args[0];
    let name;

    if (!IMAGE_NAME.test(url)) {
        name = 'image.png';
    }

    msg.channel.send({
        file: {
            name,
            attachment: url
        }
    }).then(() => {
        msg.delete();
    }).catch(() => {
        msg.error('Failed to send image.');
    });
};

exports.info = {
    name: 'image',
    usage: 'image <url>',
    description: 'Sends an image from a URL'
};
