mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
perf: message data checker
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi",
|
"description": "LiteLoaderQQNT的OneBotApi",
|
||||||
"version": "1.2.3",
|
"version": "1.2.4",
|
||||||
"thumbnail": "./icon.png",
|
"thumbnail": "./icon.png",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "linyuchen",
|
"name": "linyuchen",
|
||||||
|
@@ -1,10 +1,48 @@
|
|||||||
import {sendIPCRecallQQMsg, sendIPCSendQQMsg} from "./IPCSend";
|
|
||||||
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
import {OnebotGroupMemberRole, PostDataAction, PostDataSendMsg} from "../common/types";
|
import {sendIPCRecallQQMsg, sendIPCSendQQMsg} from "./IPCSend";
|
||||||
|
import {OnebotGroupMemberRole, PostDataAction, PostDataSendMsg, SendMessage} from "../common/types";
|
||||||
import {friends, groups, selfInfo} from "./data";
|
import {friends, groups, selfInfo} from "./data";
|
||||||
import judgeMessage from "./utils";
|
|
||||||
|
// @SiberianHusky 2021-08-15
|
||||||
|
function checkSendMessage(sendMsgList: SendMessage[]) {
|
||||||
|
function checkUri(uri: string): boolean {
|
||||||
|
const pattern = /^(file:\/\/|http:\/\/|https:\/\/|base64:\/\/)/;
|
||||||
|
return pattern.test(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let msg of sendMsgList) {
|
||||||
|
if (msg["type"] && msg["data"]) {
|
||||||
|
let type = msg["type"];
|
||||||
|
let data = msg["data"];
|
||||||
|
if (type === "text" && !data["text"]) {
|
||||||
|
return 400;
|
||||||
|
} else if (["image", "voice"].includes(type)) {
|
||||||
|
if (!data["file"]) {
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (checkUri(data["file"])) {
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (type === "at" && !data["qq"]) {
|
||||||
|
return 400;
|
||||||
|
} else if (type === "reply" && !data["id"]) {
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return 400
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
// ==end==
|
||||||
|
|
||||||
function handlePost(jsonData: any) {
|
function handlePost(jsonData: any) {
|
||||||
if (!jsonData.params) {
|
if (!jsonData.params) {
|
||||||
@@ -22,19 +60,17 @@ function handlePost(jsonData: any) {
|
|||||||
} else if (jsonData.action == "send_private_msg" || jsonData.action == "send_group_msg") {
|
} else if (jsonData.action == "send_private_msg" || jsonData.action == "send_group_msg") {
|
||||||
if (jsonData.action == "send_private_msg") {
|
if (jsonData.action == "send_private_msg") {
|
||||||
jsonData.message_type = "private"
|
jsonData.message_type = "private"
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
jsonData.message_type = "group"
|
jsonData.message_type = "group"
|
||||||
}
|
}
|
||||||
// @SiberianHuskY 2021-10-20 22:00:00
|
// @SiberianHuskY 2021-10-20 22:00:00
|
||||||
resData.status=judgeMessage(jsonData.message)||0;
|
resData.status = checkSendMessage(jsonData.message);
|
||||||
if (resData.status == 200) {
|
if (resData.status == 200) {
|
||||||
resData.message = "发送成功";
|
resData.message = "发送成功";
|
||||||
resData.data = jsonData.message;
|
resData.data = jsonData.message;
|
||||||
sendIPCSendQQMsg(jsonData);
|
sendIPCSendQQMsg(jsonData);
|
||||||
}
|
} else {
|
||||||
else{
|
resData.message = "发送失败, 请检查消息格式";
|
||||||
resData.message="发送失败";
|
|
||||||
resData.data = jsonData.message;
|
resData.data = jsonData.message;
|
||||||
}
|
}
|
||||||
// == end ==
|
// == end ==
|
||||||
@@ -53,8 +89,7 @@ function handlePost(jsonData: any) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
} else if (jsonData.action == "get_group_info") {
|
||||||
else if (jsonData.action == "get_group_info") {
|
|
||||||
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
||||||
if (group) {
|
if (group) {
|
||||||
resData["data"] = {
|
resData["data"] = {
|
||||||
@@ -63,8 +98,7 @@ function handlePost(jsonData: any) {
|
|||||||
member_count: group.members.length,
|
member_count: group.members.length,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (jsonData.action == "get_group_member_info") {
|
||||||
else if (jsonData.action == "get_group_member_info") {
|
|
||||||
let member = groups.find(group => group.uid == jsonData.params.group_id)?.members?.find(member => member.uin == jsonData.params.user_id)
|
let member = groups.find(group => group.uid == jsonData.params.group_id)?.members?.find(member => member.uin == jsonData.params.user_id)
|
||||||
resData["data"] = {
|
resData["data"] = {
|
||||||
user_id: member.uin,
|
user_id: member.uin,
|
||||||
@@ -74,8 +108,7 @@ function handlePost(jsonData: any) {
|
|||||||
card: member.cardName,
|
card: member.cardName,
|
||||||
role: OnebotGroupMemberRole[member.role],
|
role: OnebotGroupMemberRole[member.role],
|
||||||
}
|
}
|
||||||
}
|
} else if (jsonData.action == "get_group_member_list") {
|
||||||
else if (jsonData.action == "get_group_member_list") {
|
|
||||||
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
||||||
if (group) {
|
if (group) {
|
||||||
resData["data"] = group?.members?.map(member => {
|
resData["data"] = group?.members?.map(member => {
|
||||||
@@ -121,6 +154,7 @@ export function startExpress(port: number) {
|
|||||||
res.send(resData)
|
res.send(resData)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const actionList: PostDataAction[] = ["get_login_info", "send_private_msg", "send_group_msg",
|
const actionList: PostDataAction[] = ["get_login_info", "send_private_msg", "send_group_msg",
|
||||||
"get_group_list", "get_friend_list", "delete_msg", "get_group_member_list", "get_group_member_info"]
|
"get_group_list", "get_friend_list", "delete_msg", "get_group_member_list", "get_group_member_info"]
|
||||||
|
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
import { text } from "express";
|
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
export function log(msg: any) {
|
export function log(msg: any) {
|
||||||
@@ -8,38 +6,3 @@ export function log(msg: any) {
|
|||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @SiberianHusky 2021-08-15
|
|
||||||
export default function judgeMessage(msg) {
|
|
||||||
if(msg[0]!=null&&msg[0]["type"]!=null&&msg[0]["data"]!=null){
|
|
||||||
let type = msg[0]["type"];
|
|
||||||
let data = msg[0]["data"];
|
|
||||||
if(type == "text"){
|
|
||||||
if (data["text"]!=""&&data["text"]!=null){
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
else if(type==="image"){
|
|
||||||
if(data["file"]!=""&&data["file"]!=null){
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(type==="voice"){
|
|
||||||
if(data["file"]!=""&&data["file"]!=null){
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(type==="at"){
|
|
||||||
if(data["qq"]!=""&&data["qq"]!=null){
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(type==="reply"){
|
|
||||||
if(data["id"]!=""&&data["id"]!=null){
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 400;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ==end==
|
|
Reference in New Issue
Block a user