fileoverview description module import type { Message , TextChannel } from "eris" ; import type { HibikiClient } from "../../classes/Client" ; import { fullInviteRegex } from "../../utils/constants" ; import { punishMute , punishWarn } from "./punishments" ; import { validItems } from "../../utils/validItems" ; const reason = "Sent an invite (Automod)" ; const defaultPunishments = ( validItems . find ( ( item ) => item . id === "invitePunishments" ) . default as unknown ) as string [ ] ; export async function automodAntiInvite ( msg , bot , cfg ) { const string = bot . localeSystem . getLocaleFunction ( cfg ?. guildLocale ? cfg ?. guildLocale : bot . config . defaultLocale ) ; if ( fullInviteRegex . test ( msg . content ) ) { let warning = "" ; const punishments = cfg . invitePunishments ? cfg . invitePunishments : defaultPunishments ; punishments . forEach ( async ( punishment ) => { switch ( punishment ) { case "Warn" : warning = await punishWarn ( msg , bot , reason ) ; break ; case "Purge" : msg . delete ( ) ; break ; case "Mute" : punishMute ( msg , bot , cfg , reason ) ; break ; } } ) ; if ( cfg . msgOnPunishment ) { const pmsg = await msg . channel . createMessage ( { embed : { title : `⚠ ${ string ( "global.AUTOMOD" ) }` , description : string ( "global.AUTOMOD_INVITES" ) , color : msg . convertHex ( "error" ) , footer : { text : `${ string ( "global.RAN_BY" , { author : msg . tagUser ( msg . author ) } ) }` , icon_url : msg . author . dynamicAvatarURL ( ) , } , } , } ) ; setTimeout ( ( ) => pmsg . delete ( "Automod message deletion" ) . catch ( ( ) => { } ) , 5000 ) ; } bot . emit ( "automodAntiInvite" , msg . channel . guild , msg . member . user , warning , msg . content ) ; } }