mirror of
https://github.com/syuilo/ai.git
synced 2024-11-21 20:58:00 +00:00
wip
This commit is contained in:
parent
725305a2df
commit
6e0d5d9efb
31
package.json
31
package.json
|
@ -3,7 +3,8 @@
|
|||
"main": "./built/index.js",
|
||||
"scripts": {
|
||||
"start": "node ./built",
|
||||
"build": "tsc"
|
||||
"build": "tsc",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/chalk": "2.2.0",
|
||||
|
@ -22,6 +23,7 @@
|
|||
"lokijs": "1.5.11",
|
||||
"memory-streams": "0.1.3",
|
||||
"misskey-reversi": "0.0.5",
|
||||
"module-alias": "2.2.2",
|
||||
"promise-retry": "2.0.1",
|
||||
"random-seed": "0.3.0",
|
||||
"reconnecting-websocket": "4.4.0",
|
||||
|
@ -34,5 +36,32 @@
|
|||
"typescript": "4.0.2",
|
||||
"uuid": "8.3.0",
|
||||
"ws": "7.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "26.0.14",
|
||||
"jest": "26.4.2",
|
||||
"ts-jest": "26.3.0"
|
||||
},
|
||||
"_moduleAliases": {
|
||||
"@": "built"
|
||||
},
|
||||
"jest": {
|
||||
"testRegex": "/test/.*",
|
||||
"moduleFileExtensions": [
|
||||
"ts",
|
||||
"js"
|
||||
],
|
||||
"transform": {
|
||||
"^.+\\.ts$": "ts-jest"
|
||||
},
|
||||
"globals": {
|
||||
"ts-jest": {
|
||||
"tsConfig": "test/tsconfig.json"
|
||||
}
|
||||
},
|
||||
"moduleNameMapper": {
|
||||
"^@/(.+)": "<rootDir>/src/$1",
|
||||
"^#/(.+)": "<rootDir>/test/$1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,9 +80,11 @@ export default class 藍 {
|
|||
this.account = account;
|
||||
this.modules = modules;
|
||||
|
||||
this.log('Lodaing the memory...');
|
||||
const file = process.env.NODE_ENV === 'test' ? 'test.memory.json' : 'memory.json';
|
||||
|
||||
this.db = new loki('memory.json', {
|
||||
this.log(`Lodaing the memory from ${file}...`);
|
||||
|
||||
this.db = new loki(file, {
|
||||
autoload: true,
|
||||
autosave: true,
|
||||
autosaveInterval: 1000,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
// AiOS bootstrapper
|
||||
|
||||
import 'module-alias/register';
|
||||
|
||||
import * as chalk from 'chalk';
|
||||
import * as request from 'request-promise-native';
|
||||
const promiseRetry = require('promise-retry');
|
||||
|
|
|
@ -2,7 +2,7 @@ export type User = {
|
|||
id: string;
|
||||
name: string;
|
||||
username: string;
|
||||
host: string;
|
||||
isFollowing: boolean;
|
||||
host?: string | null;
|
||||
isFollowing?: boolean;
|
||||
isBot: boolean;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import Module from '@/module';
|
||||
import Friend from '../../friend';
|
||||
import serifs from '../../serifs';
|
||||
import serifs from '@/serifs';
|
||||
|
||||
function zeroPadding(num: number, length: number): string {
|
||||
return ('0000000000' + num).slice(-length);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import serifs from '../../serifs';
|
||||
import Message from '../../message';
|
||||
import Module from '@/module';
|
||||
import serifs from '@/serifs';
|
||||
import Message from '@/message';
|
||||
import { renderChart } from './render-chart';
|
||||
import { items } from '../../vocabulary';
|
||||
import config from '../../config';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import Message from '../../message';
|
||||
import serifs from '../../serifs';
|
||||
import Module from '@/module';
|
||||
import Message from '@/message';
|
||||
import serifs from '@/serifs';
|
||||
import { safeForInterpolate } from '../../utils/safe-for-interpolate';
|
||||
|
||||
const titles = ['さん', 'くん', '君', 'ちゃん', '様', '先生'];
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import Message from '../../message';
|
||||
import serifs from '../../serifs';
|
||||
import Module from '@/module';
|
||||
import Message from '@/message';
|
||||
import serifs from '@/serifs';
|
||||
|
||||
export default class extends Module {
|
||||
public readonly name = 'dice';
|
||||
|
|
|
@ -2,7 +2,7 @@ import autobind from 'autobind-decorator';
|
|||
import { parse } from 'twemoji-parser';
|
||||
|
||||
import { Note } from '../../misskey/note';
|
||||
import Module from '../../module';
|
||||
import Module from '@/module';
|
||||
import Stream from '../../stream';
|
||||
import includes from '../../utils/includes';
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import Message from '../../message';
|
||||
import serifs from '../../serifs';
|
||||
import Module from '@/module';
|
||||
import Message from '@/message';
|
||||
import serifs from '@/serifs';
|
||||
|
||||
const hands = [
|
||||
'👏',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import Message from '../../message';
|
||||
import Module from '@/module';
|
||||
import Message from '@/message';
|
||||
|
||||
export default class extends Module {
|
||||
public readonly name = 'follow';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import Message from '../../message';
|
||||
import serifs from '../../serifs';
|
||||
import Module from '@/module';
|
||||
import Message from '@/message';
|
||||
import serifs from '@/serifs';
|
||||
import * as seedrandom from 'seedrandom';
|
||||
import { genItem } from '../../vocabulary';
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import * as loki from 'lokijs';
|
||||
import Module from '../../module';
|
||||
import Message from '../../message';
|
||||
import serifs from '../../serifs';
|
||||
import Module from '@/module';
|
||||
import Message from '@/message';
|
||||
import serifs from '@/serifs';
|
||||
|
||||
export default class extends Module {
|
||||
public readonly name = 'guessingGame';
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import * as loki from 'lokijs';
|
||||
import Module from '../../module';
|
||||
import Message from '../../message';
|
||||
import serifs from '../../serifs';
|
||||
|
||||
type User = {
|
||||
id: string;
|
||||
username: string;
|
||||
host: string;
|
||||
};
|
||||
import Module from '@/module';
|
||||
import Message from '@/message';
|
||||
import serifs from '@/serifs';
|
||||
import { User } from '@/misskey/user';
|
||||
|
||||
type Game = {
|
||||
votes: {
|
||||
user: User;
|
||||
user: {
|
||||
id: string;
|
||||
username: string;
|
||||
host: User['host'];
|
||||
};
|
||||
number: number;
|
||||
}[];
|
||||
isEnded: boolean;
|
||||
|
@ -173,14 +172,14 @@ export default class extends Module {
|
|||
return;
|
||||
}
|
||||
|
||||
function acct(user: User): string {
|
||||
function acct(user: Game['votes'][0]['user']): string {
|
||||
return user.host
|
||||
? `@${user.username}@${user.host}`
|
||||
: `@${user.username}`;
|
||||
}
|
||||
|
||||
let results: string[] = [];
|
||||
let winner: User | null = null;
|
||||
let winner: Game['votes'][0]['user'] | null = null;
|
||||
|
||||
for (let i = 100; i >= 0; i--) {
|
||||
const users = game.votes
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import * as loki from 'lokijs';
|
||||
import Module from '../../module';
|
||||
import Module from '@/module';
|
||||
import config from '../../config';
|
||||
import serifs from '../../serifs';
|
||||
import serifs from '@/serifs';
|
||||
import { mecab } from './mecab';
|
||||
|
||||
function kanaToHira(str: string) {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import serifs from '../../serifs';
|
||||
import Module from '@/module';
|
||||
import serifs from '@/serifs';
|
||||
import { genMaze } from './gen-maze';
|
||||
import { renderMaze } from './render-maze';
|
||||
import Message from '../../message';
|
||||
import Message from '@/message';
|
||||
|
||||
export default class extends Module {
|
||||
public readonly name = 'maze';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import serifs from '../../serifs';
|
||||
import Module from '@/module';
|
||||
import serifs from '@/serifs';
|
||||
import { genItem } from '../../vocabulary';
|
||||
|
||||
export default class extends Module {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import Message from '../../message';
|
||||
import Module from '@/module';
|
||||
import Message from '@/message';
|
||||
|
||||
export default class extends Module {
|
||||
public readonly name = 'ping';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Message from '../../message';
|
||||
import Module from '../../module';
|
||||
import serifs from '../../serifs';
|
||||
import Message from '@/message';
|
||||
import Module from '@/module';
|
||||
import serifs from '@/serifs';
|
||||
import { genItem } from '../../vocabulary';
|
||||
import config from '../../config';
|
||||
import { Note } from '../../misskey/note';
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import * as request from 'request-promise-native';
|
||||
import Reversi, { Color } from 'misskey-reversi';
|
||||
import config from '../../config';
|
||||
import serifs from '../../serifs';
|
||||
import serifs from '@/serifs';
|
||||
import { User } from '../../misskey/user';
|
||||
|
||||
const db = {};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import * as childProcess from 'child_process';
|
||||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import serifs from '../../serifs';
|
||||
import Module from '@/module';
|
||||
import serifs from '@/serifs';
|
||||
import config from '../../config';
|
||||
import Message from '../../message';
|
||||
import Message from '@/message';
|
||||
import Friend from '../../friend';
|
||||
import getDate from '../../utils/get-date';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import serifs from '../../serifs';
|
||||
import Module from '@/module';
|
||||
import serifs from '@/serifs';
|
||||
import config from '../../config';
|
||||
|
||||
export default class extends Module {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import serifs from '../../serifs';
|
||||
import Module from '@/module';
|
||||
import serifs from '@/serifs';
|
||||
|
||||
export default class extends Module {
|
||||
public readonly name = 'sleepReport';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import { HandlerResult } from '../../ai';
|
||||
import Module from '../../module';
|
||||
import Message from '../../message';
|
||||
import Module from '@/module';
|
||||
import Message from '@/message';
|
||||
import serifs, { getSerif } from '../../serifs';
|
||||
import getDate from '../../utils/get-date';
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import Message from '../../message';
|
||||
import serifs from '../../serifs';
|
||||
import Module from '@/module';
|
||||
import Message from '@/message';
|
||||
import serifs from '@/serifs';
|
||||
|
||||
export default class extends Module {
|
||||
public readonly name = 'timer';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import Module from '@/module';
|
||||
import Friend from '../../friend';
|
||||
import serifs from '../../serifs';
|
||||
import serifs from '@/serifs';
|
||||
|
||||
export default class extends Module {
|
||||
public readonly name = 'valentine';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Module from '../../module';
|
||||
import Module from '@/module';
|
||||
|
||||
export default class extends Module {
|
||||
public readonly name = 'welcome';
|
||||
|
|
7
test/_mocks_/account.ts
Normal file
7
test/_mocks_/account.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
export const account = {
|
||||
id: '0',
|
||||
name: '藍',
|
||||
username: 'ai',
|
||||
host: null,
|
||||
isBot: true,
|
||||
};
|
17
test/_mocks_/ws.ts
Normal file
17
test/_mocks_/ws.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
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));
|
||||
}
|
||||
}
|
26
test/_modules_/test.ts
Normal file
26
test/_modules_/test.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
20
test/core.ts
Normal file
20
test/core.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
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();
|
||||
|
||||
|
||||
});
|
15
test/tsconfig.json
Normal file
15
test/tsconfig.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"rootDir": "../",
|
||||
"paths": {
|
||||
"@/*": ["../src/*"],
|
||||
"#/*": ["./*"]
|
||||
},
|
||||
},
|
||||
"compileOnSave": false,
|
||||
"include": [
|
||||
"**/*.ts"
|
||||
]
|
||||
}
|
|
@ -8,12 +8,16 @@
|
|||
"strictNullChecks": true,
|
||||
"experimentalDecorators": true,
|
||||
"sourceMap": false,
|
||||
"target": "es2017",
|
||||
"target": "es2020",
|
||||
"module": "commonjs",
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"outDir": "built",
|
||||
"rootDir": "src"
|
||||
"rootDir": "src",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
},
|
||||
},
|
||||
"compileOnSave": false,
|
||||
"include": [
|
||||
|
|
Loading…
Reference in a new issue