2022-08-31 22:55:22 +02:00
import { SlashCommandBuilder } from 'discord.js' ;
import fs from 'node:fs' ;
import os from 'node:os' ;
import YTPGenerator from 'ytpplus-node' ;
export default {
data : new SlashCommandBuilder ( )
. setName ( 'ytp' )
2022-08-31 23:09:46 +02:00
. setDescription ( 'Generate a YTP' )
. addBooleanOption ( option =>
option . setName ( 'force' )
. setDescription ( 'Force the generation of the video in non-nsfw channel.' )
. setRequired ( false ) ) ,
2022-08-31 22:55:22 +02:00
category : 'fun' ,
2024-01-30 00:07:26 +01:00
ratelimit : 2 ,
cooldown : 60 ,
parallelLimit : 30 ,
2022-08-31 23:09:46 +02:00
async execute ( interaction , args ) {
2022-11-24 21:30:59 +01:00
if ( ! interaction . channel . nsfw && ! args . force ) return interaction . reply ( ` 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 do \` \` ${ interaction . prefix } ytp --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 ` ) ;
2022-08-31 22:55:22 +02:00
// Read userVid folder and select random vid and only take .mp4
const mp4 = [ ] ;
const asset = [ ] ;
// Count number of total vid
fs . readdirSync ( './asset/ytp/userVid/' ) . forEach ( file => {
if ( file . endsWith ( 'mp4' ) ) {
mp4 . push ( file ) ;
}
} ) ;
const MAX _CLIPS = 20 ;
// Select random vid depending on the amount of MAX_CLIPS
for ( let i = 0 ; i < MAX _CLIPS ; i ++ ) {
const random = Math . floor ( Math . random ( ) * mp4 . length ) ;
const vid = ` ./asset/ytp/userVid/ ${ mp4 [ random ] } ` ;
if ( mp4 [ random ] . endsWith ( 'mp4' ) ) {
if ( ! asset . includes ( vid ) ) {
asset . push ( vid ) ;
}
}
}
2022-09-02 09:00:41 +02:00
const loadingmsg = await interaction . reply ( ` Processing, this can take a ***long*** time, i'll ping you when I finished <a:loadingmin:527579785212329984> \n Some info: There are currently ${ mp4 . length } videos, why not add yours? You can do so with the \` \` addytp \` \` command. \n Like ytp? Why not check out https://ytp.namejeff.xyz/ ` ) ;
2022-08-31 22:55:22 +02:00
const options = {
debug : false ,
MAX _STREAM _DURATION : Math . floor ( ( Math . random ( ) * 3 ) + 1 ) ,
sources : './asset/ytp/sources/' ,
sounds : './asset/ytp/sounds/' ,
music : './asset/ytp/music/' ,
resources : './asset/ytp/resources/' ,
temp : os . tmpdir ( ) ,
sourceList : asset ,
2022-09-01 01:43:59 +02:00
intro : args . force ? './asset/ytp/intro.mp4' : null ,
2022-08-31 22:55:22 +02:00
outro : './asset/ytp/outro.mp4' ,
OUTPUT _FILE : ` ${ os . tmpdir ( ) } / ${ interaction . id } _YTP.mp4 ` ,
MAX _CLIPS : MAX _CLIPS ,
transitions : true ,
showFileNames : true ,
effects : {
effect _RandomSound : true ,
effect _RandomSoundMute : true ,
effect _Reverse : true ,
effect _Chorus : true ,
effect _Vibrato : true ,
effect _HighPitch : true ,
effect _LowPitch : true ,
effect _SpeedUp : true ,
effect _SlowDown : true ,
effect _Dance : true ,
effect _Squidward : true ,
effect _How : true ,
} ,
} ;
2024-01-30 00:07:26 +01:00
await new YTPGenerator ( ) . configurateAndGo ( options )
2022-08-31 22:55:22 +02:00
. then ( ( ) => {
loadingmsg . delete ( ) ;
2024-01-30 00:07:26 +01:00
return interaction . followUp ( { content : 'Here is your YTP! Remember, it might contain nsfw, so be careful!' , files : [ ` ${ os . tmpdir ( ) } / ${ interaction . id } _YTP.mp4 ` ] } )
2022-08-31 22:55:22 +02:00
. catch ( err => {
console . error ( err ) ;
2024-01-30 00:07:26 +01:00
return interaction . followUp ( { files : [ ` ./asset/ytp/error ${ Math . floor ( Math . random ( ) * 2 ) + 1 } .mp4 ` ] } ) ;
2022-08-31 22:55:22 +02:00
} ) ;
} )
. catch ( err => {
console . error ( err ) ;
loadingmsg . delete ( ) ;
2024-01-30 00:07:26 +01:00
return interaction . followUp ( { files : [ ` ./asset/ytp/error ${ Math . floor ( Math . random ( ) * 2 ) + 1 } .mp4 ` ] } ) ;
2022-08-31 22:55:22 +02:00
} ) ;
} ,
} ;