Take random vid from the userVid folder and don't take twice the same vid

merge-requests/4/head
loicbersier 5 years ago
parent 5406bd92d2
commit 64fbce6927

@ -74,56 +74,62 @@ class ytpCommand extends Command {
if (!message.channel.nsfw && !args.force) return message.channel.send('Please execute this command in an NSFW channel ( Content might not be NSFW but since the video are user submitted better safe than sorry ) OR --force to make the command work outside of nsfw channel BE AWARE THAT IT WON\'T CHANGE THE FINAL RESULT SO NSFW CAN STILL HAPPEN'); if (!message.channel.nsfw && !args.force) return message.channel.send('Please execute this command in an NSFW channel ( Content might not be NSFW but since the video are user submitted better safe than sorry ) OR --force to make the command work outside of nsfw channel BE AWARE THAT IT WON\'T CHANGE THE FINAL RESULT SO NSFW CAN STILL HAPPEN');
let loadingmsg = await message.channel.send(`Processing, this can take a **long** time, i'll ping you when i finished <a:loadingmin:527579785212329984>\nSome info: There is currently ${fs.readdirSync('./asset/ytp/userVid/').length} videos, you can add yours by doing \`\`${prefix[0]}ytp --add (link or attachment)\`\``); let loadingmsg = await message.channel.send(`Processing, this can take a **long** time, i'll ping you when i finished <a:loadingmin:527579785212329984>\nSome info: There is currently ${fs.readdirSync('./asset/ytp/userVid/').length} videos, you can add yours by doing \`\`${prefix[0]}ytp --add (link or attachment)\`\``);
// Read userVid folder and only take .mp4 // Read userVid folder and select random vid and only take .mp4
let asset = []; let asset = [];
fs.readdir('./asset/ytp/userVid/', (err, files) => { let files = fs.readdirSync('./asset/ytp/userVid/');
files.forEach(file => { for (let i = 0; i < 20; i++) {
if (file.endsWith('.mp4')) { console.log(i);
asset.push(`./asset/ytp/userVid/${file}`); let random = Math.floor(Math.random() * files.length);
let vid = `./asset/ytp/userVid/${files[random]}`;
if (files[random].endsWith('mp4')) {
if (!asset.includes(vid)) {
asset.push(vid);
} }
}); }
}
let options = {
debug: false, // Better set this to false to avoid flood in console let options = {
MIN_STREAM_DURATION: Math.floor((Math.random() * 2) + 1), // Random duration of video clip debug: true, // Better set this to false to avoid flood in console
sources: './asset/ytp/sources/', MIN_STREAM_DURATION: Math.floor((Math.random() * 2) + 1), // Random duration of video clip
sounds: './asset/ytp/sounds/', sources: './asset/ytp/sources/',
music: './asset/ytp/music/', sounds: './asset/ytp/sounds/',
resources: './asset/ytp/resources/', music: './asset/ytp/music/',
temp: os.tmpdir(), resources: './asset/ytp/resources/',
sourceList: asset, temp: os.tmpdir(),
outro: './asset/ytp/outro.mp4', // Need an outro or it won't work sourceList: asset,
OUTPUT_FILE: `${os.tmpdir()}/${message.id}_YTP.mp4`, outro: './asset/ytp/outro.mp4', // Need an outro or it won't work
MAX_CLIPS: 20, OUTPUT_FILE: `${os.tmpdir()}/${message.id}_YTP.mp4`,
transitions: true, MAX_CLIPS: 20,
effects: { transitions: true,
effect_RandomSound: true, effects: {
effect_RandomSoundMute: true, effect_RandomSound: true,
effect_Reverse: true, effect_RandomSoundMute: true,
effect_Chorus: true, effect_Reverse: true,
effect_Vibrato: true, effect_Chorus: true,
effect_HighPitch: true, effect_Vibrato: true,
effect_LowPitch: true, effect_HighPitch: true,
effect_SpeedUp: true, effect_LowPitch: true,
effect_SlowDown: true, effect_SpeedUp: true,
effect_Dance: true, effect_SlowDown: true,
effect_Squidward: false effect_Dance: true,
} effect_Squidward: false
}; }
};
new YTPGenerator().configurateAndGo(options) new YTPGenerator().configurateAndGo(options)
.then(() => { .then(() => {
loadingmsg.delete(); loadingmsg.delete();
return message.reply('Here is your YTP!', {files: [`${os.tmpdir()}/${message.id}_YTP.mp4`]}) return message.reply('Here is your YTP!', {files: [`${os.tmpdir()}/${message.id}_YTP.mp4`]})
.catch(() => { .catch(() => {
return message.channel.send('Whoops, look like the vid might be too big for discord, my bad, please try again'); return message.channel.send('Whoops, look like the vid might be too big for discord, my bad, please try again');
}); });
}) })
.catch(() => { .catch(err => {
loadingmsg.delete(); console.error(err);
return message.reply('Oh no! An error has occured!'); loadingmsg.delete();
}); return message.reply('Oh no! An error has occured!');
}); });
} }
} }

Loading…
Cancel
Save