mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 10:02:05 +02:00
sortByName Util Function
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
const Command = require('../../structures/Command');
|
const Command = require('../../structures/Command');
|
||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
|
const { sortByName } = require('../../util/Util');
|
||||||
|
|
||||||
module.exports = class GenerateCreditCommand extends Command {
|
module.exports = class GenerateCreditCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -24,8 +25,8 @@ module.exports = class GenerateCreditCommand extends Command {
|
|||||||
|
|
||||||
async run(msg) {
|
async run(msg) {
|
||||||
let credit = [];
|
let credit = [];
|
||||||
const commands = this.client.registry.commands.filter(cmd => cmd.credit && cmd.credit.length > 1);
|
for (const command of this.client.registry.commands.values()) {
|
||||||
for (const command of commands.values()) {
|
if (!command.credit || command.credit.length <= 1) continue;
|
||||||
for (const cred of command.credit) {
|
for (const cred of command.credit) {
|
||||||
const found = credit.find(c => c.name === cred.name);
|
const found = credit.find(c => c.name === cred.name);
|
||||||
if (found) {
|
if (found) {
|
||||||
@@ -48,9 +49,9 @@ module.exports = class GenerateCreditCommand extends Command {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
credit = credit.sort((a, b) => a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1);
|
credit = sortByName(credit, 'name');
|
||||||
const mapped = credit
|
const mapped = credit
|
||||||
.map(c => `- [${c.name}](${c.url})\n${c.commands.map(cmd => {
|
.map(c => `- [${c.name}](${c.url})\n${sortByName(c.commands, 'name').map(cmd => {
|
||||||
if (!cmd.reasonURL) return ` * ${cmd.name} (${cmd.reason})`;
|
if (!cmd.reasonURL) return ` * ${cmd.name} (${cmd.reason})`;
|
||||||
return ` * ${cmd.name} ([${cmd.reason}](${cmd.reasonURL}))`;
|
return ` * ${cmd.name} ([${cmd.reason}](${cmd.reasonURL}))`;
|
||||||
}).join('\n')}`);
|
}).join('\n')}`);
|
||||||
|
|||||||
@@ -50,6 +50,13 @@ module.exports = class Util {
|
|||||||
return newArr;
|
return newArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static sortByName(arr, prop) {
|
||||||
|
return arr.sort((a, b) => {
|
||||||
|
if (prop) return a[prop].toLowerCase() > b[prop].toLowerCase() ? 1 : -1;
|
||||||
|
return a.toLowerCase() > b.toLowerCase() ? 1 : -1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static firstUpperCase(text, split = ' ') {
|
static firstUpperCase(text, split = ' ') {
|
||||||
return text.split(split).map(word => `${word.charAt(0).toUpperCase()}${word.slice(1)}`).join(' ');
|
return text.split(split).map(word => `${word.charAt(0).toUpperCase()}${word.slice(1)}`).join(' ');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user