mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
refactor
This commit is contained in:
parent
0c456e2160
commit
806798bd48
@ -17,39 +17,6 @@ export enum WebHonorType {
|
|||||||
EMOTION = 'emotion'
|
EMOTION = 'emotion'
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WebApiGroupMember {
|
|
||||||
uin: number
|
|
||||||
role: number
|
|
||||||
g: number
|
|
||||||
join_time: number
|
|
||||||
last_speak_time: number
|
|
||||||
lv: {
|
|
||||||
point: number
|
|
||||||
level: number
|
|
||||||
}
|
|
||||||
card: string
|
|
||||||
tags: string
|
|
||||||
flag: number
|
|
||||||
nick: string
|
|
||||||
qage: number
|
|
||||||
rm: number
|
|
||||||
}
|
|
||||||
|
|
||||||
interface WebApiGroupMemberRet {
|
|
||||||
ec: number
|
|
||||||
errcode: number
|
|
||||||
em: string
|
|
||||||
cache: number
|
|
||||||
adm_num: number
|
|
||||||
levelname: unknown
|
|
||||||
mems: WebApiGroupMember[]
|
|
||||||
count: number
|
|
||||||
svr_time: number
|
|
||||||
max_count: number
|
|
||||||
search_count: number
|
|
||||||
extmode: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export class NTQQWebApi extends Service {
|
export class NTQQWebApi extends Service {
|
||||||
static inject = ['ntUserApi']
|
static inject = ['ntUserApi']
|
||||||
|
|
||||||
@ -57,47 +24,6 @@ export class NTQQWebApi extends Service {
|
|||||||
super(ctx, 'ntWebApi', true)
|
super(ctx, 'ntWebApi', true)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGroupMembers(groupCode: string): Promise<WebApiGroupMember[]> {
|
|
||||||
const memberData: Array<WebApiGroupMember> = new Array<WebApiGroupMember>()
|
|
||||||
const cookieObject = await this.ctx.ntUserApi.getCookies('qun.qq.com')
|
|
||||||
const cookieStr = this.cookieToString(cookieObject)
|
|
||||||
const retList: Promise<WebApiGroupMemberRet>[] = []
|
|
||||||
const params = new URLSearchParams({
|
|
||||||
st: '0',
|
|
||||||
end: '40',
|
|
||||||
sort: '1',
|
|
||||||
gc: groupCode,
|
|
||||||
bkn: this.genBkn(cookieObject.skey)
|
|
||||||
})
|
|
||||||
const fastRet = await RequestUtil.HttpGetJson<WebApiGroupMemberRet>(`https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?${params}`, 'POST', '', { 'Cookie': cookieStr })
|
|
||||||
if (!fastRet?.count || fastRet?.errcode !== 0 || !fastRet?.mems) {
|
|
||||||
return []
|
|
||||||
} else {
|
|
||||||
for (const member of fastRet.mems) {
|
|
||||||
memberData.push(member)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const pageNum = Math.ceil(fastRet.count / 40)
|
|
||||||
//遍历批量请求
|
|
||||||
for (let i = 2; i <= pageNum; i++) {
|
|
||||||
params.set('st', String((i - 1) * 40))
|
|
||||||
params.set('end', String(i * 40))
|
|
||||||
const ret = RequestUtil.HttpGetJson<WebApiGroupMemberRet>(`https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?${params}`, 'POST', '', { 'Cookie': cookieStr })
|
|
||||||
retList.push(ret)
|
|
||||||
}
|
|
||||||
//批量等待
|
|
||||||
for (let i = 1; i <= pageNum; i++) {
|
|
||||||
const ret = await (retList[i])
|
|
||||||
if (!ret?.count || ret?.errcode !== 0 || !ret?.mems) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for (const member of ret.mems) {
|
|
||||||
memberData.push(member)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return memberData
|
|
||||||
}
|
|
||||||
|
|
||||||
genBkn(sKey: string) {
|
genBkn(sKey: string) {
|
||||||
sKey = sKey || ''
|
sKey = sKey || ''
|
||||||
let hash = 5381
|
let hash = 5381
|
||||||
|
@ -5,7 +5,7 @@ interface Payload {
|
|||||||
message_id: number | string
|
message_id: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DelEssenceMsg extends BaseAction<Payload, unknown> {
|
export class DeleteEssenceMsg extends BaseAction<Payload, unknown> {
|
||||||
actionName = ActionName.GoCQHTTP_DelEssenceMsg
|
actionName = ActionName.GoCQHTTP_DelEssenceMsg
|
||||||
payloadSchema = Schema.object({
|
payloadSchema = Schema.object({
|
||||||
message_id: Schema.union([Number, String]).required()
|
message_id: Schema.union([Number, String]).required()
|
||||||
|
@ -16,7 +16,7 @@ interface EssenceMsg {
|
|||||||
message_id: number
|
message_id: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GetGroupEssence extends BaseAction<Payload, EssenceMsg[]> {
|
export class GetEssenceMsgList extends BaseAction<Payload, EssenceMsg[]> {
|
||||||
actionName = ActionName.GoCQHTTP_GetEssenceMsgList
|
actionName = ActionName.GoCQHTTP_GetEssenceMsgList
|
||||||
payloadSchema = Schema.object({
|
payloadSchema = Schema.object({
|
||||||
group_id: Schema.union([Number, String]).required()
|
group_id: Schema.union([Number, String]).required()
|
@ -1,24 +1,22 @@
|
|||||||
import { BaseAction } from '../BaseAction'
|
import { BaseAction, Schema } from '../BaseAction'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
message_id: number | string
|
message_id: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetEssenceMsg extends BaseAction<Payload, unknown> {
|
export class SetEssenceMsg extends BaseAction<Payload, null> {
|
||||||
actionName = ActionName.GoCQHTTP_SetEssenceMsg
|
actionName = ActionName.GoCQHTTP_SetEssenceMsg
|
||||||
|
payloadSchema = Schema.object({
|
||||||
|
message_id: Schema.union([Number, String]).required()
|
||||||
|
})
|
||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
if (!payload.message_id) {
|
|
||||||
throw Error('message_id不能为空')
|
|
||||||
}
|
|
||||||
const msg = await this.ctx.store.getMsgInfoByShortId(+payload.message_id)
|
const msg = await this.ctx.store.getMsgInfoByShortId(+payload.message_id)
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
throw new Error('msg not found')
|
throw new Error('msg not found')
|
||||||
}
|
}
|
||||||
return await this.ctx.ntGroupApi.addGroupEssence(
|
await this.ctx.ntGroupApi.addGroupEssence(msg.peer.peerUid, msg.msgId)
|
||||||
msg.peer.peerUid,
|
return null
|
||||||
msg.msgId
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
35
src/onebot11/action/go-cqhttp/UploadGroupFile.ts
Normal file
35
src/onebot11/action/go-cqhttp/UploadGroupFile.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { BaseAction, Schema } from '../BaseAction'
|
||||||
|
import { ActionName } from '../types'
|
||||||
|
import { SendElementEntities } from '@/ntqqapi/entities'
|
||||||
|
import { uri2local } from '@/common/utils'
|
||||||
|
import { sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage'
|
||||||
|
|
||||||
|
interface Payload {
|
||||||
|
group_id: number | string
|
||||||
|
file: string
|
||||||
|
name: string
|
||||||
|
folder?: string
|
||||||
|
folder_id?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class UploadGroupFile extends BaseAction<Payload, null> {
|
||||||
|
actionName = ActionName.GoCQHTTP_UploadGroupFile
|
||||||
|
payloadSchema = Schema.object({
|
||||||
|
group_id: Schema.union([Number, String]).required(),
|
||||||
|
file: Schema.string().required(),
|
||||||
|
name: Schema.string(),
|
||||||
|
folder: Schema.string(),
|
||||||
|
folder_id: Schema.string()
|
||||||
|
})
|
||||||
|
|
||||||
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
|
const { success, errMsg, path, fileName } = await uri2local(payload.file)
|
||||||
|
if (!success) {
|
||||||
|
throw new Error(errMsg)
|
||||||
|
}
|
||||||
|
const file = await SendElementEntities.file(this.ctx, path, payload.name || fileName, payload.folder ?? payload.folder_id)
|
||||||
|
const peer = await createPeer(this.ctx, payload, CreatePeerMode.Group)
|
||||||
|
await sendMsg(this.ctx, peer, [file], [])
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
@ -1,32 +1,9 @@
|
|||||||
import { BaseAction } from '../BaseAction'
|
import { BaseAction, Schema } from '../BaseAction'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { SendElementEntities } from '@/ntqqapi/entities'
|
import { SendElementEntities } from '@/ntqqapi/entities'
|
||||||
import { uri2local } from '@/common/utils'
|
import { uri2local } from '@/common/utils'
|
||||||
import { sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage'
|
import { sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage'
|
||||||
|
|
||||||
interface UploadGroupFilePayload {
|
|
||||||
group_id: number | string
|
|
||||||
file: string
|
|
||||||
name: string
|
|
||||||
folder?: string
|
|
||||||
folder_id?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export class UploadGroupFile extends BaseAction<UploadGroupFilePayload, null> {
|
|
||||||
actionName = ActionName.GoCQHTTP_UploadGroupFile
|
|
||||||
|
|
||||||
protected async _handle(payload: UploadGroupFilePayload): Promise<null> {
|
|
||||||
const { success, errMsg, path, fileName } = await uri2local(payload.file)
|
|
||||||
if (!success) {
|
|
||||||
throw new Error(errMsg)
|
|
||||||
}
|
|
||||||
const file = await SendElementEntities.file(this.ctx, path, payload.name || fileName, payload.folder ?? payload.folder_id)
|
|
||||||
const peer = await createPeer(this.ctx, payload, CreatePeerMode.Group)
|
|
||||||
await sendMsg(this.ctx, peer, [file], [])
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface UploadPrivateFilePayload {
|
interface UploadPrivateFilePayload {
|
||||||
user_id: number | string
|
user_id: number | string
|
||||||
file: string
|
file: string
|
||||||
@ -35,6 +12,11 @@ interface UploadPrivateFilePayload {
|
|||||||
|
|
||||||
export class UploadPrivateFile extends BaseAction<UploadPrivateFilePayload, null> {
|
export class UploadPrivateFile extends BaseAction<UploadPrivateFilePayload, null> {
|
||||||
actionName = ActionName.GoCQHTTP_UploadPrivateFile
|
actionName = ActionName.GoCQHTTP_UploadPrivateFile
|
||||||
|
payloadSchema = Schema.object({
|
||||||
|
user_id: Schema.union([Number, String]).required(),
|
||||||
|
file: Schema.string().required(),
|
||||||
|
name: Schema.string()
|
||||||
|
})
|
||||||
|
|
||||||
protected async _handle(payload: UploadPrivateFilePayload): Promise<null> {
|
protected async _handle(payload: UploadPrivateFilePayload): Promise<null> {
|
||||||
const { success, errMsg, path, fileName } = await uri2local(payload.file)
|
const { success, errMsg, path, fileName } = await uri2local(payload.file)
|
@ -1,6 +1,6 @@
|
|||||||
import { OB11Group } from '../../types'
|
import { OB11Group } from '../../types'
|
||||||
import { OB11Entities } from '../../entities'
|
import { OB11Entities } from '../../entities'
|
||||||
import { BaseAction } from '../BaseAction'
|
import { BaseAction, Schema } from '../BaseAction'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
@ -9,14 +9,17 @@ interface Payload {
|
|||||||
|
|
||||||
class GetGroupInfo extends BaseAction<Payload, OB11Group> {
|
class GetGroupInfo extends BaseAction<Payload, OB11Group> {
|
||||||
actionName = ActionName.GetGroupInfo
|
actionName = ActionName.GetGroupInfo
|
||||||
|
payloadSchema = Schema.object({
|
||||||
|
group_id: Schema.union([Number, String]).required()
|
||||||
|
})
|
||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
const group = (await this.ctx.ntGroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString())
|
const groupCode = payload.group_id.toString()
|
||||||
|
const group = (await this.ctx.ntGroupApi.getGroups()).find(e => e.groupCode === groupCode)
|
||||||
if (group) {
|
if (group) {
|
||||||
return OB11Entities.group(group)
|
return OB11Entities.group(group)
|
||||||
} else {
|
|
||||||
throw `群${payload.group_id}不存在`
|
|
||||||
}
|
}
|
||||||
|
throw new Error(`群${payload.group_id}不存在`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import { BaseAction } from '../BaseAction'
|
import { BaseAction, Schema } from '../BaseAction'
|
||||||
import { OB11GroupMember } from '../../types'
|
import { OB11GroupMember } from '../../types'
|
||||||
import { OB11Entities } from '../../entities'
|
import { OB11Entities } from '../../entities'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { selfInfo } from '@/common/globalVars'
|
|
||||||
import { isNullable } from 'cosmokit'
|
import { isNullable } from 'cosmokit'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
@ -12,35 +11,26 @@ interface Payload {
|
|||||||
|
|
||||||
class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
||||||
actionName = ActionName.GetGroupMemberInfo
|
actionName = ActionName.GetGroupMemberInfo
|
||||||
|
payloadSchema = Schema.object({
|
||||||
|
group_id: Schema.union([Number, String]).required(),
|
||||||
|
user_id: Schema.union([Number, String]).required()
|
||||||
|
})
|
||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
const member = await this.ctx.ntGroupApi.getGroupMember(payload.group_id.toString(), payload.user_id.toString())
|
const groupCode = payload.group_id.toString()
|
||||||
|
const member = await this.ctx.ntGroupApi.getGroupMember(groupCode, payload.user_id.toString())
|
||||||
if (member) {
|
if (member) {
|
||||||
if (isNullable(member.sex)) {
|
if (isNullable(member.sex)) {
|
||||||
//log('获取群成员详细信息')
|
|
||||||
const info = await this.ctx.ntUserApi.getUserDetailInfo(member.uid)
|
const info = await this.ctx.ntUserApi.getUserDetailInfo(member.uid)
|
||||||
//log('群成员详细信息结果', info)
|
|
||||||
Object.assign(member, info)
|
Object.assign(member, info)
|
||||||
}
|
}
|
||||||
const ret = OB11Entities.groupMember(payload.group_id.toString(), member)
|
const ret = OB11Entities.groupMember(groupCode, member)
|
||||||
const self = await this.ctx.ntGroupApi.getGroupMember(payload.group_id.toString(), selfInfo.uid)
|
|
||||||
if (self?.role === 3 || self?.role === 4) {
|
|
||||||
const webGroupMembers = await this.ctx.ntWebApi.getGroupMembers(payload.group_id.toString())
|
|
||||||
const target = webGroupMembers.find(e => e?.uin && e.uin === ret.user_id)
|
|
||||||
if (target) {
|
|
||||||
ret.join_time = target.join_time
|
|
||||||
ret.last_sent_time = target.last_speak_time
|
|
||||||
ret.qage = target.qage
|
|
||||||
ret.level = target.lv.level.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const date = Math.round(Date.now() / 1000)
|
const date = Math.round(Date.now() / 1000)
|
||||||
ret.last_sent_time ||= Number(member.lastSpeakTime || date)
|
ret.last_sent_time ??= date
|
||||||
ret.join_time ||= Number(member.joinTime || date)
|
ret.join_time ??= date
|
||||||
return ret
|
return ret
|
||||||
} else {
|
|
||||||
throw `群成员${payload.user_id}不存在`
|
|
||||||
}
|
}
|
||||||
|
throw new Error(`群成员${payload.user_id}不存在`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
import { OB11GroupMember } from '../../types'
|
import { OB11GroupMember } from '../../types'
|
||||||
import { OB11Entities } from '../../entities'
|
import { OB11Entities } from '../../entities'
|
||||||
import { BaseAction } from '../BaseAction'
|
import { BaseAction, Schema } from '../BaseAction'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { selfInfo } from '@/common/globalVars'
|
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number | string
|
group_id: number | string
|
||||||
no_cache: boolean | string
|
no_cache?: boolean | string
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
||||||
actionName = ActionName.GetGroupMemberList
|
actionName = ActionName.GetGroupMemberList
|
||||||
|
payloadSchema = Schema.object({
|
||||||
|
group_id: Schema.union([Number, String]).required()
|
||||||
|
})
|
||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
const groupCode = payload.group_id.toString()
|
const groupCode = payload.group_id.toString()
|
||||||
@ -20,43 +22,14 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
|||||||
groupMembers = await this.ctx.ntGroupApi.getGroupMembers(groupCode)
|
groupMembers = await this.ctx.ntGroupApi.getGroupMembers(groupCode)
|
||||||
}
|
}
|
||||||
const groupMembersArr = Array.from(groupMembers.values())
|
const groupMembersArr = Array.from(groupMembers.values())
|
||||||
|
|
||||||
const _groupMembers = groupMembersArr.map(item => {
|
|
||||||
return OB11Entities.groupMember(groupCode, item)
|
|
||||||
})
|
|
||||||
|
|
||||||
const MemberMap: Map<number, OB11GroupMember> = new Map<number, OB11GroupMember>()
|
|
||||||
const date = Math.round(Date.now() / 1000)
|
const date = Math.round(Date.now() / 1000)
|
||||||
|
|
||||||
for (let i = 0, len = _groupMembers.length; i < len; i++) {
|
return groupMembersArr.map(item => {
|
||||||
// 保证基础数据有这个 同时避免群管插件过于依赖这个杀了
|
const member = OB11Entities.groupMember(groupCode, item)
|
||||||
_groupMembers[i].join_time ||= date
|
member.join_time ??= date
|
||||||
_groupMembers[i].last_sent_time ||= date
|
member.last_sent_time ??= date
|
||||||
MemberMap.set(_groupMembers[i].user_id, _groupMembers[i])
|
return member
|
||||||
}
|
})
|
||||||
|
|
||||||
const selfRole = groupMembers.get(selfInfo.uid)?.role
|
|
||||||
const isPrivilege = selfRole === 3 || selfRole === 4
|
|
||||||
|
|
||||||
if (isPrivilege) {
|
|
||||||
const webGroupMembers = await this.ctx.ntWebApi.getGroupMembers(groupCode)
|
|
||||||
for (let i = 0, len = webGroupMembers.length; i < len; i++) {
|
|
||||||
if (!webGroupMembers[i]?.uin) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
const MemberData = MemberMap.get(webGroupMembers[i]?.uin)
|
|
||||||
if (MemberData) {
|
|
||||||
if (MemberData.join_time === date) {
|
|
||||||
MemberData.join_time = webGroupMembers[i]?.join_time
|
|
||||||
MemberData.last_sent_time = webGroupMembers[i]?.last_speak_time
|
|
||||||
}
|
|
||||||
MemberData.qage = webGroupMembers[i]?.qage
|
|
||||||
MemberMap.set(webGroupMembers[i]?.uin, MemberData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Array.from(MemberMap.values())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import type Adapter from '../adapter'
|
import type Adapter from '../adapter'
|
||||||
import GetMsg from './msg/GetMsg'
|
import GetMsg from './msg/GetMsg'
|
||||||
import GetLoginInfo from './system/GetLoginInfo'
|
import GetLoginInfo from './system/GetLoginInfo'
|
||||||
import { GetFriendList, GetFriendWithCategory } from './user/GetFriendList'
|
import { GetFriendList } from './user/GetFriendList'
|
||||||
import GetGroupList from './group/GetGroupList'
|
import GetGroupList from './group/GetGroupList'
|
||||||
import GetGroupInfo from './group/GetGroupInfo'
|
import GetGroupInfo from './group/GetGroupInfo'
|
||||||
import GetGroupMemberList from './group/GetGroupMemberList'
|
import GetGroupMemberList from './group/GetGroupMemberList'
|
||||||
@ -37,7 +37,6 @@ import GetImage from './file/GetImage'
|
|||||||
import GetRecord from './file/GetRecord'
|
import GetRecord from './file/GetRecord'
|
||||||
import { MarkMsgAsRead } from './go-cqhttp/MarkMsgAsRead'
|
import { MarkMsgAsRead } from './go-cqhttp/MarkMsgAsRead'
|
||||||
import CleanCache from './system/CleanCache'
|
import CleanCache from './system/CleanCache'
|
||||||
import { UploadGroupFile, UploadPrivateFile } from './go-cqhttp/UploadFile'
|
|
||||||
import { GetConfigAction, SetConfigAction } from './llonebot/Config'
|
import { GetConfigAction, SetConfigAction } from './llonebot/Config'
|
||||||
import GetGroupAddRequest from './llonebot/GetGroupAddRequest'
|
import GetGroupAddRequest from './llonebot/GetGroupAddRequest'
|
||||||
import SetQQAvatar from './llonebot/SetQQAvatar'
|
import SetQQAvatar from './llonebot/SetQQAvatar'
|
||||||
@ -48,11 +47,11 @@ import { GetForwardMsg } from './go-cqhttp/GetForwardMsg'
|
|||||||
import { GetCookies } from './user/GetCookie'
|
import { GetCookies } from './user/GetCookie'
|
||||||
import { SetMsgEmojiLike } from './msg/SetMsgEmojiLike'
|
import { SetMsgEmojiLike } from './msg/SetMsgEmojiLike'
|
||||||
import { ForwardFriendSingleMsg, ForwardGroupSingleMsg } from './msg/ForwardSingleMsg'
|
import { ForwardFriendSingleMsg, ForwardGroupSingleMsg } from './msg/ForwardSingleMsg'
|
||||||
import { GetGroupEssence } from './group/GetGroupEssence'
|
import { GetEssenceMsgList } from './go-cqhttp/GetGroupEssence'
|
||||||
import { GetGroupHonorInfo } from './group/GetGroupHonorInfo'
|
import { GetGroupHonorInfo } from './group/GetGroupHonorInfo'
|
||||||
import { HandleQuickOperation } from './go-cqhttp/QuickOperation'
|
import { HandleQuickOperation } from './go-cqhttp/QuickOperation'
|
||||||
import { SetEssenceMsg } from './go-cqhttp/SetEssenceMsg'
|
import { SetEssenceMsg } from './go-cqhttp/SetEssenceMsg'
|
||||||
import { DelEssenceMsg } from './go-cqhttp/DelEssenceMsg'
|
import { DeleteEssenceMsg } from './go-cqhttp/DelEssenceMsg'
|
||||||
import { GetEvent } from './llonebot/GetEvent'
|
import { GetEvent } from './llonebot/GetEvent'
|
||||||
import { DelGroupFile } from './go-cqhttp/DelGroupFile'
|
import { DelGroupFile } from './go-cqhttp/DelGroupFile'
|
||||||
import { GetGroupSystemMsg } from './go-cqhttp/GetGroupSystemMsg'
|
import { GetGroupSystemMsg } from './go-cqhttp/GetGroupSystemMsg'
|
||||||
@ -67,6 +66,9 @@ import { FetchEmojiLike } from './llonebot/FetchEmojiLike'
|
|||||||
import { FetchCustomFace } from './llonebot/FetchCustomFace'
|
import { FetchCustomFace } from './llonebot/FetchCustomFace'
|
||||||
import { GetFriendMsgHistory } from './llonebot/GetFriendMsgHistory'
|
import { GetFriendMsgHistory } from './llonebot/GetFriendMsgHistory'
|
||||||
import { GetGroupFilesByFolder } from './go-cqhttp/GetGroupFilesByFolder'
|
import { GetGroupFilesByFolder } from './go-cqhttp/GetGroupFilesByFolder'
|
||||||
|
import { GetFriendWithCategory } from './llonebot/GetFriendWithCategory'
|
||||||
|
import { UploadGroupFile } from './go-cqhttp/UploadGroupFile'
|
||||||
|
import { UploadPrivateFile } from './go-cqhttp/UploadPrivateFile'
|
||||||
|
|
||||||
export function initActionMap(adapter: Adapter) {
|
export function initActionMap(adapter: Adapter) {
|
||||||
const actionHandlers = [
|
const actionHandlers = [
|
||||||
@ -117,7 +119,7 @@ export function initActionMap(adapter: Adapter) {
|
|||||||
new ForwardFriendSingleMsg(adapter),
|
new ForwardFriendSingleMsg(adapter),
|
||||||
new ForwardGroupSingleMsg(adapter),
|
new ForwardGroupSingleMsg(adapter),
|
||||||
// go-cqhttp
|
// go-cqhttp
|
||||||
new GetGroupEssence(adapter),
|
new GetEssenceMsgList(adapter),
|
||||||
new GetGroupHonorInfo(adapter),
|
new GetGroupHonorInfo(adapter),
|
||||||
new SendForwardMsg(adapter),
|
new SendForwardMsg(adapter),
|
||||||
new SendGroupForwardMsg(adapter),
|
new SendGroupForwardMsg(adapter),
|
||||||
@ -132,7 +134,7 @@ export function initActionMap(adapter: Adapter) {
|
|||||||
new GetForwardMsg(adapter),
|
new GetForwardMsg(adapter),
|
||||||
new HandleQuickOperation(adapter),
|
new HandleQuickOperation(adapter),
|
||||||
new SetEssenceMsg(adapter),
|
new SetEssenceMsg(adapter),
|
||||||
new DelEssenceMsg(adapter),
|
new DeleteEssenceMsg(adapter),
|
||||||
new DelGroupFile(adapter),
|
new DelGroupFile(adapter),
|
||||||
new GetGroupSystemMsg(adapter),
|
new GetGroupSystemMsg(adapter),
|
||||||
new CreateGroupFileFolder(adapter),
|
new CreateGroupFileFolder(adapter),
|
||||||
|
@ -43,9 +43,9 @@ export class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
|||||||
}
|
}
|
||||||
if (msgList.length === 0) throw new Error('未找到消息')
|
if (msgList.length === 0) throw new Error('未找到消息')
|
||||||
if (payload.reverseOrder) msgList.reverse()
|
if (payload.reverseOrder) msgList.reverse()
|
||||||
msgList.map(msg => {
|
for (const msg of msgList) {
|
||||||
msg.msgShortId = this.ctx.store.createMsgShortId({ chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId)
|
msg.msgShortId = this.ctx.store.createMsgShortId({ chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId)
|
||||||
})
|
}
|
||||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Entities.message(this.ctx, msg)))
|
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Entities.message(this.ctx, msg)))
|
||||||
return { messages: filterNullable(ob11MsgList) }
|
return { messages: filterNullable(ob11MsgList) }
|
||||||
}
|
}
|
||||||
|
17
src/onebot11/action/llonebot/GetFriendWithCategory.ts
Normal file
17
src/onebot11/action/llonebot/GetFriendWithCategory.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { BaseAction } from '../BaseAction'
|
||||||
|
import { OB11User } from '../../types'
|
||||||
|
import { OB11Entities } from '../../entities'
|
||||||
|
import { ActionName } from '../types'
|
||||||
|
import { getBuildVersion } from '@/common/utils'
|
||||||
|
|
||||||
|
export class GetFriendWithCategory extends BaseAction<void, OB11User[]> {
|
||||||
|
actionName = ActionName.GetFriendsWithCategory
|
||||||
|
|
||||||
|
protected async _handle() {
|
||||||
|
if (getBuildVersion() >= 26702) {
|
||||||
|
return OB11Entities.friendsV2(await this.ctx.ntFriendApi.getBuddyV2ExWithCate(true))
|
||||||
|
} else {
|
||||||
|
throw new Error('this ntqq version not support, must be 26702 or later')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
import { BaseAction } from '../BaseAction'
|
import { BaseAction } from '../BaseAction'
|
||||||
import { GroupNotify, GroupNotifyStatus } from '@/ntqqapi/types'
|
import { GroupNotifyStatus } from '@/ntqqapi/types'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
|
|
||||||
interface OB11GroupRequestNotify {
|
interface OB11GroupRequestNotify {
|
||||||
@ -13,7 +13,7 @@ export default class GetGroupAddRequest extends BaseAction<null, OB11GroupReques
|
|||||||
|
|
||||||
protected async _handle(): Promise<OB11GroupRequestNotify[]> {
|
protected async _handle(): Promise<OB11GroupRequestNotify[]> {
|
||||||
const data = await this.ctx.ntGroupApi.getGroupIgnoreNotifies()
|
const data = await this.ctx.ntGroupApi.getGroupIgnoreNotifies()
|
||||||
const notifies: GroupNotify[] = data.notifies.filter((notify) => notify.status === GroupNotifyStatus.KUNHANDLE)
|
const notifies = data.notifies.filter(notify => notify.status === GroupNotifyStatus.KUNHANDLE)
|
||||||
const returnData: OB11GroupRequestNotify[] = []
|
const returnData: OB11GroupRequestNotify[] = []
|
||||||
for (const notify of notifies) {
|
for (const notify of notifies) {
|
||||||
const uin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid)
|
const uin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid)
|
||||||
|
@ -8,10 +8,10 @@ export class GetProfileLike extends BaseAction<void, Dict[]> {
|
|||||||
|
|
||||||
async _handle() {
|
async _handle() {
|
||||||
const ret = await this.ctx.ntUserApi.getProfileLike(selfInfo.uid)
|
const ret = await this.ctx.ntUserApi.getProfileLike(selfInfo.uid)
|
||||||
const listdata = ret.info.userLikeInfos[0].favoriteInfo.userInfos
|
const data = ret.info.userLikeInfos[0].favoriteInfo.userInfos
|
||||||
for (const item of listdata) {
|
for (const item of data) {
|
||||||
item.uin = Number(await this.ctx.ntUserApi.getUinByUid(item.uid)) || 0
|
item.uin = Number(await this.ctx.ntUserApi.getUinByUid(item.uid)) || 0
|
||||||
}
|
}
|
||||||
return listdata
|
return data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import fs from 'node:fs'
|
import { unlink } from 'node:fs/promises'
|
||||||
import { BaseAction } from '../BaseAction'
|
import { BaseAction } from '../BaseAction'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { checkFileReceived, uri2local } from '../../../common/utils/file'
|
import { checkFileReceived, uri2local } from '../../../common/utils/file'
|
||||||
@ -13,18 +13,17 @@ export default class SetAvatar extends BaseAction<Payload, null> {
|
|||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const { path, isLocal, errMsg } = await uri2local(payload.file)
|
const { path, isLocal, errMsg } = await uri2local(payload.file)
|
||||||
if (errMsg) {
|
if (errMsg) {
|
||||||
throw `头像${payload.file}设置失败,file字段可能格式不正确`
|
throw new Error(errMsg)
|
||||||
}
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
await checkFileReceived(path, 5000) // 文件不存在QQ会崩溃,需要提前判断
|
await checkFileReceived(path, 5000) // 文件不存在QQ会崩溃,需要提前判断
|
||||||
const ret = await this.ctx.ntUserApi.setQQAvatar(path)
|
const ret = await this.ctx.ntUserApi.setQQAvatar(path)
|
||||||
if (!isLocal) {
|
if (!isLocal) {
|
||||||
fs.unlink(path, () => { })
|
unlink(path)
|
||||||
}
|
}
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
throw `头像${payload.file}设置失败,api无返回`
|
throw `头像${payload.file}设置失败,api无返回`
|
||||||
}
|
}
|
||||||
// log(`头像设置返回:${JSON.stringify(ret)}`)
|
|
||||||
if ((ret.result as number) === 1004022) {
|
if ((ret.result as number) === 1004022) {
|
||||||
throw `头像${payload.file}设置失败,文件可能不是图片格式`
|
throw `头像${payload.file}设置失败,文件可能不是图片格式`
|
||||||
} else if (ret.result !== 0) {
|
} else if (ret.result !== 0) {
|
||||||
@ -32,7 +31,7 @@ export default class SetAvatar extends BaseAction<Payload, null> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!isLocal) {
|
if (!isLocal) {
|
||||||
fs.unlink(path, () => { })
|
unlink(path)
|
||||||
}
|
}
|
||||||
throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在`
|
throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在`
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,24 @@
|
|||||||
import { BaseAction } from '../BaseAction'
|
import { BaseAction, Schema } from '../BaseAction'
|
||||||
import { OB11User } from '../../types'
|
import { OB11User } from '../../types'
|
||||||
import { OB11Entities } from '../../entities'
|
import { OB11Entities } from '../../entities'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { getBuildVersion } from '@/common/utils'
|
import { getBuildVersion } from '@/common/utils'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
no_cache: boolean | string
|
no_cache: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GetFriendList extends BaseAction<Payload, OB11User[]> {
|
export class GetFriendList extends BaseAction<Payload, OB11User[]> {
|
||||||
actionName = ActionName.GetFriendList
|
actionName = ActionName.GetFriendList
|
||||||
|
payloadSchema = Schema.object({
|
||||||
|
no_cache: Schema.boolean().default(false)
|
||||||
|
})
|
||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
const refresh = payload?.no_cache === true || payload?.no_cache === 'true'
|
const refresh = payload.no_cache
|
||||||
if (getBuildVersion() >= 26702) {
|
if (getBuildVersion() >= 26702) {
|
||||||
return OB11Entities.friendsV2(await this.ctx.ntFriendApi.getBuddyV2(refresh))
|
return OB11Entities.friendsV2(await this.ctx.ntFriendApi.getBuddyV2(refresh))
|
||||||
}
|
}
|
||||||
return OB11Entities.friends(await this.ctx.ntFriendApi.getFriends())
|
return OB11Entities.friends(await this.ctx.ntFriendApi.getFriends())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// extend
|
|
||||||
export class GetFriendWithCategory extends BaseAction<void, OB11User[]> {
|
|
||||||
actionName = ActionName.GetFriendsWithCategory
|
|
||||||
|
|
||||||
protected async _handle() {
|
|
||||||
if (getBuildVersion() >= 26702) {
|
|
||||||
//全新逻辑
|
|
||||||
return OB11Entities.friendsV2(await this.ctx.ntFriendApi.getBuddyV2ExWithCate(true))
|
|
||||||
} else {
|
|
||||||
throw new Error('this ntqq version not support, must be 26702 or later')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user