mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
opt
This commit is contained in:
parent
25691a4124
commit
51f8db3a83
@ -98,14 +98,4 @@ export async function getGroupMember(groupQQ: string | number, memberUinOrUid: s
|
||||
member = getMember()
|
||||
}
|
||||
return member
|
||||
}
|
||||
|
||||
export const uidMaps: Record<string, string> = {} // 一串加密的字符串(uid) -> qq号
|
||||
|
||||
export function getUidByUin(uin: string) {
|
||||
for (const uid in uidMaps) {
|
||||
if (uidMaps[uid] === uin) {
|
||||
return uid
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,14 @@
|
||||
import BaseAction from '../BaseAction'
|
||||
import { NTQQMsgApi } from '@/ntqqapi/api'
|
||||
import { ChatType, RawMessage } from '@/ntqqapi/types'
|
||||
import { NTQQMsgApi, NTQQUserApi } from '@/ntqqapi/api'
|
||||
import { ChatType } from '@/ntqqapi/types'
|
||||
import { dbUtil } from '@/common/db'
|
||||
import { getUidByUin } from '@/common/data'
|
||||
import { ActionName } from '../types'
|
||||
import { Peer } from '@/ntqqapi/types'
|
||||
|
||||
interface Payload {
|
||||
message_id: number
|
||||
group_id: number
|
||||
user_id?: number
|
||||
group_id: number | string
|
||||
user_id?: number | string
|
||||
}
|
||||
|
||||
interface Response {
|
||||
@ -19,13 +18,20 @@ interface Response {
|
||||
abstract class ForwardSingleMsg extends BaseAction<Payload, Response> {
|
||||
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
||||
if (payload.user_id) {
|
||||
return { chatType: ChatType.friend, peerUid: getUidByUin(payload.user_id.toString())! }
|
||||
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString())
|
||||
if (!peerUid) {
|
||||
throw new Error(`无法找到私聊对象${payload.user_id}`)
|
||||
}
|
||||
return { chatType: ChatType.friend, peerUid }
|
||||
}
|
||||
return { chatType: ChatType.group, peerUid: payload.group_id.toString() }
|
||||
return { chatType: ChatType.group, peerUid: payload.group_id!.toString() }
|
||||
}
|
||||
|
||||
protected async _handle(payload: Payload): Promise<Response> {
|
||||
const msg = (await dbUtil.getMsgByShortId(payload.message_id))!
|
||||
const msg = await dbUtil.getMsgByShortId(payload.message_id)
|
||||
if (!msg) {
|
||||
throw new Error(`无法找到消息${payload.message_id}`)
|
||||
}
|
||||
const peer = await this.getTargetPeer(payload)
|
||||
const sentMsg = await NTQQMsgApi.forwardMsg(
|
||||
{
|
||||
|
@ -2,14 +2,12 @@ import {
|
||||
AtType,
|
||||
ChatType,
|
||||
ElementType,
|
||||
Friend,
|
||||
Group,
|
||||
GroupMemberRole,
|
||||
PicSubType,
|
||||
RawMessage,
|
||||
SendMessageElement,
|
||||
} from '../../../ntqqapi/types'
|
||||
import { friends, getGroup, getGroupMember, getUidByUin, selfInfo } from '../../../common/data'
|
||||
import { getGroup, getGroupMember, selfInfo } from '../../../common/data'
|
||||
import {
|
||||
OB11MessageCustomMusic,
|
||||
OB11MessageData,
|
||||
@ -27,7 +25,7 @@ import { ActionName, BaseCheckResult } from '../types'
|
||||
import fs from 'node:fs'
|
||||
import { decodeCQCode } from '../../cqcode'
|
||||
import { dbUtil } from '../../../common/db'
|
||||
import { ALLOW_SEND_TEMP_MSG, getConfigUtil } from '../../../common/config'
|
||||
import { getConfigUtil } from '../../../common/config'
|
||||
import { log } from '../../../common/utils/log'
|
||||
import { sleep } from '../../../common/utils/helper'
|
||||
import { uri2local } from '../../../common/utils'
|
||||
|
@ -5,9 +5,8 @@ import { OB11Message, OB11MessageAt, OB11MessageData, OB11MessageDataType } from
|
||||
import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest'
|
||||
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest'
|
||||
import { dbUtil } from '@/common/db'
|
||||
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi } from '@/ntqqapi/api'
|
||||
import { ChatType, Group, GroupRequestOperateTypes, Peer } from '@/ntqqapi/types'
|
||||
import { getGroup, getUidByUin } from '@/common/data'
|
||||
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from '@/ntqqapi/api'
|
||||
import { ChatType, GroupRequestOperateTypes, Peer } from '@/ntqqapi/types'
|
||||
import { convertMessage2List, createSendElements, sendMsg } from './msg/SendMsg'
|
||||
import { isNull, log } from '@/common/utils'
|
||||
import { getConfigUtil } from '@/common/config'
|
||||
@ -62,16 +61,15 @@ export async function handleQuickOperation(context: QuickOperationEvent, quickAc
|
||||
}
|
||||
|
||||
async function handleMsg(msg: OB11Message, quickAction: QuickOperationPrivateMessage | QuickOperationGroupMessage) {
|
||||
msg = msg as OB11Message
|
||||
const rawMessage = await dbUtil.getMsgByShortId(msg.message_id)
|
||||
const reply = quickAction.reply
|
||||
const ob11Config = getConfigUtil().getConfig().ob11
|
||||
let peer: Peer = {
|
||||
const peer: Peer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: msg.user_id.toString(),
|
||||
}
|
||||
if (msg.message_type == 'private') {
|
||||
peer.peerUid = getUidByUin(msg.user_id.toString())!
|
||||
peer.peerUid = (await NTQQUserApi.getUidByUin(msg.user_id.toString()))!
|
||||
if (msg.sub_type === 'group') {
|
||||
peer.chatType = ChatType.temp
|
||||
}
|
||||
@ -81,7 +79,6 @@ async function handleMsg(msg: OB11Message, quickAction: QuickOperationPrivateMes
|
||||
peer.peerUid = msg.group_id?.toString()!
|
||||
}
|
||||
if (reply) {
|
||||
let group: Group | null = null
|
||||
let replyMessage: OB11MessageData[] = []
|
||||
if (ob11Config.enableQOAutoQuote) {
|
||||
replyMessage.push({
|
||||
@ -93,7 +90,6 @@ async function handleMsg(msg: OB11Message, quickAction: QuickOperationPrivateMes
|
||||
}
|
||||
|
||||
if (msg.message_type == 'group') {
|
||||
group = (await getGroup(msg.group_id?.toString()!))!
|
||||
if ((quickAction as QuickOperationGroupMessage).at_sender) {
|
||||
replyMessage.push({
|
||||
type: 'at',
|
||||
@ -104,8 +100,7 @@ async function handleMsg(msg: OB11Message, quickAction: QuickOperationPrivateMes
|
||||
}
|
||||
}
|
||||
replyMessage = replyMessage.concat(convertMessage2List(reply, quickAction.auto_escape))
|
||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(replyMessage, group!)
|
||||
log(`发送消息给`, peer, sendElements)
|
||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(replyMessage, peer)
|
||||
sendMsg(peer, sendElements, deleteAfterSentFiles, false).then().catch(log)
|
||||
}
|
||||
if (msg.message_type === 'group') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user