import type { EmbedField , Member , Message , TextChannel } from "eris" ; import { Command } from "../../classes/Command" ; import { generateSnowflake } from "../../utils/snowflake" ; export class WarnCommand extends Command { description = "Gives a member a warning." ; requiredperms = [ "manageMessages" ] ; args = "<member:member&strict> [reason:string]" ; aliases = [ "p" , "punish" , "s" , "strike" , "w" , "warn" ] ; staff = true ; async run ( msg , pargs , args ) { const id = generateSnowflake ( ) ; const member = pargs [ 0 ] . value as Member ; let reason = args . slice ( 1 ) . join ( " " ) ; if ( reason . length > 512 ) reason = reason . slice ( 0 , 512 ) ; await this . bot . db . insertUserWarning ( { id : id , receiver : member . id , guild : msg . channel . guild . id , reason : reason || null , giver : msg . author . id , } ) ; const dmchannel = await member . user . getDMChannel ( ) . catch ( ( ) => { } ) ; if ( dmchannel ) { const victimLocale = await this . bot . localeSystem . getUserLocale ( member . id , this . bot ) ; const NO_REASON = this . bot . localeSystem . getLocale ( `${ victimLocale }` , "global.NO_REASON" ) ; const DM_TITLE = this . bot . localeSystem . getLocale ( `${ victimLocale }` , "moderation.WARN_DM_TITLE" , { guild : msg . channel . guild . name } ) ; const DM_DESCRIPTION = this . bot . localeSystem . getLocale ( `${ victimLocale }` , "moderation.WARN_DM" , { reason : reason || NO_REASON . toLowerCase ( ) , } ) ; const DM_FOOTER = this . bot . localeSystem . getLocale ( `${ victimLocale }` , "moderation.WARN_FOOTER" , { member : msg . tagUser ( msg . author ) , id : id , } ) ; dmchannel . createMessage ( { embed : { title : `⚠ ${ DM_TITLE }` , description : DM_DESCRIPTION , color : msg . convertHex ( "error" ) , footer : { icon_url : msg . author . dynamicAvatarURL ( ) , text : DM_FOOTER , } , } , } ) . catch ( ( ) => { } ) ; } this . bot . emit ( "memberWarn" , msg . channel . guild , member . user , msg . author , reason , id ) ; const warnings = await this . bot . db . getAllUserGuildWarnings ( member . id , msg . channel . guild . id ) ; const fields = [ ] ; fields . push ( { name : msg . string ( "global.ID" ) , value : `${ id }` , inline : true , } ) ; if ( warnings . length > 1 ) { fields . push ( { name : msg . string ( "moderation.WARN_TOTAL" ) , value : `${ warnings . length }` , inline : true , } ) ; } if ( reason ) { fields . push ( { name : msg . string ( "global.REASON" ) , value : `${ reason }` , } ) ; } msg . channel . createMessage ( { embed : { title : msg . string ( "global.SUCCESS" ) , description : msg . string ( "moderation.WARN_ADDED" , { member : member . user . username } ) , color : msg . convertHex ( "success" ) , fields : fields , footer : { text : msg . string ( "global.RAN_BY" , { author : msg . tagUser ( msg . author ) } ) , icon_url : msg . author . dynamicAvatarURL ( ) , } , } , } ) ; } }