@ -1,39 +1,40 @@
import { GuildChannel , AuditLogEvent } from 'discord.js' ;
import humanizeDuration from "humanize-duration" ;
import type { NucleusClient } from "../utils/client.js" ;
import getEmojiByName from "../utils/getEmojiByName.js" ;
export const event = "channelUpdate" ;
export async function callback ( client , oc , nc ) {
const config = await client . memory . readGuildInfo ( nc . guild . id ) ;
return ;
export async function callback ( client : NucleusClient , oldChannel : GuildChannel , newChannel : GuildChannel ) {
const config = await client . memory . readGuildInfo ( newChannel . guild . id ) ;
const { getAuditLog , log , NucleusColors , entry , renderDelta , renderUser , renderChannel } = client . logger ;
if ( n c. parent && nc . parent . id === config . tickets . category ) return ;
if ( n ewChannel. parent && newChannel . parent . id === config . tickets . category ) return ;
const auditLog = await getAuditLog ( n c . guild , "CHANNEL_UPDATE" ) ;
const audit = auditLog . entries . filter ( ( entry ) = > entry . target . id === n c . id ) . first ( ) ;
const auditLog = await getAuditLog ( n ewChannel . guild , "CHANNEL_UPDATE" ) ;
const audit = auditLog . entries . filter ( ( entry ) = > entry . target . id === n ewChannel . id ) . first ( ) ;
if ( audit . executor . id === client . user . id ) return ;
let emoji : string ;
let readableType : string ;
let displayName : string ;
const changes = {
channelId : entry ( n c. id , ` \` ${ nc . id } \` ` ) ,
channel : entry ( n c. id , renderChannel ( nc ) ) ,
channelId : entry ( n ewChannel. id , ` \` ${ newChannel . id } \` ` ) ,
channel : entry ( n ewChannel. id , renderChannel ( newChannel ) ) ,
edited : entry ( new Date ( ) . getTime ( ) , renderDelta ( new Date ( ) . getTime ( ) ) ) ,
editedBy : entry ( audit . executor . id , renderUser ( ( await n c . guild . members . fetch ( audit . executor . id ) ) . user ) )
editedBy : entry ( audit . executor . id , renderUser ( ( await n ewChannel . guild . members . fetch ( audit . executor . id ) ) . user ) )
} ;
if ( o c. name !== nc . name ) changes . name = entry ( [ o c. name , nc . name ] , ` ${ oc . name } -> ${ nc . name } ` ) ;
if ( o c. position !== nc . position )
changes . position = entry ( [ o c. position , nc . position ] , ` ${ oc . position } -> ${ nc . position } ` ) ;
if ( o ldChannel. name !== newChannel . name ) changes . name = entry ( [ o ldChannel. name , newChannel . name ] , ` ${ oldChannel . name } -> ${ newChannel . name } ` ) ;
if ( o ldChannel. position !== newChannel . position )
changes . position = entry ( [ o ldChannel. position , newChannel . position ] , ` ${ oldChannel . position } -> ${ newChannel . position } ` ) ;
switch ( n c . type ) {
switch ( n ewChannel . type ) {
case "GUILD_TEXT" : {
emoji = "CHANNEL.TEXT.EDIT" ;
readableType = "Text" ;
displayName = "Text Channel" ;
let oldTopic = o c . topic ,
newTopic = n c . topic ;
let oldTopic = o ldChannel . topic ,
newTopic = n ewChannel . topic ;
if ( oldTopic ) {
if ( oldTopic . length > 256 )
oldTopic = ` \` \` \` \ n ${ oldTopic . replace ( "`" , "'" ) . substring ( 0 , 253 ) + "..." } \ n \` \` \` ` ;
@ -49,15 +50,15 @@ export async function callback(client, oc, nc) {
newTopic = "None" ;
}
const nsfw = [ "" , "" ] ;
nsfw [ 0 ] = o c . nsfw ? ` ${ getEmojiByName ( "CONTROL.TICK" ) } Yes ` : ` ${ getEmojiByName ( "CONTROL.CROSS" ) } No ` ;
nsfw [ 1 ] = n c . nsfw ? ` ${ getEmojiByName ( "CONTROL.TICK" ) } Yes ` : ` ${ getEmojiByName ( "CONTROL.CROSS" ) } No ` ;
if ( o c. topic !== nc . topic )
changes . description = entry ( [ o c. topic , nc . topic ] , ` \ nBefore: ${ oldTopic } \ nAfter: ${ newTopic } ` ) ;
if ( o c. nsfw !== nc . nsfw ) changes . nsfw = entry ( [ o c. nsfw , nc . nsfw ] , ` ${ nsfw [ 0 ] } -> ${ nsfw [ 1 ] } ` ) ;
if ( o c. rateLimitPerUser !== nc . rateLimitPerUser )
nsfw [ 0 ] = o ldChannel . nsfw ? ` ${ getEmojiByName ( "CONTROL.TICK" ) } Yes ` : ` ${ getEmojiByName ( "CONTROL.CROSS" ) } No ` ;
nsfw [ 1 ] = n ewChannel . nsfw ? ` ${ getEmojiByName ( "CONTROL.TICK" ) } Yes ` : ` ${ getEmojiByName ( "CONTROL.CROSS" ) } No ` ;
if ( o ldChannel. topic !== newChannel . topic )
changes . description = entry ( [ o ldChannel. topic , newChannel . topic ] , ` \ nBefore: ${ oldTopic } \ nAfter: ${ newTopic } ` ) ;
if ( o ldChannel. nsfw !== newChannel . nsfw ) changes . nsfw = entry ( [ o ldChannel. nsfw , newChannel . nsfw ] , ` ${ nsfw [ 0 ] } -> ${ nsfw [ 1 ] } ` ) ;
if ( o ldChannel. rateLimitPerUser !== newChannel . rateLimitPerUser )
changes . rateLimitPerUser = entry (
[ o c. rateLimitPerUser , nc . rateLimitPerUser ] ,
` ${ humanizeDuration ( o c . rateLimitPerUser * 1000 ) } -> ${ humanizeDuration ( n c . rateLimitPerUser * 1000 ) } `
[ o ldChannel. rateLimitPerUser , newChannel . rateLimitPerUser ] ,
` ${ humanizeDuration ( o ldChannel . rateLimitPerUser * 1000 ) } -> ${ humanizeDuration ( n ewChannel . rateLimitPerUser * 1000 ) } `
) ;
break ;
@ -66,8 +67,8 @@ export async function callback(client, oc, nc) {
emoji = "CHANNEL.TEXT.EDIT" ;
readableType = "News" ;
displayName = "News Channel" ;
let oldTopic = o c . topic ,
newTopic = n c . topic ;
let oldTopic = o ldChannel . topic ,
newTopic = n ewChannel . topic ;
if ( oldTopic ) {
if ( oldTopic . length > 256 )
oldTopic = ` \` \` \` \ n ${ oldTopic . replace ( "`" , "'" ) . substring ( 0 , 253 ) + "..." } \ n \` \` \` ` ;
@ -82,25 +83,25 @@ export async function callback(client, oc, nc) {
} else {
newTopic = "None" ;
}
if ( o c. nsfw !== nc . nsfw )
changes . nsfw = entry ( [ o c. nsfw , nc . nsfw ] , ` ${ oc . nsfw ? "On" : "Off" } -> ${ n c . nsfw ? "On" : "Off" } ` ) ;
if ( o ldChannel. nsfw !== newChannel . nsfw )
changes . nsfw = entry ( [ o ldChannel. nsfw , newChannel . nsfw ] , ` ${ oldChannel . nsfw ? "On" : "Off" } -> ${ n ewChannel . nsfw ? "On" : "Off" } ` ) ;
break ;
}
case "GUILD_VOICE" : {
emoji = "CHANNEL.VOICE.EDIT" ;
readableType = "Voice" ;
displayName = "Voice Channel" ;
if ( o c. bitrate !== nc . bitrate )
changes . bitrate = entry ( [ o c. bitrate , nc . bitrate ] , ` ${ oc . bitrate } -> ${ nc . bitrate } ` ) ;
if ( o c. userLimit !== nc . userLimit )
if ( o ldChannel. bitrate !== newChannel . bitrate )
changes . bitrate = entry ( [ o ldChannel. bitrate , newChannel . bitrate ] , ` ${ oldChannel . bitrate } -> ${ newChannel . bitrate } ` ) ;
if ( o ldChannel. userLimit !== newChannel . userLimit )
changes . maxUsers = entry (
[ o c. userLimit , nc . userLimit ] ,
` ${ o c. userLimit ? oc . userLimit : "Unlimited" } -> ${ n c . userLimit } `
[ o ldChannel. userLimit , newChannel . userLimit ] ,
` ${ o ldChannel. userLimit ? oldChannel . userLimit : "Unlimited" } -> ${ n ewChannel . userLimit } `
) ;
if ( o c. rtcRegion !== nc . rtcRegion )
if ( o ldChannel. rtcRegion !== newChannel . rtcRegion )
changes . region = entry (
[ o c. rtcRegion , nc . rtcRegion ] ,
` ${ o c . rtcRegion || "Automatic" } -> ${ n c . rtcRegion || "Automatic" } `
[ o ldChannel. rtcRegion , newChannel . rtcRegion ] ,
` ${ o ldChannel . rtcRegion || "Automatic" } -> ${ n ewChannel . rtcRegion || "Automatic" } `
) ;
break ;
}
@ -108,8 +109,8 @@ export async function callback(client, oc, nc) {
emoji = "CHANNEL.VOICE.EDIT" ;
readableType = "Stage" ;
displayName = "Stage Channel" ;
let oldTopic = o c . topic ,
newTopic = n c . topic ;
let oldTopic = o ldChannel . topic ,
newTopic = n ewChannel . topic ;
if ( oldTopic ) {
if ( oldTopic . length > 256 )
oldTopic = ` \` \` \` \ n ${ oldTopic . replace ( "`" , "'" ) . substring ( 0 , 253 ) + "..." } \ n \` \` \` ` ;
@ -124,17 +125,17 @@ export async function callback(client, oc, nc) {
} else {
newTopic = "None" ;
}
if ( o c. bitrate !== nc . bitrate )
changes . bitrate = entry ( [ o c. bitrate , nc . bitrate ] , ` ${ oc . bitrate } -> ${ nc . bitrate } ` ) ;
if ( o c. userLimit !== nc . userLimit )
if ( o ldChannel. bitrate !== newChannel . bitrate )
changes . bitrate = entry ( [ o ldChannel. bitrate , newChannel . bitrate ] , ` ${ oldChannel . bitrate } -> ${ newChannel . bitrate } ` ) ;
if ( o ldChannel. userLimit !== newChannel . userLimit )
changes . maxUsers = entry (
[ o c. userLimit , nc . userLimit ] ,
` ${ o c. userLimit ? oc . userLimit : "Unlimited" } -> ${ n c . userLimit } `
[ o ldChannel. userLimit , newChannel . userLimit ] ,
` ${ o ldChannel. userLimit ? oldChannel . userLimit : "Unlimited" } -> ${ n ewChannel . userLimit } `
) ;
if ( o c. rtcRegion !== nc . rtcRegion )
if ( o ldChannel. rtcRegion !== newChannel . rtcRegion )
changes . region = entry (
[ o c. rtcRegion , nc . rtcRegion ] ,
` ${ o c . rtcRegion || "Automatic" } -> ${ n c . rtcRegion || "Automatic" } `
[ o ldChannel. rtcRegion , newChannel . rtcRegion ] ,
` ${ o ldChannel . rtcRegion || "Automatic" } -> ${ n ewChannel . rtcRegion || "Automatic" } `
) ;
break ;
}
@ -150,9 +151,9 @@ export async function callback(client, oc, nc) {
displayName = "Channel" ;
}
}
const t = o c . type . split ( "_" ) [ 1 ] ;
if ( o c. type !== nc . type )
changes . type = entry ( [ o c. type , nc . type ] , ` ${ t [ 0 ] + t . splice ( 1 ) . toLowerCase ( ) } -> ${ readableType } ` ) ;
const t = o ldChannel . type . split ( "_" ) [ 1 ] ;
if ( o ldChannel. type !== newChannel . type )
changes . type = entry ( [ o ldChannel. type , newChannel . type ] , ` ${ t [ 0 ] + t . splice ( 1 ) . toLowerCase ( ) } -> ${ readableType } ` ) ;
if ( ! ( Object . values ( changes ) . length - 4 ) ) return ;
const data = {
meta : {
@ -165,7 +166,7 @@ export async function callback(client, oc, nc) {
} ,
list : changes ,
hidden : {
guild : n c .guild.id
guild : n ewChannel .guild.id
}
} ;
log ( data ) ;