stats
This commit is contained in:
parent
763a9b2dfc
commit
60b870d30e
3 changed files with 73 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { Client, Collection, Snowflake, Collector, Message, VoiceChannel, VoiceState } from 'discord.js';
|
import { Client, Collection, Snowflake, Collector, Message, VoiceChannel, VoiceState } from 'discord.js';
|
||||||
import { LyricsData, PlayerOptions, PlayerProgressbarOptions, QueueFilters } from './types/types';
|
import { LyricsData, PlayerOptions, PlayerProgressbarOptions, PlayerStats, QueueFilters } from './types/types';
|
||||||
import Util from './utils/Util';
|
import Util from './utils/Util';
|
||||||
import AudioFilters from './utils/AudioFilters';
|
import AudioFilters from './utils/AudioFilters';
|
||||||
import { Queue } from './Structures/Queue';
|
import { Queue } from './Structures/Queue';
|
||||||
|
@ -9,6 +9,7 @@ import { PlayerErrorEventCodes, PlayerEvents } from './utils/Constants';
|
||||||
import PlayerError from './utils/PlayerError';
|
import PlayerError from './utils/PlayerError';
|
||||||
import ytdl from 'discord-ytdl-core';
|
import ytdl from 'discord-ytdl-core';
|
||||||
import { ExtractorModel } from './Structures/ExtractorModel';
|
import { ExtractorModel } from './Structures/ExtractorModel';
|
||||||
|
import os from 'os';
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import spotify from 'spotify-url-info';
|
import spotify from 'spotify-url-info';
|
||||||
|
@ -887,6 +888,33 @@ export class Player extends EventEmitter {
|
||||||
queue.autoPlay = Boolean(enable);
|
queue.autoPlay = Boolean(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getStats(): PlayerStats {
|
||||||
|
return {
|
||||||
|
uptime: this.client.uptime,
|
||||||
|
connections: this.client.voice.connections.size,
|
||||||
|
users: this.client.voice.connections.reduce((a, c) => a + c.channel.members.size, 0),
|
||||||
|
queues: this.queues.size,
|
||||||
|
extractors: this.Extractors.size,
|
||||||
|
versions: {
|
||||||
|
ffmpeg: Util.getFFmpegVersion(),
|
||||||
|
node: process.version,
|
||||||
|
v8: process.versions.v8
|
||||||
|
},
|
||||||
|
system: {
|
||||||
|
arch: process.arch,
|
||||||
|
platform: process.platform,
|
||||||
|
cpu: os.cpus().length,
|
||||||
|
memory: {
|
||||||
|
total: (process.memoryUsage().heapTotal / 1024 / 1024).toFixed(2),
|
||||||
|
usage: (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2),
|
||||||
|
rss: (process.memoryUsage().rss / 1024 / 1024).toFixed(2),
|
||||||
|
arrayBuffers: (process.memoryUsage().arrayBuffers / 1024 / 1024).toFixed(2)
|
||||||
|
},
|
||||||
|
uptime: process.uptime()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private _handleVoiceStateUpdate(oldState: VoiceState, newState: VoiceState) {
|
private _handleVoiceStateUpdate(oldState: VoiceState, newState: VoiceState) {
|
||||||
const queue = this.queues.find((g) => g.guildID === oldState.guild.id);
|
const queue = this.queues.find((g) => g.guildID === oldState.guild.id);
|
||||||
if (!queue) return;
|
if (!queue) return;
|
||||||
|
|
|
@ -110,3 +110,38 @@ export interface LyricsData {
|
||||||
};
|
};
|
||||||
lyrics?: string;
|
lyrics?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PlayerStats {
|
||||||
|
uptime: number;
|
||||||
|
connections: number;
|
||||||
|
users: number;
|
||||||
|
queues: number;
|
||||||
|
extractors: number;
|
||||||
|
versions: {
|
||||||
|
ffmpeg: string;
|
||||||
|
node: string;
|
||||||
|
v8: string;
|
||||||
|
};
|
||||||
|
system: {
|
||||||
|
arch: string;
|
||||||
|
platform:
|
||||||
|
| 'aix'
|
||||||
|
| 'android'
|
||||||
|
| 'darwin'
|
||||||
|
| 'freebsd'
|
||||||
|
| 'linux'
|
||||||
|
| 'openbsd'
|
||||||
|
| 'sunos'
|
||||||
|
| 'win32'
|
||||||
|
| 'cygwin'
|
||||||
|
| 'netbsd';
|
||||||
|
cpu: number;
|
||||||
|
memory: {
|
||||||
|
total: string;
|
||||||
|
usage: string;
|
||||||
|
rss: string;
|
||||||
|
arrayBuffers: string;
|
||||||
|
};
|
||||||
|
uptime: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -31,16 +31,21 @@ export class Util {
|
||||||
} as PlayerOptions;
|
} as PlayerOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
static checkFFmpeg(force?: boolean) {
|
static getFFmpegVersion(force?: boolean) {
|
||||||
try {
|
try {
|
||||||
FFmpeg.getInfo(Boolean(force));
|
const info = FFmpeg.getInfo(Boolean(force));
|
||||||
|
|
||||||
return true;
|
return info.version;
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static checkFFmpeg(force?: boolean) {
|
||||||
|
const version = Util.getFFmpegVersion(force);
|
||||||
|
return version === null ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
static alertFFmpeg() {
|
static alertFFmpeg() {
|
||||||
const hasFFmpeg = Util.checkFFmpeg();
|
const hasFFmpeg = Util.checkFFmpeg();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue