import * as Glob from "glob" ; import { MetadataStorage , DiscordParams , DDiscord , DIService , } from "../.." ; param classType param target Discord function importCommand ( classType , target ) { DIService . instance . addService ( classType ) ; const ons = MetadataStorage . instance . events . filter ( ( on ) => { return on . classRef === classType ; } ) ; ons . map ( ( event ) => { event . from = target ; } ) ; } export function Discord ( ) ; export function Discord ( params ? ) { return ( target , key ) => { if ( params ?. import ) { let importCommands = params ?. import || [ ] ; if ( ! Array . isArray ( importCommands ) ) { importCommands = [ importCommands ] ; } importCommands . map ( ( cmd ) => { if ( typeof cmd === "string" ) { const files = Glob . sync ( cmd ) ; files . map ( ( file ) => { let classType ; const classImport = require ( file ) ; if ( classImport . default ) { classType = classImport . default ; } else { const key = Object . keys ( classImport ) [ 0 ] ; classType = classImport [ key ] ; } importCommand ( classType , target ) ; } ) ; } else { importCommand ( cmd , target ) ; } } ) ; } const instance = DDiscord . create ( target . name ) . decorate ( target , target . name ) ; MetadataStorage . instance . addDiscord ( instance ) ; } ; }