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-12-24 10:21:40 -05:00
import HookMgr from '../components/HookManager.js' ;
export default class Suggest {
static async run ( client :TClient , interaction :Discord.ChatInputCommandInteraction < 'cached' > ) {
const idVal = interaction . options . getInteger ( 'id' ) ;
2023-02-26 23:31:16 -05:00
( {
2023-12-24 10:21:40 -05:00
create : async ( ) = > {
const suggestion = interaction . options . getString ( 'suggestion' , true ) ;
const newSugg = await client . suggestions . create ( interaction . user . id , suggestion ) ;
this . newWebhookMessage ( client , newSugg . dataValues . id , suggestion , interaction . user . username ) ;
return interaction . reply ( { content : ` Your suggestion has been sent to bot developers. \` # ${ newSugg . dataValues . id } \` ` , ephemeral : true } ) ;
2023-02-26 23:31:16 -05:00
} ,
2023-12-24 10:21:40 -05:00
delete : async ( ) = > {
if ( client . config . dcServer . id === interaction . guildId ) {
if ( ! interaction . member . roles . cache . has ( client . config . dcServer . roles . bottech ) ) return MessageTool . youNeedRole ( interaction , 'bottech' ) ;
2023-04-24 06:10:11 -04:00
}
2023-12-24 10:21:40 -05:00
const sugg = await this . deleteSuggestion ( client , idVal ) ;
if ( sugg ) return interaction . reply ( ` Suggestion \` # ${ idVal } \` has been deleted. ` ) ;
else return interaction . reply ( ` Suggestion \` # ${ idVal } \` does not exist. ` ) ;
2023-02-26 23:31:16 -05:00
} ,
2023-12-24 10:21:40 -05:00
update : async ( ) = > {
if ( client . config . dcServer . id === interaction . guildId ) {
if ( ! interaction . member . roles . cache . has ( client . config . dcServer . roles . bottech ) ) return MessageTool . youNeedRole ( interaction , 'bottech' ) ;
2023-04-24 06:10:11 -04:00
}
2023-12-24 10:21:40 -05:00
const status = interaction . options . getString ( 'status' , true ) ;
await this . updateSuggestion ( client , idVal , status as 'Accepted' | 'Rejected' ) ;
client . users . fetch ( ( await client . suggestions . fetchById ( idVal ) ) . dataValues . userid ) . then ( x = > x . send ( ` Your suggestion \` # ${ idVal } \` has been updated to \` ${ status } \` by ** ${ interaction . user . username } ** ` ) ) . catch ( ( ) = > interaction . channel . send ( ` Unable to send DM to user of suggestion \` # ${ idVal } \` ` ) )
return await interaction . reply ( ` Suggestion \` # ${ idVal } \` has been updated to \` ${ status } \` . ` ) ;
2023-03-05 05:04:10 -05:00
}
2023-02-26 23:31:16 -05:00
} as any ) [ interaction . options . getSubcommand ( ) ] ( ) ;
2023-12-24 10:21:40 -05:00
}
static async updateSuggestion ( client :TClient , id :number , status : 'Accepted' | 'Rejected' ) {
return await client . suggestions . updateStatus ( id , status ) ;
}
static async deleteSuggestion ( client :TClient , id :number ) {
return await client . suggestions . delete ( id ) ;
}
static newWebhookMessage ( client :TClient , id :number , suggestion :string , username :string ) {
const hook = new HookMgr ( client , 'bot_suggestions' , '1079621523561779272' ) ;
if ( hook ) return hook . send ( { embeds : [ new client . embed ( ) . setColor ( client . config . embedColor ) . setTitle ( ` Suggestion # ${ id } ` ) . setAuthor ( { name : username } ) . setDescription ( ` \` \` \` ${ suggestion } \` \` \` ` ) ] } ) ;
else throw new Error ( '[SUGGESTION-HOOK] Provided webhook cannot be fetched, not sending message.' )
}
static data = new Discord . SlashCommandBuilder ( )
2023-02-26 23:31:16 -05:00
. setName ( 'suggest' )
2023-12-24 10:21:40 -05:00
. setDescription ( 'Want to suggest something to the bot devs? You can do so!' )
2023-05-23 01:14:17 -04:00
. addSubcommand ( x = > x
2023-12-24 10:21:40 -05:00
. setName ( 'create' )
. setDescription ( 'Create a new suggestion for your idea' )
2023-05-23 01:14:17 -04:00
. addStringOption ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'suggestion' )
2023-12-24 10:21:40 -05:00
. setDescription ( 'Your precious idea' )
. setRequired ( true ) ) )
2023-05-23 01:14:17 -04:00
. addSubcommand ( x = > x
2023-12-24 10:21:40 -05:00
. setName ( 'delete' )
. setDescription ( 'Delete a suggestion (Bot Tech only)' )
. addIntegerOption ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'id' )
2023-12-24 10:21:40 -05:00
. setDescription ( 'The ID of the suggestion' )
. setRequired ( true ) ) )
2023-05-23 01:14:17 -04:00
. addSubcommand ( x = > x
2023-12-24 10:21:40 -05:00
. setName ( 'update' )
. setDescription ( 'Update a suggestion (Bot Tech only)' )
. addIntegerOption ( x = > x
2023-02-26 23:31:16 -05:00
. setName ( 'id' )
2023-12-24 10:21:40 -05:00
. setDescription ( 'The ID of the suggestion' )
2023-02-26 23:31:16 -05:00
. setRequired ( true ) )
2023-05-23 01:14:17 -04:00
. addStringOption ( x = > x
2023-12-24 10:21:40 -05:00
. setName ( 'status' )
. setDescription ( 'The status of the suggestion (Accepted/Rejected)' )
2023-08-07 17:44:02 -04:00
. setRequired ( true )
2023-12-24 10:21:40 -05:00
. setChoices (
{ name : 'Accept' , value : 'Accepted' } ,
{ name : 'Reject' , value : 'Rejected' }
) ) )
2023-10-06 01:54:27 -04:00
}