Compare commits

..

14 Commits

Author SHA1 Message Date
idranme
85001a40da Merge pull request #366 from LLOneBot/dev
3.30.4
2024-08-23 17:05:03 +08:00
idranme
867a05c85a chore: v3.30.4 2024-08-23 17:03:58 +08:00
idranme
d8a63f6561 fix 2024-08-23 17:02:31 +08:00
idranme
e9fb9d1b30 Update publish.yml 2024-08-23 16:08:59 +08:00
idranme
b4fc987537 Merge pull request #365 from LLOneBot/dev
3.30.3
2024-08-23 13:40:59 +08:00
idranme
d0ccf53d88 chore: v3.30.3 2024-08-23 13:39:26 +08:00
idranme
d5ca94569d fix 2024-08-23 13:32:58 +08:00
idranme
bf72685501 Merge pull request #363 from LLOneBot/dev
3.30.2
2024-08-23 00:30:48 +08:00
idranme
c07467b670 chore: v3.30.2 2024-08-23 00:08:52 +08:00
idranme
ea164fb048 fix: friend list 2024-08-22 23:47:15 +08:00
idranme
0c0ad9a616 Merge pull request #362 from LLOneBot/dev
3.30.1
2024-08-22 20:41:32 +08:00
idranme
7bb4808e2d chore: v3.30.1 2024-08-22 20:18:16 +08:00
idranme
3f7592d06d opt 2024-08-22 20:17:28 +08:00
idranme
2f341fcf43 fix 2024-08-22 18:16:08 +08:00
13 changed files with 92 additions and 71 deletions

View File

@@ -14,7 +14,7 @@ jobs:
- name: setup node
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
- name: install dependenies
run: |

View File

