mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dc38275660 | ||
![]() |
3d077550cd | ||
![]() |
44fe01f94b | ||
![]() |
5f9679dfbf |
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
## 支持的API
|
## 支持的API
|
||||||
|
|
||||||
目前只支持http协议,不支持websocket,事件上报也是http协议
|
目前只支持http协议POST方法,不支持websocket,事件上报也是http协议
|
||||||
|
|
||||||
- [x] 获取群列表
|
- [x] 获取群列表
|
||||||
- [x] 获取群成员列表
|
- [x] 获取群成员列表
|
||||||
@@ -50,3 +50,9 @@
|
|||||||
- [x] get_friend_list
|
- [x] get_friend_list
|
||||||
|
|
||||||
**自己发送成功的消息也会上报,可以用于获取需要撤回消息的id**
|
**自己发送成功的消息也会上报,可以用于获取需要撤回消息的id**
|
||||||
|
|
||||||
|
## 示例
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
*暂时不支持`"message": "hello"`这种message为字符串的形式*
|
||||||
|
BIN
doc/image/example.jpg
Normal file
BIN
doc/image/example.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 102 KiB |
@@ -4,7 +4,7 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi",
|
"description": "LiteLoaderQQNT的OneBotApi",
|
||||||
"version": "1.2.2",
|
"version": "1.2.3",
|
||||||
"thumbnail": "./icon.png",
|
"thumbnail": "./icon.png",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "linyuchen",
|
"name": "linyuchen",
|
||||||
|
@@ -97,8 +97,8 @@ function handlePost(jsonData: any) {
|
|||||||
export function startExpress(port: number) {
|
export function startExpress(port: number) {
|
||||||
const app = express();
|
const app = express();
|
||||||
// 中间件,用于解析POST请求的请求体
|
// 中间件,用于解析POST请求的请求体
|
||||||
app.use(express.urlencoded({extended: true, limit: "50mb"}));
|
app.use(express.urlencoded({extended: true, limit: "500mb"}));
|
||||||
app.use(bodyParser({limit: '50mb'}))
|
app.use(bodyParser({limit: '500mb'}))
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
function parseToOnebot12(action: PostDataAction) {
|
function parseToOnebot12(action: PostDataAction) {
|
||||||
|
@@ -53,6 +53,7 @@ function onLoad(plugin: any) {
|
|||||||
let buffer = await blob.arrayBuffer();
|
let buffer = await blob.arrayBuffer();
|
||||||
fs.writeFileSync(arg.localFilePath, Buffer.from(buffer));
|
fs.writeFileSync(arg.localFilePath, Buffer.from(buffer));
|
||||||
}
|
}
|
||||||
|
// todo: 需要识别gif格式
|
||||||
return arg.localFilePath;
|
return arg.localFilePath;
|
||||||
})
|
})
|
||||||
ipcMain.on(CHANNEL_SET_CONFIG, (event: any, arg: Config) => {
|
ipcMain.on(CHANNEL_SET_CONFIG, (event: any, arg: Config) => {
|
||||||
|
@@ -20,8 +20,25 @@ async function getUserInfo(uid: string): Promise<User> {
|
|||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFriend(qq: string) {
|
async function getFriends(){
|
||||||
return friends.find(friend => friend.uid == qq)
|
let _friends = await window.LLAPI.getFriendsList(false)
|
||||||
|
for (let friend of _friends) {
|
||||||
|
let existFriend = friends.find(f => f.uin == friend.uin)
|
||||||
|
if (!existFriend) {
|
||||||
|
friends.push(friend)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.llonebot.updateFriends(friends)
|
||||||
|
return friends
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getFriend(qq: string) {
|
||||||
|
let friend = friends.find(friend => friend.uin == qq)
|
||||||
|
if (!friend) {
|
||||||
|
await getFriends();
|
||||||
|
friend = friends.find(friend => friend.uin == qq);
|
||||||
|
}
|
||||||
|
return friend;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGroup(qq: string) {
|
async function getGroup(qq: string) {
|
||||||
@@ -39,11 +56,11 @@ async function getGroups() {
|
|||||||
group.members = [];
|
group.members = [];
|
||||||
let existGroup = groups.find(g => g.uid == group.uid)
|
let existGroup = groups.find(g => g.uid == group.uid)
|
||||||
if (!existGroup) {
|
if (!existGroup) {
|
||||||
console.log("更新群列表", groups)
|
// console.log("更新群列表", groups)
|
||||||
groups.push(group)
|
groups.push(group)
|
||||||
window.llonebot.updateGroups(groups)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
window.llonebot.updateGroups(groups)
|
||||||
return groups
|
return groups
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +132,7 @@ async function handleNewMessage(messages: MessageElement[]) {
|
|||||||
console.log("收到群消息", onebot_message_data)
|
console.log("收到群消息", onebot_message_data)
|
||||||
} else if (message.peer.chatType == "private") {
|
} else if (message.peer.chatType == "private") {
|
||||||
onebot_message_data["user_id"] = message.peer.uid
|
onebot_message_data["user_id"] = message.peer.uid
|
||||||
let friend = getFriend(message.sender.uid)
|
let friend = await getFriend(message.sender.uid)
|
||||||
onebot_message_data.sender = {
|
onebot_message_data.sender = {
|
||||||
user_id: friend!.uin,
|
user_id: friend!.uin,
|
||||||
nickname: friend!.nickName
|
nickname: friend!.nickName
|
||||||
@@ -171,12 +188,12 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (postData.action == "send_private_msg") {
|
if (postData.action == "send_private_msg") {
|
||||||
let friend = getFriend(postData.params.user_id)
|
let friend = await getFriend(postData.params.user_id)
|
||||||
if (friend) {
|
if (friend) {
|
||||||
peer = {
|
peer = {
|
||||||
chatType: "private",
|
chatType: "private",
|
||||||
name: friend.nickName,
|
name: friend.nickName,
|
||||||
uid: friend.uin
|
uid: friend.uid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (postData.action == "send_group_msg") {
|
} else if (postData.action == "send_group_msg") {
|
||||||
@@ -212,6 +229,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
let uri = new URL(url);
|
let uri = new URL(url);
|
||||||
let ext: string;
|
let ext: string;
|
||||||
if (message.type == "image") {
|
if (message.type == "image") {
|
||||||
|
// todo: 需要识别gif格式
|
||||||
ext = ".png"
|
ext = ".png"
|
||||||
}
|
}
|
||||||
if (message.type == "voice") {
|
if (message.type == "voice") {
|
||||||
@@ -233,7 +251,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
}
|
}
|
||||||
// 发送完之后要删除下载的文件
|
// 发送完之后要删除下载的文件
|
||||||
console.log("发送消息", postData)
|
console.log("发送消息", postData)
|
||||||
window.LLAPI.sendMessage(peer, postData.params.message).then(res => console.log("消息发送成功:", res),
|
window.LLAPI.sendMessage(peer, postData.params.message).then(res => console.log("消息发送成功:", peer, postData.params.message),
|
||||||
err => console.log("消息发送失败", postData, err))
|
err => console.log("消息发送失败", postData, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,8 +267,8 @@ let chatListEle: HTMLCollectionOf<Element>
|
|||||||
function onLoad() {
|
function onLoad() {
|
||||||
|
|
||||||
window.llonebot.listenSendMessage((postData: PostDataSendMsg) => {
|
window.llonebot.listenSendMessage((postData: PostDataSendMsg) => {
|
||||||
listenSendMessage(postData).then()
|
listenSendMessage(postData).then().catch(err => console.log("listenSendMessage err", err))
|
||||||
});
|
})
|
||||||
window.llonebot.listenRecallMessage((arg: { message_id: string }) => {
|
window.llonebot.listenRecallMessage((arg: { message_id: string }) => {
|
||||||
recallMessage(arg.message_id)
|
recallMessage(arg.message_id)
|
||||||
})
|
})
|
||||||
@@ -287,7 +305,7 @@ function onLoad() {
|
|||||||
})
|
})
|
||||||
console.log("chatListEle", chatListEle)
|
console.log("chatListEle", chatListEle)
|
||||||
}
|
}
|
||||||
|
getFriends().then();
|
||||||
getGroups().then(() => {
|
getGroups().then(() => {
|
||||||
getGroupsMembers(groups).then(() => {
|
getGroupsMembers(groups).then(() => {
|
||||||
window.LLAPI.on("new-messages", onNewMessages);
|
window.LLAPI.on("new-messages", onNewMessages);
|
||||||
@@ -340,7 +358,7 @@ function onLoad() {
|
|||||||
}
|
}
|
||||||
btn.innerText = "获取群成员列表"
|
btn.innerText = "获取群成员列表"
|
||||||
console.log(qContextMenu)
|
console.log(qContextMenu)
|
||||||
qContextMenu.appendChild(btn)
|
// qContextMenu.appendChild(btn)
|
||||||
})
|
})
|
||||||
|
|
||||||
window.LLAPI.on("context-msg-menu", (event, target, msgIds) => {
|
window.LLAPI.on("context-msg-menu", (event, target, msgIds) => {
|
||||||
|
Reference in New Issue
Block a user