mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: 新增主动获取被过滤的加群通知
This commit is contained in:
parent
b3ea8fbc0c
commit
fccb0852aa
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 4,
|
"manifest_version": 4,
|
||||||
"type": "extension",
|
"type": "extension",
|
||||||
"name": "LLOneBot v3.14.1",
|
"name": "LLOneBot v3.15.0",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
||||||
"version": "3.14.1",
|
"version": "3.15.0",
|
||||||
"icon": "./icon.jpg",
|
"icon": "./icon.jpg",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
import {type FileCache, type LLOneBotError} from './types'
|
import {type FileCache, type LLOneBotError} from './types'
|
||||||
import {dbUtil} from "./db";
|
import {dbUtil} from "./db";
|
||||||
import {raw} from "express";
|
import {raw} from "express";
|
||||||
import {log} from "./utils";
|
import {isNumeric, log} from "./utils";
|
||||||
|
|
||||||
export const selfInfo: SelfInfo = {
|
export const selfInfo: SelfInfo = {
|
||||||
uid: '',
|
uid: '',
|
||||||
@ -28,9 +28,9 @@ export const llonebotError: LLOneBotError = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function getFriend(qq: string, uid: string = ""): Promise<Friend | undefined> {
|
export async function getFriend(uinOrUid: string): Promise<Friend | undefined> {
|
||||||
let filterKey = uid ? "uid" : "uin"
|
let filterKey = isNumeric(uinOrUid) ? "uin" : "uid"
|
||||||
let filterValue = uid ? uid : qq
|
let filterValue = uinOrUid
|
||||||
let friend = friends.find(friend => friend[filterKey] === filterValue.toString())
|
let friend = friends.find(friend => friend[filterKey] === filterValue.toString())
|
||||||
// if (!friend) {
|
// if (!friend) {
|
||||||
// try {
|
// try {
|
||||||
@ -59,15 +59,13 @@ export async function getGroup(qq: string): Promise<Group | undefined> {
|
|||||||
return group
|
return group
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGroupMember(groupQQ: string | number, memberQQ: string | number, memberUid: string = null) {
|
export async function getGroupMember(groupQQ: string | number, memberUinOrUid: string | number) {
|
||||||
groupQQ = groupQQ.toString()
|
groupQQ = groupQQ.toString()
|
||||||
if (memberQQ) {
|
memberUinOrUid = memberUinOrUid.toString()
|
||||||
memberQQ = memberQQ.toString()
|
|
||||||
}
|
|
||||||
const group = await getGroup(groupQQ)
|
const group = await getGroup(groupQQ)
|
||||||
if (group) {
|
if (group) {
|
||||||
const filterKey = memberQQ ? "uin" : "uid"
|
const filterKey = isNumeric(memberUinOrUid) ? "uin" : "uid"
|
||||||
const filterValue = memberQQ ? memberQQ : memberUid
|
const filterValue = memberUinOrUid
|
||||||
let filterFunc: (member: GroupMember) => boolean = member => member[filterKey] === filterValue
|
let filterFunc: (member: GroupMember) => boolean = member => member[filterKey] === filterValue
|
||||||
let member = group.members?.find(filterFunc)
|
let member = group.members?.find(filterFunc)
|
||||||
if (!member) {
|
if (!member) {
|
||||||
|
@ -32,6 +32,11 @@ function truncateString(obj: any, maxLength = 500) {
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isNumeric(str: string) {
|
||||||
|
return /^\d+$/.test(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function log(...msg: any[]) {
|
export function log(...msg: any[]) {
|
||||||
if (!getConfigUtil().getConfig().log) {
|
if (!getConfigUtil().getConfig().log) {
|
||||||
return //console.log(...msg);
|
return //console.log(...msg);
|
||||||
@ -225,8 +230,7 @@ export async function encodeSilk(filePath: string) {
|
|||||||
const pcm = fs.readFileSync(filePath);
|
const pcm = fs.readFileSync(filePath);
|
||||||
const silk = await encode(pcm, 0);
|
const silk = await encode(pcm, 0);
|
||||||
fs.writeFileSync(pttPath, silk.data);
|
fs.writeFileSync(pttPath, silk.data);
|
||||||
// fs.unlink(wavPath, (err) => {
|
fs.unlink(wavPath, (err) => { });
|
||||||
// });
|
|
||||||
log(`语音文件${filePath}转换成功!`, pttPath)
|
log(`语音文件${filePath}转换成功!`, pttPath)
|
||||||
return {
|
return {
|
||||||
converted: true,
|
converted: true,
|
||||||
|
@ -148,7 +148,7 @@ function onLoad() {
|
|||||||
let operatorId = message.senderUin
|
let operatorId = message.senderUin
|
||||||
for (const element of message.elements) {
|
for (const element of message.elements) {
|
||||||
const operatorUid = element.grayTipElement?.revokeElement.operatorUid
|
const operatorUid = element.grayTipElement?.revokeElement.operatorUid
|
||||||
const operator = await getGroupMember(message.peerUin, null, operatorUid)
|
const operator = await getGroupMember(message.peerUin, operatorUid)
|
||||||
operatorId = operator.uin
|
operatorId = operator.uin
|
||||||
}
|
}
|
||||||
const groupRecallEvent = new OB11GroupRecallNoticeEvent(
|
const groupRecallEvent = new OB11GroupRecallNoticeEvent(
|
||||||
@ -215,7 +215,7 @@ function onLoad() {
|
|||||||
// member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid);
|
// member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid);
|
||||||
// }
|
// }
|
||||||
if ([GroupNotifyTypes.ADMIN_SET, GroupNotifyTypes.ADMIN_UNSET].includes(notify.type)) {
|
if ([GroupNotifyTypes.ADMIN_SET, GroupNotifyTypes.ADMIN_UNSET].includes(notify.type)) {
|
||||||
const member1 = await getGroupMember(notify.group.groupCode, null, notify.user1.uid);
|
const member1 = await getGroupMember(notify.group.groupCode, notify.user1.uid);
|
||||||
log("有管理员变动通知");
|
log("有管理员变动通知");
|
||||||
refreshGroupMembers(notify.group.groupCode).then()
|
refreshGroupMembers(notify.group.groupCode).then()
|
||||||
let groupAdminNoticeEvent = new OB11GroupAdminNoticeEvent()
|
let groupAdminNoticeEvent = new OB11GroupAdminNoticeEvent()
|
||||||
@ -253,7 +253,7 @@ function onLoad() {
|
|||||||
log("收到邀请我加群通知")
|
log("收到邀请我加群通知")
|
||||||
let groupInviteEvent = new OB11GroupRequestEvent();
|
let groupInviteEvent = new OB11GroupRequestEvent();
|
||||||
groupInviteEvent.group_id = parseInt(notify.group.groupCode);
|
groupInviteEvent.group_id = parseInt(notify.group.groupCode);
|
||||||
let user_id = (await getFriend("", notify.user2.uid))?.uin
|
let user_id = (await getFriend(notify.user2.uid))?.uin
|
||||||
if (!user_id) {
|
if (!user_id) {
|
||||||
user_id = (await NTQQApi.getUserDetailInfo(notify.user2.uid))?.uin
|
user_id = (await NTQQApi.getUserDetailInfo(notify.user2.uid))?.uin
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {ipcMain} from "electron";
|
import {BrowserWindow, ipcMain} from "electron";
|
||||||
import {hookApiCallbacks, ReceiveCmd, registerReceiveHook, removeReceiveHook} from "./hook";
|
import {hookApiCallbacks, ReceiveCmd, registerReceiveHook, removeReceiveHook} from "./hook";
|
||||||
import {log, sleep} from "../common/utils";
|
import {log, sleep} from "../common/utils";
|
||||||
import {
|
import {
|
||||||
@ -42,6 +42,7 @@ export enum NTQQApiClass {
|
|||||||
NT_API = "ns-ntApi",
|
NT_API = "ns-ntApi",
|
||||||
FS_API = "ns-FsApi",
|
FS_API = "ns-FsApi",
|
||||||
OS_API = "ns-OsApi",
|
OS_API = "ns-OsApi",
|
||||||
|
WINDOW_API = "ns-WindowApi",
|
||||||
HOTUPDATE_API = "ns-HotUpdateApi",
|
HOTUPDATE_API = "ns-HotUpdateApi",
|
||||||
BUSINESS_API = "ns-BusinessApi",
|
BUSINESS_API = "ns-BusinessApi",
|
||||||
GLOBAL_DATA = "ns-GlobalDataApi"
|
GLOBAL_DATA = "ns-GlobalDataApi"
|
||||||
@ -93,6 +94,8 @@ export enum NTQQApiMethod {
|
|||||||
CACHE_CHAT_GET = 'nodeIKernelStorageCleanService/getChatCacheInfo',
|
CACHE_CHAT_GET = 'nodeIKernelStorageCleanService/getChatCacheInfo',
|
||||||
CACHE_FILE_GET = 'nodeIKernelStorageCleanService/getFileCacheInfo',
|
CACHE_FILE_GET = 'nodeIKernelStorageCleanService/getFileCacheInfo',
|
||||||
CACHE_CHAT_CLEAR = 'nodeIKernelStorageCleanService/clearChatCacheInfo',
|
CACHE_CHAT_CLEAR = 'nodeIKernelStorageCleanService/clearChatCacheInfo',
|
||||||
|
|
||||||
|
OPEN_EXTRA_WINDOW = 'openExternalWindow',
|
||||||
}
|
}
|
||||||
|
|
||||||
enum NTQQApiChannel {
|
enum NTQQApiChannel {
|
||||||
@ -209,6 +212,7 @@ export class NTQQApi {
|
|||||||
args: [path]
|
args: [path]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async likeFriend(uid: string, count = 1) {
|
static async likeFriend(uid: string, count = 1) {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.LIKE_FRIEND,
|
methodName: NTQQApiMethod.LIKE_FRIEND,
|
||||||
@ -256,7 +260,11 @@ export class NTQQApi {
|
|||||||
null
|
null
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
return result.info
|
const info = result.info
|
||||||
|
if (info?.uin) {
|
||||||
|
uidMaps[info.uid] = info.uin
|
||||||
|
}
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getFriends(forced = false) {
|
static async getFriends(forced = false) {
|
||||||
@ -482,8 +490,7 @@ export class NTQQApi {
|
|||||||
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
||||||
return sentMessage
|
return sentMessage
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
return sentMessage
|
return sentMessage
|
||||||
}
|
}
|
||||||
// log(`给${peerUid}发送消息成功`)
|
// log(`给${peerUid}发送消息成功`)
|
||||||
@ -525,6 +532,7 @@ export class NTQQApi {
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||||
const msgInfos = msgIds.map(id => {
|
const msgInfos = msgIds.map(id => {
|
||||||
return {msgId: id, senderShowName: selfInfo.nick}
|
return {msgId: id, senderShowName: selfInfo.nick}
|
||||||
@ -596,6 +604,29 @@ export class NTQQApi {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getGroupIgnoreNotifies() {
|
||||||
|
await NTQQApi.getGroupNotifies();
|
||||||
|
const result = callNTQQApi<GroupNotifies>({
|
||||||
|
className: NTQQApiClass.WINDOW_API,
|
||||||
|
methodName: NTQQApiMethod.OPEN_EXTRA_WINDOW,
|
||||||
|
cbCmd: ReceiveCmd.GROUP_NOTIFY,
|
||||||
|
afterFirstCmd: false,
|
||||||
|
args: [
|
||||||
|
"GroupNotifyFilterWindow"
|
||||||
|
]
|
||||||
|
})
|
||||||
|
// 关闭窗口
|
||||||
|
setTimeout(() => {
|
||||||
|
for (const w of BrowserWindow.getAllWindows()) {
|
||||||
|
// log("close window", w.webContents.getURL())
|
||||||
|
if (w.webContents.getURL().indexOf("#/notify-filter/") != -1) {
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||||
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
||||||
if (!notify) {
|
if (!notify) {
|
||||||
|
@ -392,11 +392,17 @@ export interface GroupNotifies {
|
|||||||
notifies: GroupNotify[],
|
notifies: GroupNotify[],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum GroupNotifyStatus {
|
||||||
|
IGNORE = 0,
|
||||||
|
WAIT_HANDLE = 1,
|
||||||
|
APPROVE = 2,
|
||||||
|
REJECT = 3
|
||||||
|
}
|
||||||
export interface GroupNotify {
|
export interface GroupNotify {
|
||||||
time: number; // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify
|
time: number; // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify
|
||||||
seq: string, // 唯一标识符,转成数字再除以1000应该就是时间戳?
|
seq: string, // 唯一标识符,转成数字再除以1000应该就是时间戳?
|
||||||
type: GroupNotifyTypes,
|
type: GroupNotifyTypes,
|
||||||
status: 0, // 未知
|
status: GroupNotifyStatus, // 0是已忽略?,1是未处理,2是已同意
|
||||||
group: { groupCode: string, groupName: string },
|
group: { groupCode: string, groupName: string },
|
||||||
user1: { uid: string, nickName: string }, // 被设置管理员的人
|
user1: { uid: string, nickName: string }, // 被设置管理员的人
|
||||||
user2: { uid: string, nickName: string }, // 操作者
|
user2: { uid: string, nickName: string }, // 操作者
|
||||||
|
@ -34,11 +34,13 @@ import GoCQHTTPMarkMsgAsRead from "./MarkMsgAsRead";
|
|||||||
import CleanCache from "./CleanCache";
|
import CleanCache from "./CleanCache";
|
||||||
import GoCQHTTPUploadGroupFile from "./go-cqhttp/UploadGroupFile";
|
import GoCQHTTPUploadGroupFile from "./go-cqhttp/UploadGroupFile";
|
||||||
import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
|
import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
|
||||||
|
import GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
new Debug(),
|
new Debug(),
|
||||||
new GetConfigAction(),
|
new GetConfigAction(),
|
||||||
new SetConfigAction(),
|
new SetConfigAction(),
|
||||||
|
new GetGroupAddRequest(),
|
||||||
// onebot11
|
// onebot11
|
||||||
new SendLike(),
|
new SendLike(),
|
||||||
new GetMsg(),
|
new GetMsg(),
|
||||||
|
32
src/onebot11/action/llonebot/GetGroupAddRequest.ts
Normal file
32
src/onebot11/action/llonebot/GetGroupAddRequest.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import {GroupNotify, GroupNotifyStatus} from "../../../ntqqapi/types";
|
||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import {NTQQApi} from "../../../ntqqapi/ntcall";
|
||||||
|
import {uidMaps} from "../../../common/data";
|
||||||
|
import {log} from "../../../common/utils";
|
||||||
|
|
||||||
|
interface OB11GroupRequestNotify {
|
||||||
|
group_id: number,
|
||||||
|
user_id: number,
|
||||||
|
flag: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class GetGroupAddRequest extends BaseAction<null, OB11GroupRequestNotify[]> {
|
||||||
|
actionName = ActionName.GetGroupIgnoreAddRequest
|
||||||
|
|
||||||
|
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[]> {
|
||||||
|
const data = await NTQQApi.getGroupIgnoreNotifies()
|
||||||
|
log(data);
|
||||||
|
let notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE);
|
||||||
|
let returnData: OB11GroupRequestNotify[] = []
|
||||||
|
for (const notify of notifies) {
|
||||||
|
const uin = uidMaps[notify.user1.uid] || (await NTQQApi.getUserDetailInfo(notify.user1.uid))?.uin
|
||||||
|
returnData.push({
|
||||||
|
group_id: parseInt(notify.group.groupCode),
|
||||||
|
user_id: parseInt(uin),
|
||||||
|
flag: notify.seq
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return returnData;
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ export interface InvalidCheckResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum ActionName {
|
export enum ActionName {
|
||||||
|
GetGroupIgnoreAddRequest = "get_group_ignore_add_request",
|
||||||
GetConfig = "get_config",
|
GetConfig = "get_config",
|
||||||
SetConfig = "set_config",
|
SetConfig = "set_config",
|
||||||
Debug = "llonebot_debug",
|
Debug = "llonebot_debug",
|
||||||
|
@ -1 +1 @@
|
|||||||
export const version = "3.14.1"
|
export const version = "3.15.0"
|
Loading…
x
Reference in New Issue
Block a user