@ -14,6 +14,7 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
. addUserOption ( ( option ) = > option . setName ( "user" ) . setDescription ( "The user to warn" ) . setRequired ( true ) ) ;
. addUserOption ( ( option ) = > option . setName ( "user" ) . setDescription ( "The user to warn" ) . setRequired ( true ) ) ;
const callback = async ( interaction : CommandInteraction ) : Promise < unknown > = > {
const callback = async ( interaction : CommandInteraction ) : Promise < unknown > = > {
if ( interaction . guild === null ) return ;
const { log , NucleusColors , renderUser , entry } = client . logger ;
const { log , NucleusColors , renderUser , entry } = client . logger ;
// TODO:[Modals] Replace this with a modal
// TODO:[Modals] Replace this with a modal
let reason : string | null = null ;
let reason : string | null = null ;
@ -37,7 +38,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
. addCustomBoolean (
. addCustomBoolean (
"appeal" ,
"appeal" ,
"Create appeal ticket" ,
"Create appeal ticket" ,
! ( await areTicketsEnabled ( interaction . guild ! . id ) ) ,
! ( await areTicketsEnabled ( interaction . guild . id ) ) ,
async ( ) = > await create ( interaction . guild ! , interaction . options . getUser ( "user" ) ! , interaction . user , reason ) ,
async ( ) = > await create ( interaction . guild ! , interaction . options . getUser ( "user" ) ! , interaction . user , reason ) ,
"An appeal ticket will be created" ,
"An appeal ticket will be created" ,
"CONTROL.TICKET" ,
"CONTROL.TICKET" ,
@ -64,79 +65,166 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}
}
} while ( ! timedOut && ! success )
} while ( ! timedOut && ! success )
if ( timedOut ) return ;
if ( timedOut ) return ;
if ( confirmation . success ) {
if ( ! confirmation . success ) {
let dmSent = false ;
await interaction . editReply ( {
const config = await client . database . guilds . read ( interaction . guild ! . id ) ;
embeds : [
try {
new EmojiEmbed ( )
if ( notify ) {
. setEmoji ( "PUNISH.WARN.GREEN" )
const messageData : {
. setTitle ( "Warn" )
embeds : EmojiEmbed [ ] ;
. setDescription ( "No changes were made" )
components : ActionRowBuilder < ButtonBuilder > [ ] ;
. setStatus ( "Success" )
} = {
] ,
embeds : [
components : [ ]
new EmojiEmbed ( )
} ) ;
. setEmoji ( "PUNISH.WARN.RED" )
return ;
. setTitle ( "Warned" )
}
. setDescription (
let dmSent = false ;
` You have been warned in ${ interaction . guild ! . name } ` +
const config = await client . database . guilds . read ( interaction . guild . id ) ;
( reason ? ` for: \ n> ${ reason } ` : ".\n*No reason was provided*" ) +
try {
"\n\n" +
if ( notify ) {
( createAppealTicket
const messageData : {
? ` You can appeal this in the ticket created in <# ${ confirmation . components ! [ "appeal" ] ! . response } > `
embeds : EmojiEmbed [ ] ;
: "" )
components : ActionRowBuilder < ButtonBuilder > [ ] ;
)
} = {
. setStatus ( "Danger" )
embeds : [
] ,
new EmojiEmbed ( )
components : [ ]
. setEmoji ( "PUNISH.WARN.RED" )
} ;
. setTitle ( "Warned" )
if ( config . moderation . warn . text && config . moderation . warn . link ) {
. setDescription (
messageData . embeds [ 0 ] ! . setFooter ( LinkWarningFooter )
` You have been warned in ${ interaction . guild . name } ` +
messageData . components . push ( new ActionRowBuilder < Discord.ButtonBuilder > ( )
( reason ? ` for: \ n> ${ reason } ` : ".\n*No reason was provided*" ) +
. addComponents ( new ButtonBuilder ( )
"\n\n" +
. setStyle ( ButtonStyle . Link )
( createAppealTicket
. setLabel ( config . moderation . warn . text )
? ` You can appeal this in the ticket created in <# ${ confirmation . components ! [ "appeal" ] ! . response } > `
. setURL ( config . moderation . warn . link )
: "" )
)
)
)
. setStatus ( "Danger" )
}
] ,
await ( interaction . options . getMember ( "user" ) as GuildMember ) . send ( messageData ) ;
components : [ ]
dmSent = true ;
} ;
if ( config . moderation . warn . text && config . moderation . warn . link ) {
messageData . embeds [ 0 ] ! . setFooter ( LinkWarningFooter )
messageData . components . push ( new ActionRowBuilder < Discord.ButtonBuilder > ( )
. addComponents ( new ButtonBuilder ( )
. setStyle ( ButtonStyle . Link )
. setLabel ( config . moderation . warn . text )
. setURL ( config . moderation . warn . link )
)
)
}
}
await ( interaction . options . getMember ( "user" ) as GuildMember ) . send ( messageData ) ;
dmSent = true ;
}
} catch ( e ) {
dmSent = false ;
}
const data = {
meta : {
type : "memberWarn" ,
displayName : "Member warned" ,
calculateType : "guildMemberPunish" ,
color : NucleusColors.yellow ,
emoji : "PUNISH.WARN.YELLOW" ,
timestamp : new Date ( ) . getTime ( )
} ,
list : {
user : entry (
( interaction . options . getMember ( "user" ) as GuildMember ) . user . id ,
renderUser ( ( interaction . options . getMember ( "user" ) as GuildMember ) . user )
) ,
warnedBy : entry ( interaction . member ! . user . id , renderUser ( interaction . member ! . user as Discord . User ) ) ,
reason : reason ? ` \ n> ${ reason } ` : "*No reason provided*"
} ,
hidden : {
guild : interaction.guild.id
}
} ;
await client . database . history . create (
"warn" ,
interaction . guild . id ,
( interaction . options . getMember ( "user" ) as GuildMember ) . user ,
interaction . user ,
reason
) ;
log ( data ) ;
const failed = ! dmSent && notify ;
if ( ! failed ) {
await interaction . editReply ( {
embeds : [
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.GREEN" )
. setTitle ( "Warn" )
. setDescription (
"The user was warned" +
( createAppealTicket
? ` and an appeal ticket was opened in <# ${ confirmation . components ! [ "appeal" ] ! . response } > `
: "" )
)
. setStatus ( "Success" )
] ,
components : [ ]
} ) ;
} else {
const canSeeChannel = ( interaction . options . getMember ( "user" ) as GuildMember )
. permissionsIn ( interaction . channel as Discord . TextChannel )
. has ( "ViewChannel" ) ;
const m = ( await interaction . editReply ( {
embeds : [
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.RED" )
. setTitle ( "Warn" )
. setDescription ( "The user's DMs are not open\n\nWhat would you like to do?" )
. setStatus ( "Danger" )
] ,
components : [
new ActionRowBuilder < Discord.ButtonBuilder > ( ) . addComponents (
new Discord . ButtonBuilder ( ) . setCustomId ( "log" ) . setLabel ( "Ignore and log" ) . setStyle ( ButtonStyle . Secondary ) ,
new Discord . ButtonBuilder ( )
. setCustomId ( "here" )
. setLabel ( "Warn here" )
. setStyle ( canSeeChannel ? ButtonStyle.Primary : ButtonStyle.Secondary )
. setDisabled ( ! canSeeChannel ) ,
new Discord . ButtonBuilder ( )
. setCustomId ( "ticket" )
. setLabel ( "Create ticket" )
. setStyle ( canSeeChannel ? ButtonStyle.Primary : ButtonStyle.Secondary )
. setDisabled ( createAppealTicket )
)
]
} ) ) as Discord . Message ;
let component ;
try {
component = await m . awaitMessageComponent ( {
filter : ( m ) = > m . user . id === interaction . user . id ,
time : 300000
} ) ;
} catch ( e ) {
} catch ( e ) {
dmSent = false ;
return await interaction . editReply ( {
embeds : [
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.GREEN" )
. setTitle ( "Warn" )
. setDescription ( "No changes were made" )
. setStatus ( "Success" )
] ,
components : [ ]
} ) ;
}
}
const data = {
if ( component . customId === "here" ) {
meta : {
await interaction . channel ! . send ( {
type : "memberWarn" ,
embeds : [
displayName : "Member warned" ,
new EmojiEmbed ( )
calculateType : "guildMemberPunish" ,
. setEmoji ( "PUNISH.WARN.RED" )
color : NucleusColors.yellow ,
. setTitle ( "Warn" )
emoji : "PUNISH.WARN.YELLOW" ,
. setDescription ( "You have been warned" + ( reason ? ` for: \ n> ${ reason } ` : "." ) )
timestamp : new Date ( ) . getTime ( )
. setStatus ( "Danger" )
} ,
] ,
list : {
content : ` <@! ${ ( interaction . options . getMember ( "user" ) as GuildMember ) . id } > ` ,
user : entry (
allowedMentions : {
( interaction . options . getMember ( "user" ) as GuildMember ) . user . id ,
users : [ ( interaction . options . getMember ( "user" ) as GuildMember ) . id ]
renderUser ( ( interaction . options . getMember ( "user" ) as GuildMember ) . user )
}
) ,
} ) ;
warnedBy : entry ( interaction . member ! . user . id , renderUser ( interaction . member ! . user as Discord . User ) ) ,
return await interaction . editReply ( {
reason : reason ? ` \ n> ${ reason } ` : "*No reason provided*"
} ,
hidden : {
guild : interaction.guild ! . id
}
} ;
await client . database . history . create (
"warn" ,
interaction . guild ! . id ,
( interaction . options . getMember ( "user" ) as GuildMember ) . user ,
interaction . user ,
reason
) ;
log ( data ) ;
const failed = ! dmSent && notify ;
if ( ! failed ) {
await interaction . editReply ( {
embeds : [
embeds : [
new EmojiEmbed ( )
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.GREEN" )
. setEmoji ( "PUNISH.WARN.GREEN" )
@ -151,139 +239,53 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
] ,
] ,
components : [ ]
components : [ ]
} ) ;
} ) ;
} else {
} else if ( component . customId === "log" ) {
const canSeeChannel = ( interaction . options . getMember ( "user" ) as GuildMember )
await interaction . editReply ( {
. permissionsIn ( interaction . channel as Discord . TextChannel )
. has ( "ViewChannel" ) ;
const m = ( await interaction . editReply ( {
embeds : [
embeds : [
new EmojiEmbed ( )
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN. RED ")
. setEmoji ( "PUNISH.WARN.GREEN" )
. setTitle ( "Warn" )
. setTitle ( "Warn" )
. setDescription ( "The user's DMs are not open\n\nWhat would you like to do? ")
. setDescription ( "The warn was logged ")
. setStatus ( " Danger ")
. setStatus ( " Success ")
] ,
] ,
components : [
components : [ ]
new ActionRowBuilder < Discord.ButtonBuilder > ( ) . addComponents (
} ) ;
new Discord . ButtonBuilder ( ) . setCustomId ( "log" ) . setLabel ( "Ignore and log" ) . setStyle ( ButtonStyle . Secondary ) ,
} else if ( component . customId === "ticket" ) {
new Discord . ButtonBuilder ( )
const ticketChannel = await create (
. setCustomId ( "here" )
interaction . guild ,
. setLabel ( "Warn here" )
interaction . options . getUser ( "user" ) ! ,
. setStyle ( canSeeChannel ? ButtonStyle.Primary : ButtonStyle.Secondary )
interaction . user ,
. setDisabled ( ! canSeeChannel ) ,
reason ,
new Discord . ButtonBuilder ( )
"Warn Notification"
. setCustomId ( "ticket" )
) ;
. setLabel ( "Create ticket" )
if ( ticketChannel === null ) {
. setStyle ( canSeeChannel ? ButtonStyle.Primary : ButtonStyle.Secondary )
. setDisabled ( createAppealTicket )
)
]
} ) ) as Discord . Message ;
let component ;
try {
component = await m . awaitMessageComponent ( {
filter : ( m ) = > m . user . id === interaction . user . id ,
time : 300000
} ) ;
} catch ( e ) {
return await interaction . editReply ( {
return await interaction . editReply ( {
embeds : [
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.GREEN" )
. setTitle ( "Warn" )
. setDescription ( "No changes were made" )
. setStatus ( "Success" )
] ,
components : [ ]
} ) ;
}
if ( component . customId === "here" ) {
await interaction . channel ! . send ( {
embeds : [
embeds : [
new EmojiEmbed ( )
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.RED" )
. setEmoji ( "PUNISH.WARN.RED" )
. setTitle ( "Warn" )
. setTitle ( "Warn" )
. setDescription ( " You have been warned" + ( reason ? ` for: \ n> ${ reason } ` : "." ) )
. setDescription ( "A ticket could not be created" )
. setStatus ( "Danger" )
. setStatus ( "Danger" )
] ,
] ,
content : ` <@! ${ ( interaction . options . getMember ( "user" ) as GuildMember ) . id } > ` ,
allowedMentions : {
users : [ ( interaction . options . getMember ( "user" ) as GuildMember ) . id ]
}
} ) ;
return await interaction . editReply ( {
embeds : [
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.GREEN" )
. setTitle ( "Warn" )
. setDescription (
"The user was warned" +
( createAppealTicket
? ` and an appeal ticket was opened in <# ${ confirmation . components ! [ "appeal" ] ! . response } > `
: "" )
)
. setStatus ( "Success" )
] ,
components : [ ]
} ) ;
} else if ( component . customId === "log" ) {
await interaction . editReply ( {
embeds : [
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.GREEN" )
. setTitle ( "Warn" )
. setDescription ( "The warn was logged" )
. setStatus ( "Success" )
] ,
components : [ ]
} ) ;
} else if ( component . customId === "ticket" ) {
const ticketChannel = await create (
interaction . guild ! ,
interaction . options . getUser ( "user" ) ! ,
interaction . user ,
reason ,
"Warn Notification"
) ;
if ( ticketChannel === null ) {
return await interaction . editReply ( {
embeds : [
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.RED" )
. setTitle ( "Warn" )
. setDescription ( "A ticket could not be created" )
. setStatus ( "Danger" )
] ,
components : [ ]
} ) ;
}
await interaction . editReply ( {
embeds : [
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.GREEN" )
. setTitle ( "Warn" )
. setDescription ( ` A ticket was created in <# ${ ticketChannel } > ` )
. setStatus ( "Success" )
] ,
components : [ ]
components : [ ]
} ) ;
} ) ;
}
}
await interaction . editReply ( {
embeds : [
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.GREEN" )
. setTitle ( "Warn" )
. setDescription ( ` A ticket was created in <# ${ ticketChannel } > ` )
. setStatus ( "Success" )
] ,
components : [ ]
} ) ;
}
}
} else {
await interaction . editReply ( {
embeds : [
new EmojiEmbed ( )
. setEmoji ( "PUNISH.WARN.GREEN" )
. setTitle ( "Warn" )
. setDescription ( "No changes were made" )
. setStatus ( "Success" )
] ,
components : [ ]
} ) ;
}
}
} ;
} ;
const check = ( interaction : CommandInteraction ) = > {
const check = ( interaction : CommandInteraction ) = > {
if ( ! interaction . guild ) return ;
const member = interaction . member as GuildMember ;
const member = interaction . member as GuildMember ;
const apply = interaction . options . getMember ( "user" ) as GuildMember | null ;
const apply = interaction . options . getMember ( "user" ) as GuildMember | null ;
if ( apply === null ) throw new Error ( "That member is not in the server" ) ;
if ( apply === null ) throw new Error ( "That member is not in the server" ) ;
@ -292,7 +294,7 @@ const check = (interaction: CommandInteraction) => {
// Do not allow warning bots
// Do not allow warning bots
if ( member . user . bot ) throw new Error ( "I cannot warn bots" ) ;
if ( member . user . bot ) throw new Error ( "I cannot warn bots" ) ;
// Allow the owner to warn anyone
// Allow the owner to warn anyone
if ( member . id === interaction . guild ! . ownerId ) return true ;
if ( member . id === interaction . guild . ownerId ) return true ;
// Check if the user has moderate_members permission
// Check if the user has moderate_members permission
if ( ! member . permissions . has ( "ModerateMembers" ) )
if ( ! member . permissions . has ( "ModerateMembers" ) )
throw new Error ( "You do not have the *Moderate Members* permission" ) ;
throw new Error ( "You do not have the *Moderate Members* permission" ) ;