补全一些onebot action实现 2 (#24)
* feat: implement get profile like * feat: implement get at all remain * feat: implement get undirectional friends * feat: implement set self long nick * feat: implement set input status * feat: implement EN 2 ZH * feat: implement get mini app ark * feat: implement click inline button * feat: implement set and send group sign * feat: implement set qq avatar * feat: group notice with pic and delete notice implement * fix(group-notice): POST api and fix new bkn logic
This commit is contained in:
1 parent
bec23c4dbb
commit
6f6ce1144b
8 files changed
+1022
-74
No files matched your search
@@ -239,16 +239,13 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and content are required');
|
||||
}
|
||||
|
||||
if (image) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented: image upload for group notice is not supported yet');
|
||||
}
|
||||
|
||||
if (!ctx.sendGroupNotice) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const options = {
|
||||
image: image || undefined,
|
||||
pinned: params.pinned !== undefined ? Number(params.pinned) : 0,
|
||||
type: params.type !== undefined ? Number(params.type) : 1,
|
||||
confirm_required: params.confirm_required !== undefined ? Number(params.confirm_required) : 1,
|
||||
@@ -277,8 +274,28 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('_del_group_notice', async () => {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
h.registerAction('_del_group_notice', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const fid = asString(params.fid) || asString(params.notice_id);
|
||||
|
||||
if (!groupId || !fid) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and fid/notice_id are required');
|
||||
}
|
||||
|
||||
if (!ctx.deleteGroupNotice) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const success = await ctx.deleteGroupNotice(groupId, fid);
|
||||
if (success) {
|
||||
return okResponse();
|
||||
} else {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'delete failed');
|
||||
}
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
});
|
||||
|
||||
// --- Forward messages ---
|
||||
@@ -605,12 +622,26 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
});
|
||||
|
||||
// todo 我的建议是引入数据库api 纯协议我不知道这种api怎么实现,ntQQ在实现这个方法的时候只进行了数据库查询,完全没碰网络
|
||||
h.registerAction('get_recent_contact', async () => {
|
||||
return okResponse([]);
|
||||
});
|
||||
|
||||
h.registerAction('get_profile_like', async () => {
|
||||
return okResponse({});
|
||||
h.registerAction('get_profile_like', async (params) => {
|
||||
const userId = asNumber(params.user_id);
|
||||
const start = asNumber(params.start) || 0;
|
||||
const count = asNumber(params.count) || 10;
|
||||
|
||||
if (!ctx.getProfileLike) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await ctx.getProfileLike(userId, start, count);
|
||||
return okResponse(data);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('get_friends_with_category', async () => {
|
||||
@@ -622,6 +653,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
// --- Additional NapCat-compatible stubs ---
|
||||
|
||||
///napcat 似乎也用不了??,暂时不管了
|
||||
h.registerAction('get_online_clients', async () => {
|
||||
return okResponse({ clients: [] });
|
||||
});
|
||||
@@ -638,16 +670,55 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
});
|
||||
|
||||
h.registerAction('get_group_at_all_remain', async () => {
|
||||
return okResponse({ can_at_all: false, remain_at_all_count_for_group: 0, remain_at_all_count_for_uin: 0 });
|
||||
h.registerAction('get_group_at_all_remain', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
|
||||
if (!groupId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'invalid group_id');
|
||||
}
|
||||
|
||||
if (!ctx.getGroupAtAllRemain) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await ctx.getGroupAtAllRemain(groupId);
|
||||
return okResponse(data);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('get_unidirectional_friend_list', async () => {
|
||||
return okResponse([]);
|
||||
if (!ctx.getUnidirectionalFriendList) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await ctx.getUnidirectionalFriendList();
|
||||
return okResponse(data);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('set_self_longnick', async () => {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
h.registerAction('set_self_longnick', async (params) => {
|
||||
const longNick = params.longNick || params.long_nick;
|
||||
|
||||
if (typeof longNick !== 'string') {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'invalid longNick');
|
||||
}
|
||||
|
||||
if (!ctx.setSelfLongNick) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
await ctx.setSelfLongNick(longNick);
|
||||
return okResponse({});
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('get_collection_list', async () => {
|
||||
@@ -658,16 +729,66 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
});
|
||||
|
||||
h.registerAction('set_qq_avatar', async () => {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
h.registerAction('set_qq_avatar', async (params) => {
|
||||
const file = asString(params.file);
|
||||
if (!file) return failedResponse(RETCODE.BAD_REQUEST, 'file is required');
|
||||
|
||||
if (!ctx.setAvatar) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
await ctx.setAvatar(file);
|
||||
return okResponse();
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('set_input_status', async () => {
|
||||
return okResponse();
|
||||
h.registerAction('set_input_status', async (params) => {
|
||||
const userId = asNumber(params.user_id);
|
||||
const eventType = asNumber(params.event_type);
|
||||
|
||||
if (!userId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'invalid user_id');
|
||||
}
|
||||
|
||||
// event_type 有可能是 0 (取消输入状态),所以这里严格判断 undefined 或 isNaN
|
||||
if (eventType === undefined || isNaN(eventType)) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'invalid event_type');
|
||||
}
|
||||
|
||||
if (!ctx.setInputStatus) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
await ctx.setInputStatus(userId, eventType);
|
||||
return okResponse({});
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('translate_en2zh', async () => {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
h.registerAction('translate_en2zh', async (params) => {
|
||||
const rawWords = params.words;
|
||||
|
||||
if (!Array.isArray(rawWords)) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'invalid words array');
|
||||
}
|
||||
|
||||
const words = rawWords.map(w => String(w));
|
||||
|
||||
if (!ctx.translateEn2Zh) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const translated = await ctx.translateEn2Zh(words);
|
||||
return okResponse({ words: translated });
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('get_clientkey', async () => {
|
||||
@@ -681,21 +802,81 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return okResponse(clientKeyInfo);
|
||||
});
|
||||
|
||||
h.registerAction('get_mini_app_ark', async () => {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
h.registerAction('get_mini_app_ark', async (params) => {
|
||||
const type = params.type || 'bili';
|
||||
const title = params.title || '';
|
||||
const desc = params.desc || '';
|
||||
const picUrl = params.picUrl || params.pic_url || '';
|
||||
const jumpUrl = params.jumpUrl || params.jump_url || '';
|
||||
|
||||
if (!ctx.getMiniAppArk) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await ctx.getMiniAppArk(
|
||||
String(type),
|
||||
String(title),
|
||||
String(desc),
|
||||
String(picUrl),
|
||||
String(jumpUrl)
|
||||
);
|
||||
return okResponse(data);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('click_inline_keyboard_button', async () => {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
h.registerAction('click_inline_keyboard_button', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const botAppid = asNumber(params.bot_appid);
|
||||
const buttonId = params.button_id;
|
||||
const callbackData = params.callback_data || '';
|
||||
const msgSeq = asNumber(params.msg_seq);
|
||||
|
||||
if (!groupId || !botAppid || !buttonId || !msgSeq) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'missing required parameters');
|
||||
}
|
||||
|
||||
if (!ctx.clickInlineKeyboardButton) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await ctx.clickInlineKeyboardButton(
|
||||
groupId,
|
||||
botAppid,
|
||||
String(buttonId),
|
||||
String(callbackData),
|
||||
msgSeq
|
||||
);
|
||||
return okResponse(data);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('set_group_sign', async () => {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
});
|
||||
const handleGroupSign = async (params: any) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
|
||||
h.registerAction('send_group_sign', async () => {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
});
|
||||
if (!groupId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'invalid group_id');
|
||||
}
|
||||
|
||||
if (!ctx.sendGroupSign) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
await ctx.sendGroupSign(groupId);
|
||||
return okResponse({});
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
};
|
||||
|
||||
h.registerAction('set_group_sign', handleGroupSign);
|
||||
h.registerAction('send_group_sign', handleGroupSign);
|
||||
|
||||
h.registerAction('get_group_info_ex', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
|
||||
@@ -55,6 +55,7 @@ export interface ApiActionContext {
|
||||
setGroupName?: (groupId: number, name: string) => Promise<void>;
|
||||
setGroupLeave?: (groupId: number) => Promise<void>;
|
||||
setGroupSpecialTitle?: (groupId: number, userId: number, title: string) => Promise<void>;
|
||||
getGroupAtAllRemain?: (groupId: number) => Promise<any>;
|
||||
// Group file
|
||||
uploadGroupFile?: (groupId: number, file: string, name?: string, folderId?: string, uploadFile?: boolean) => Promise<string | null>;
|
||||
uploadPrivateFile?: (userId: number, file: string, name?: string, uploadFile?: boolean) => Promise<string | null>;
|
||||
@@ -78,6 +79,13 @@ export interface ApiActionContext {
|
||||
forceFetchClientKey? : () => Promise<{clientKey: string, keyIndex: string, expireTime: string}>;
|
||||
setOnlineStatus?: (status: number, extStatus?: number, batteryStatus?: number) => Promise<void>;
|
||||
setProfile?: (nickname?: string, personalNote?: string) => Promise<void>;
|
||||
getUnidirectionalFriendList?: () => Promise<any>;
|
||||
setSelfLongNick?: (longNick: string) => Promise<void>;
|
||||
setInputStatus?: (userId: number, eventType: number) => Promise<void>;
|
||||
translateEn2Zh?: (words: string[]) => Promise<string[]>;
|
||||
getMiniAppArk?: (type: string, title: string, desc: string, picUrl: string, jumpUrl: string) => Promise<any>;
|
||||
clickInlineKeyboardButton?: (groupId: number, botAppid: number, buttonId: string, callbackData: string, msgSeq: number) => Promise<any>;
|
||||
sendGroupSign?: (groupId: number) => Promise<void>;
|
||||
// New context methods
|
||||
setGroupReaction?: (groupId: number, sequence: number, code: string, isSet: boolean) => Promise<void>;
|
||||
handleDeleteFriend?: (userId: number, block?: boolean) => Promise<void>;
|
||||
@@ -96,18 +104,22 @@ export interface ApiActionContext {
|
||||
setMsgEmojiLike?: (messageId: number, emojiId: string, set: boolean) => Promise<void>;
|
||||
markGroupMsgAsRead?: (groupId: number, sequence: number) => Promise<void>;
|
||||
markPrivateMsgAsRead?: (userId: number, sequence: number) => Promise<void>;
|
||||
getProfileLike?: (userId?: number, start?: number, limit?: number) => Promise<any>;
|
||||
// Web
|
||||
getGroupHonorInfo?: (groupId: number, type: WebHonorType | string) => Promise<any>;
|
||||
getGroupEssence?: (groupId: number, pageStart?: number, pageLimit?: number) => Promise<GroupEssenceMsgRet>;
|
||||
getGroupEssenceAll?: (groupId: number) => Promise<GroupEssenceMsgRet[]>;
|
||||
sendGroupNotice?: (groupId: number, content: string, options?: any) => Promise<any>;
|
||||
getGroupNotice?: (groupId: number) => Promise<any[]>;
|
||||
deleteGroupNotice?: (groupId: number, fid: string) => Promise<boolean>;
|
||||
getCookiesStr?: (domain: string) => Promise<string>;
|
||||
getCsrfToken?: () => Promise<number>;
|
||||
getCredentials?: (domain: string) => Promise<{ cookies: string; token: number; csrf_token: number }>;
|
||||
// Media lookup (populated from previously dispatched message segments)
|
||||
getImageInfo?: (file: string) => Promise<JsonObject | null>;
|
||||
getRecordInfo?: (file: string) => Promise<JsonObject | null>;
|
||||
// Avatar
|
||||
setAvatar?: (source: string) => Promise<void>;
|
||||
}
|
||||
|
||||
type ActionHandler = (params: JsonObject) => Promise<import('./types').ApiResponse>;
|
||||
|
||||
@@ -79,6 +79,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
setGroupName: (groupId, name) => bridge.setGroupName(groupId, name),
|
||||
setGroupLeave: (groupId) => bridge.leaveGroup(groupId),
|
||||
setGroupSpecialTitle: (groupId, userId, title) => bridge.setGroupSpecialTitle(groupId, userId, title),
|
||||
getGroupAtAllRemain: (groupId) => bridge.getGroupAtAllRemain(groupId),
|
||||
// Group file
|
||||
uploadGroupFile: async (groupId, file, name, folderId, uploadFile) => {
|
||||
const result = await bridge.uploadGroupFile(groupId, file, name ?? '', folderId ?? '/', uploadFile ?? true);
|
||||
@@ -105,6 +106,14 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
sendGroupPoke: (groupId, userId) => bridge.sendPoke(true, groupId, userId),
|
||||
setEssenceMsg: (messageId) => handleSetEssence(bridge, messageStore, messageId, true),
|
||||
deleteEssenceMsg: (messageId) => handleSetEssence(bridge, messageStore, messageId, false),
|
||||
getProfileLike: (userId?: number, start: number = 0, limit: number = 10) => bridge.getProfileLike(userId, start, limit),
|
||||
getUnidirectionalFriendList: () => bridge.getUnidirectionalFriendList(),
|
||||
setSelfLongNick: (longNick) => bridge.setSelfLongNick(longNick),
|
||||
setInputStatus: (userId, eventType) => bridge.setInputStatus(userId, eventType),
|
||||
translateEn2Zh: (words) => bridge.translateEn2Zh(words),
|
||||
getMiniAppArk: (type, title, desc, picUrl, jumpUrl) => bridge.getMiniAppArk(type, title, desc, picUrl, jumpUrl),
|
||||
clickInlineKeyboardButton: (groupId, botAppid, buttonId, callbackData, msgSeq) => bridge.clickInlineKeyboardButton(groupId, botAppid, buttonId, callbackData, msgSeq),
|
||||
sendGroupSign: (groupId) => bridge.sendGroupSign(groupId),
|
||||
// New extended
|
||||
setGroupReaction: (groupId, sequence, code, isSet) => bridge.setGroupReaction(groupId, sequence, code, isSet),
|
||||
handleDeleteFriend: (userId, block) => bridge.deleteFriend(userId, !!block),
|
||||
@@ -161,12 +170,15 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
getGroupEssenceAll: (groupId: number) => bridge.getGroupEssenceAll(groupId),
|
||||
sendGroupNotice: (groupId: number, content: string, options?: any) => bridge.sendGroupNotice(groupId, content, options),
|
||||
getGroupNotice: (groupId: number) => bridge.getGroupNotice(groupId),
|
||||
deleteGroupNotice: (groupId: number, fid: string) => bridge.deleteGroupNotice(groupId, fid),
|
||||
getCookiesStr: (domain: string) => bridge.getCookiesStr(domain),
|
||||
getCsrfToken: () => bridge.getCsrfToken(),
|
||||
getCredentials: (domain: string) => bridge.getCredentials(domain),
|
||||
// Media lookup
|
||||
getImageInfo: (file) => handleGetImageInfo(mediaStore, file),
|
||||
getRecordInfo: (file) => handleGetRecordInfo(bridge, mediaStore, file),
|
||||
// Avatar
|
||||
setAvatar: (source: string) => bridge.setAvatar(source),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user