mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-11 15:57:50 +02:00
trimArray util function
This commit is contained in:
+3
-12
@@ -1,6 +1,7 @@
|
|||||||
const { Command } = require('discord.js-commando');
|
const { Command } = require('discord.js-commando');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
const snekfetch = require('snekfetch');
|
const snekfetch = require('snekfetch');
|
||||||
|
const { trimArray } = require('../../util/Util');
|
||||||
|
|
||||||
module.exports = class NPMCommand extends Command {
|
module.exports = class NPMCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -26,18 +27,8 @@ module.exports = class NPMCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
const { body } = await snekfetch.get(`https://registry.npmjs.com/${query}`);
|
const { body } = await snekfetch.get(`https://registry.npmjs.com/${query}`);
|
||||||
const version = body.versions[body['dist-tags'].latest];
|
const version = body.versions[body['dist-tags'].latest];
|
||||||
let maintainers = body.maintainers.map(user => user.name);
|
const maintainers = trimArray(body.maintainers.map(user => user.name));
|
||||||
if (maintainers.length > 10) {
|
const dependencies = version.dependencies ? trimArray(Object.keys(version.dependencies)) : null;
|
||||||
const len = maintainers.length - 10;
|
|
||||||
maintainers = maintainers.slice(0, 10);
|
|
||||||
maintainers.push(`...${len} more.`);
|
|
||||||
}
|
|
||||||
let dependencies = version.dependencies ? Object.keys(version.dependencies) : null;
|
|
||||||
if (dependencies && dependencies.length > 10) {
|
|
||||||
const len = dependencies.length - 10;
|
|
||||||
dependencies = dependencies.slice(0, 10);
|
|
||||||
dependencies.push(`...${len} more.`);
|
|
||||||
}
|
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setColor(0xCB0000)
|
.setColor(0xCB0000)
|
||||||
.setAuthor('NPM', 'https://i.imgur.com/ErKf5Y0.png')
|
.setAuthor('NPM', 'https://i.imgur.com/ErKf5Y0.png')
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiaobot",
|
"name": "xiaobot",
|
||||||
"version": "51.4.0",
|
"version": "51.4.1",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "XiaoBot.js",
|
"main": "XiaoBot.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -52,6 +52,15 @@ class Util {
|
|||||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static trimArray(arr, maxLen = 10) {
|
||||||
|
if (arr.length > maxLen) {
|
||||||
|
const len = arr.length - maxLen;
|
||||||
|
arr = arr.slice(0, maxLen);
|
||||||
|
arr.push(`${len} more...`);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
static promisifyAll(obj, suffix = 'Async') {
|
static promisifyAll(obj, suffix = 'Async') {
|
||||||
for (const key of Object.keys(obj)) {
|
for (const key of Object.keys(obj)) {
|
||||||
if (typeof obj[key] !== 'function') continue;
|
if (typeof obj[key] !== 'function') continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user