2021-11-18 18:56:42 +01:00
const client = require ( "../" ) ;
const cooldown = require ( "../models/cooldown" ) ;
2021-09-06 12:38:25 +02:00
const utils = require ( "../util/functions/function" ) ;
2022-10-26 12:38:28 +02:00
const { EmbedBuilder } = require ( "discord.js" ) ;
2021-09-06 12:38:25 +02:00
client . on ( "interactionCreate" , async interaction => {
if ( interaction . isCommand ( ) ) {
await interaction . deferReply ( { ephemeral : false } ) . catch ( ( ) => { } ) ;
const cmd = client . slashCommands . get ( interaction . commandName ) ;
if ( ! cmd ) return ;
const args = [ ] ;
2021-11-18 18:56:42 +01:00
for ( const option of interaction . options . data ) {
2023-04-06 02:28:29 +02:00
if ( option . type === 2 ) {
2021-11-18 18:56:42 +01:00
if ( option . name ) args . push ( option . name ) ;
option . options ? . forEach ( x => {
2022-02-03 11:57:59 +01:00
if ( x . type === 1 ) {
2021-11-18 18:56:42 +01:00
if ( x . name ) args . push ( x . name ) ;
x . options ? . forEach ( y => {
if ( y . value ) args . push ( y . value ) ;
} ) ;
} else if ( x . value ) {
args . push ( x . value ) ;
}
if ( x . value ) args . push ( x . value ) ;
} ) ;
}
2023-04-06 02:28:29 +02:00
if ( option . type === 1 ) {
2021-09-06 12:38:25 +02:00
if ( option . name ) args . push ( option . name ) ;
option . options ? . forEach ( x => {
if ( x . value ) args . push ( x . value ) ;
} ) ;
2021-11-18 18:56:42 +01:00
} else if ( option . value ) {
args . push ( option . value ) ;
}
2021-09-06 12:38:25 +02:00
}
interaction . member = interaction . guild . members . cache . get (
interaction . user . id
) ;
2021-09-21 01:51:56 +02:00
const data = { } ;
2021-11-18 18:56:42 +01:00
const guildDB = await client . data . getGuild ( interaction . guild . id ) ;
2021-09-21 01:51:56 +02:00
if ( ! guildDB ) return ;
2021-11-18 18:56:42 +01:00
const userDB = await client . data . getUser ( interaction . user . id ) ;
2021-09-21 01:51:56 +02:00
if ( ! userDB ) return ;
data . Guild = guildDB ;
data . User = userDB ;
if ( ! guildDB ) await client . data . CreateGuild ( interaction . guild . id ) ;
2023-04-06 14:23:31 +02:00
if ( data . User ? . Blacklist )
return interaction . followUp ( {
content :
"You have been blacklisted from the bot, please contact the developers to appeal" ,
} ) ;
if ( cmd . Owner && ! client . owners . includes ( interaction . user . id ) ) return ;
if ( cmd . Premium && ! data . User . Premium ) {
return interaction . followUp ( {
embeds : [
new EmbedBuilder ( )
. setURL ( client . web )
. setAuthor ( {
name : interaction . user . tag ,
iconURL : interaction . user . displayAvatarURL ( { dynamic : true } ) ,
} )
. setColor ( client . color )
. setDescription (
` You aren't a premium user. You can either boost support server or subscribe to developer's team [Ko-fi](https://ko-fi.com/cathteam) or gift a nitro to one of the developer team to be premium user `
)
. setTimestamp ( )
. setFooter ( {
text : ` Made by ${ client . author } ` ,
iconURL : client . user . displayAvatarURL ( { dynamic : true } ) ,
} ) ,
] ,
} ) ;
2021-11-18 18:56:42 +01:00
}
2023-04-06 14:23:31 +02:00
if ( data . Guild ? . Category ) {
if ( data . Guild . Category . includes ( cmd . directory ) ) {
return interaction . followUp ( {
content : "This command has been disabled in this server" ,
} ) ;
2021-09-21 01:51:56 +02:00
}
2023-04-06 14:23:31 +02:00
}
if ( data . Guild ? . Commands ) {
if ( data . Guild . Commands . includes ( cmd . name ) ) {
return interaction . followUp ( {
content : "This command has been disabled in this server" ,
} ) ;
2021-09-21 01:51:56 +02:00
}
2021-11-18 18:56:42 +01:00
}
2023-04-06 14:23:31 +02:00
2022-02-02 23:46:57 +01:00
if ( cmd . timeout ) {
const current _time = Date . now ( ) ;
const cooldown _amount = cmd . timeout ;
cooldown . findOne (
{ User : interaction . user . id , CMD : cmd . name } ,
async ( er , d ) => {
if ( d ) {
const expiration _time = d . Time + cooldown _amount ;
if ( current _time < expiration _time ) {
if ( data . Guild . Tips ) utils . tips ( interaction , client ) ;
utils . cooldown ( d . Time , cooldown _amount , interaction ) ;
2021-11-18 18:56:42 +01:00
} else {
if ( data . Guild . Tips ) utils . tips ( interaction , client ) ;
2022-02-02 23:46:57 +01:00
await cooldown . findOneAndUpdate (
{ User : interaction . user . id , CMD : cmd . name } ,
{ Time : current _time }
) ;
cmd
. run ( client , interaction , args , utils , data )
2022-10-26 12:38:28 +02:00
. catch ( e => sendE ( e , interaction ) ) ;
2021-11-18 18:56:42 +01:00
client . channels . cache . get ( client . config . CMDLog ) . send ( {
content : ` \` ${ interaction . user . tag } ( ${ interaction . user . id } ) \` \n has used \n ** ${ cmd . name } ** \n command in \n \` ${ interaction . guild . name } ( ${ interaction . guild . id } ) \` ` ,
} ) ;
}
2022-02-02 23:46:57 +01:00
} else {
if ( data . Guild . Tips ) utils . tips ( interaction , client ) ;
cmd
. run ( client , interaction , args , utils , data )
2022-10-26 12:38:28 +02:00
. catch ( e => sendE ( e , interaction ) ) ;
2022-02-02 23:46:57 +01:00
client . channels . cache . get ( client . config . CMDLog ) . send ( {
content : ` \` ${ interaction . user . tag } ( ${ interaction . user . id } ) \` \n has used \n ** ${ cmd . name } ** \n command in \n \` ${ interaction . guild . name } ( ${ interaction . guild . id } ) \` ` ,
} ) ;
new cooldown ( {
User : interaction . user . id ,
CMD : cmd . name ,
Time : current _time ,
Cooldown : cmd . timeout ,
} ) . save ( ) ;
2021-11-18 18:56:42 +01:00
}
2022-02-02 23:46:57 +01:00
}
) ;
} else {
if ( data . Guild . Tips ) utils . tips ( interaction , client ) ;
2022-10-26 12:38:28 +02:00
cmd
. run ( client , interaction , args , utils , data )
. catch ( e => sendE ( e , interaction ) ) ;
2022-02-02 23:46:57 +01:00
client . channels . cache . get ( client . config . CMDLog ) . send ( {
content : ` \` ${ interaction . user . tag } ( ${ interaction . user . id } ) \` \n has used \n ** ${ cmd . name } ** \n command in \n \` ${ interaction . guild . name } ( ${ interaction . guild . id } ) \` ` ,
} ) ;
2021-09-06 12:38:25 +02:00
}
}
2022-10-26 12:38:28 +02:00
if ( interaction . isContextMenuCommand ( ) ) {
2021-09-06 12:38:25 +02:00
await interaction . deferReply ( { ephemeral : false } ) ;
const command = client . slashCommands . get ( interaction . commandName ) ;
if ( command ) command . run ( client , interaction ) ;
}
} ) ;
client . on ( "interactionCreate" , async interaction => {
if ( interaction . isCommand ( ) ) {
await interaction . deferReply ( { ephemeral : false } ) . catch ( ( ) => { } ) ;
const ownercmd = client . hide . get ( interaction . commandName ) ;
if ( ! ownercmd ) return ;
const args = [ ] ;
2021-11-18 18:56:42 +01:00
for ( const option of interaction . options . data ) {
2022-02-03 11:57:59 +01:00
if ( option . type === 1 ) {
2021-09-06 12:38:25 +02:00
if ( option . name ) args . push ( option . name ) ;
option . options ? . forEach ( x => {
if ( x . value ) args . push ( x . value ) ;
} ) ;
2021-11-18 18:56:42 +01:00
} else if ( option . value ) {
args . push ( option . value ) ;
}
2021-09-06 12:38:25 +02:00
}
interaction . member = interaction . guild . members . cache . get (
interaction . user . id
) ;
2022-10-26 12:38:28 +02:00
ownercmd
. run ( client , interaction , args , utils )
. catch ( e => sendE ( e , interaction ) ) ;
2022-02-02 23:46:57 +01:00
client . channels . cache . get ( client . config . CMDLog ) . send ( {
content : ` \` ${ interaction . user . tag } ( ${ interaction . user . id } ) \` \n has used \n ** ${ ownercmd . name } ** \n command in \n \` ${ interaction . guild . name } ( ${ interaction . guild . id } ) \` ` ,
} ) ;
2021-09-06 12:38:25 +02:00
}
} ) ;
2022-10-26 12:38:28 +02:00
function sendE ( e , i ) {
2023-04-02 14:12:53 +02:00
console . error ( e . stack ) ;
2022-10-26 12:38:28 +02:00
const embed = new EmbedBuilder ( )
2022-02-02 23:46:57 +01:00
. setTitle ( "Command Error" )
. setDescription ( ` \` \` \` yaml \n ${ e . stack } \` \` \` ` )
. setTimestamp ( )
. setColor ( client . color )
. setFooter ( { text : client . user . username } ) ;
2022-10-26 12:38:28 +02:00
i . channel . send ( { embeds : [ embed ] } ) ;
2022-02-02 23:46:57 +01:00
client . channels . cache . get ( client . config . ErrorLog ) . send ( { embeds : [ embed ] } ) ;
}