mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Merge branch 'dev'
# Conflicts: # src/main/main.ts # src/version.ts
This commit is contained in:
commit
e716c28e9a
@ -44,6 +44,7 @@ export class ConfigUtil {
|
|||||||
reportSelfMessage: false,
|
reportSelfMessage: false,
|
||||||
autoDeleteFile: false,
|
autoDeleteFile: false,
|
||||||
autoDeleteFileSecond: 60,
|
autoDeleteFileSecond: 60,
|
||||||
|
enablePoke: false
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!fs.existsSync(this.configPath)) {
|
if (!fs.existsSync(this.configPath)) {
|
||||||
|
@ -4,6 +4,7 @@ import {DATA_DIR, log} from "./utils";
|
|||||||
import {selfInfo} from "./data";
|
import {selfInfo} from "./data";
|
||||||
import {FileCache} from "./types";
|
import {FileCache} from "./types";
|
||||||
|
|
||||||
|
type ReceiveTempUinMap = Record<string, string>;
|
||||||
|
|
||||||
class DBUtil {
|
class DBUtil {
|
||||||
public readonly DB_KEY_PREFIX_MSG_ID = "msg_id_";
|
public readonly DB_KEY_PREFIX_MSG_ID = "msg_id_";
|
||||||
@ -11,8 +12,9 @@ class DBUtil {
|
|||||||
public readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
public readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
||||||
public readonly DB_KEY_PREFIX_FILE = "file_";
|
public readonly DB_KEY_PREFIX_FILE = "file_";
|
||||||
public readonly DB_KEY_PREFIX_GROUP_NOTIFY = "group_notify_";
|
public readonly DB_KEY_PREFIX_GROUP_NOTIFY = "group_notify_";
|
||||||
|
private readonly DB_KEY_RECEIVED_TEMP_UIN_MAP = "received_temp_uin_map";
|
||||||
public db: Level;
|
public db: Level;
|
||||||
public cache: Record<string, RawMessage | string | FileCache | GroupNotify> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
public cache: Record<string, RawMessage | string | FileCache | GroupNotify | ReceiveTempUinMap> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
||||||
private currentShortId: number;
|
private currentShortId: number;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -67,6 +69,17 @@ class DBUtil {
|
|||||||
}, expiredMilliSecond)
|
}, expiredMilliSecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getReceivedTempUinMap(): Promise<ReceiveTempUinMap> {
|
||||||
|
try{
|
||||||
|
this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] = JSON.parse(await this.db.get(this.DB_KEY_RECEIVED_TEMP_UIN_MAP));
|
||||||
|
}catch (e) {
|
||||||
|
}
|
||||||
|
return (this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] || {}) as ReceiveTempUinMap;
|
||||||
|
}
|
||||||
|
public setReceivedTempUinMap(data: ReceiveTempUinMap) {
|
||||||
|
this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] = data;
|
||||||
|
this.db.put(this.DB_KEY_RECEIVED_TEMP_UIN_MAP, JSON.stringify(data)).then();
|
||||||
|
}
|
||||||
private addCache(msg: RawMessage) {
|
private addCache(msg: RawMessage) {
|
||||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
||||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + msg.msgShortId
|
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + msg.msgShortId
|
||||||
|
@ -24,6 +24,7 @@ export interface Config {
|
|||||||
autoDeleteFile?: boolean
|
autoDeleteFile?: boolean
|
||||||
autoDeleteFileSecond?: number
|
autoDeleteFileSecond?: number
|
||||||
ffmpeg?: string // ffmpeg路径
|
ffmpeg?: string // ffmpeg路径
|
||||||
|
enablePoke?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LLOneBotError {
|
export interface LLOneBotError {
|
||||||
|
@ -21,7 +21,7 @@ import {
|
|||||||
getGroupMember,
|
getGroupMember,
|
||||||
llonebotError,
|
llonebotError,
|
||||||
refreshGroupMembers,
|
refreshGroupMembers,
|
||||||
selfInfo
|
selfInfo, uidMaps
|
||||||
} from "../common/data";
|
} from "../common/data";
|
||||||
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook} from "../ntqqapi/hook";
|
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook} from "../ntqqapi/hook";
|
||||||
import {OB11Constructor} from "../onebot11/constructor";
|
import {OB11Constructor} from "../onebot11/constructor";
|
||||||
@ -115,11 +115,18 @@ function onLoad() {
|
|||||||
OB11Constructor.message(message).then((msg) => {
|
OB11Constructor.message(message).then((msg) => {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
msg.raw = message;
|
msg.raw = message;
|
||||||
|
} else {
|
||||||
|
if (msg.message.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const isSelfMsg = msg.user_id.toString() == selfInfo.uin
|
const isSelfMsg = msg.user_id.toString() == selfInfo.uin
|
||||||
if (isSelfMsg && !reportSelfMessage) {
|
if (isSelfMsg && !reportSelfMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (isSelfMsg) {
|
||||||
|
msg.target_id = parseInt(message.peerUin);
|
||||||
|
}
|
||||||
postOB11Event(msg);
|
postOB11Event(msg);
|
||||||
// log("post msg", msg)
|
// log("post msg", msg)
|
||||||
}).catch(e => log("constructMessage error: ", e.stack.toString()));
|
}).catch(e => log("constructMessage error: ", e.stack.toString()));
|
||||||
@ -133,17 +140,21 @@ function onLoad() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function startReceiveHook() {
|
async function startReceiveHook() {
|
||||||
registerPokeHandler((id, isGroup) => {
|
if (getConfigUtil().getConfig().enablePoke) {
|
||||||
log(`收到戳一戳消息了!是否群聊:${isGroup},id:${id}`)
|
registerPokeHandler((id, isGroup) => {
|
||||||
let pokeEvent: OB11FriendPokeEvent | OB11GroupPokeEvent;
|
log(`收到戳一戳消息了!是否群聊:${isGroup},id:${id}`)
|
||||||
if (isGroup) {
|
let pokeEvent: OB11FriendPokeEvent | OB11GroupPokeEvent;
|
||||||
pokeEvent = new OB11GroupPokeEvent(parseInt(id));
|
if (isGroup) {
|
||||||
}else{
|
pokeEvent = new OB11GroupPokeEvent(parseInt(id));
|
||||||
pokeEvent = new OB11FriendPokeEvent(parseInt(id));
|
} else {
|
||||||
}
|
pokeEvent = new OB11FriendPokeEvent(parseInt(id));
|
||||||
postOB11Event(pokeEvent);
|
}
|
||||||
})
|
postOB11Event(pokeEvent);
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], async (payload) => {
|
})
|
||||||
|
}
|
||||||
|
registerReceiveHook<{
|
||||||
|
msgList: Array<RawMessage>
|
||||||
|
}>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], async (payload) => {
|
||||||
try {
|
try {
|
||||||
await postReceiveMsg(payload.msgList);
|
await postReceiveMsg(payload.msgList);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -316,7 +327,13 @@ function onLoad() {
|
|||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
log("llonebot pid", process.pid)
|
log("llonebot pid", process.pid)
|
||||||
|
|
||||||
startTime = Date.now();
|
startTime = Date.now();
|
||||||
|
dbUtil.getReceivedTempUinMap().then(m=>{
|
||||||
|
for (const [key, value] of Object.entries(m)) {
|
||||||
|
uidMaps[value] = key;
|
||||||
|
}
|
||||||
|
})
|
||||||
startReceiveHook().then();
|
startReceiveHook().then();
|
||||||
NTQQGroupApi.getGroups(true).then()
|
NTQQGroupApi.getGroups(true).then()
|
||||||
const config = getConfigUtil().getConfig()
|
const config = getConfigUtil().getConfig()
|
||||||
|
@ -3,7 +3,7 @@ import {getConfigUtil, log, sleep} from "../common/utils";
|
|||||||
import {NTQQApiClass} from "./ntcall";
|
import {NTQQApiClass} from "./ntcall";
|
||||||
import {NTQQMsgApi, sendMessagePool} from "./api/msg"
|
import {NTQQMsgApi, sendMessagePool} from "./api/msg"
|
||||||
import {ChatType, Group, RawMessage, User} from "./types";
|
import {ChatType, Group, RawMessage, User} from "./types";
|
||||||
import {friends, groups, selfInfo, tempGroupCodeMap} from "../common/data";
|
import {friends, groups, receivedTempUinMap, selfInfo, tempGroupCodeMap, uidMaps} from "../common/data";
|
||||||
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
||||||
import {v4 as uuidv4} from "uuid"
|
import {v4 as uuidv4} from "uuid"
|
||||||
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
||||||
@ -249,8 +249,26 @@ registerReceiveHook<{
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 新消息
|
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], (payload) => {
|
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], (payload) => {
|
||||||
|
// 保存一下uid
|
||||||
|
for (const message of payload.msgList) {
|
||||||
|
const uid = message.senderUid;
|
||||||
|
const uin = message.senderUin;
|
||||||
|
if (uid && uin) {
|
||||||
|
if (message.chatType === ChatType.temp){
|
||||||
|
dbUtil.getReceivedTempUinMap().then(receivedTempUinMap=>{
|
||||||
|
if (!receivedTempUinMap[uin]){
|
||||||
|
receivedTempUinMap[uin] = uid;
|
||||||
|
dbUtil.setReceivedTempUinMap(receivedTempUinMap)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
uidMaps[uid] = uin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 自动清理新消息文件
|
||||||
const {autoDeleteFile} = getConfigUtil().getConfig();
|
const {autoDeleteFile} = getConfigUtil().getConfig();
|
||||||
if (!autoDeleteFile) {
|
if (!autoDeleteFile) {
|
||||||
return
|
return
|
||||||
|
@ -7,7 +7,14 @@ import {
|
|||||||
SendArkElement,
|
SendArkElement,
|
||||||
SendMessageElement
|
SendMessageElement
|
||||||
} from "../../ntqqapi/types";
|
} from "../../ntqqapi/types";
|
||||||
import {friends, getFriend, getGroup, getGroupMember, getUidByUin, selfInfo,} from "../../common/data";
|
import {
|
||||||
|
friends,
|
||||||
|
getFriend,
|
||||||
|
getGroup,
|
||||||
|
getGroupMember,
|
||||||
|
getUidByUin,
|
||||||
|
selfInfo,
|
||||||
|
} from "../../common/data";
|
||||||
import {
|
import {
|
||||||
OB11MessageCustomMusic,
|
OB11MessageCustomMusic,
|
||||||
OB11MessageData,
|
OB11MessageData,
|
||||||
@ -87,7 +94,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
if (payload.user_id && payload.message_type !== "group") {
|
if (payload.user_id && payload.message_type !== "group") {
|
||||||
if (!(await getFriend(payload.user_id))) {
|
if (!(await getFriend(payload.user_id))) {
|
||||||
if (!ALLOW_SEND_TEMP_MSG) {
|
if (!ALLOW_SEND_TEMP_MSG && !(await dbUtil.getReceivedTempUinMap())[payload.user_id.toString()]) {
|
||||||
return {
|
return {
|
||||||
valid: false,
|
valid: false,
|
||||||
message: `不能发送临时消息`
|
message: `不能发送临时消息`
|
||||||
|
@ -344,7 +344,8 @@ export class OB11Constructor {
|
|||||||
sex: OB11Constructor.sex(member.sex),
|
sex: OB11Constructor.sex(member.sex),
|
||||||
age: 0,
|
age: 0,
|
||||||
area: "",
|
area: "",
|
||||||
level: member.qqLevel && calcQQLevel(member.qqLevel) || 0,
|
level: 0,
|
||||||
|
qq_level: member.qqLevel && calcQQLevel(member.qqLevel) || 0,
|
||||||
join_time: 0, // 暂时没法获取
|
join_time: 0, // 暂时没法获取
|
||||||
last_sent_time: 0, // 暂时没法获取
|
last_sent_time: 0, // 暂时没法获取
|
||||||
title_expire_time: 0,
|
title_expire_time: 0,
|
||||||
|
@ -29,6 +29,7 @@ export interface OB11GroupMember {
|
|||||||
join_time?: number
|
join_time?: number
|
||||||
last_sent_time?: number
|
last_sent_time?: number
|
||||||
level?: number
|
level?: number
|
||||||
|
qq_level?: number
|
||||||
role?: OB11GroupMemberRole
|
role?: OB11GroupMemberRole
|
||||||
title?: string
|
title?: string
|
||||||
area?: string
|
area?: string
|
||||||
@ -64,6 +65,7 @@ export enum OB11MessageType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface OB11Message {
|
export interface OB11Message {
|
||||||
|
target_id?: number; // 自己发送的消息才有此字段
|
||||||
self_id?: number,
|
self_id?: number,
|
||||||
time: number,
|
time: number,
|
||||||
message_id: number,
|
message_id: number,
|
||||||
|
@ -99,6 +99,11 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
SettingItem(
|
||||||
|
'接收戳一戳消息, 暂时只支持Windows版的LLOneBot',
|
||||||
|
`重启QQ后生效,如果导致QQ崩溃请勿开启此项`,
|
||||||
|
SettingSwitch('enablePoke', config.enablePoke),
|
||||||
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'使用 Base64 编码获取文件',
|
'使用 Base64 编码获取文件',
|
||||||
'开启后,调用 /get_image、/get_record 时,获取不到 url 时添加一个 Base64 字段',
|
'开启后,调用 /get_image、/get_record 时,获取不到 url 时添加一个 Base64 字段',
|
||||||
|
@ -1 +1 @@
|
|||||||
export const version = "3.16.0"
|
export const version = "3.16.1"
|
Loading…
x
Reference in New Issue
Block a user