2023-12-24 10:21:40 -05:00
import Discord from 'discord.js' ;
import TClient from '../client.js' ;
import MessageTool from '../helpers/MessageTool.js' ;
2024-01-21 23:45:25 -05:00
import Logger from '../helpers/Logger.js' ;
2024-01-14 01:51:17 -05:00
export default async ( client :TClient , interaction : Discord.ChatInputCommandInteraction < 'cached' > , type : 'ban' | 'softban' | 'kick' | 'mute' | 'warn' | 'remind' ) = > {
2024-01-14 01:58:25 -05:00
if ( ! MessageTool . isModerator ( interaction . member ) ) return MessageTool . youNeedRole ( interaction , 'dcmod' ) ;
2023-12-24 10:21:40 -05:00
2024-01-21 23:45:25 -05:00
const isInBKL = [ 'ban' , 'kick' ] . includes ( type ) && interaction . channelId === client . config . dcServer . channels . bankick_log ;
2023-12-24 10:21:40 -05:00
const time = interaction . options . getString ( 'time' ) ? ? undefined ;
const reason = interaction . options . getString ( 'reason' ) ? ? 'Reason unspecified' ;
const GuildMember = interaction . options . getMember ( 'member' ) ? ? undefined ;
const User = interaction . options . getUser ( 'member' , true ) ;
2024-01-23 15:24:09 -05:00
if ( reason . length > 1020 ) return interaction . reply ( { content : 'Reason cannot be longer than 1020 characters due to Discord\'s limit.' , ephemeral : true } ) ;
2023-12-24 10:21:40 -05:00
2024-01-21 23:45:25 -05:00
const punishLog = ` ${ GuildMember ? . user ? . username ? ? User ? . username ? ? 'No user data' } ${ time ? [ 'warn' , 'kick' ] . includes ( type ) ? 'and no duration set' : ` and ${ time } (duration) ` : '' } was used in \` / ${ interaction . commandName } \` for \` ${ reason } \` ` ;
Logger . console ( 'log' , 'PunishmentLog' , punishLog ) ;
( client . channels . cache . get ( client . config . dcServer . channels . punishment_log ) as Discord . TextChannel ) . send ( { embeds : [ new client . embed ( ) . setColor ( client . config . embedColor ) . setTitle ( 'Punishment Log' ) . setDescription ( punishLog ) . setTimestamp ( ) ] } ) ;
2023-12-24 10:21:40 -05:00
if ( interaction . user . id === User . id ) return interaction . reply ( ` You cannot ${ type } yourself. ` ) ;
if ( ! GuildMember && ! [ 'unban' , 'ban' ] . includes ( type ) ) return interaction . reply ( ` You cannot ${ type } someone who is not in the server. ` ) ;
if ( User . bot ) return interaction . reply ( ` You cannot ${ type } a bot! ` ) ;
2024-01-21 23:45:25 -05:00
await interaction . deferReply ( { ephemeral : isInBKL } ) ;
2023-12-24 10:21:40 -05:00
await client . punishments . punishmentAdd ( type , { time , interaction } , interaction . user . id , reason , User , GuildMember ) ;
}