Change BOTCore
这个提交包含在:
@ -16,7 +16,7 @@ Core.AddListener((Connect, Info) => {
|
||||
Core.frame.SendMsg(Connect, Info, "[利刃后端]更新成功!");
|
||||
}
|
||||
if (Info.message.substr(0, 4) == "利刃执行") {
|
||||
if (!Debug.add.Interfaces.IsAdmin(Info.user_id)) {
|
||||
if (!(Debug.add.Interfaces.IsAdmin(Info.user_id))) {
|
||||
Core.frame.SendMsg(Connect, Info, "只有Ai管理员才有权使用本指令");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ Core.AddListener((Connect,Info)=>{
|
||||
Core.frame.SendMsg(Connect,Info,"[利刃后端]更新成功!")
|
||||
}
|
||||
if(Info.message.substr(0,4) == "利刃执行"){
|
||||
if(!Debug.add.Interfaces.IsAdmin(Info.user_id)){
|
||||
if(!(Debug.add.Interfaces.IsAdmin(Info.user_id))){
|
||||
Core.frame.SendMsg(Connect,Info,"只有Ai管理员才有权使用本指令");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -62,12 +62,14 @@ exports.解析 = ((内容, 收到) => {
|
||||
返回 = 返回.replace(/\{/g, "[");
|
||||
FunctionKeys.forEach((Key) => {
|
||||
var Function = new RegExp(`^\\[${Key} (.*?)\\]$`);
|
||||
Function.exec(返回.valueOf());
|
||||
var 处理 = RegExp.$1;
|
||||
if (处理.indexOf("[") != -1) {
|
||||
处理 = exports.解析(处理, 收到);
|
||||
if (Function.test(返回.valueOf())) {
|
||||
Function.exec(返回.valueOf());
|
||||
var 处理 = RegExp.$1;
|
||||
if (处理.indexOf("[") != -1) {
|
||||
处理 = exports.解析(处理, 收到);
|
||||
}
|
||||
返回 = 返回.replace(Function, eval(`${API.Base.Function[Key]}("${处理}",收到)`));
|
||||
}
|
||||
返回 = 返回.replace(Function, eval(`${API.Base.Function[Key]}("${处理}",收到)`));
|
||||
});
|
||||
return 返回;
|
||||
});
|
||||
|
||||
@ -54,12 +54,14 @@ export var 解析:((内容:String,收到:Core.InfoType)=> String) = ((内容,收
|
||||
返回 = 返回.replace(/\{/g,"[");
|
||||
FunctionKeys.forEach((Key)=>{
|
||||
var Function = new RegExp(`^\\[${Key} (.*?)\\]$`);
|
||||
Function.exec(返回.valueOf());
|
||||
var 处理 = RegExp.$1 as String;
|
||||
if(处理.indexOf("[") != -1){
|
||||
处理 = 解析(处理,收到);
|
||||
if(Function.test(返回.valueOf())){
|
||||
Function.exec(返回.valueOf());
|
||||
var 处理 = RegExp.$1 as String;
|
||||
if(处理.indexOf("[") != -1){
|
||||
处理 = 解析(处理,收到);
|
||||
}
|
||||
返回 = 返回.replace(Function,eval(`${API.Base.Function[Key]}("${处理}",收到)`));
|
||||
}
|
||||
返回 = 返回.replace(Function,eval(`${API.Base.Function[Key]}("${处理}",收到)`));
|
||||
})
|
||||
return 返回;
|
||||
});
|
||||
|
||||
165
CGI.js
165
CGI.js
@ -1,56 +1,123 @@
|
||||
const ws = require("websocket");
|
||||
const fs = require("fs");
|
||||
const Key = "INITKEYHvwZAL37";
|
||||
const iconv = require("iconv-lite");
|
||||
const request = require("request");
|
||||
const Core = require("./Core");
|
||||
const net = require("net");
|
||||
const zlib = require("zlib");
|
||||
var HOOK = false;
|
||||
var Session = "";
|
||||
console.log("["+new Date().toString()+"][./Core.js]服务器已启动");
|
||||
var wss = new ws.client();
|
||||
wss.connect("ws://127.0.0.1:6700");
|
||||
global.ReConnect = (()=>{
|
||||
throw new Error("Reconnect");
|
||||
})
|
||||
wss.once("connectFailed",()=>{
|
||||
console.log("["+new Date().toString()+"][./Core.js]功能已断线。");
|
||||
process.exit(-1)
|
||||
});
|
||||
exports.HOOK = HOOK;
|
||||
exports.frame={
|
||||
SendMsg: function (connect, info, message) {
|
||||
message = new String(message);
|
||||
this.SetHook(true);
|
||||
if(message == undefined||message == ""){
|
||||
this.SendMsg(connect,info,"[ERROR]Ai出现了一些问题。并没有接受到回复。")
|
||||
return;
|
||||
}
|
||||
/"/g.exec(message);
|
||||
message = message.replace(/"/g,`\\\"`);
|
||||
if(info["message_type"]=="group"){
|
||||
var m = `{"action":"send_group_msg","params":{"group_id":`+info["group_id"]+`,"message":"`+message+`"}}`;
|
||||
}else if(info["message_type"]=="private"){
|
||||
var m = `{"action":"send_private_msg","params":{"user_id":`+info["user_id"]+`,"message":"`+message+`"}}`
|
||||
}
|
||||
console.log(m);
|
||||
connect.send(m);
|
||||
},
|
||||
SetHook:function(value){
|
||||
exports.HOOK = value;
|
||||
var last = {};
|
||||
// var hs = new http.Server();
|
||||
request.post({
|
||||
url:"http://127.0.0.1:8080/auth",
|
||||
body:JSON.stringify({authKey:Key})
|
||||
},(err,res)=>{
|
||||
if(res == null){
|
||||
console.log("["+new Date().toString()+"][./Core.js]系统断线.");
|
||||
process.exit(-1);
|
||||
}
|
||||
}
|
||||
wss.on("connect",(connect)=>{
|
||||
console.log("["+new Date().toString()+"][./Core.js]链接成功");
|
||||
exports.connect = connect;
|
||||
exports.frame.SetHook(false);
|
||||
exports.HOOK = HOOK;
|
||||
connect.on("message",(data)=>{
|
||||
if(JSON.parse(data.utf8Data)["post_type"]=="request"){//自动加好友
|
||||
var s = JSON.parse(data.utf8Data);
|
||||
console.log(data.utf8Data);
|
||||
if(s["request_type"]!="group"){
|
||||
connect.send(`{"action":"set_friend_add_request","params":{"flag":"${s["flag"]}","approve":true}}`)
|
||||
}else{
|
||||
connect.send(`{"action":"set_group_add_request","params":{"flag":"${s["flag"]}","sub_type":"${s["sub_type"]}","approve":true}}`);
|
||||
var Session = JSON.parse(res.body).session;
|
||||
request.post({
|
||||
url:"http://127.0.0.1:8080/verify",
|
||||
body:JSON.stringify({
|
||||
sessionKey:Session,
|
||||
qq:2142562417
|
||||
})
|
||||
},(err2,res2)=>{
|
||||
console.log("["+new Date().toString()+"][./Core.js]Session激活成功.");
|
||||
console.log(Session);
|
||||
exports.HOOK = HOOK;
|
||||
exports.frame={
|
||||
SendMsg: function (connect, info, message) {
|
||||
var Zmessage = new String(message);
|
||||
this.SetHook(true);
|
||||
if(Zmessage == undefined||Zmessage == ""){
|
||||
this.SendMsg(connect,info,"[ERROR]Ai出现了一些问题。并没有接受到回复。")
|
||||
return;
|
||||
}
|
||||
/"/g.exec(Zmessage);
|
||||
Zmessage = Zmessage.replace(/"/g,`\\\"`);
|
||||
// if(info.group != undefined){
|
||||
// var Kdata = JSON.stringify({
|
||||
// sessionKey:Session,
|
||||
// group:info.group_id,
|
||||
// messageChain:[{type:"Plain",text:Zmessage}]
|
||||
// });
|
||||
// }else{
|
||||
// var Kdata = JSON.stringify({
|
||||
// sessionKey:Session,
|
||||
// qq:info.sender.id,
|
||||
// messageChain:[{type:"Plain",text:Zmessage}]
|
||||
// });
|
||||
// }
|
||||
|
||||
var Kdata = JSON.stringify({
|
||||
sessionKey:Session,
|
||||
qq:info.user_id,
|
||||
messageChain:[{type:"Plain",text:Zmessage}]
|
||||
});
|
||||
var BData = Buffer.from(Kdata);
|
||||
var Ret = "";
|
||||
var To = "Friend";
|
||||
if(info.group != undefined){
|
||||
To = "Group"
|
||||
}
|
||||
var Req = new net.Socket();
|
||||
console.log(Kdata);
|
||||
console.log(Kdata);
|
||||
var MainData = `POST /send${To}Message HTTP/1.1\r\nHost: 127.0.0.1:8080\r\nContent-Type: application/json; charset=UTF-8;\r\nContent-Length:${BData.length}\r\n\r\n`;
|
||||
Req.connect(8080,"127.0.0.1",()=>{
|
||||
Req.write(MainData);
|
||||
Req.write(BData);
|
||||
Req.on("data",(data)=>{
|
||||
console.log(data.toString());
|
||||
});
|
||||
Req.on("end",()=>{
|
||||
Req.end();
|
||||
});
|
||||
Req.on("close",()=>{
|
||||
Req.end();
|
||||
})
|
||||
});
|
||||
// var Req = http.request({
|
||||
// method:"POST",
|
||||
// hostname:"127.0.0.1",
|
||||
// port:8080,
|
||||
// path:`/send${To}Message`
|
||||
// },(res)=>{
|
||||
// Req.socket.setDefaultEncoding("utf-8");
|
||||
// Req.write(Kdata);
|
||||
// Req.end();
|
||||
// console.log(res.headers);
|
||||
// res.on("data",(chunk)=>{
|
||||
// Ret = Ret + chunk;
|
||||
// });
|
||||
// res.on("end",()=>{
|
||||
// console.log(Ret);
|
||||
// })
|
||||
// });
|
||||
// console.log(m);
|
||||
},
|
||||
SetHook:function(value){
|
||||
exports.HOOK = value;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Core.frame.CGI(connect,JSON.parse(data.utf8Data));
|
||||
});
|
||||
setInterval(()=>{
|
||||
request.get({
|
||||
url:`http://127.0.0.1:8080/fetchLatestMessage?sessionKey=${Session}&count=1`
|
||||
},(err,data)=>{
|
||||
|
||||
if(data == null || data == undefined){return}
|
||||
|
||||
var data_obj = JSON.parse(data.body).data[0];
|
||||
if(data_obj == last){
|
||||
return
|
||||
}else{
|
||||
Core.frame.CGI("",data_obj);
|
||||
last = data_obj;
|
||||
}
|
||||
});
|
||||
},100);
|
||||
})
|
||||
});
|
||||
23
Core.js
23
Core.js
@ -90,7 +90,7 @@ class Config{
|
||||
};
|
||||
exports.frame={
|
||||
__Ban:function(connect,group,someone,time){
|
||||
connect.send(`{"action":"set_group_ban","params":{"group_id":"${group}","user_id":"${someone}","duration":${time}}}`);
|
||||
// connect.send(`{"action":"set_group_ban","params":{"group_id":"${group}","user_id":"${someone}","duration":${time}}}`);
|
||||
},
|
||||
_Ban:function(connect,info,user,time){
|
||||
this.__Ban(connect,info["group_id"],user,time);
|
||||
@ -152,8 +152,29 @@ exports.frame={
|
||||
return 0;
|
||||
},
|
||||
CGI:function(connect,info){
|
||||
|
||||
if(info == undefined){return};
|
||||
|
||||
console.log("["+new Date().toString()+"][./Core.js]收到新消息");
|
||||
|
||||
info.raw_message = "";
|
||||
info.messageChain.forEach(element => {
|
||||
if(element.type == "Plain"){
|
||||
info.raw_message = info.raw_message + element.text;
|
||||
}
|
||||
});
|
||||
info.message = info.raw_message;
|
||||
|
||||
console.log(Buffer.from(info.message));
|
||||
|
||||
info.user_id = info.sender.id;
|
||||
|
||||
if(info.group){
|
||||
console.log("isGroup!")
|
||||
info.group_id = info.group.id;
|
||||
info.message_type = "group";
|
||||
}
|
||||
|
||||
if(info.group_id){
|
||||
|
||||
if(info.message == "Ai服务状态"){
|
||||
|
||||
14
Debug.js
14
Debug.js
@ -3,9 +3,14 @@ const fs=require("fs");
|
||||
const Core = require("./Core");
|
||||
const child_p = require("child_process");
|
||||
var SandBox = Core.frame.ReadSystemConfig("SandBox");
|
||||
var Sudo = false;
|
||||
exports.add={
|
||||
Interfaces:{
|
||||
IsAdmin:function(user){
|
||||
if(Sudo){
|
||||
Sudo = false;
|
||||
return true;
|
||||
}
|
||||
if(!fs.existsSync("./Debug.json")){
|
||||
fs.writeFile("./Debug.json",JSON.stringify({}),(err)=>{
|
||||
console.log(`[${new Date().toString()}][Debug.js]加载Debug.json成功!`);
|
||||
@ -146,6 +151,15 @@ exports.add={
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if(Temp1 == "管理员授权"){
|
||||
if(exports.add.Interfaces.IsAdmin(Core.GetUser(info["user_id"]))){
|
||||
Sudo = true;
|
||||
Core.frame.SendMsg(connect,info,"[DEBUG]已进行授权!");
|
||||
}else{
|
||||
Core.frame.SendMsg(connect,info,"[DEBUG]未进行授权!理由:非管理员身份");
|
||||
}
|
||||
}
|
||||
|
||||
if(Temp1=="重启Ai"){
|
||||
if(!exports.add.Interfaces.IsAdmin(Core.GetUser(info["user_id"]))){
|
||||
Core.frame.SendMsg(connect,info,"此功能只允许机器人管理员使用。");
|
||||
|
||||
14
EasyTools.js
14
EasyTools.js
@ -22,5 +22,17 @@ exports.EasyTools = {
|
||||
}
|
||||
});
|
||||
return (EC / (KeyA.length + KeyB.length) * 2);
|
||||
})
|
||||
}),
|
||||
生成群信: ((群号) => {
|
||||
var Info = {};
|
||||
Info.group_id = 群号;
|
||||
Info.message_type = "group";
|
||||
return Info;
|
||||
}),
|
||||
生成私信: ((号码) => {
|
||||
var Info = {};
|
||||
Info.user_id = 号码;
|
||||
Info.message_type = "privace";
|
||||
return Info;
|
||||
}),
|
||||
};
|
||||
|
||||
16
EasyTools.ts
16
EasyTools.ts
@ -1,3 +1,5 @@
|
||||
import { InfoType } from "./Core";
|
||||
|
||||
// EasyTools : 提供语言分析(不准确)
|
||||
const Width = 5;//默认权重
|
||||
var FIn = ((Arr:string[],Location:Number,IsIt:string)=>{
|
||||
@ -20,5 +22,17 @@ export var EasyTools = {
|
||||
}
|
||||
});
|
||||
return (EC/(KeyA.length + KeyB.length) * 2);
|
||||
})
|
||||
}),
|
||||
生成群信:((群号:Number)=>{
|
||||
var Info = {} as InfoType;
|
||||
Info.group_id = 群号;
|
||||
Info.message_type = "group";
|
||||
return Info;
|
||||
}),
|
||||
生成私信:((号码:Number)=>{
|
||||
var Info = {} as InfoType;
|
||||
Info.user_id = 号码;
|
||||
Info.message_type = "privace";
|
||||
return Info;
|
||||
}),
|
||||
}
|
||||
@ -37,6 +37,12 @@
|
||||
"利刃":{
|
||||
"Allow":true,
|
||||
"FindIn":"fs",
|
||||
"Path":"./API/Main.js"
|
||||
"Path":"./API/Main.js",
|
||||
"About":"利刃是一个全中文开发平台"
|
||||
},
|
||||
"复读机":{
|
||||
"Allow":true,
|
||||
"FindIn":"fs",
|
||||
"Path":"./复读机.js"
|
||||
}
|
||||
}
|
||||
77
build/config.gypi
普通文件
77
build/config.gypi
普通文件
@ -0,0 +1,77 @@
|
||||
# Do not edit. File was generated by node-gyp's "configure" step
|
||||
{
|
||||
"target_defaults": {
|
||||
"cflags": [],
|
||||
"default_configuration": "Release",
|
||||
"defines": [],
|
||||
"include_dirs": [],
|
||||
"libraries": [],
|
||||
"msbuild_toolset": "v142",
|
||||
"msvs_windows_target_platform_version": "10.0.18362.0"
|
||||
},
|
||||
"variables": {
|
||||
"asan": 0,
|
||||
"build_v8_with_gn": "false",
|
||||
"coverage": "false",
|
||||
"debug_nghttp2": "false",
|
||||
"enable_lto": "false",
|
||||
"enable_pgo_generate": "false",
|
||||
"enable_pgo_use": "false",
|
||||
"force_dynamic_crt": 0,
|
||||
"host_arch": "x64",
|
||||
"icu_data_in": "..\\..\\deps/icu-small\\source/data/in\\icudt64l.dat",
|
||||
"icu_endianness": "l",
|
||||
"icu_gyp_path": "tools/icu/icu-generic.gyp",
|
||||
"icu_locales": "en,root",
|
||||
"icu_path": "deps/icu-small",
|
||||
"icu_small": "true",
|
||||
"icu_ver_major": "64",
|
||||
"nasm_version": "2.14",
|
||||
"node_byteorder": "little",
|
||||
"node_debug_lib": "false",
|
||||
"node_enable_d8": "false",
|
||||
"node_enable_v8_vtunejit": "false",
|
||||
"node_install_npm": "true",
|
||||
"node_module_version": 64,
|
||||
"node_no_browser_globals": "false",
|
||||
"node_prefix": "/usr/local",
|
||||
"node_release_urlbase": "https://nodejs.org/download/release/",
|
||||
"node_shared": "false",
|
||||
"node_shared_cares": "false",
|
||||
"node_shared_http_parser": "false",
|
||||
"node_shared_libuv": "false",
|
||||
"node_shared_nghttp2": "false",
|
||||
"node_shared_openssl": "false",
|
||||
"node_shared_zlib": "false",
|
||||
"node_tag": "",
|
||||
"node_target_type": "executable",
|
||||
"node_use_bundled_v8": "true",
|
||||
"node_use_dtrace": "false",
|
||||
"node_use_etw": "true",
|
||||
"node_use_large_pages": "false",
|
||||
"node_use_openssl": "true",
|
||||
"node_use_pch": "false",
|
||||
"node_use_perfctr": "true",
|
||||
"node_use_v8_platform": "true",
|
||||
"node_with_ltcg": "true",
|
||||
"node_without_node_options": "false",
|
||||
"openssl_fips": "",
|
||||
"openssl_no_asm": 0,
|
||||
"shlib_suffix": "so.64",
|
||||
"target_arch": "x64",
|
||||
"v8_enable_gdbjit": 0,
|
||||
"v8_enable_i18n_support": 1,
|
||||
"v8_enable_inspector": 1,
|
||||
"v8_no_strict_aliasing": 1,
|
||||
"v8_optimized_debug": 0,
|
||||
"v8_promise_internal_field_count": 1,
|
||||
"v8_random_seed": 0,
|
||||
"v8_trace_maps": 0,
|
||||
"v8_typed_array_max_size_in_heap": 0,
|
||||
"v8_use_snapshot": "true",
|
||||
"want_separate_host_toolset": 0,
|
||||
"nodedir": "C:\\Users\\1\\AppData\\Local\\node-gyp\\Cache\\10.16.3",
|
||||
"standalone_static_library": 1,
|
||||
"msbuild_path": "D:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe"
|
||||
}
|
||||
}
|
||||
12
package-lock.json
自动生成的
12
package-lock.json
自动生成的
@ -33,9 +33,9 @@
|
||||
"integrity": "sha512-TMeqbNl2fMW0nMjTEPOwe3J/PRFP4vqeoNuQMG0HlMrtm5QxKqdvAkZ1pRBQ/ulIyDD5Yq0nJ7YbdD8ey0TO3g=="
|
||||
},
|
||||
"ajv": {
|
||||
"version": "6.11.0",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.11.0.tgz",
|
||||
"integrity": "sha512-nCprB/0syFYy9fVYU1ox1l2KN8S9I+tziH8D4zdZuLT3N6RMlGSGt5FSTpAiHB/Whv8Qs1cWHma1aMKZyaHRKA==",
|
||||
"version": "6.12.2",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.2.tgz",
|
||||
"integrity": "sha512-k+V+hzjm5q/Mr8ef/1Y9goCmlsK4I6Sm74teeyGvFk1XrOsbsKLjEdrvny42CZ+a8sXbk8KWpY/bDwS+FLL2UQ==",
|
||||
"requires": {
|
||||
"fast-deep-equal": "^3.1.1",
|
||||
"fast-json-stable-stringify": "^2.0.0",
|
||||
@ -996,9 +996,9 @@
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||
},
|
||||
"psl": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/psl/-/psl-1.7.0.tgz",
|
||||
"integrity": "sha512-5NsSEDv8zY70ScRnOTn7bK7eanl2MvFrOrS/R6x+dBt5g1ghnj9Zv90kO8GwT8gxcu2ANyFprnFYB85IogIJOQ=="
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz",
|
||||
"integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ=="
|
||||
},
|
||||
"punycode": {
|
||||
"version": "2.1.1",
|
||||
|
||||
10
test2.js
普通文件
10
test2.js
普通文件
@ -0,0 +1,10 @@
|
||||
const icovn = require("iconv-lite");
|
||||
console.log(icovn.encode("你好","utf8"));
|
||||
console.log(icovn.encode("你好","gbk"));
|
||||
console.log(icovn.encode("你好","utf8").toString());
|
||||
console.log(icovn.encode("你好","gbk").toString());
|
||||
|
||||
console.log(icovn.decode(Buffer.from("你好"),"utf8"));
|
||||
console.log(icovn.decode(Buffer.from("你好"),"gbk"));
|
||||
console.log(icovn.decode(Buffer.from("你好"),"utf8").toString());
|
||||
console.log(icovn.decode(Buffer.from("你好"),"gbk").toString());
|
||||
19
复读机.js
普通文件
19
复读机.js
普通文件
@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const Core = __importStar(require("./Core"));
|
||||
(() => {
|
||||
var LastMsg = "";
|
||||
Core.AddListener((Connect, Info) => {
|
||||
if (Info.message == LastMsg) {
|
||||
Core.frame.SendMsg(Connect, Info, LastMsg);
|
||||
}
|
||||
LastMsg = Info.message;
|
||||
});
|
||||
})();
|
||||
在新工单中引用
屏蔽一个用户