Skip to content

Commit

Permalink
feat:设置自身在线状态
Browse files Browse the repository at this point in the history
  • Loading branch information
MliKiowa committed Apr 27, 2024
1 parent cd6c32b commit f0a0c90
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
7. 表情回应api和上报
8. 支持获取Cookies 实现更加稳定 API: /get_cookies
9. 新增wsHost和httpHost配置
10. 新增获取官方Bot账号范围 API: /get_robot_uin_range
10. 新增获取官方Bot账号范围 API: /get_robot_uin_range
11. 新增设置自身在线状态 API: /set_online_status
29 changes: 29 additions & 0 deletions src/onebot11/action/extends/SetOnlineStatus.ts
Original file line number Diff line number Diff line change
@@ -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<Payload, null> {
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;
}
}
2 changes: 2 additions & 0 deletions src/onebot11/action/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -86,6 +87,7 @@ export const actionHandlers = [
// new CleanCache(),
new GetCookies(),
//
new SetOnlineStatus(),
new GetRobotUinRange(),
//以下为go-cqhttp api
new GoCQHTTPSendForwardMsg(),
Expand Down
1 change: 1 addition & 0 deletions src/onebot11/action/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f0a0c90

Please sign in to comment.