2023-05-23 01:14:17 -04:00
import Discord from 'discord.js' ;
2023-04-14 06:47:58 -04:00
import TClient from '../client.js' ;
2023-09-29 17:27:32 -04:00
import Logger from '../helpers/Logger.js' ;
2023-10-06 01:54:27 -04:00
import MessageTool from '../helpers/MessageTool.js' ;
2023-12-24 10:21:40 -05:00
export default class Unpunish {
static async run ( client : TClient , interaction : Discord.ChatInputCommandInteraction < 'cached' > ) {
2024-01-16 06:41:30 -05:00
if ( ! MessageTool . isModerator ( interaction . member as Discord . GuildMember ) ) return MessageTool . youNeedRole ( interaction , 'dcmod' ) ;
2023-12-24 10:21:40 -05:00
const punishment = await client . punishments . findCase ( interaction . options . getInteger ( 'case_id' , true ) ) ;
if ( ! punishment ) return interaction . reply ( { content : 'Case ID is not found in database.' , ephemeral : true } ) ;
if ( [ 'unban' , 'unmute' , 'punishmentOverride' ] . includes ( punishment . dataValues . type ) ) return interaction . reply ( { content : 'This case ID is immutable. (Informative case)' , ephemeral : true } ) ;
2023-02-24 19:55:11 -05:00
const reason = interaction . options . getString ( 'reason' ) ? ? 'Reason unspecified' ;
2023-12-24 10:21:40 -05:00
await client . punishments . punishmentRemove ( punishment . dataValues . case_id , interaction . user . id , reason , interaction ) ;
2024-01-21 23:45:25 -05:00
const unpunishLog = ` Case # ${ interaction . options . getInteger ( 'case_id' ) } was used in \` / ${ interaction . commandName } \` for \` ${ reason } \` ` ;
Logger . console ( 'log' , 'UnpunishmentLog' , unpunishLog ) ;
( client . channels . cache . get ( client . config . dcServer . channels . punishment_log ) as Discord . TextChannel ) . send ( { embeds : [ new client . embed ( ) . setColor ( client . config . embedColor ) . setTitle ( 'Unpunishment Log' ) . setDescription ( unpunishLog ) . setTimestamp ( ) ] } ) ;
2023-12-24 10:21:40 -05:00
}
static data = new Discord . SlashCommandBuilder ( )
2023-02-24 19:55:11 -05:00
. setName ( 'unpunish' )
. setDescription ( 'Remove the active punishment from a member' )
2023-05-23 01:14:17 -04:00
. addIntegerOption ( x = > x
2023-02-24 19:55:11 -05:00
. setName ( 'case_id' )
2023-03-29 07:21:46 -04:00
. setDescription ( 'Case ID of the punishment to be overwritten' )
2023-02-24 19:55:11 -05:00
. setRequired ( true ) )
2023-05-23 01:14:17 -04:00
. addStringOption ( x = > x
2023-02-24 19:55:11 -05:00
. setName ( 'reason' )
. setDescription ( 'Reason for removing the punishment' ) )
2023-10-06 01:54:27 -04:00
}