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