From f0a0c90304326c6e4737ee1d07d0520eecde01b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sat, 27 Apr 2024 23:18:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=AE=BE=E7=BD=AE=E8=87=AA=E8=BA=AB?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +- .../action/extends/SetOnlineStatus.ts | 29 +++++++++++++++++++ src/onebot11/action/index.ts | 2 ++ src/onebot11/action/types.ts | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/onebot11/action/extends/SetOnlineStatus.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f1a37a562..542d983b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,4 +7,5 @@ 7. 表情回应api和上报 8. 支持获取Cookies 实现更加稳定 API: /get_cookies 9. 新增wsHost和httpHost配置 -10. 新增获取官方Bot账号范围 API: /get_robot_uin_range \ No newline at end of file +10. 新增获取官方Bot账号范围 API: /get_robot_uin_range +11. 新增设置自身在线状态 API: /set_online_status \ No newline at end of file diff --git a/src/onebot11/action/extends/SetOnlineStatus.ts b/src/onebot11/action/extends/SetOnlineStatus.ts new file mode 100644 index 000000000..cea88a2c7 --- /dev/null +++ b/src/onebot11/action/extends/SetOnlineStatus.ts @@ -0,0 +1,29 @@ +import { OB11User } from '../../types'; +import { OB11Constructor } from '../../constructor'; +import { friends } from '../../../common/data'; +import BaseAction from '../BaseAction'; +import { ActionName } from '../types'; +import { NTQQUserApi } from '@/core/apis'; +// 设置在线状态 +interface Payload { + status: number; + extStatus: number; + batteryStatus: number; +} +export class SetOnlineStatus extends BaseAction { + actionName = ActionName.SetOnlineStatus; + + protected async _handle(payload: Payload) { + // 可设置状态 + // { status: 10, extStatus: 1027, batteryStatus: 0 } + // { status: 30, extStatus: 0, batteryStatus: 0 } + // { status: 50, extStatus: 0, batteryStatus: 0 } + // { status: 60, extStatus: 0, batteryStatus: 0 } + // { status: 70, extStatus: 0, batteryStatus: 0 } + let ret = await NTQQUserApi.setSelfOnlineStatus(payload.status, payload.extStatus, payload.batteryStatus); + if (ret.result !== 0) { + throw new Error("设置在线状态失败"); + } + return null; + } +} diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index 285d37f3e..7bcf595ae 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -48,6 +48,7 @@ import GetFriendMsgHistory from './go-cqhttp/GetFriendMsgHistory'; import { GetCookies } from './user/GetCookies'; import { SetMsgEmojiLike } from '@/onebot11/action/msg/SetMsgEmojiLike'; import { GetRobotUinRange } from './extends/GetRobotUinRange'; +import { SetOnlineStatus } from './extends/SetOnlineStatus'; export const actionHandlers = [ new GetFile(), @@ -86,6 +87,7 @@ export const actionHandlers = [ // new CleanCache(), new GetCookies(), // + new SetOnlineStatus(), new GetRobotUinRange(), //以下为go-cqhttp api new GoCQHTTPSendForwardMsg(), diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index f70594bce..7d70e4bb5 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -54,6 +54,7 @@ export enum ActionName { GetCookies = 'get_cookies', // 以下为扩展napcat扩展 GetRobotUinRange = 'get_robot_uin_range', + SetOnlineStatus = 'set_online_status', // 以下为go-cqhttp api GoCQHTTP_SendForwardMsg = 'send_forward_msg', GoCQHTTP_SendGroupForwardMsg = 'send_group_forward_msg',