2022-07-29 23:31:08 +05:00
const table = require ( "markdown-table" ) ,
fs = require ( "fs" ) ;
2022-08-30 14:26:56 +05:00
/ * *
*
2023-11-05 16:03:23 +05:00
* @ param { import ( "../base/Client" ) } client
2022-08-30 14:26:56 +05:00
* /
2022-07-26 17:20:10 +05:00
module . exports . update = function ( client ) {
2024-10-03 11:07:02 +05:00
const commands = [ ... new Map ( client . commands . map ( v => [ v . constructor . name , v ] ) ) . values ( ) ] ;
const categories = [ ] ;
2022-07-29 23:31:08 +05:00
2024-10-03 11:07:02 +05:00
// Collect unique command categories, ignoring the "Owner" category
2022-08-13 19:55:20 +05:00
commands . forEach ( cmd => {
2022-07-26 17:20:10 +05:00
if ( ! categories . includes ( cmd . category ) ) categories . push ( cmd . category ) ;
} ) ;
2022-07-29 23:31:08 +05:00
2024-10-03 11:07:02 +05:00
// Build the initial text for the documentation
let text = ` # JaBa has ** ${ commands . length } ${ client . functions . getNoun ( commands . length , "command" , "commands" , "commands" ) } ** in ** ${ categories . length } ${ client . functions . getNoun ( categories . length , "category" , "categories" , "categories" ) } **! \n \n ` +
"#### Table content \n" +
"**Name**: Command name \n" +
"**Description**: Command description \n" +
"**Usage**: How to use the command (*[]* - required, *()* - optional) \n" +
"**Accessible in**: Where you can use the command \n\n" ;
2022-07-29 23:31:08 +05:00
2024-10-03 11:07:02 +05:00
// Sort categories and generate command documentation for each category
2022-08-01 20:06:09 +05:00
categories . sort ( ) . forEach ( cat => {
2023-10-10 20:44:42 +05:00
const categoriesArray = [ [ "Name" , "Description" , "Usage" , "Accessible in" ] ] ;
2024-10-03 11:07:02 +05:00
const cmds = commands . filter ( cmd => cmd . category === cat ) ;
2022-07-26 19:46:32 +05:00
2023-10-10 20:44:42 +05:00
text += ` ### ${ cat } ( ${ cmds . length } ${ client . functions . getNoun ( cmds . length , "command" , "commands" , "commands" ) } ) \n \n ` ;
2024-10-03 11:07:02 +05:00
// Sort commands alphabetically by name
cmds . sort ( ( a , b ) => a . command . name . localeCompare ( b . command . name ) ) . forEach ( cmd => {
2022-07-26 17:20:10 +05:00
categoriesArray . push ( [
2024-02-06 21:45:53 +05:00
` ** ${ cmd . command . name } ** ` ,
2022-07-26 17:20:10 +05:00
client . translate ( ` ${ cmd . category . toLowerCase ( ) } / ${ cmd . command . name } :DESCRIPTION ` ) ,
2023-03-28 00:15:00 +05:00
` ${ cmd . command . name } ${ client . translate ( ` ${ cmd . category . toLowerCase ( ) } / ${ cmd . command . name } :USAGE ` ) . replace ( /\n/ , " \\| " ) } ` ,
2024-02-06 21:45:53 +05:00
cmd . command . dm _permission ? "Anywhere" : "Servers only" ,
2022-07-26 17:20:10 +05:00
] ) ;
2022-01-04 02:18:28 +05:00
} ) ;
2024-10-03 11:07:02 +05:00
// Append the generated table to the documentation text
2022-07-26 17:20:10 +05:00
text += ` ${ table ( categoriesArray ) } \n \n ` ;
} ) ;
2022-07-29 23:31:08 +05:00
2024-10-03 11:07:02 +05:00
// Ensure the output directory exists
const outputDir = "./dashboard/public/docs" ;
if ( ! fs . existsSync ( outputDir ) )
fs . mkdirSync ( outputDir , { recursive : true } ) ;
// Write the generated documentation to a Markdown file
fs . writeFileSync ( ` ${ outputDir } /commands.md ` , text ) ;
2024-02-06 21:45:53 +05:00
2022-07-26 17:20:10 +05:00
client . logger . log ( "Dashboard docs updated!" ) ;
2023-07-05 00:58:06 +05:00
} ;