2023-05-23 01:14:17 -04:00
import Discord from 'discord.js' ;
2023-08-24 19:15:56 -04:00
import TClient from '../client.js' ;
2023-08-29 20:21:53 -04:00
import MessageTool from '../helpers/MessageTool.js' ;
2023-10-06 10:26:23 -04:00
import HookMgr from '../funcs/HookManager.js' ;
2023-02-26 23:31:16 -05:00
export default {
async run ( client : TClient , interaction : Discord.ChatInputCommandInteraction < 'cached' > ) {
const replyInDM = interaction . options . getString ( 'message' ) ;
const suggestionIDReply = interaction . options . getString ( 'id' ) ;
const suggestionID = ( Math . random ( ) + 1 ) . toString ( 36 ) . substring ( 5 ) ;
const userid = ( await client . suggestion . _content . findById ( suggestionIDReply ) ) ? . user . _id ;
2023-04-24 06:10:11 -04:00
const theirIdea = ( await client . suggestion . _content . findById ( suggestionIDReply ) ) ? . idea ;
2023-10-07 17:01:16 -04:00
const timeFormatting = client . dayjs ( ) . format ( 'DD/MM/YY h:mm A' ) ;
2023-02-26 23:31:16 -05:00
const stateChanged = 'Suggestion state has been successfully updated and DM is sent.' ;
2023-10-06 01:54:27 -04:00
const dmFail = ` Failed to send a DM to ${ MessageTool . formatMention ( userid , 'user' ) } , they possibly have it turned off or blocked me. \ nSuggestion ID: ** ${ suggestionIDReply } ** ` ;
2023-02-26 23:31:16 -05:00
( {
your : async ( ) = > {
const suggestionText = interaction . options . getString ( 'suggestion' ) ;
const suggestionImage = interaction . options . getAttachment ( 'image' ) ;
const notifEmbed = new client . embed ( )
. setColor ( client . config . embedColor )
. setTitle ( ` Suggestion ID: ${ suggestionID } ` )
2023-06-09 21:11:19 -04:00
. setAuthor ( { name : interaction.user.username , iconURL : interaction.user.avatarURL ( { size : 256 } ) } )
2023-02-26 23:31:16 -05:00
. setFooter ( { text : ` Timestamp: ${ timeFormatting } ` } )
2023-08-29 20:21:53 -04:00
. setDescription ( MessageTool . concatMessage (
2023-02-26 23:31:16 -05:00
'> **Suggestion:**' ,
suggestionText
2023-08-29 20:21:53 -04:00
) ) ;
2023-02-26 23:31:16 -05:00
if ( suggestionImage ) notifEmbed . setImage ( suggestionImage . url ) ;
2023-10-06 10:26:23 -04:00
HookMgr . send ( client , 'bot_suggestions' , '1079621523561779272' , { embeds : [ notifEmbed ] , username : ` ${ client . user . username } Suggestions ` , avatarURL : client.user.avatarURL ( { size :256 } ) } ) . catch ( e = > {
2023-02-26 23:31:16 -05:00
console . log ( e . message ) ;
interaction . reply ( { content : 'Failed to send suggestion, try again later.' , ephemeral : true } )
2023-10-06 10:26:23 -04:00
} ) ;
2023-08-07 17:44:02 -04:00
await client . suggestion . _content . create ( { _id : suggestionID , idea : suggestionText , user : { _id : interaction.user.id , name : interaction.user.username } , state : 'Pending' } ) ;
2023-02-26 23:31:16 -05:00
interaction . reply ( { content : ` Suggestion sent, here is your suggestion ID to take note of it: \` ${ suggestionID } \` ` , ephemeral : true } )
} ,
approve : async ( ) = > {
2023-04-24 06:10:11 -04:00
if ( client . config . mainServer . id === interaction . guildId ) {
2023-10-06 01:54:27 -04:00
if ( ! interaction . member . roles . cache . has ( client . config . mainServer . roles . bottech ) ) return MessageTool . youNeedRole ( interaction , 'bottech' ) ;
2023-04-24 06:10:11 -04:00
}
2023-07-07 09:49:24 -04:00
if ( ( await client . suggestion . _content . findById ( suggestionIDReply ) ) . state === 'Rejected' ) return interaction . reply ( { content : 'This suggestion\'s state is locked and cannot be modified.' , ephemeral : true } ) ;
2023-02-26 23:31:16 -05:00
( await client . users . fetch ( userid ) ) . send ( { embeds : [ new client . embed ( )
. setColor ( client . config . embedColorGreen )
2023-06-09 21:11:19 -04:00
. setAuthor ( { name : interaction.user.username , iconURL : interaction.user.avatarURL ( { size : 256 } ) } )
2023-02-26 23:31:16 -05:00
. setTitle ( 'Your suggestion has been approved.' )
2023-08-07 17:44:02 -04:00
. setDescription ( ` > **Your suggestion:** \ n ${ theirIdea } \ n> **Their message:** \ n ${ replyInDM } ` )
2023-02-26 23:31:16 -05:00
. setFooter ( { text : ` Timestamp: ${ timeFormatting } | Suggestion ID: ${ suggestionIDReply } ` } )
2023-08-04 21:40:07 -04:00
] } ) . catch ( ( err :Discord.DiscordjsErrorCodes ) = > { if ( err ) return ( client . channels . resolve ( '1040018521746325586' ) as Discord . TextChannel ) . send ( dmFail ) } ) ;
2023-02-26 23:31:16 -05:00
await client . suggestion . _content . findByIdAndUpdate ( suggestionIDReply , { state : 'Approved' } ) ;
return interaction . reply ( { embeds : [ new client . embed ( ) . setColor ( client . config . embedColorGreen ) . setTitle ( ` Suggestion approved | ${ suggestionIDReply } ` ) . setDescription ( stateChanged ) ] } ) ;
} ,
reject : async ( ) = > {
2023-04-24 06:10:11 -04:00
if ( client . config . mainServer . id === interaction . guildId ) {
2023-10-06 01:54:27 -04:00
if ( ! interaction . member . roles . cache . has ( client . config . mainServer . roles . bottech ) ) return MessageTool . youNeedRole ( interaction , 'bottech' ) ;
2023-04-24 06:10:11 -04:00
}
2023-07-07 09:49:24 -04:00
if ( ( await client . suggestion . _content . findById ( suggestionIDReply ) ) . state === 'Approved' ) return interaction . reply ( { content : 'This suggestion\'s state is locked and cannot be modified.' , ephemeral : true } ) ;
2023-02-26 23:31:16 -05:00
( await client . users . fetch ( userid ) ) . send ( { embeds : [ new client . embed ( )
. setColor ( client . config . embedColorRed )
2023-06-09 21:11:19 -04:00
. setAuthor ( { name : interaction.user.username , iconURL : interaction.user.avatarURL ( { size : 256 } ) } )
2023-02-26 23:31:16 -05:00
. setTitle ( 'Your suggestion has been rejected.' )
2023-08-07 17:44:02 -04:00
. setDescription ( ` > **Your suggestion:** \ n ${ theirIdea } \ n> **Their message:** \ n ${ replyInDM } ` )
2023-02-26 23:31:16 -05:00
. setFooter ( { text : ` Timestamp: ${ timeFormatting } | Suggestion ID: ${ suggestionIDReply } ` } )
2023-08-04 21:40:07 -04:00
] } ) . catch ( ( err :Discord.DiscordjsErrorCodes ) = > { if ( err ) return ( client . channels . resolve ( '1040018521746325586' ) as Discord . TextChannel ) . send ( dmFail ) } ) ;
2023-02-26 23:31:16 -05:00
await client . suggestion . _content . findByIdAndUpdate ( suggestionIDReply , { state : 'Rejected' } ) ;
return interaction . reply ( { embeds : [ new client . embed ( ) . setColor ( client . config . embedColorRed ) . setTitle ( ` Suggestion rejected | ${ suggestionIDReply } ` ) . setDescription ( stateChanged ) ] } ) ;
2023-03-05 05:04:10 -05:00
}
2023-02-26 23:31:16 -05:00
} as any ) [ interaction . options . getSubcommand ( ) ] ( ) ;
} ,
2023-05-23 01:14:17 -04:00
data : new Discord . SlashCommandBuilder ( )
2023-02-26 23:31:16 -05:00
. setName ( 'suggest' )
2023-03-29 07:21:46 -04:00
. setDescription ( 'Want to suggest ideas/thoughts to bot techs? Suggest it here' )
2023-05-23 01:14:17 -04:00
. addSubcommand ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'your' )
. setDescription ( 'What do you want to suggest?' )
2023-05-23 01:14:17 -04:00
. addStringOption ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'suggestion' )
. setDescription ( 'Suggest something to bot techs. (You will be DM\'d by bot if your idea was approved/rejected)' )
. setMaxLength ( 1024 )
. setRequired ( true ) )
2023-05-23 01:14:17 -04:00
. addAttachmentOption ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'image' )
. setDescription ( 'If your idea seems complicated or prefer to show what your idea may look like then attach the image.' ) ) )
2023-05-23 01:14:17 -04:00
. addSubcommand ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'approve' )
2023-03-29 07:21:46 -04:00
. setDescription ( '[Bot Tech] Approve the suggestion sent by the user' )
2023-05-23 01:14:17 -04:00
. addStringOption ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'id' )
. setDescription ( 'User\'s suggestion ID' )
. setRequired ( true ) )
2023-05-23 01:14:17 -04:00
. addStringOption ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'message' )
2023-03-29 07:21:46 -04:00
. setDescription ( '(Optional) Include a message with your approval' )
2023-08-07 17:44:02 -04:00
. setRequired ( true )
2023-02-26 23:31:16 -05:00
. setMaxLength ( 256 ) ) )
2023-05-23 01:14:17 -04:00
. addSubcommand ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'reject' )
2023-03-29 07:21:46 -04:00
. setDescription ( '[Bot Tech] Reject the suggestion sent by the user' )
2023-05-23 01:14:17 -04:00
. addStringOption ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'id' )
. setDescription ( 'User\'s suggestion ID' )
. setRequired ( true ) )
2023-05-23 01:14:17 -04:00
. addStringOption ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'message' )
2023-03-29 07:21:46 -04:00
. setDescription ( '(Optional) Include a message with your rejection' )
2023-08-07 17:44:02 -04:00
. setRequired ( true )
2023-02-26 23:31:16 -05:00
. setMaxLength ( 256 ) ) )
2023-10-06 01:54:27 -04:00
}