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",
|
"main": "./built/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./built",
|
"start": "node ./built",
|
||||||
"build": "tsc"
|
"build": "tsc",
|
||||||
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/chalk": "2.2.0",
|
"@types/chalk": "2.2.0",
|
||||||
|
@ -22,6 +23,7 @@
|
||||||
"lokijs": "1.5.11",
|
"lokijs": "1.5.11",
|
||||||
"memory-streams": "0.1.3",
|
"memory-streams": "0.1.3",
|
||||||
"misskey-reversi": "0.0.5",
|
"misskey-reversi": "0.0.5",
|
||||||
|
"module-alias": "2.2.2",
|
||||||
"promise-retry": "2.0.1",
|
"promise-retry": "2.0.1",
|
||||||
"random-seed": "0.3.0",
|
"random-seed": "0.3.0",
|
||||||
"reconnecting-websocket": "4.4.0",
|
"reconnecting-websocket": "4.4.0",
|
||||||
|
@ -34,5 +36,32 @@
|
||||||
"typescript": "4.0.2",
|
"typescript": "4.0.2",
|
||||||
"uuid": "8.3.0",
|
"uuid": "8.3.0",
|
||||||
"ws": "7.3.1"
|
"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.account = account;
|
||||||
this.modules = modules;
|
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,
|
autoload: true,
|
||||||
autosave: true,
|
autosave: true,
|
||||||
autosaveInterval: 1000,
|
autosaveInterval: 1000,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
// AiOS bootstrapper
|
// AiOS bootstrapper
|
||||||
|
|
||||||
|
import 'module-alias/register';
|
||||||
|
|
||||||
import * as chalk from 'chalk';
|
import * as chalk from 'chalk';
|
||||||
import * as request from 'request-promise-native';
|
import * as request from 'request-promise-native';
|
||||||
const promiseRetry = require('promise-retry');
|
const promiseRetry = require('promise-retry');
|
||||||
|
|
|
@ -2,7 +2,7 @@ export type User = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
username: string;
|
username: string;
|
||||||
host: string;
|
host?: string | null;
|
||||||
isFollowing: boolean;
|
isFollowing?: boolean;
|
||||||
isBot: boolean;
|
isBot: boolean;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Friend from '../../friend';
|
import Friend from '../../friend';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
|
|
||||||
function zeroPadding(num: number, length: number): string {
|
function zeroPadding(num: number, length: number): string {
|
||||||
return ('0000000000' + num).slice(-length);
|
return ('0000000000' + num).slice(-length);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
import { renderChart } from './render-chart';
|
import { renderChart } from './render-chart';
|
||||||
import { items } from '../../vocabulary';
|
import { items } from '../../vocabulary';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
import { safeForInterpolate } from '../../utils/safe-for-interpolate';
|
import { safeForInterpolate } from '../../utils/safe-for-interpolate';
|
||||||
|
|
||||||
const titles = ['さん', 'くん', '君', 'ちゃん', '様', '先生'];
|
const titles = ['さん', 'くん', '君', 'ちゃん', '様', '先生'];
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
public readonly name = 'dice';
|
public readonly name = 'dice';
|
||||||
|
|
|
@ -2,7 +2,7 @@ import autobind from 'autobind-decorator';
|
||||||
import { parse } from 'twemoji-parser';
|
import { parse } from 'twemoji-parser';
|
||||||
|
|
||||||
import { Note } from '../../misskey/note';
|
import { Note } from '../../misskey/note';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Stream from '../../stream';
|
import Stream from '../../stream';
|
||||||
import includes from '../../utils/includes';
|
import includes from '../../utils/includes';
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
|
|
||||||
const hands = [
|
const hands = [
|
||||||
'👏',
|
'👏',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
public readonly name = 'follow';
|
public readonly name = 'follow';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
import * as seedrandom from 'seedrandom';
|
import * as seedrandom from 'seedrandom';
|
||||||
import { genItem } from '../../vocabulary';
|
import { genItem } from '../../vocabulary';
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import * as loki from 'lokijs';
|
import * as loki from 'lokijs';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
public readonly name = 'guessingGame';
|
public readonly name = 'guessingGame';
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import * as loki from 'lokijs';
|
import * as loki from 'lokijs';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
|
import { User } from '@/misskey/user';
|
||||||
type User = {
|
|
||||||
id: string;
|
|
||||||
username: string;
|
|
||||||
host: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Game = {
|
type Game = {
|
||||||
votes: {
|
votes: {
|
||||||
user: User;
|
user: {
|
||||||
|
id: string;
|
||||||
|
username: string;
|
||||||
|
host: User['host'];
|
||||||
|
};
|
||||||
number: number;
|
number: number;
|
||||||
}[];
|
}[];
|
||||||
isEnded: boolean;
|
isEnded: boolean;
|
||||||
|
@ -173,14 +172,14 @@ export default class extends Module {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function acct(user: User): string {
|
function acct(user: Game['votes'][0]['user']): string {
|
||||||
return user.host
|
return user.host
|
||||||
? `@${user.username}@${user.host}`
|
? `@${user.username}@${user.host}`
|
||||||
: `@${user.username}`;
|
: `@${user.username}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let results: string[] = [];
|
let results: string[] = [];
|
||||||
let winner: User | null = null;
|
let winner: Game['votes'][0]['user'] | null = null;
|
||||||
|
|
||||||
for (let i = 100; i >= 0; i--) {
|
for (let i = 100; i >= 0; i--) {
|
||||||
const users = game.votes
|
const users = game.votes
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import * as loki from 'lokijs';
|
import * as loki from 'lokijs';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
import { mecab } from './mecab';
|
import { mecab } from './mecab';
|
||||||
|
|
||||||
function kanaToHira(str: string) {
|
function kanaToHira(str: string) {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
import { genMaze } from './gen-maze';
|
import { genMaze } from './gen-maze';
|
||||||
import { renderMaze } from './render-maze';
|
import { renderMaze } from './render-maze';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
public readonly name = 'maze';
|
public readonly name = 'maze';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
import { genItem } from '../../vocabulary';
|
import { genItem } from '../../vocabulary';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
public readonly name = 'ping';
|
public readonly name = 'ping';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
import { genItem } from '../../vocabulary';
|
import { genItem } from '../../vocabulary';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import { Note } from '../../misskey/note';
|
import { Note } from '../../misskey/note';
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import * as request from 'request-promise-native';
|
import * as request from 'request-promise-native';
|
||||||
import Reversi, { Color } from 'misskey-reversi';
|
import Reversi, { Color } from 'misskey-reversi';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
import { User } from '../../misskey/user';
|
import { User } from '../../misskey/user';
|
||||||
|
|
||||||
const db = {};
|
const db = {};
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
import Friend from '../../friend';
|
import Friend from '../../friend';
|
||||||
import getDate from '../../utils/get-date';
|
import getDate from '../../utils/get-date';
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
public readonly name = 'sleepReport';
|
public readonly name = 'sleepReport';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import { HandlerResult } from '../../ai';
|
import { HandlerResult } from '../../ai';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
import serifs, { getSerif } from '../../serifs';
|
import serifs, { getSerif } from '../../serifs';
|
||||||
import getDate from '../../utils/get-date';
|
import getDate from '../../utils/get-date';
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Message from '../../message';
|
import Message from '@/message';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
public readonly name = 'timer';
|
public readonly name = 'timer';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
import Friend from '../../friend';
|
import Friend from '../../friend';
|
||||||
import serifs from '../../serifs';
|
import serifs from '@/serifs';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
public readonly name = 'valentine';
|
public readonly name = 'valentine';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import autobind from 'autobind-decorator';
|
import autobind from 'autobind-decorator';
|
||||||
import Module from '../../module';
|
import Module from '@/module';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
public readonly name = 'welcome';
|
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,
|
"strictNullChecks": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"target": "es2017",
|
"target": "es2020",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"removeComments": false,
|
"removeComments": false,
|
||||||
"noLib": false,
|
"noLib": false,
|
||||||
"outDir": "built",
|
"outDir": "built",
|
||||||
"rootDir": "src"
|
"rootDir": "src",
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["src/*"]
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"compileOnSave": false,
|
"compileOnSave": false,
|
||||||
"include": [
|
"include": [
|
||||||
|
|
Loading…
Reference in a new issue