onebot: clean up comments, imports and whitespace

Remove extraneous comments, redundant explanatory notes and extra blank lines across onebot packages; reorder and normalize import lists in group-admin and group-album; remove unused comment blocks in event-converter. These are non-functional cleanup changes in packages/onebot/src/actions/extended.ts, packages/onebot/src/actions/group-admin.ts, packages/onebot/src/actions/group-album.ts and packages/onebot/src/event-converter/index.ts to improve readability and maintain consistent style.
This commit is contained in:
手瓜一十雪 committed 2026-05-24 13:08:24 +08:00
1 parent 245405d294
commit a52a9724cb
33 files changed
+213 -705

No files matched your search

-12
View File
@@ -635,7 +635,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
});
h.registerAction('set_online_status', async (params) => {
// 按 OneBot/NapCat 习惯提取参数,状态码默认为 11
const status = asNumber(params.status);
const extStatus = asNumber(params.ext_status) || 0;
const batteryStatus = asNumber(params.battery_status) || 100;
@@ -838,8 +837,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
if (!groupId) {
return failedResponse(RETCODE.BAD_REQUEST, 'invalid group_id');
}
try {
const data = await ctx.bridge.apis.groupAdmin.getAtAllRemain(groupId);
return okResponse(data);
@@ -864,8 +861,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
if (typeof longNick !== 'string') {
return failedResponse(RETCODE.BAD_REQUEST, 'invalid longNick');
}
try {
await ctx.bridge.apis.profile.setSelfLongNick(longNick);
return okResponse({});
@@ -908,7 +903,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
return failedResponse(RETCODE.BAD_REQUEST, 'invalid event_type');
}
try {
await ctx.bridge.apis.profile.setInputStatus(userId, eventType);
return okResponse({});
@@ -1042,9 +1036,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
});
// 原始数据包逃生口(兼容 NapCat)。
// NapCat 暴露了两个名称:带点前缀的是 gocqhttp 时代的原始后门,不带前缀的是现代接口。
// 它们在 SnowLuma 中执行相同逻辑:十六进制编码 → Bridge.sendRawPacket → 十六进制编码。
const handleSendPacket = async (params: JsonObject) => {
const cmd = asString(params.cmd);
const dataHex = asString(params.data);
@@ -1070,14 +1061,11 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
h.registerAction('.send_packet', handleSendPacket);
// 机器人生命周期(兼容 NapCat)。
h.registerAction('bot_exit', async () => {
setTimeout(() => process.exit(0), 50);
return okResponse();
});
// SnowLuma 没有独立的数据包后端进程。
// NapCat 的数据包服务在进程外运行,可能独立失败;这里始终报告健康。
h.registerAction('nc_get_packet_status', async () => {
return okResponse(null);
});
+3 -7
View File
@@ -1,5 +1,5 @@
import type { ApiHandler, ApiActionContext } from '../api-handler';
import { asNumber, asString, asBoolean } from '../api-handler';
import type { ApiActionContext, ApiHandler } from '../api-handler';
import { asBoolean, asNumber, asString } from '../api-handler';
import { RETCODE, failedResponse, okResponse } from '../types';
export function register(h: ApiHandler, ctx: ApiActionContext): void {
@@ -103,10 +103,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
return okResponse();
});
// Highway upload with cmdId 3000 + GroupAvatarExtra (Lagrange protocol).
// `file` accepts everything bridge.setGroupAvatar's underlying
// loadBinarySource handles: local paths, file:// URLs, http(s) URLs,
// and base64:// data URIs — same surface as set_qq_avatar.
h.registerAction('set_group_portrait', async (params) => {
const groupId = asNumber(params.group_id);
const file = asString(params.file);
@@ -119,4 +115,4 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
}
});
}
}
+2 -9
View File
@@ -1,7 +1,7 @@
import type { ApiHandler, ApiActionContext } from '../api-handler';
import type { ApiActionContext, ApiHandler } from '../api-handler';
import { asNumber, asString } from '../api-handler';
import { RETCODE, failedResponse, okResponse } from '../types';
import type { JsonValue } from '../types';
import { RETCODE, failedResponse, okResponse } from '../types';
export function register(h: ApiHandler, ctx: ApiActionContext): void {
h.registerAction('get_group_album_list', async (params) => {
@@ -47,9 +47,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
try {
const mediaList = await ctx.bridge.apis.groupAlbum.getMediaList(groupId, albumId, attachInfo);
// GroupAlbumMediaResult is a concrete domain type; okResponse
// expects JsonValue. The shape is JSON-compatible — same as the
// old ctx wrapper returning `Promise<any>`.
return okResponse(mediaList as unknown as JsonValue);
} catch (error) {
const message = error instanceof Error ? error.message : 'failed to get group album media list';
@@ -70,10 +67,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
try {
const comment = await ctx.bridge.apis.groupAlbum.comment(groupId, albumId, lloc, content);
// GroupAlbumCommentResult is a concrete domain type; okResponse
// expects JsonValue. The shape is JSON-compatible (no functions
// / classes / bigints), so cast is safe — same as the old ctx
// wrapper returning `Promise<any>`.
return okResponse(comment as unknown as JsonValue);
} catch (error) {
const message = error instanceof Error ? error.message : 'failed to comment on album media';