1- import { EventBase } from "src/ types/index.js " ;
1+ import { EventBase } from "@ types" ;
22import {
3- AuditLogEvent ,
4- ChannelType ,
5- EmbedBuilder ,
63 Events ,
7- NonThreadGuildBasedChannel ,
8- time ,
9- TimestampStyles ,
104} from "discord.js" ;
115import { getOrCreateGuild , GuildWithLogs } from "@repo/database" ;
12- import { returnWebhook , sleep , WebhookType } from "src/utils/index.js" ;
13- import { logger } from "src/lib/index.js" ;
6+ import { logChannelCreate } from "@utils" ;
147
158export default {
169 name : Events . ChannelCreate ,
@@ -20,58 +13,4 @@ export default {
2013 if ( ! guildConfig ) return ;
2114 await logChannelCreate ( channel , guildConfig ) ;
2215 } ,
23- } satisfies EventBase < Events . ChannelCreate > ;
24-
25- async function logChannelCreate ( channel : NonThreadGuildBasedChannel , guildConfig : GuildWithLogs ) {
26- if ( ! guildConfig . logConfig ?. channelLogsChannelId ) return ;
27- const t = channel . client . i18next . getFixedT ( guildConfig . language , "events" , "channelCreate" ) ;
28- const logChannel = channel . guild . channels . cache . get ( guildConfig . logConfig ?. channelLogsChannelId ) ;
29- if ( logChannel ?. type !== ChannelType . GuildText ) return ;
30-
31- await sleep ( 2000 ) ; // Wait for 2 seconds to ensure audit logs are updated
32-
33- const auditLogs = await channel . guild
34- . fetchAuditLogs ( {
35- limit : 1 ,
36- type : AuditLogEvent . ChannelCreate ,
37- } )
38- . catch ( ( ) => null ) ;
39-
40- const logEntry = auditLogs ?. entries . first ( ) ;
41- const executor = logEntry && logEntry . target ?. id === channel . id ? logEntry . executor : null ;
42-
43- const embed = new EmbedBuilder ( )
44- . setColor ( "Green" )
45- . setTitle ( t ( "embed.title" ) )
46- . setDescription (
47- t ( "embed.description" , {
48- channel : channel . toString ( ) , // Explicitly stringify to <#ID>
49- channel_type : t ( `channel_types.${ channel . type } ` ) ,
50- timestamp : time ( channel . createdAt , TimestampStyles . LongDateShortTime ) ,
51- } ) ,
52- )
53- . setThumbnail ( channel . guild . iconURL ( ) ?? null )
54- . setTimestamp ( )
55- . setFooter ( {
56- text : executor ?. tag ?? t ( "unknown_executor" ) ,
57- iconURL : executor ?. displayAvatarURL ( ) ?? undefined ,
58- } ) ;
59-
60- const webhook = await returnWebhook ( channel . client , logChannel , channel . guildId , guildConfig , {
61- id : guildConfig . logConfig . channelLogsWebhookId ,
62- type : WebhookType . CHANNEL_LOGS ,
63- } ) ;
64- if ( ! webhook ) return ;
65- await webhook
66- . send ( {
67- embeds : [ embed ] ,
68- } )
69- . catch ( ( error ) => {
70- logger . log ( {
71- level : "error" ,
72- error,
73- message : `Failed to send channelCreate embed in ${ channel . guild . name } (${ channel . guild . id } )` ,
74- channel : logChannel . id ,
75- } ) ;
76- } ) ;
77- }
16+ } satisfies EventBase < Events . ChannelCreate > ;
0 commit comments