mirror of
https://github.com/syuilo/ai.git
synced 2024-11-22 05:08:00 +00:00
v
This commit is contained in:
parent
5ea387c070
commit
57aed93aff
11
package.json
11
package.json
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"_v": "1.2.6",
|
"_v": "1.2.7",
|
||||||
"main": "./built/index.js",
|
"main": "./built/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./built",
|
"start": "node ./built",
|
||||||
|
@ -38,9 +38,16 @@
|
||||||
"ws": "7.3.1"
|
"ws": "7.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@koa/router": "9.4.0",
|
||||||
"@types/jest": "26.0.14",
|
"@types/jest": "26.0.14",
|
||||||
|
"@types/koa": "2.11.4",
|
||||||
|
"@types/koa__router": "8.0.2",
|
||||||
|
"@types/websocket": "1.0.1",
|
||||||
"jest": "26.4.2",
|
"jest": "26.4.2",
|
||||||
"ts-jest": "26.3.0"
|
"koa": "2.13.0",
|
||||||
|
"koa-json-body": "5.3.0",
|
||||||
|
"ts-jest": "26.3.0",
|
||||||
|
"websocket": "1.0.32"
|
||||||
},
|
},
|
||||||
"_moduleAliases": {
|
"_moduleAliases": {
|
||||||
"@": "built"
|
"@": "built"
|
||||||
|
|
|
@ -61,6 +61,7 @@ export default class extends Module {
|
||||||
['絵文字になってほしいもの', '絵文字になってほしいものはどれですか?'],
|
['絵文字になってほしいもの', '絵文字になってほしいものはどれですか?'],
|
||||||
['Misskey本部にありそうなもの', 'みなさんは、Misskey本部にありそうなものはどれだと思いますか?'],
|
['Misskey本部にありそうなもの', 'みなさんは、Misskey本部にありそうなものはどれだと思いますか?'],
|
||||||
['燃えるゴミ', 'みなさんは、どれが燃えるゴミだと思いますか?'],
|
['燃えるゴミ', 'みなさんは、どれが燃えるゴミだと思いますか?'],
|
||||||
|
['好きなおにぎりの具', 'みなさんの好きなおにぎりの具はなんですか?'],
|
||||||
['そして輝くウルトラ', 'みなさんは、そして輝くウルトラ…?'],
|
['そして輝くウルトラ', 'みなさんは、そして輝くウルトラ…?'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,7 @@ export const itemPrefixes = [
|
||||||
'シュレディンガーの',
|
'シュレディンガーの',
|
||||||
'分散型',
|
'分散型',
|
||||||
'卵かけ',
|
'卵かけ',
|
||||||
|
'次世代',
|
||||||
];
|
];
|
||||||
|
|
||||||
export const items = [
|
export const items = [
|
||||||
|
|
67
test/_mocks_/misskey.ts
Normal file
67
test/_mocks_/misskey.ts
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
import * as http from 'http';
|
||||||
|
import * as Koa from 'koa';
|
||||||
|
import * as websocket from 'websocket';
|
||||||
|
|
||||||
|
export class Misskey {
|
||||||
|
private server: http.Server;
|
||||||
|
private streaming: websocket.connection;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
const app = new Koa();
|
||||||
|
|
||||||
|
this.server = http.createServer(app.callback());
|
||||||
|
|
||||||
|
const ws = new websocket.server({
|
||||||
|
httpServer: this.server
|
||||||
|
});
|
||||||
|
|
||||||
|
ws.on('request', async (request) => {
|
||||||
|
const q = request.resourceURL.query as ParsedUrlQuery;
|
||||||
|
|
||||||
|
this.streaming = request.accept();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.server.listen(3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public waitForStreamingMessage(handler) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const onMessage = (data: websocket.IMessage) => {
|
||||||
|
if (data.utf8Data == null) return;
|
||||||
|
const message = JSON.parse(data.utf8Data);
|
||||||
|
const result = handler(message);
|
||||||
|
if (result) {
|
||||||
|
this.streaming.off('message', onMessage);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.streaming.on('message', onMessage);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async waitForMainChannelConnected() {
|
||||||
|
await this.waitForStreamingMessage(message => {
|
||||||
|
const { type, body } = message;
|
||||||
|
if (type === 'connect') {
|
||||||
|
const { channel, id, params, pong } = body;
|
||||||
|
|
||||||
|
if (channel !== 'main') return;
|
||||||
|
|
||||||
|
if (pong) {
|
||||||
|
this.sendStreamingMessage('connected', {
|
||||||
|
id: id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public sendStreamingMessage(type: string, payload: any) {
|
||||||
|
this.streaming.send(JSON.stringify({
|
||||||
|
type: type,
|
||||||
|
body: payload
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue