This commit is contained in:
syuilo 2020-09-19 10:40:44 +09:00
parent 725305a2df
commit 6e0d5d9efb
33 changed files with 225 additions and 104 deletions

View file

@ -1,38 +1,67 @@
{
"_v": "1.2.6",
"main": "./built/index.js",
"scripts": {
"start": "node ./built",
"build": "tsc"
},
"dependencies": {
"@types/chalk": "2.2.0",
"@types/lokijs": "1.5.3",
"@types/node": "14.6.0",
"@types/promise-retry": "1.1.3",
"@types/random-seed": "0.3.3",
"@types/request-promise-native": "1.0.17",
"@types/seedrandom": "2.4.28",
"@types/twemoji-parser": "12.1.0",
"@types/uuid": "8.3.0",
"@types/ws": "7.2.6",
"autobind-decorator": "2.4.0",
"canvas": "2.6.1",
"chalk": "4.1.0",
"lokijs": "1.5.11",
"memory-streams": "0.1.3",
"misskey-reversi": "0.0.5",
"promise-retry": "2.0.1",
"random-seed": "0.3.0",
"reconnecting-websocket": "4.4.0",
"request": "2.88.2",
"request-promise-native": "1.0.9",
"seedrandom": "3.0.5",
"timeout-as-promise": "1.0.0",
"ts-node": "9.0.0",
"twemoji-parser": "13.0.0",
"typescript": "4.0.2",
"uuid": "8.3.0",
"ws": "7.3.1"
}
"main": "./built/index.js",
"scripts": {
"start": "node ./built",
"build": "tsc",
"test": "jest"
},
"dependencies": {
"@types/chalk": "2.2.0",
"@types/lokijs": "1.5.3",
"@types/node": "14.6.0",
"@types/promise-retry": "1.1.3",
"@types/random-seed": "0.3.3",
"@types/request-promise-native": "1.0.17",
"@types/seedrandom": "2.4.28",
"@types/twemoji-parser": "12.1.0",
"@types/uuid": "8.3.0",
"@types/ws": "7.2.6",
"autobind-decorator": "2.4.0",
"canvas": "2.6.1",
"chalk": "4.1.0",
"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",
"request": "2.88.2",
"request-promise-native": "1.0.9",
"seedrandom": "3.0.5",
"timeout-as-promise": "1.0.0",
"ts-node": "9.0.0",
"twemoji-parser": "13.0.0",
"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"
}
}
}

View file

@ -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,

View file

@ -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');

View file

@ -2,7 +2,7 @@ export type User = {
id: string;
name: string;
username: string;
host: string;
isFollowing: boolean;
host?: string | null;
isFollowing?: boolean;
isBot: boolean;
};

View file

@ -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);

View file

@ -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';

View file

@ -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 = ['さん', 'くん', '君', 'ちゃん', '様', '先生'];

View file

@ -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';

View file

@ -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';

View file

@ -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 = [
'👏',

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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

View file

@ -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) {

View file

@ -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';

View file

@ -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 {

View file

@ -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';

View file

@ -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';

View file

@ -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 = {};

View file

@ -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';

View file

@ -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 {

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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
View file

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

17
test/_mocks_/ws.ts Normal file
View 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
View 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
View 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
View file

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

View file

@ -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": [