@@ -4,7 +4,7 @@
"name": "LLOneBot",
"slug": "LLOneBot",
"description": "实现 OneBot 11 协议,用于 QQ 机器人开发",
"version": "3.30.0",
"version": "3.30.4",
"icon": "./icon.webp",
"authors": [
{

View File

@@ -5,6 +5,7 @@ import { getSession } from '@/ntqqapi/wrapper'
import { BuddyListReqType, NodeIKernelProfileService } from '../services'
import { NTEventDispatch } from '@/common/utils/EventTask'
import { LimitedHashTable } from '@/common/utils/table'
import { pick } from 'cosmokit'
export class NTQQFriendApi {
/** 大于或等于 26702 应使用 getBuddyV2 */
@@ -73,7 +74,7 @@ export class NTQQFriendApi {
} else {
const data = await invoke<{
buddyCategory: CategoryFriend[]
userSimpleInfos: Map<string, SimpleInfo>
userSimpleInfos: Record<string, SimpleInfo>
}>({
className: NTClass.NODE_STORE_API,
methodName: 'getBuddyList',
@@ -81,7 +82,11 @@ export class NTQQFriendApi {
cbCmd: ReceiveCmdS.FRIENDS,
afterFirstCmd: false,
})
return Array.from(data.userSimpleInfos.values())
const categoryUids: Map<number, string[]> = new Map()
for (const item of data.buddyCategory) {
categoryUids.set(item.categoryId, item.buddyUids)
}
return Object.values(data.userSimpleInfos).filter(v => v.baseInfo && categoryUids.get(v.baseInfo.categoryId)?.includes(v.uid!))
}
}
@@ -102,7 +107,7 @@ export class NTQQFriendApi {
} else {
const data = await invoke<{
buddyCategory: CategoryFriend[]
userSimpleInfos: Map<string, SimpleInfo>
userSimpleInfos: Record<string, SimpleInfo>
}>({
className: NTClass.NODE_STORE_API,
methodName: 'getBuddyList',
@@ -110,9 +115,9 @@ export class NTQQFriendApi {
cbCmd: ReceiveCmdS.FRIENDS,
afterFirstCmd: false,
})
data.userSimpleInfos.forEach((value, key) => {
retMap.set(value.uin!, value.uid!)
})
for (const item of Object.values(data.userSimpleInfos)) {
retMap.set(item.uin!, item.uid!)
}
}
return retMap
}
@@ -141,7 +146,7 @@ export class NTQQFriendApi {
} else {
const data = await invoke<{
buddyCategory: CategoryFriend[]
userSimpleInfos: Map<string, SimpleInfo>
userSimpleInfos: Record<string, SimpleInfo>
}>({
className: NTClass.NODE_STORE_API,
methodName: 'getBuddyList',
@@ -149,16 +154,19 @@ export class NTQQFriendApi {
cbCmd: ReceiveCmdS.FRIENDS,
afterFirstCmd: false,
})
return Array.from(data.userSimpleInfos).map(([key, value]) => {
if (value.baseInfo) {
const category: Map<number, Pick<CategoryFriend, 'buddyUids' | 'categroyName'>> = new Map()
for (const item of data.buddyCategory) {
category.set(item.categoryId, pick(item, ['buddyUids', 'categroyName']))
}
return Object.values(data.userSimpleInfos)
.filter(v => v.baseInfo && category.get(v.baseInfo.categoryId)?.buddyUids.includes(v.uid!))
.map(value => {
return {
...value,
categoryId: value.baseInfo.categoryId,
categroyName: data.buddyCategory.find(e => e.categoryId === value.baseInfo.categoryId)?.categroyName
categroyName: category.get(value.baseInfo.categoryId)?.categroyName
}
}
return value
})
})
}
}

View File

@@ -98,6 +98,10 @@ export class NTQQGroupApi {
)
return notifies
} else {
invoke({
methodName: ReceiveCmdS.GROUP_NOTIFY,
classNameIsRegister: true,
})
return (await invoke<GroupNotifies>({
methodName: NTMethod.GET_GROUP_NOTICE,
cbCmd: ReceiveCmdS.GROUP_NOTIFY,

View File

@@ -1,5 +1,5 @@
import { invoke, NTMethod } from '../ntcall'
import { GeneralCallResult } from '../services'
import { GeneralCallResult, TmpChatInfoApi } from '../services'
import { RawMessage, SendMessageElement, Peer, ChatType2 } from '../types'
import { getSelfNick, getSelfUid } from '../../common/data'
import { getSession } from '@/ntqqapi/wrapper'
@@ -16,10 +16,22 @@ function generateMsgId() {
}
export class NTQQMsgApi {
/** 27187 TODO */
static async getTempChatInfo(chatType: ChatType2, peerUid: string) {
const session = getSession()
return session?.getMsgService().getTempChatInfo(chatType, peerUid)
if (session) {
return session.getMsgService().getTempChatInfo(chatType, peerUid)
} else {
return await invoke<TmpChatInfoApi>({
methodName: 'nodeIKernelMsgService/getTempChatInfo',
args: [
{
chatType,
peerUid,
},
null,
],
})
}
}
static async setEmojiLike(peer: Peer, msgSeq: string, emojiId: string, set: boolean = true) {

View File

@@ -5,7 +5,7 @@ import { friends, groupMembers, getSelfUin } from '@/common/data'
import { CacheClassFuncAsync, getBuildVersion } from '@/common/utils'
import { getSession } from '@/ntqqapi/wrapper'
import { RequestUtil } from '@/common/utils/request'
import { NodeIKernelProfileService, UserDetailSource, ProfileBizType } from '../services'
import { NodeIKernelProfileService, UserDetailSource, ProfileBizType, forceFetchClientKeyRetType } from '../services'
import { NodeIKernelProfileListener } from '../listeners'
import { NTEventDispatch } from '@/common/utils/EventTask'
import { NTQQFriendApi } from './friend'
@@ -146,25 +146,31 @@ export class NTQQUserApi {
return (hash & 0x7fffffff).toString()
}
/** 27187 TODO */
static async getPSkey(domains: string[]): Promise<Map<string, string>> {
const session = getSession()
const res = await session?.getTipOffService().getPskey(domains, true)
if (res?.result !== 0) {
throw new Error(`获取Pskey失败: ${res?.errMsg}`)
}
return res.domainPskeyMap
}
/** 27187 TODO */
static async like(uid: string, count = 1) {
const session = getSession()
return session?.getProfileLikeService().setBuddyProfileLike({
friendUid: uid,
sourceId: 71,
doLikeCount: count,
doLikeTollCount: 0
})
if (session) {
return session.getProfileLikeService().setBuddyProfileLike({
friendUid: uid,
sourceId: 71,
doLikeCount: count,
doLikeTollCount: 0
})
} else {
return await invoke<GeneralCallResult & { succCounts: number }>({
methodName: 'nodeIKernelProfileLikeService/setBuddyProfileLike',
args: [
{
doLikeUserInfo: {
friendUid: uid,
sourceId: 71,
doLikeCount: count,
doLikeTollCount: 0
}
},
null,
],
})
}
}
static async getUidByUinV1(Uin: string) {
@@ -348,9 +354,17 @@ export class NTQQUserApi {
return await NTQQUserApi.getUinByUidV1(Uid)
}
/** 27187 TODO */
static async forceFetchClientKey() {
const session = getSession()
return await session?.getTicketService().forceFetchClientKey('')
if (session) {
return await session.getTicketService().forceFetchClientKey('')
} else {
return await invoke<forceFetchClientKeyRetType>({
methodName: 'nodeIKernelTicketService/forceFetchClientKey',
args: [{
domain: ''
}, null],
})
}
}
}

View File

@@ -178,29 +178,6 @@ export class WebApi {
return memberData
}
static async setGroupNotice(GroupCode: string, Content: string = '') {
//https://web.qun.qq.com/cgi-bin/announce/add_qun_notice?bkn=${bkn}
//qid=${群号}&bkn=${bkn}&text=${内容}&pinned=0&type=1&settings={"is_show_edit_card":1,"tip_window_type":1,"confirm_required":1}
const _Pskey = (await NTQQUserApi.getPSkey(['qun.qq.com']))['qun.qq.com']
const _Skey = await NTQQUserApi.getSkey()
const CookieValue = 'p_skey=' + _Pskey + '; skey=' + _Skey + '; p_uin=o' + getSelfUin()
let ret: any = undefined
//console.log(CookieValue)
if (!_Skey || !_Pskey) {
//获取Cookies失败
return undefined
}
const Bkn = WebApi.genBkn(_Skey)
const data = 'qid=' + GroupCode + '&bkn=' + Bkn + '&text=' + Content + '&pinned=0&type=1&settings={"is_show_edit_card":1,"tip_window_type":1,"confirm_required":1}'
const url = 'https://web.qun.qq.com/cgi-bin/announce/add_qun_notice?bkn=' + Bkn
try {
ret = await RequestUtil.HttpGetJson<any>(url, 'GET', '', { 'Cookie': CookieValue })
return ret
} catch (e) {
return undefined
}
}
static genBkn(sKey: string) {
sKey = sKey || '';
let hash = 5381;
@@ -220,7 +197,7 @@ export class WebApi {
let res = '';
let resJson;
try {
res = await RequestUtil.HttpGetText(url, 'GET', '', { 'Cookie': CookieValue });
res = await RequestUtil.HttpGetText(url, 'GET', '', { 'Cookie': cookieStr });
const match = res.match(/window\.__INITIAL_STATE__=(.*?);/);
if (match) {
resJson = JSON.parse(match[1].trim());
@@ -237,7 +214,8 @@ export class WebApi {
}
let HonorInfo: any = { group_id: groupCode };
const CookieValue = (await NTQQUserApi.getCookies('qun.qq.com')).cookies;
const cookieObject = await NTQQUserApi.getCookies('qun.qq.com')
const cookieStr = Object.entries(cookieObject).map(([key, value]) => `${key}=${value}`).join('; ')
if (getType === WebHonorType.TALKACTIVE || getType === WebHonorType.ALL) {
try {

View File

@@ -82,7 +82,8 @@ export interface CategoryFriend {
categroyName: string
categroyMbCount: number
onlineCount: number
buddyList: User[]
buddyList: User[] // V1
buddyUids: string[]
}
export interface CoreInfo {

View File

@@ -63,7 +63,7 @@ export abstract class GetFileBase extends BaseAction<GetFilePayload, GetFileResp
} else if (fileCache[0].elementType === ElementType.VIDEO) {
res.url = await NTQQFileApi.getVideoUrl(peer, fileCache[0].msgId, fileCache[0].elementId)
}
if (enableLocalFile2Url && downloadPath && res.file === res.url) {
if (enableLocalFile2Url && downloadPath && (res.file === res.url || res.url === undefined)) {
try {
res.base64 = await fsPromise.readFile(downloadPath, 'base64')
} catch (e) {

View File

@@ -15,10 +15,13 @@ export class GetCookies extends BaseAction<Payload, Response> {
actionName = ActionName.GetCookies
protected async _handle(payload: Payload) {
if (!payload.domain) {
throw '缺少参数 domain'
}
const cookiesObject = await NTQQUserApi.getCookies(payload.domain)
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ')
const bkn = WebApi.genBkn(cookiesObject.p_skey)
const bkn = cookiesObject.skey ? WebApi.genBkn(cookiesObject.skey) : ''
return { cookies, bkn }
}
}

View File

@@ -3,8 +3,8 @@ import { ActionName } from '../types'
import { NTQQUserApi } from '@/ntqqapi/api'
interface Payload {
user_id: number
times: number
user_id: number | string
times: number | string
}
export default class SendLike extends BaseAction<Payload, null> {
@@ -14,7 +14,7 @@ export default class SendLike extends BaseAction<Payload, null> {
try {
const qq = payload.user_id.toString()
const uid: string = await NTQQUserApi.getUidByUin(qq) || ''
const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1)
const result = await NTQQUserApi.like(uid, +payload.times || 1)
if (result?.result !== 0) {
throw Error(result?.errMsg)
}

View File

@@ -49,6 +49,7 @@ import { OB11GroupRecallNoticeEvent } from './event/notice/OB11GroupRecallNotice
import { OB11FriendPokeEvent, OB11GroupPokeEvent } from './event/notice/OB11PokeEvent'
import { OB11BaseNoticeEvent } from './event/notice/OB11BaseNoticeEvent'
import { OB11GroupEssenceEvent } from './event/notice/OB11GroupEssenceEvent'
import { omit } from 'cosmokit'
export class OB11Constructor {
static async message(msg: RawMessage): Promise<OB11Message> {
@@ -661,7 +662,7 @@ export class OB11Constructor {
for (const friend of friends) {
const sexValue = this.sex(friend.baseInfo.sex!)
data.push({
...friend.baseInfo,
...omit(friend.baseInfo, ['richBuffer']),
...friend.coreInfo,
user_id: parseInt(friend.coreInfo.uin),
nickname: friend.coreInfo.nick,

View File

@@ -1 +1 @@
export const version = '3.30.0'
export const version = '3.30.4'