11require ( "./other/patchConsoleLog" ) ;
22console . info ( `[BİLGİ] Basit Altyapı v${ require ( "./package.json" ) . version } - by Kıraç Armağan Önal` ) ;
33const config = require ( "./config" ) ;
4+ const utils = require ( "./other/utils" ) ;
45globalThis . Underline = config . globalObjects ;
56const Discord = require ( "discord.js" ) ;
67const chillout = require ( "chillout" ) ;
@@ -17,10 +18,12 @@ let localeFiles;
1718globalThis . Underline = {
1819 ...config . globalObjects ,
1920 config,
21+ other : config . other ,
2022 client,
2123 interactions,
2224 events,
2325 locales,
26+ utils,
2427 Interaction : require ( './types/Interaction' ) ,
2528 Event : require ( './types/Event' ) ,
2629 SlashCommand : require ( "./types/SlashCommand" ) ,
@@ -238,9 +241,22 @@ async function load() {
238241 let before = await Underline . config . onEvent ( eventName , args , other ) ;
239242 if ( ! before ) return ;
240243 args . push ( other ) ;
241- chillout . forEach ( events , ( event ) => {
244+ chillout . forEach ( events ,
245+ /** @param {import("./types/Event") } event */
246+ ( event ) => {
242247 if ( ! event . disabled ) {
243- event . onEvent ( ...args ) ;
248+ try {
249+ event . onEvent ( ...args ) ;
250+ Underline . config . onAfterEvent ( eventName , args , other ) ;
251+ } catch ( err ) {
252+ console . error ( `[HATA] "${ event . id } " idli ve "${ eventName } " isimli olayda bir hata oluÅŸtu!` ) ;
253+ if ( err . message ) console . error ( `[HATA] ${ err . message } ` ) ;
254+ if ( err . stack ) {
255+ `${ err . stack } ` . split ( "\n" ) . forEach ( ( line ) => {
256+ console . error ( `[HATA] ${ line } ` ) ;
257+ } ) ;
258+ }
259+ }
244260 }
245261 } ) ;
246262
@@ -281,6 +297,7 @@ async function unload() {
281297 await chillout . forEach ( eventListeners , ( el ) => {
282298 el . base . off ( el . name , el . listener ) ;
283299 } )
300+ eventListeners . length = 0 ;
284301
285302 console . info ( `[BILGI] Dil listesi temizleniyor..` ) ;
286303 Underline . locales . clear ( ) ;
@@ -325,20 +342,60 @@ client.on("interactionCreate", async (interaction) => {
325342
326343 if ( ! uInter ) return ;
327344
345+ let other = { } ;
346+
328347 if ( interaction . isAutocomplete ( ) ) {
348+ if ( uInter . disabled ) {
349+ let r = await config . userErrors . disabled ( interaction , uInter , other ) ;
350+ interaction . respond ( r ) ;
351+ return ;
352+ }
353+ if ( config . blockedUsers . has ( interaction . user . id ) ) {
354+ let r = await config . userErrors . blocked ( interaction , uInter , other ) ;
355+ interaction . respond ( r ) ;
356+ return ;
357+ }
358+ if ( uInter . guildOnly && ! interaction . guildId ) {
359+ let r = await config . userErrors . guildOnly ( interaction , uInter , other ) ;
360+ interaction . respond ( r ) ;
361+ return ;
362+ }
363+ if ( uInter . calculated . developerOnly && ! config . developers . has ( interaction . user . id ) ) {
364+ let r = await config . userErrors . developerOnly ( interaction , uInter , other ) ;
365+ interaction . respond ( r ) ;
366+ return ;
367+ }
368+ if ( uInter . calculated . guildOwnerOnly && ! config . developers . has ( interaction . user . id ) && interaction . guild . ownerId != interaction . user . id ) {
369+ let r = await config . userErrors . guildOwnerOnly ( interaction , uInter , other ) ;
370+ interaction . respond ( r ) ;
371+ return ;
372+ }
373+ if ( uInter . guildOnly && ( ! config . developers . has ( interaction . user . id ) ) && uInter . perms . user . length != 0 && ! uInter . perms . user . every ( perm => interaction . member . permissions . has ( perm ) ) ) {
374+ let r = await config . userErrors . userPermsRequired ( interaction , uInter , uInter . perms . user , other ) ;
375+ interaction . respond ( r ) ;
376+ return ;
377+ }
329378 /** @type {Discord.ApplicationCommandOptionChoice } */
330379 let focussed = null ;
331380 try { focussed = interaction . options . getFocused ( true ) } catch { } ;
332381 let option = uInter . options . find ( i => i . autocomplete && i . name == focussed ?. name ) ;
333382 if ( option ) {
334- let completeResponse = await option . onComplete ( interaction , focussed . value ) ;
335- interaction . respond ( completeResponse ) ;
383+ try {
384+ let completeResponse = await option . onComplete ( interaction , focussed . value ) ;
385+ interaction . respond ( completeResponse ) ;
386+ } catch ( err ) {
387+ console . error ( `[HATA] "${ uInter . actionType == "CHAT_INPUT" ? `/${ uInter . name . join ( " " ) } ` : `${ uInter . name [ 0 ] } ` } " adlı interaksiyon için otomatik tamamlama çalıştırılırken bir hata ile karşılaşıldı!` )
388+ if ( err . message ) console . error ( `[HATA] ${ err . message } ` ) ;
389+ if ( err . stack ) {
390+ `${ err . stack } ` . split ( "\n" ) . forEach ( ( line ) => {
391+ console . error ( `[HATA] ${ line } ` ) ;
392+ } ) ;
393+ }
394+ }
336395 }
337396 return ;
338397 }
339398
340- let other = { } ;
341-
342399 {
343400 let locale_id = ( interaction . user . locale || interaction . locale ) ?. split ( "-" ) [ 0 ] ;
344401 other . locale = ( Underline . locales . get ( locale_id ) || Underline . locales . get ( Underline . config . defaultLanguage ) ) . data ;
@@ -384,9 +441,30 @@ client.on("interactionCreate", async (interaction) => {
384441 return ;
385442 }
386443
444+ if ( uInter . autoDefer != "off" ) {
445+ const newDefer = ( ) => {
446+ console . warn ( `[UYARI] "${ uInter . actionType == "CHAT_INPUT" ? `/${ uInter . name . join ( " " ) } ` : `${ uInter . name [ 0 ] } ` } " adlı interaksiyon için "deferReply" umursanmadı, interaksiyon zaten otomatik olarak bekleme moduna alınmış.` ) ;
447+ } ;
448+ if (
449+ interaction . isCommand ( ) || interaction . isApplicationCommand ( ) || interaction . isMessageContextMenu ( ) || interaction . isUserContextMenu ( )
450+ ) {
451+ await interaction . deferReply ( uInter . autoDefer == "ephemeral" ? { ephemeral : true } : null ) ;
452+ interaction . deferReply = newDefer ;
453+ interaction . reply = interaction . editReply ;
454+ } else if (
455+ interaction . isButton ( ) || interaction . isSelectMenu ( )
456+ ) {
457+ await utils . nullDefer ( interaction ) ;
458+ interaction . deferReply = newDefer ;
459+ interaction . reply = interaction . editReply = interaction . followUp = ( ) => {
460+ console . warn ( `[UYARI] "${ uInter . name [ 0 ] } " adlı interaksiyon için "reply" umursanmadı, interaksiyona zaten otomatik olarak boş cevap verilmiş.` ) ;
461+ } ;
462+ }
463+ }
464+
387465 if ( typeof uInter . coolDown == "number" ) uInter . coolDown = [ {
388466 type : "user" ,
389- amount : uInter . coolDown ,
467+ amount : uInter . coolDown
390468 } ] ;
391469 if ( typeof uInter . coolDown == "object" && ! Array . isArray ( uInter . coolDown ) ) uInter . coolDown = [ uInter . coolDown ] ;
392470
0 commit comments