不要ファイル削除

This commit is contained in:
nullnyat 2023-09-23 04:05:18 +09:00
parent 9b24a61eff
commit 3566725948
6 changed files with 0 additions and 152 deletions

View File

@ -1,7 +0,0 @@
export const account = {
id: '0',
name: '藍',
username: 'ai',
host: null,
isBot: true,
};

View File

@ -1,67 +0,0 @@
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
}));
}
}

View File

@ -1,17 +0,0 @@
import * as websocket from 'websocket';
export class StreamingApi {
private ws: WS;
constructor() {
this.ws = new WS('ws://localhost/streaming');
}
public async waitForMainChannelConnected() {
await expect(this.ws).toReceiveMessage("hello");
}
public send(message) {
this.ws.send(JSON.stringify(message));
}
}

View File

@ -1,26 +0,0 @@
import autobind from 'autobind-decorator';
import Module from '@/module';
import Message from '@/message';
export default class extends Module {
public readonly name = 'test';
@autobind
public install() {
return {
mentionHook: this.mentionHook
};
}
@autobind
private async mentionHook(msg: Message) {
if (msg.text && msg.text.includes('ping')) {
msg.reply('PONG!', {
immediate: true
});
return true;
} else {
return false;
}
}
}

View File

@ -1,20 +0,0 @@
import from '@/ai';
import { account } from '#/__mocks__/account';
import TestModule from '#/__modules__/test';
import { StreamingApi } from '#/__mocks__/ws';
process.env.NODE_ENV = 'test';
let ai: ;
beforeEach(() => {
ai = new (account, [
new TestModule(),
]);
});
test('mention hook', async () => {
const streaming = new StreamingApi();
});

View File

@ -1,15 +0,0 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "../",
"paths": {
"@/*": ["../src/*"],
"#/*": ["./*"]
},
},
"compileOnSave": false,
"include": [
"**/*.ts"
]
}