mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
sync
This commit is contained in:
@@ -5,9 +5,8 @@ import {
|
||||
type Group,
|
||||
type GroupMember,
|
||||
type SelfInfo,
|
||||
User,
|
||||
} from '../ntqqapi/types'
|
||||
import { type FileCache, type LLOneBotError } from './types'
|
||||
import { type LLOneBotError } from './types'
|
||||
import { NTQQGroupApi } from '../ntqqapi/api/group'
|
||||
import { log } from './utils/log'
|
||||
import { isNumeric } from './utils/helper'
|
||||
@@ -26,7 +25,6 @@ export const WebGroupData = {
|
||||
}
|
||||
export let groups: Group[] = []
|
||||
export let friends: Friend[] = []
|
||||
export let friendRequests: Map<number, FriendRequest> = new Map<number, FriendRequest>()
|
||||
export const llonebotError: LLOneBotError = {
|
||||
ffmpegError: '',
|
||||
httpServerError: '',
|
||||
|
@@ -1,7 +1,7 @@
|
||||
// 运行在 Electron 主进程 下的插件入口
|
||||
|
||||
import { BrowserWindow, dialog, ipcMain } from 'electron'
|
||||
import * as fs from 'node:fs'
|
||||
import fs from 'node:fs'
|
||||
import { Config } from '../common/types'
|
||||
import {
|
||||
CHANNEL_CHECK_VERSION,
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
import { ob11WebsocketServer } from '../onebot11/server/ws/WebsocketServer'
|
||||
import { DATA_DIR } from '../common/utils'
|
||||
import {
|
||||
friendRequests,
|
||||
getGroupMember,
|
||||
llonebotError,
|
||||
selfInfo,
|
||||
@@ -28,24 +27,23 @@ import {
|
||||
GroupNotifies,
|
||||
GroupNotifyTypes,
|
||||
RawMessage,
|
||||
BuddyReqType,
|
||||
} from '../ntqqapi/types'
|
||||
import { httpHeart, ob11HTTPServer } from '../onebot11/server/http'
|
||||
import { postOb11Event } from '../onebot11/server/post-ob11-event'
|
||||
import { ob11ReverseWebsockets } from '../onebot11/server/ws/ReverseWebsocket'
|
||||
import { OB11GroupRequestEvent } from '../onebot11/event/request/OB11GroupRequest'
|
||||
import { OB11FriendRequestEvent } from '../onebot11/event/request/OB11FriendRequest'
|
||||
import * as path from 'node:path'
|
||||
import path from 'node:path'
|
||||
import { dbUtil } from '../common/db'
|
||||
import { setConfig } from './setConfig'
|
||||
import { NTQQUserApi } from '../ntqqapi/api/user'
|
||||
import { NTQQGroupApi } from '../ntqqapi/api/group'
|
||||
import { NTQQUserApi, NTQQGroupApi, sentMessages } from '../ntqqapi/api'
|
||||
import { checkNewVersion, upgradeLLOneBot } from '../common/utils/upgrade'
|
||||
import { log } from '../common/utils/log'
|
||||
import { getConfigUtil } from '../common/config'
|
||||
import { checkFfmpeg } from '../common/utils/video'
|
||||
import { GroupDecreaseSubType, OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent'
|
||||
import '../ntqqapi/wrapper'
|
||||
import { sentMessages } from '@/ntqqapi/api'
|
||||
import { NTEventDispatch } from '../common/utils/EventTask'
|
||||
import { wrapperConstructor, getSession } from '../ntqqapi/wrapper'
|
||||
|
||||
@@ -284,6 +282,7 @@ function onLoad() {
|
||||
}
|
||||
log('收到群通知', notify)
|
||||
await dbUtil.addGroupNotify(notify)
|
||||
const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type
|
||||
// let member2: GroupMember;
|
||||
// if (notify.user2.uid) {
|
||||
// member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid);
|
||||
@@ -342,48 +341,47 @@ function onLoad() {
|
||||
}
|
||||
else if ([GroupNotifyTypes.JOIN_REQUEST, GroupNotifyTypes.JOIN_REQUEST_BY_INVITED].includes(notify.type)) {
|
||||
log('有加群请求')
|
||||
let requestQQ = uidMaps[notify.user1.uid]
|
||||
if (!requestQQ) {
|
||||
try {
|
||||
let requestQQ = ''
|
||||
try {
|
||||
// uid-->uin
|
||||
requestQQ = (await NTQQUserApi.getUinByUid(notify.user1.uid))
|
||||
if (isNaN(parseInt(requestQQ))) {
|
||||
requestQQ = (await NTQQUserApi.getUserDetailInfo(notify.user1.uid)).uin
|
||||
} catch (e) {
|
||||
log('获取加群人QQ号失败', e)
|
||||
}
|
||||
} catch (e) {
|
||||
log('获取加群人QQ号失败 Uid:', notify.user1.uid, e)
|
||||
}
|
||||
let invitorId: number
|
||||
let invitorId: string
|
||||
if (notify.type == GroupNotifyTypes.JOIN_REQUEST_BY_INVITED) {
|
||||
// groupRequestEvent.sub_type = 'invite'
|
||||
let invitorQQ = uidMaps[notify.user2.uid]
|
||||
if (!invitorQQ) {
|
||||
try {
|
||||
let invitor = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid))
|
||||
invitorId = parseInt(invitor.uin)
|
||||
} catch (e) {
|
||||
invitorId = 0
|
||||
log('获取邀请人QQ号失败', e)
|
||||
try {
|
||||
// uid-->uin
|
||||
invitorId = (await NTQQUserApi.getUinByUid(notify.user2.uid))
|
||||
if (isNaN(parseInt(invitorId))) {
|
||||
invitorId = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid)).uin
|
||||
}
|
||||
} catch (e) {
|
||||
invitorId = ''
|
||||
log('获取邀请人QQ号失败 Uid:', notify.user2.uid, e)
|
||||
}
|
||||
}
|
||||
const groupRequestEvent = new OB11GroupRequestEvent(
|
||||
parseInt(notify.group.groupCode),
|
||||
parseInt(requestQQ) || 0,
|
||||
notify.seq,
|
||||
flag,
|
||||
notify.postscript,
|
||||
invitorId!,
|
||||
invitorId! === undefined ? undefined : +invitorId,
|
||||
'add'
|
||||
)
|
||||
postOb11Event(groupRequestEvent)
|
||||
}
|
||||
else if (notify.type == GroupNotifyTypes.INVITE_ME) {
|
||||
log('收到邀请我加群通知')
|
||||
let userId = uidMaps[notify.user2.uid]
|
||||
if (!userId) {
|
||||
userId = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid))?.uin
|
||||
}
|
||||
const userId = (await NTQQUserApi.getUinByUid(notify.user2.uid)) || ''
|
||||
const groupInviteEvent = new OB11GroupRequestEvent(
|
||||
parseInt(notify.group.groupCode),
|
||||
parseInt(userId),
|
||||
notify.seq,
|
||||
flag,
|
||||
undefined,
|
||||
undefined,
|
||||
'invite'
|
||||
@@ -402,20 +400,24 @@ function onLoad() {
|
||||
|
||||
registerReceiveHook<FriendRequestNotify>(ReceiveCmdS.FRIEND_REQUEST, async (payload) => {
|
||||
for (const req of payload.data.buddyReqs) {
|
||||
const flag = req.friendUid + req.reqTime
|
||||
if (req.isUnread && parseInt(req.reqTime) > startTime / 1000) {
|
||||
friendRequests[flag] = req
|
||||
log('有新的好友请求', req)
|
||||
let userId: number
|
||||
try {
|
||||
const requester = await NTQQUserApi.getUserDetailInfo(req.friendUid)
|
||||
userId = parseInt(requester.uin)
|
||||
} catch (e) {
|
||||
log('获取加好友者QQ号失败', e)
|
||||
}
|
||||
const friendRequestEvent = new OB11FriendRequestEvent(userId!, req.extWords, flag)
|
||||
postOb11Event(friendRequestEvent)
|
||||
if (!!req.isInitiator || (req.isDecide && req.reqType !== BuddyReqType.KMEINITIATORWAITPEERCONFIRM)) {
|
||||
continue
|
||||
}
|
||||
let userId = 0
|
||||
try {
|
||||
const requesterUin = await NTQQUserApi.getUinByUid(req.friendUid)
|
||||
userId = parseInt(requesterUin!)
|
||||
} catch (e) {
|
||||
log('获取加好友者QQ号失败', e)
|
||||
}
|
||||
const flag = req.friendUid + '|' + req.reqTime
|
||||
const comment = req.extWords
|
||||
const friendRequestEvent = new OB11FriendRequestEvent(
|
||||
userId,
|
||||
comment,
|
||||
flag
|
||||
)
|
||||
postOb11Event(friendRequestEvent)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import { Friend, FriendRequest, FriendV2 } from '../types'
|
||||
import { Friend, FriendV2 } from '../types'
|
||||
import { ReceiveCmdS } from '../hook'
|
||||
import { callNTQQApi, GeneralCallResult, NTQQApiMethod } from '../ntcall'
|
||||
import { friendRequests } from '@/common/data'
|
||||
import { getSession } from '@/ntqqapi/wrapper'
|
||||
import { BuddyListReqType, NodeIKernelProfileService } from '../services'
|
||||
import { NTEventDispatch } from '@/common/utils/EventTask'
|
||||
@@ -49,24 +48,18 @@ export class NTQQFriendApi {
|
||||
}
|
||||
|
||||
static async handleFriendRequest(flag: string, accept: boolean) {
|
||||
const request: FriendRequest = friendRequests[flag]
|
||||
if (!request) {
|
||||
throw `flat: ${flag}, 对应的好友请求不存在`
|
||||
const data = flag.split('|')
|
||||
if (data.length < 2) {
|
||||
return
|
||||
}
|
||||
const result = await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.HANDLE_FRIEND_REQUEST,
|
||||
args: [
|
||||
{
|
||||
approvalInfo: {
|
||||
friendUid: request.friendUid,
|
||||
reqTime: request.reqTime,
|
||||
accept,
|
||||
},
|
||||
},
|
||||
],
|
||||
const friendUid = data[0]
|
||||
const reqTime = data[1]
|
||||
const session = getSession()
|
||||
return session?.getBuddyService().approvalFriendRequest({
|
||||
friendUid,
|
||||
reqTime,
|
||||
accept
|
||||
})
|
||||
delete friendRequests[flag]
|
||||
return result
|
||||
}
|
||||
|
||||
static async getBuddyV2(refresh = false): Promise<FriendV2[]> {
|
||||
|
@@ -1,9 +1,6 @@
|
||||
import { ReceiveCmdS } from '../hook'
|
||||
import { Group, GroupMember, GroupMemberRole, GroupNotifies, GroupRequestOperateTypes } from '../types'
|
||||
import { callNTQQApi, GeneralCallResult, NTQQApiMethod } from '../ntcall'
|
||||
import { deleteGroup } from '../../common/data'
|
||||
import { dbUtil } from '../../common/db'
|
||||
import { log } from '../../common/utils/log'
|
||||
import { NTQQWindowApi, NTQQWindows } from './window'
|
||||
import { getSession } from '../wrapper'
|
||||
import { NTEventDispatch } from '@/common/utils/EventTask'
|
||||
@@ -103,130 +100,64 @@ export class NTQQGroupApi {
|
||||
)
|
||||
}
|
||||
|
||||
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||
const notify = await dbUtil.getGroupNotify(seq)
|
||||
if (!notify) {
|
||||
throw `${seq}对应的加群通知不存在`
|
||||
}
|
||||
// delete groupNotifies[seq]
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.HANDLE_GROUP_REQUEST,
|
||||
args: [
|
||||
{
|
||||
doubt: false,
|
||||
operateMsg: {
|
||||
operateType: operateType, // 2 拒绝
|
||||
targetMsg: {
|
||||
seq: seq, // 通知序列号
|
||||
type: notify.type,
|
||||
groupCode: notify.group.groupCode,
|
||||
postscript: reason,
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
],
|
||||
})
|
||||
static async handleGroupRequest(flag: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||
const flagitem = flag.split('|')
|
||||
const groupCode = flagitem[0]
|
||||
const seq = flagitem[1]
|
||||
const type = parseInt(flagitem[2])
|
||||
const session = getSession()
|
||||
return session?.getGroupService().operateSysNotify(
|
||||
false,
|
||||
{
|
||||
'operateType': operateType, // 2 拒绝
|
||||
'targetMsg': {
|
||||
'seq': seq, // 通知序列号
|
||||
'type': type,
|
||||
'groupCode': groupCode,
|
||||
'postscript': reason || ' ' // 仅传空值可能导致处理失败,故默认给个空格
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static async quitGroup(groupQQ: string) {
|
||||
const result = await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.QUIT_GROUP,
|
||||
args: [{ groupCode: groupQQ }, null],
|
||||
})
|
||||
if (result.result === 0) {
|
||||
deleteGroup(groupQQ)
|
||||
}
|
||||
return result
|
||||
const session = getSession()
|
||||
return session?.getGroupService().quitGroup(groupQQ)
|
||||
}
|
||||
|
||||
static async kickMember(
|
||||
groupQQ: string,
|
||||
kickUids: string[],
|
||||
refuseForever: boolean = false,
|
||||
kickReason: string = '',
|
||||
refuseForever = false,
|
||||
kickReason = '',
|
||||
) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.KICK_MEMBER,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
kickUids,
|
||||
refuseForever,
|
||||
kickReason,
|
||||
},
|
||||
],
|
||||
})
|
||||
const session = getSession()
|
||||
return session?.getGroupService().kickMember(groupQQ, kickUids, refuseForever, kickReason)
|
||||
}
|
||||
|
||||
static async banMember(groupQQ: string, memList: Array<{ uid: string, timeStamp: number }>) {
|
||||
// timeStamp为秒数, 0为解除禁言
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.MUTE_MEMBER,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
memList,
|
||||
},
|
||||
],
|
||||
})
|
||||
const session = getSession()
|
||||
return session?.getGroupService().setMemberShutUp(groupQQ, memList)
|
||||
}
|
||||
|
||||
static async banGroup(groupQQ: string, shutUp: boolean) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.MUTE_GROUP,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
shutUp,
|
||||
},
|
||||
null,
|
||||
],
|
||||
})
|
||||
const session = getSession()
|
||||
return session?.getGroupService().setGroupShutUp(groupQQ, shutUp)
|
||||
}
|
||||
|
||||
static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
||||
NTQQGroupApi.activateMemberListChange().then().catch(log)
|
||||
const res = await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_MEMBER_CARD,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid: memberUid,
|
||||
cardName,
|
||||
},
|
||||
null,
|
||||
],
|
||||
})
|
||||
NTQQGroupApi.getGroupMembersInfo(groupQQ, [memberUid], true).then().catch(log)
|
||||
return res
|
||||
const session = getSession()
|
||||
return session?.getGroupService().modifyMemberCardName(groupQQ, memberUid, cardName)
|
||||
}
|
||||
|
||||
static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_MEMBER_ROLE,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid: memberUid,
|
||||
role,
|
||||
},
|
||||
null,
|
||||
],
|
||||
})
|
||||
const session = getSession()
|
||||
return session?.getGroupService().modifyMemberRole(groupQQ, memberUid, role)
|
||||
}
|
||||
|
||||
static async setGroupName(groupQQ: string, groupName: string) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_GROUP_NAME,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
groupName,
|
||||
},
|
||||
null,
|
||||
],
|
||||
})
|
||||
const session = getSession()
|
||||
return session?.getGroupService().modifyGroupName(groupQQ, groupName, false)
|
||||
}
|
||||
|
||||
static async getGroupAtAllRemainCount(groupCode: string) {
|
||||
@@ -251,19 +182,13 @@ export class NTQQGroupApi {
|
||||
})
|
||||
}
|
||||
|
||||
static async getGroupRemainAtTimes(GroupCode: string) {
|
||||
const session = getSession()
|
||||
return session?.getGroupService().getGroupRemainAtTimes(GroupCode)!
|
||||
}
|
||||
|
||||
// 头衔不可用
|
||||
static async setGroupTitle(groupQQ: string, uid: string, title: string) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_GROUP_TITLE,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid,
|
||||
title,
|
||||
},
|
||||
null,
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
static publishGroupBulletin(groupQQ: string, title: string, content: string) { }
|
||||
|
@@ -291,4 +291,49 @@ export class NTQQUserApi {
|
||||
Uin
|
||||
)
|
||||
}
|
||||
|
||||
static async getUinByUidV1(Uid: string) {
|
||||
const ret = await NTEventDispatch.CallNoListenerEvent
|
||||
<(Uin: string[]) => Promise<{ uinInfo: Map<string, string> }>>(
|
||||
'NodeIKernelUixConvertService/getUin',
|
||||
5000,
|
||||
[Uid]
|
||||
)
|
||||
let uin = ret.uinInfo.get(Uid)
|
||||
if (!uin) {
|
||||
//从Buddy缓存获取Uin
|
||||
friends.forEach((t) => {
|
||||
if (t.uid == Uid) {
|
||||
uin = t.uin
|
||||
}
|
||||
})
|
||||
}
|
||||
if (!uin) {
|
||||
uin = (await NTQQUserApi.getUserDetailInfo(Uid)).uin //从QQ Native 转换
|
||||
}
|
||||
return uin
|
||||
}
|
||||
|
||||
static async getUinByUidV2(Uid: string) {
|
||||
const session = getSession()
|
||||
let uin = (await session?.getProfileService().getUinByUid('FriendsServiceImpl', [Uid]))?.get(Uid)
|
||||
if (uin) return uin
|
||||
uin = (await session?.getGroupService().getUinByUids([Uid]))?.uins.get(Uid)
|
||||
if (uin) return uin
|
||||
uin = (await session?.getUixConvertService().getUin([Uid]))?.uinInfo.get(Uid)
|
||||
if (uin) return uin
|
||||
uin = (await NTQQFriendApi.getBuddyIdMapCache(true)).getKey(Uid) //从Buddy缓存获取Uin
|
||||
if (uin) return uin
|
||||
uin = (await NTQQFriendApi.getBuddyIdMap(true)).getKey(Uid)
|
||||
if (uin) return uin
|
||||
uin = (await NTQQUserApi.getUserDetailInfo(Uid)).uin //从QQ Native 转换
|
||||
return uin
|
||||
}
|
||||
|
||||
static async getUinByUid(Uid: string) {
|
||||
if (getBuildVersion() >= 26702) {
|
||||
return await NTQQUserApi.getUinByUidV2(Uid)
|
||||
}
|
||||
return await NTQQUserApi.getUinByUidV1(Uid)
|
||||
}
|
||||
}
|
||||
|
@@ -48,8 +48,28 @@ export enum GroupRequestOperateTypes {
|
||||
reject = 2,
|
||||
}
|
||||
|
||||
export enum BuddyReqType {
|
||||
KMEINITIATOR,
|
||||
KPEERINITIATOR,
|
||||
KMEAGREED,
|
||||
KMEAGREEDANDADDED,
|
||||
KPEERAGREED,
|
||||
KPEERAGREEDANDADDED,
|
||||
KPEERREFUSED,
|
||||
KMEREFUSED,
|
||||
KMEIGNORED,
|
||||
KMEAGREEANYONE,
|
||||
KMESETQUESTION,
|
||||
KMEAGREEANDADDFAILED,
|
||||
KMSGINFO,
|
||||
KMEINITIATORWAITPEERCONFIRM
|
||||
}
|
||||
|
||||
export interface FriendRequest {
|
||||
isInitiator?: boolean
|
||||
isDecide: boolean
|
||||
friendUid: string
|
||||
reqType: BuddyReqType
|
||||
reqTime: string // 时间戳,秒
|
||||
extWords: string // 申请人填写的验证消息
|
||||
isUnread: boolean
|
||||
|
@@ -5,22 +5,19 @@ import { NTQQGroupApi } from '../../../ntqqapi/api/group'
|
||||
|
||||
interface Payload {
|
||||
flag: string
|
||||
// sub_type: "add" | "invite",
|
||||
// type: "add" | "invite"
|
||||
approve: boolean
|
||||
reason: string
|
||||
approve?: boolean | string
|
||||
reason?: string
|
||||
}
|
||||
|
||||
export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupAddRequest
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const seq = payload.flag.toString()
|
||||
const approve = payload.approve.toString() === 'true'
|
||||
await NTQQGroupApi.handleGroupRequest(
|
||||
seq,
|
||||
const flag = payload.flag.toString()
|
||||
const approve = payload.approve?.toString() !== 'false'
|
||||
await NTQQGroupApi.handleGroupRequest(flag,
|
||||
approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||
payload.reason,
|
||||
payload.reason || ''
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ import { NTQQFriendApi } from '../../../ntqqapi/api/friend'
|
||||
|
||||
interface Payload {
|
||||
flag: string
|
||||
approve: boolean
|
||||
approve?: boolean | string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export default class SetFriendAddRequest extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetFriendAddRequest
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const approve = payload.approve.toString() === 'true'
|
||||
const approve = payload.approve?.toString() !== 'false'
|
||||
await NTQQFriendApi.handleFriendRequest(payload.flag, approve)
|
||||
return null
|
||||
}
|
||||
|
Reference in New Issue
Block a user