diff --git a/packages/adapter-cqhttp/src/api.ts b/packages/adapter-cqhttp/src/api.ts index cc62e7ed5d..2d125afebc 100644 --- a/packages/adapter-cqhttp/src/api.ts +++ b/packages/adapter-cqhttp/src/api.ts @@ -1,5 +1,5 @@ import { camelCase, Logger, snakeCase, capitalize } from 'koishi-utils' -import { Bot, AccountInfo, SenderInfo, StatusInfo, StrangerInfo, BotStatus } from 'koishi-core' +import { Bot, AccountInfo, SenderInfo, StatusInfo, StrangerInfo, BotStatusCode } from 'koishi-core' const logger = new Logger('bot') @@ -248,13 +248,13 @@ Bot.prototype.getSelfId = async function getSelfId(this: Bot) { return userId } -Bot.prototype.getStatus = async function getStatus(this: Bot) { - if (!this.ready) return BotStatus.BOT_IDLE +Bot.prototype.getStatusCode = async function getStatusCode(this: Bot) { + if (!this.ready) return BotStatusCode.BOT_IDLE try { const data = await this.get('get_status') - return data.good ? BotStatus.GOOD : data.online ? BotStatus.SERVER_ERROR : BotStatus.BOT_OFFLINE + return data.good ? BotStatusCode.GOOD : data.online ? BotStatusCode.SERVER_ERROR : BotStatusCode.BOT_OFFLINE } catch { - return BotStatus.NET_ERROR + return BotStatusCode.NET_ERROR } } diff --git a/packages/koishi-core/src/server.ts b/packages/koishi-core/src/server.ts index 97798412d8..22b9590873 100644 --- a/packages/koishi-core/src/server.ts +++ b/packages/koishi-core/src/server.ts @@ -95,7 +95,7 @@ export abstract class Server { } } -export enum BotStatus { +export enum BotStatusCode { /** 正常运行 */ GOOD, /** Bot 处于闲置状态 */ @@ -112,7 +112,7 @@ export interface Bot extends BotOptions { ready?: boolean version?: string getSelfId(): Promise - getStatus(): Promise + getStatusCode(): Promise getMemberMap(groupId: number): Promise> sendGroupMsg(groupId: number, message: string, autoEscape?: boolean): Promise sendPrivateMsg(userId: number, message: string, autoEscape?: boolean): Promise diff --git a/packages/plugin-status/src/index.ts b/packages/plugin-status/src/index.ts index f16c56a82b..6c4a17a6f8 100644 --- a/packages/plugin-status/src/index.ts +++ b/packages/plugin-status/src/index.ts @@ -1,4 +1,4 @@ -import { Context, App } from 'koishi-core' +import { Context, App, BotStatusCode } from 'koishi-core' import { cpus, totalmem, freemem } from 'os' import { ActiveData } from './database' @@ -71,7 +71,7 @@ export interface Status extends ActiveData { export interface BotStatus { label?: string selfId: number - code: number + code: BotStatusCode rate?: number } @@ -140,9 +140,11 @@ export function apply(ctx: Context, config: Config) { .action(async () => { const { bots: apps, cpu, memory, startTime, activeUsers, activeGroups } = await getStatus(config) - const output = apps.map(({ label, selfId, code, rate }) => { - return `${label || selfId}:${code ? '无法连接' : `工作中(${rate}/min)`}` - }) + const output = apps + .filter(bot => bot.code !== BotStatusCode.BOT_IDLE) + .map(({ label, selfId, code, rate }) => { + return `${label || selfId}:${code ? '无法连接' : `工作中(${rate}/min)`}` + }) output.push('==========') @@ -163,7 +165,7 @@ export function apply(ctx: Context, config: Config) { Promise.all(app.bots.map(async (bot): Promise => ({ selfId: bot.selfId, label: bot.label, - code: await bot.getStatus(), + code: await bot.getStatusCode(), rate: bot.counter.slice(1).reduce((prev, curr) => prev + curr, 0), }))), ])