mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dcaa07dc1c | ||
![]() |
5194c279d8 | ||
![]() |
b830cfbfa0 | ||
![]() |
ce25c9752f | ||
![]() |
5e00aee176 | ||
![]() |
a25c1b24fc | ||
![]() |
afed1b8575 | ||
![]() |
0fe58c1965 | ||
![]() |
b3cae5f1c6 | ||
![]() |
d09fc78747 | ||
![]() |
19d7ecd4f0 | ||
![]() |
070eee6c1c | ||
![]() |
fe5e0ea4e0 | ||
![]() |
7ba7af13a8 | ||
![]() |
fae61fbbde | ||
![]() |
a249139fe0 | ||
![]() |
ebc3968c4e | ||
![]() |
3d03aec976 | ||
![]() |
083d3ddf67 |
16
README.md
16
README.md
@@ -1,6 +1,5 @@
|
|||||||
# LLOneBot API
|
# LLOneBot API
|
||||||
|
|
||||||
|
|
||||||
将NTQQLiteLoaderAPI封装成OneBot11/12标准的API, V12没有完整测试
|
将NTQQLiteLoaderAPI封装成OneBot11/12标准的API, V12没有完整测试
|
||||||
|
|
||||||
*注意:本文档对应的是 LiteLoader 1.0.0及以上版本,如果你使用的是旧版本请切换到本项目v1分支查看文档*
|
*注意:本文档对应的是 LiteLoader 1.0.0及以上版本,如果你使用的是旧版本请切换到本项目v1分支查看文档*
|
||||||
@@ -105,24 +104,11 @@
|
|||||||
</details>
|
</details>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>撤回消息无效</summary>
|
|
||||||
<br/>
|
|
||||||
如果接口调用的传的`message`是number类型会导致精度丢失,使用string类型可解决,详情见<a href="https://github.com/linyuchen/LiteLoaderQQNT-OneBotApi/issues/17">issue#17</a>
|
|
||||||
</details>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>如何查看日志</summary>
|
|
||||||
<br/>
|
|
||||||
LiteLoaderQQNT/data/LLOneBot/*.log
|
|
||||||
</details>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- [x] 接口返回更详细的错误信息,目前消息发不出去也会返回发送成功(这河里吗)
|
|
||||||
- [ ] 转发消息记录
|
- [ ] 转发消息记录
|
||||||
|
- [ ] 好友点赞api
|
||||||
- [ ] 支持websocket,等个有缘人提PR实现
|
- [ ] 支持websocket,等个有缘人提PR实现
|
||||||
- [ ] 重构摆脱LLAPI,目前调用LLAPI只能在renderer进程调用,需重构成在main进程调用
|
- [ ] 重构摆脱LLAPI,目前调用LLAPI只能在renderer进程调用,需重构成在main进程调用
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi",
|
"description": "LiteLoaderQQNT的OneBotApi",
|
||||||
"version": "2.2.0",
|
"version": "2.4.1",
|
||||||
"thumbnail": "./icon.png",
|
"thumbnail": "./icon.png",
|
||||||
"authors": [{
|
"authors": [{
|
||||||
"name": "linyuchen",
|
"name": "linyuchen",
|
||||||
|
@@ -181,15 +181,17 @@ export interface PostDataSendMsg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Config {
|
export interface Config {
|
||||||
port: number,
|
port: number
|
||||||
hosts: string[],
|
hosts: string[]
|
||||||
enableBase64?: boolean
|
enableBase64?: boolean
|
||||||
debug?: boolean
|
debug?: boolean
|
||||||
|
reportSelfMessage?: boolean
|
||||||
|
log?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SendMsgResult {
|
export interface SendMsgResult {
|
||||||
status: number,
|
status: number
|
||||||
retcode: number,
|
retcode: number
|
||||||
data: any,
|
data: any
|
||||||
message: string,
|
message: string
|
||||||
}
|
}
|
@@ -18,7 +18,7 @@ import {
|
|||||||
} from "../common/IPCChannel";
|
} from "../common/IPCChannel";
|
||||||
import {ConfigUtil} from "./config";
|
import {ConfigUtil} from "./config";
|
||||||
import {startExpress} from "./HttpServer";
|
import {startExpress} from "./HttpServer";
|
||||||
import {checkFileReceived, CONFIG_DIR, isGIF, log} from "./utils";
|
import {checkFileReceived, CONFIG_DIR, getConfigUtil, isGIF, log} from "./utils";
|
||||||
import {friends, groups, selfInfo} from "./data";
|
import {friends, groups, selfInfo} from "./data";
|
||||||
import {} from "../global";
|
import {} from "../global";
|
||||||
|
|
||||||
@@ -32,10 +32,7 @@ function onLoad() {
|
|||||||
log("main onLoaded");
|
log("main onLoaded");
|
||||||
|
|
||||||
// const config_dir = browserWindow.LiteLoader.plugins["LLOneBot"].path.data;
|
// const config_dir = browserWindow.LiteLoader.plugins["LLOneBot"].path.data;
|
||||||
function getConfigUtil() {
|
|
||||||
const configFilePath = path.join(CONFIG_DIR, `config_${selfInfo.user_id}.json`)
|
|
||||||
return new ConfigUtil(configFilePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fs.existsSync(CONFIG_DIR)) {
|
if (!fs.existsSync(CONFIG_DIR)) {
|
||||||
fs.mkdirSync(CONFIG_DIR, {recursive: true});
|
fs.mkdirSync(CONFIG_DIR, {recursive: true});
|
||||||
|
@@ -1,11 +1,21 @@
|
|||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import {json} from "express";
|
import {json} from "express";
|
||||||
import {selfInfo} from "./data";
|
import {selfInfo} from "./data";
|
||||||
|
import {ConfigUtil} from "./config";
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
export const CONFIG_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
export const CONFIG_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
||||||
|
|
||||||
|
export function getConfigUtil() {
|
||||||
|
const configFilePath = path.join(CONFIG_DIR, `config_${selfInfo.user_id}.json`)
|
||||||
|
return new ConfigUtil(configFilePath)
|
||||||
|
}
|
||||||
|
|
||||||
export function log(msg: any) {
|
export function log(msg: any) {
|
||||||
|
if (!getConfigUtil().getConfig().log){
|
||||||
|
return
|
||||||
|
}
|
||||||
let currentDateTime = new Date().toLocaleString();
|
let currentDateTime = new Date().toLocaleString();
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const year = date.getFullYear();
|
const year = date.getFullYear();
|
||||||
@@ -44,4 +54,4 @@ export function checkFileReceived(path: string, timeout: number=3000): Promise<v
|
|||||||
|
|
||||||
check();
|
check();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
/// <reference path="./global.d.ts" />
|
/// <reference path="./global.d.ts" />
|
||||||
|
|
||||||
// import express from "express";
|
|
||||||
// const { ipcRenderer } = require('electron');
|
|
||||||
import {
|
import {
|
||||||
AtType,
|
AtType,
|
||||||
ChatType,
|
ChatType,
|
||||||
@@ -13,7 +11,6 @@ import {
|
|||||||
SendMsgResult,
|
SendMsgResult,
|
||||||
User
|
User
|
||||||
} from "./common/types";
|
} from "./common/types";
|
||||||
import {checkFileReceived} from "./main/utils";
|
|
||||||
|
|
||||||
let self_qq: string = ""
|
let self_qq: string = ""
|
||||||
let groups: Group[] = []
|
let groups: Group[] = []
|
||||||
@@ -125,7 +122,7 @@ async function getGroupMember(group_qq: string, member_uid: string) {
|
|||||||
|
|
||||||
async function handleNewMessage(messages: MessageElement[]) {
|
async function handleNewMessage(messages: MessageElement[]) {
|
||||||
console.log("llonebot 收到消息:", messages);
|
console.log("llonebot 收到消息:", messages);
|
||||||
const {debug, enableBase64} = await window.llonebot.getConfig();
|
const {debug, enableBase64, reportSelfMessage} = await window.llonebot.getConfig();
|
||||||
for (let message of messages) {
|
for (let message of messages) {
|
||||||
let onebot_message_data: any = {
|
let onebot_message_data: any = {
|
||||||
self: {
|
self: {
|
||||||
@@ -236,14 +233,20 @@ async function handleNewMessage(messages: MessageElement[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onebot_message_data.message.push(message_data)
|
if (message_data.type !== "unknown"){
|
||||||
|
onebot_message_data.message.push(message_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (msgHistory.length > 10000) {
|
if (msgHistory.length > 10000) {
|
||||||
msgHistory.splice(0, 100)
|
msgHistory.splice(0, 100)
|
||||||
}
|
}
|
||||||
msgHistory.push(message)
|
msgHistory.push(message)
|
||||||
console.log("发送上传消息给ipc main", onebot_message_data)
|
if (!reportSelfMessage && onebot_message_data["user_id"] == self_qq){
|
||||||
window.llonebot.postData(onebot_message_data);
|
console.log("开启了不上传自己发送的消息,进行拦截 ", onebot_message_data);
|
||||||
|
} else {
|
||||||
|
console.log("发送上传消息给ipc main", onebot_message_data);
|
||||||
|
window.llonebot.postData(onebot_message_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,7 +300,6 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
name: group.name,
|
name: group.name,
|
||||||
uid: group.uid
|
uid: group.uid
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sendMsgResult.status = -1;
|
sendMsgResult.status = -1;
|
||||||
sendMsgResult.retcode = -1;
|
sendMsgResult.retcode = -1;
|
||||||
@@ -357,9 +359,9 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
} else {
|
} else {
|
||||||
localFilePath = path;
|
localFilePath = path;
|
||||||
}
|
}
|
||||||
|
sendFiles.push(localFilePath);
|
||||||
}
|
}
|
||||||
message.file = localFilePath
|
message.file = localFilePath
|
||||||
sendFiles.push(localFilePath);
|
|
||||||
} else if (message.type == "reply") {
|
} else if (message.type == "reply") {
|
||||||
let msgId = message.data?.id || message.msgId
|
let msgId = message.data?.id || message.msgId
|
||||||
let replyMessage = msgHistory.find(msg => msg.raw.msgId == msgId)
|
let replyMessage = msgHistory.find(msg => msg.raw.msgId == msgId)
|
||||||
@@ -590,7 +592,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
hostsEleStr += creatHostEleStr(host);
|
hostsEleStr += creatHostEleStr(host);
|
||||||
}
|
}
|
||||||
let html = `
|
let html = `
|
||||||
<div class="config_view">
|
<div class="config_view llonebot">
|
||||||
<setting-section>
|
<setting-section>
|
||||||
<setting-panel>
|
<setting-panel>
|
||||||
<setting-list class="wrap">
|
<setting-list class="wrap">
|
||||||
@@ -622,16 +624,35 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
</div>
|
</div>
|
||||||
<setting-switch id="debug" ${config.debug ? "is-active" : ""}></setting-switch>
|
<setting-switch id="debug" ${config.debug ? "is-active" : ""}></setting-switch>
|
||||||
</setting-item>
|
</setting-item>
|
||||||
|
<setting-item data-direction="row" class="hostItem vertical-list-item">
|
||||||
|
<div>
|
||||||
|
<div>上报自身消息</div>
|
||||||
|
<div class="tips">开启后上报自己发出的消息</div>
|
||||||
|
</div>
|
||||||
|
<setting-switch id="reportSelfMessage" ${config.reportSelfMessage ? "is-active" : ""}></setting-switch>
|
||||||
|
</setting-item>
|
||||||
|
<setting-item data-direction="row" class="hostItem vertical-list-item">
|
||||||
|
<div>
|
||||||
|
<div>日志</div>
|
||||||
|
<div class="tips">日志目录:${window.LiteLoader.plugins["LLOneBot"].path.data}</div>
|
||||||
|
</div>
|
||||||
|
<setting-switch id="log" ${config.log ? "is-active" : ""}></setting-switch>
|
||||||
|
</setting-item>
|
||||||
</setting-panel>
|
</setting-panel>
|
||||||
</setting-section>
|
</setting-section>
|
||||||
</div>
|
</div>
|
||||||
<style>
|
<style>
|
||||||
setting-panel {
|
setting-panel {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
.tips {
|
.tips {
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
@media (prefers-color-scheme: dark){
|
||||||
|
.llonebot input {
|
||||||
|
color: white;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -665,6 +686,8 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
|
|
||||||
switchClick("debug", "debug");
|
switchClick("debug", "debug");
|
||||||
switchClick("switchBase64", "enableBase64");
|
switchClick("switchBase64", "enableBase64");
|
||||||
|
switchClick("reportSelfMessage", "reportSelfMessage");
|
||||||
|
switchClick("log", "log");
|
||||||
|
|
||||||
doc.getElementById("save")?.addEventListener("click",
|
doc.getElementById("save")?.addEventListener("click",
|
||||||
() => {
|
() => {
|
||||||
@@ -698,4 +721,4 @@ setTimeout(onLoad, 5000)
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
onSettingWindowCreated
|
onSettingWindowCreated
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user