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' ;
const { prefix } = process . env ;
const prefixs = prefix . split ( ',' ) ;
export default {
data : new SlashCommandBuilder ( )
. setName ( 'ytp' )
2022-08-31 23:09:46 +02:00
. setDescription ( 'Generate a YTP' )
. addBooleanOption ( option =>
option . setName ( 'force' )
2022-10-31 13:13:09 +01:00
. setDescription ( 'Force the generation of the video in a non-NSFW channel.' )
2022-08-31 23:09:46 +02:00
. setRequired ( false ) ) ,
2022-08-31 22:55:22 +02:00
category : 'fun' ,
2022-08-31 23:09:46 +02:00
async execute ( interaction , args ) {
2022-09-01 01:43:59 +02: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 \` \` ${ prefixs [ 0 ] } 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-10-31 13:13:09 +01:00
const loadingmsg = await interaction . reply ( ` Processing, this can take a ***long*** time, I'll ping you when it's 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 ,
} ,
} ;
new YTPGenerator ( ) . configurateAndGo ( options )
. then ( ( ) => {
loadingmsg . delete ( ) ;
2022-10-31 13:13:09 +01:00
return interaction . reply ( { content : 'Here is your YTP! Remember, it might contain NSFW content, so be careful!' , files : [ ` ${ os . tmpdir ( ) } / ${ interaction . id } _YTP.mp4 ` ] } )
2022-08-31 22:55:22 +02:00
. catch ( err => {
console . error ( err ) ;
return interaction . reply ( 'Whoops, look like the vid might be too big for discord, my bad, please try again' ) ;
} ) ;
} )
. catch ( err => {
console . error ( err ) ;
loadingmsg . delete ( ) ;
return interaction . reply ( { files : [ ` ./asset/ytp/error ${ Math . floor ( Math . random ( ) * 2 ) + 1 } .mp4 ` ] } ) ;
} ) ;
} ,
} ;