@@ -13,6 +13,18 @@ const noContentEmbed = (command: string, version: string) => makeEmbed({
1313 color : Colors . Red ,
1414} ) ;
1515
16+ const noCommandEmbed = ( command : string ) => makeEmbed ( {
17+ title : 'Prefix Commands - Delete Content - No Command' ,
18+ description : `Failed to delete command content for command ${ command } as the command does not exist or there are more than one matching.` ,
19+ color : Colors . Red ,
20+ } ) ;
21+
22+ const noVersionEmbed = ( version : string ) => makeEmbed ( {
23+ title : 'Prefix Commands - Delete Content - No Version' ,
24+ description : `Failed to delete command content for version ${ version } as the version does not exist or there are more than one matching.` ,
25+ color : Colors . Red ,
26+ } ) ;
27+
1628const failedEmbed = ( version : string ) => makeEmbed ( {
1729 title : 'Prefix Commands - Delete Content - Failed' ,
1830 description : `Failed to delete the prefix command content with version ${ version } .` ,
@@ -52,7 +64,7 @@ const modLogEmbed = (moderator: User, commandName: string, versionName: string,
5264 value : `${ moderator } ` ,
5365 } ,
5466 ] ,
55- color : Colors . Green ,
67+ color : Colors . Red ,
5668} ) ;
5769
5870const noModLogs = makeEmbed ( {
@@ -80,10 +92,25 @@ export async function handleDeletePrefixCommandContent(interaction: ChatInputCom
8092 await interaction . followUp ( { embeds : [ noModLogs ] , ephemeral : true } ) ;
8193 }
8294
83- const foundVersion = await PrefixCommandVersion . findOne ( { name : version } ) ;
84- const { versionId } = foundVersion ?? { versionId : 'GENERIC' } ;
8595 const foundCommand = await PrefixCommand . findOne ( { name : command } ) ;
86- const [ existingContent ] = foundCommand ?. contents . filter ( ( content ) => content . versionId === versionId ) ?? [ ] ;
96+ if ( ! foundCommand ) {
97+ await interaction . followUp ( { embeds : [ noCommandEmbed ( command ) ] , ephemeral : true } ) ;
98+ return ;
99+ }
100+ let versionId = '' ;
101+ let foundVersions = null ;
102+ if ( version === 'GENERIC' || version === 'generic' ) {
103+ versionId = 'GENERIC' ;
104+ } else {
105+ foundVersions = await PrefixCommandVersion . find ( { name : version } ) ;
106+ if ( foundVersions && foundVersions . length === 1 ) {
107+ [ { _id : versionId } ] = foundVersions ;
108+ } else {
109+ await interaction . followUp ( { embeds : [ noVersionEmbed ( version ) ] , ephemeral : true } ) ;
110+ return ;
111+ }
112+ }
113+ const existingContent = foundCommand . contents . find ( ( content ) => content . versionId . toString ( ) === versionId . toString ( ) ) ;
87114
88115 if ( foundCommand && existingContent ) {
89116 const { title, content, image } = existingContent ;
@@ -97,7 +124,7 @@ export async function handleDeletePrefixCommandContent(interaction: ChatInputCom
97124 versionName = foundVersion . name || '' ;
98125 }
99126 try {
100- foundCommand . contents . find ( ( con ) => con . versionId === versionId ) ?. deleteOne ( ) ;
127+ foundCommand . contents . find ( ( con ) => con . versionId . toString ( ) === versionId . toString ( ) ) ?. deleteOne ( ) ;
101128 await foundCommand . save ( ) ;
102129 await refreshSinglePrefixCommandCache ( foundCommand , foundCommand ) ;
103130 await interaction . followUp ( { embeds : [ successEmbed ( `${ commandName } ` , `${ versionName } ` ) ] , ephemeral : true } ) ;
0 commit comments