x
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
protoc-gen-grpc --js_out=import_style=commonjs:. --grpc_out=. srpc.proto
|
||||
protoc-gen-grpc --ts_out=service=grpc-node:. --grpc_out=. srpc.proto
|
||||
|
||||
protoc --go_out=. -I. --go-grpc_out=. srpc.proto
|
||||
|
||||
protoc --plugin=protoc-gen-ts=$(which protoc-gen-ts) --js_out=import_style=commonjs,binary:./ --ts_out=./ srpc.proto
|
||||
|
||||
protoc --js_out=import_style=commonjs,binary:. --grpc_out=. srpc.proto
|
||||
|
||||
|
||||
#ok
|
||||
protoc --go_out=. -I. --go-grpc_out=. srpc.proto
|
||||
protoc-gen-grpc --ts_out=service=grpc-node:. --grpc_out=. srpc.proto
|
||||
|
||||
#打包
|
||||
npx webpack --config webpack.config.js
|
||||
|
||||
#linux编译:
|
||||
scp /Users/a1-6/Code/sillyplus/proto3/dist/sillygirl.js root@imdraw.com:/root/node/node-18.16.1/lib
|
||||
ssh root@imdraw.com
|
||||
cd /root/node/node-18.16.1 && ninja -C out/Release && scp -P 20211 out/Release/node a1-6@frp2.echowxsy.cn:/Users/a1-6/Code/nodes/node_linux_amd64
|
||||
#
|
||||
macos编译:
|
||||
cp /Users/a1-6/Code/sillyplus/proto3/dist/sillygirl.js /Users/a1-6/Code/node/node-v18.16.1/lib/sillygirl.js && cd /Users/a1-6/Code/node/node-v18.16.1 && ninja -C out/Release && cp out/Release/node /Users/a1-6/Code/nodes/node_darwin_arm64
|
||||
|
||||
#压缩
|
||||
cd /Users/a1-6/Code/nodes/node_darwin_arm64 && zip node_darwin_arm64.zip node
|
||||
cd /Users/a1-6/Code/nodes/node_linux_amd64 && zip node_linux_amd64.zip node
|
||||
@@ -1,13 +0,0 @@
|
||||
protoc-gen-grpc --js_out=import_style=commonjs:. --grpc_out=. srpc.proto
|
||||
protoc-gen-grpc --ts_out=service=grpc-node:. --grpc_out=. srpc.proto
|
||||
|
||||
protoc --go_out=. -I. --go-grpc_out=. srpc.proto
|
||||
|
||||
protoc --plugin=protoc-gen-ts=$(which protoc-gen-ts) --js_out=import_style=commonjs,binary:./ --ts_out=./ srpc.proto
|
||||
|
||||
protoc --js_out=import_style=commonjs,binary:. --grpc_out=. srpc.proto
|
||||
|
||||
|
||||
//ok
|
||||
protoc --go_out=. -I. --go-grpc_out=. srpc.proto
|
||||
protoc-gen-grpc --ts_out=service=grpc-node:. --grpc_out=. srpc.proto
|
||||
Vendored
+9
-3
@@ -73,8 +73,8 @@ declare class Adapter {
|
||||
constructor(options: {
|
||||
platform?: string;
|
||||
bot_id?: string;
|
||||
replyHandler?: (message: Message) => string | undefined;
|
||||
actionHandler?: (message: Message) => string | undefined;
|
||||
replyHandler?: (message: Message) => string | undefined | Promise<string | undefined>;
|
||||
actionHandler?: (message: Message) => string | undefined | Promise<string | undefined>;
|
||||
});
|
||||
setActionHandler(func: (action: {}) => any): void;
|
||||
receive(message: Message): Promise<Sender>;
|
||||
@@ -84,4 +84,10 @@ declare class Adapter {
|
||||
}
|
||||
declare let sender: Sender;
|
||||
declare function sleep(ms: number | undefined): Promise<unknown>;
|
||||
export { Adapter, Bucket, sender, sleep };
|
||||
declare let utils: {
|
||||
parseCQText: (text: string, prefix?: string) => (string | {
|
||||
type: string;
|
||||
params: any;
|
||||
})[];
|
||||
};
|
||||
export { Adapter, Bucket, sender, sleep, utils };
|
||||
|
||||
+40
-9
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.sleep = exports.sender = exports.Bucket = exports.Adapter = void 0;
|
||||
exports.utils = exports.sleep = exports.sender = exports.Bucket = exports.Adapter = void 0;
|
||||
const srpc_1 = require("./srpc");
|
||||
const grpc_1 = __importStar(require("@grpc/grpc-js"));
|
||||
let client = new srpc_1.srpc.SillyGirlServiceClient("localhost:50051", grpc_1.credentials.createInsecure());
|
||||
@@ -538,23 +538,23 @@ class Adapter {
|
||||
this.bot_id = options.bot_id;
|
||||
if (options.replyHandler) {
|
||||
const call = client.AdapterRegist();
|
||||
let callback = options.replyHandler;
|
||||
call.on("data", (response) => {
|
||||
// console.log("start on data")
|
||||
call.on("data", async (response) => {
|
||||
let message = JSON.parse(response.value);
|
||||
const { echo, __type__ } = message;
|
||||
delete message.__type__;
|
||||
delete message.echo;
|
||||
if (__type__ == "reply") {
|
||||
if (__type__ == "reply" && options.replyHandler) {
|
||||
let v = (await options.replyHandler(message)) ?? "";
|
||||
call.write(new srpc_1.srpc.AdapterRegistRequest({
|
||||
bot_id: echo,
|
||||
platform: callback(message),
|
||||
platform: v,
|
||||
}));
|
||||
}
|
||||
if (__type__ == "action" && options.actionHandler) {
|
||||
let v = await options.actionHandler(message);
|
||||
call.write(new srpc_1.srpc.AdapterRegistRequest({
|
||||
bot_id: echo,
|
||||
platform: options.actionHandler(message),
|
||||
platform: v,
|
||||
}));
|
||||
}
|
||||
// console.log("end on data")
|
||||
@@ -637,9 +637,40 @@ async function sleep(ms) {
|
||||
}
|
||||
exports.sleep = sleep;
|
||||
class Console {
|
||||
error = (message, ...optionalParams) => {
|
||||
};
|
||||
error = (message, ...optionalParams) => { };
|
||||
info = (message, ...optionalParams) => { };
|
||||
log = (message, ...optionalParams) => { };
|
||||
debug = (message, ...optionalParams) => { };
|
||||
}
|
||||
let utils = {
|
||||
parseCQText: (text, prefix = "CQ") => {
|
||||
const cqRegex = new RegExp(`\\[${prefix}:(\\w+)(.*?)\\]`, "g");
|
||||
const cqMatches = text.matchAll(cqRegex);
|
||||
const result = [];
|
||||
let lastIndex = 0;
|
||||
for (const match of cqMatches) {
|
||||
// 添加 CQ 码前的文本
|
||||
const matchIndex = text.indexOf(match[0], lastIndex);
|
||||
if (matchIndex > lastIndex) {
|
||||
result.push(text.slice(lastIndex, matchIndex));
|
||||
}
|
||||
// 解析 CQ 码
|
||||
const params = {};
|
||||
const paramRegex = /(\w+)=([^,]+)/g;
|
||||
const paramMatches = match[2].matchAll(paramRegex);
|
||||
for (const paramMatch of paramMatches) {
|
||||
params[paramMatch[1]] = paramMatch[2].trim();
|
||||
}
|
||||
result.push({
|
||||
type: match[1],
|
||||
params: params,
|
||||
});
|
||||
lastIndex = matchIndex + match[0].length;
|
||||
}
|
||||
if (lastIndex < text.length) {
|
||||
result.push(text.slice(lastIndex));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
||||
exports.utils = utils;
|
||||
|
||||
+50
-11
@@ -619,33 +619,39 @@ class Adapter {
|
||||
constructor(options: {
|
||||
platform?: string;
|
||||
bot_id?: string;
|
||||
replyHandler?: (message: Message) => string | undefined;
|
||||
actionHandler?: (message: Message) => string | undefined;
|
||||
replyHandler?: (
|
||||
message: Message
|
||||
) => string | undefined | Promise<string | undefined>;
|
||||
actionHandler?: (
|
||||
message: Message
|
||||
) => string | undefined | Promise<string | undefined>;
|
||||
}) {
|
||||
this.platform = options.platform;
|
||||
this.bot_id = options.bot_id;
|
||||
if (options.replyHandler) {
|
||||
const call = client.AdapterRegist();
|
||||
let callback: any = options.replyHandler;
|
||||
call.on("data", (response) => {
|
||||
// let callback: any = ;
|
||||
call.on("data", async (response) => {
|
||||
// console.log("start on data")
|
||||
let message = JSON.parse(response.value);
|
||||
const { echo, __type__ } = message;
|
||||
delete message.__type__;
|
||||
delete message.echo;
|
||||
if (__type__ == "reply") {
|
||||
if (__type__ == "reply" && options.replyHandler) {
|
||||
let v = (await options.replyHandler(message)) ?? "";
|
||||
call.write(
|
||||
new srpc.AdapterRegistRequest({
|
||||
bot_id: echo,
|
||||
platform: callback(message),
|
||||
platform: v,
|
||||
})
|
||||
);
|
||||
}
|
||||
if (__type__ == "action" && options.actionHandler) {
|
||||
let v = await options.actionHandler(message);
|
||||
call.write(
|
||||
new srpc.AdapterRegistRequest({
|
||||
bot_id: echo,
|
||||
platform: options.actionHandler(message),
|
||||
platform: v,
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -737,12 +743,45 @@ async function sleep(ms: number | undefined) {
|
||||
}
|
||||
|
||||
class Console {
|
||||
error = (message?: any, ...optionalParams: any[]) => {
|
||||
|
||||
};
|
||||
error = (message?: any, ...optionalParams: any[]) => {};
|
||||
info = (message?: any, ...optionalParams: any[]) => {};
|
||||
log = (message?: any, ...optionalParams: any[]) => {};
|
||||
debug = (message?: any, ...optionalParams: any[]) => {};
|
||||
}
|
||||
|
||||
export { Adapter, Bucket, sender, sleep };
|
||||
let utils = {
|
||||
parseCQText: (text: string, prefix = "CQ") => {
|
||||
const cqRegex = new RegExp(`\\[${prefix}:(\\w+)(.*?)\\]`, "g");
|
||||
const cqMatches = text.matchAll(cqRegex);
|
||||
const result = [];
|
||||
|
||||
let lastIndex = 0;
|
||||
for (const match of cqMatches) {
|
||||
// 添加 CQ 码前的文本
|
||||
const matchIndex = text.indexOf(match[0], lastIndex);
|
||||
if (matchIndex > lastIndex) {
|
||||
result.push(text.slice(lastIndex, matchIndex));
|
||||
}
|
||||
|
||||
// 解析 CQ 码
|
||||
const params: any = {};
|
||||
const paramRegex = /(\w+)=([^,]+)/g;
|
||||
const paramMatches = match[2].matchAll(paramRegex);
|
||||
for (const paramMatch of paramMatches) {
|
||||
params[paramMatch[1]] = paramMatch[2].trim();
|
||||
}
|
||||
result.push({
|
||||
type: match[1],
|
||||
params: params,
|
||||
});
|
||||
|
||||
lastIndex = matchIndex + match[0].length;
|
||||
}
|
||||
if (lastIndex < text.length) {
|
||||
result.push(text.slice(lastIndex));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
||||
|
||||
export { Adapter, Bucket, sender, sleep, utils };
|
||||
|
||||
@@ -61,5 +61,4 @@ module.exports = {
|
||||
allowlist: [/grpc/, "google-protobuf"],
|
||||
}),
|
||||
],
|
||||
};
|
||||
// npx webpack --config webpack.config.js
|
||||
};
|
||||
Reference in New Issue
Block a user