2022-07-29 23:31:08 +05:00
const table = require ( "markdown-table" ) ,
fs = require ( "fs" ) ;
2022-08-30 14:26:56 +05:00
/ * *
*
* @ param { import ( "../base/JaBa" ) } client
* /
2022-07-26 17:20:10 +05:00
module . exports . update = function ( client ) {
2022-07-29 23:31:08 +05:00
const commands = [ ... new Map ( client . commands . map ( v => [ v . constructor . name , v ] ) ) . values ( ) ] ,
2022-07-26 19:46:32 +05:00
categories = [ ] ;
2022-07-29 23:31:08 +05:00
2022-08-13 19:55:20 +05:00
commands . forEach ( cmd => {
if ( cmd . category === "Owner" ) return ;
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
2022-07-26 19:46:32 +05:00
let text = ` # JaBa имеет ** ${ commands . length } ${ client . getNoun ( commands . length , "команда" , "команды" , "команд" ) } ** в ** ${ categories . length } ${ client . getNoun ( categories . length , "категории" , "категориях" , "категориях" ) } **! \n \n #### Содержимое таблицы \n **Название**: Название команды \n **Описание**: Описание команды \n **Использование**: Использование команды ( [] - обязательно, () - необязательно ) \n **Разрешено использование**: Где можно использовать команду \n \n ` ;
2022-07-29 23:31:08 +05:00
2022-07-26 17:20:10 +05:00
// categories.sort(function(a, b) {
2023-02-01 00:23:01 +05:00
// const aCmdsSize = commands.filter(cmd => cmd.category === a).size;
// const bCmdsSize = commands.filter(cmd => cmd.category === b).size;
2022-07-26 17:20:10 +05:00
// if (aCmdsSize > bCmdsSize) return -1;
// else return 1;
// })
2022-07-29 23:31:08 +05:00
2022-08-01 20:06:09 +05:00
categories . sort ( ) . forEach ( cat => {
2022-07-26 17:20:10 +05:00
const categoriesArray = [
2022-12-15 21:02:38 +05:00
[ "Название" , "Описание" , "Использование" , "Разрешено использование" ] ,
2022-07-26 17:20:10 +05:00
] ;
2022-08-01 20:06:09 +05:00
const cmds = [ ... new Map ( commands . filter ( cmd => cmd . category === cat ) . map ( v => [ v . constructor . name , v ] ) ) . values ( ) ] ;
2022-07-26 19:46:32 +05:00
text += ` ### ${ cat } ( ${ cmds . length } ${ client . getNoun ( cmds . length , "команда" , "команды" , "команд" ) } ) \n \n ` ;
2022-07-26 17:20:10 +05:00
cmds . sort ( function ( a , b ) {
if ( a . command . name < b . command . name ) return - 1 ;
else return 1 ;
2022-08-13 19:55:20 +05:00
} ) . forEach ( cmd => {
2022-07-26 17:20:10 +05:00
categoriesArray . push ( [
` ** ${ cmd . command . name } ** ${ cmd . aliases . length ? ` **( ${ cmd . aliases . join ( ", " ) } )** ` : "" } ` ,
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/ , " \\| " ) } ` ,
2022-12-15 21:02:38 +05:00
cmd . guildOnly ? "Только на сервере" : "Н а сервере и в ЛС бота" ,
2022-07-26 17:20:10 +05:00
] ) ;
2022-01-04 02:18:28 +05:00
} ) ;
2022-07-26 17:20:10 +05:00
text += ` ${ table ( categoriesArray ) } \n \n ` ;
} ) ;
2022-07-29 23:31:08 +05:00
2022-07-26 17:20:10 +05:00
if ( ! fs . existsSync ( "./dashboard/public/docs" ) ) fs . mkdirSync ( "./dashboard/public/docs" ) ;
fs . writeFileSync ( "./dashboard/public/docs/commands.md" , text ) ;
client . logger . log ( "Dashboard docs updated!" ) ;
2022-01-04 02:18:28 +05:00
} ;