ai/src/index.ts

95 lines
2.6 KiB
TypeScript
Raw Normal View History

2019-02-01 16:53:06 +00:00
// AiOS bootstrapper
2020-09-19 01:40:44 +00:00
import 'module-alias/register';
2020-08-23 02:31:35 +00:00
import * as chalk from 'chalk';
import * as request from 'request-promise-native';
const promiseRetry = require('promise-retry');
2018-08-11 06:26:25 +00:00
import from './ai';
2018-08-11 01:42:06 +00:00
import config from './config';
2019-01-15 09:58:04 +00:00
import _log from './utils/log';
2020-09-02 12:54:01 +00:00
const pkg = require('../package.json');
2018-08-23 08:27:39 +00:00
2018-08-26 21:59:18 +00:00
import CoreModule from './modules/core';
2020-08-30 01:06:55 +00:00
import TalkModule from './modules/talk';
2019-01-14 09:17:30 +00:00
import BirthdayModule from './modules/birthday';
2018-08-11 01:42:06 +00:00
import ReversiModule from './modules/reversi';
2018-08-11 06:26:25 +00:00
import PingModule from './modules/ping';
2018-08-11 06:53:49 +00:00
import EmojiModule from './modules/emoji';
2020-08-23 03:15:11 +00:00
import EmojiReactModule from './modules/emoji-react';
2018-08-11 09:43:50 +00:00
import FortuneModule from './modules/fortune';
import GuessingGameModule from './modules/guessing-game';
2019-01-23 13:18:02 +00:00
import KazutoriModule from './modules/kazutori';
2018-08-13 08:54:56 +00:00
import KeywordModule from './modules/keyword';
2018-08-13 21:14:47 +00:00
import WelcomeModule from './modules/welcome';
2018-08-23 08:27:39 +00:00
import TimerModule from './modules/timer';
2018-09-03 14:42:28 +00:00
import DiceModule from './modules/dice';
2018-09-03 02:56:58 +00:00
import ServerModule from './modules/server';
2018-12-03 08:12:47 +00:00
import FollowModule from './modules/follow';
2019-01-12 04:14:16 +00:00
import ValentineModule from './modules/valentine';
2019-05-10 02:55:07 +00:00
import MazeModule from './modules/maze';
2019-05-12 17:09:56 +00:00
import ChartModule from './modules/chart';
2020-08-29 06:52:33 +00:00
import SleepReportModule from './modules/sleep-report';
2020-08-31 11:46:00 +00:00
import NotingModule from './modules/noting';
2020-09-12 10:46:33 +00:00
import PollModule from './modules/poll';
2020-10-31 03:18:42 +00:00
import ReminderModule from './modules/reminder';
2018-08-23 08:27:39 +00:00
2019-02-03 13:51:39 +00:00
console.log(' __ ____ _____ ___ ');
console.log(' /__\\ (_ _)( _ )/ __)');
console.log(' /(__)\\ _)(_ )(_)( \\__ \\');
console.log('(__)(__)(____)(_____)(___/\n');
2019-01-14 15:14:22 +00:00
function log(msg: string): void {
2019-01-15 03:29:11 +00:00
_log(`[Boot]: ${msg}`);
2019-01-14 15:14:22 +00:00
}
2020-09-02 12:54:01 +00:00
log(chalk.bold(`Ai v${pkg._v}`));
2018-08-23 08:27:39 +00:00
2018-08-11 06:26:25 +00:00
promiseRetry(retry => {
2019-01-15 17:10:42 +00:00
log(`Account fetching... ${chalk.gray(config.host)}`);
2019-02-01 16:53:06 +00:00
// アカウントをフェッチ
2018-08-11 06:26:25 +00:00
return request.post(`${config.apiUrl}/i`, {
json: {
i: config.i
2018-08-10 17:28:31 +00:00
}
2018-08-11 06:26:25 +00:00
}).catch(retry);
2019-01-14 15:14:22 +00:00
}, {
retries: 3
2018-08-11 06:26:25 +00:00
}).then(account => {
2019-01-15 17:10:42 +00:00
const acct = `@${account.username}`;
log(chalk.green(`Account fetched successfully: ${chalk.underline(acct)}`));
2019-01-14 15:14:22 +00:00
log('Starting AiOS...');
2019-02-01 16:53:06 +00:00
// 藍起動
2019-01-15 17:10:42 +00:00
new (account, [
2020-08-30 01:06:55 +00:00
new CoreModule(),
2019-01-15 17:10:42 +00:00
new EmojiModule(),
2020-08-23 03:15:11 +00:00
new EmojiReactModule(),
2019-01-15 17:10:42 +00:00
new FortuneModule(),
new GuessingGameModule(),
2019-01-23 13:18:02 +00:00
new KazutoriModule(),
2019-01-15 17:10:42 +00:00
new ReversiModule(),
new TimerModule(),
new DiceModule(),
2020-08-30 01:06:55 +00:00
new TalkModule(),
2019-01-15 17:10:42 +00:00
new PingModule(),
new WelcomeModule(),
new ServerModule(),
new FollowModule(),
new BirthdayModule(),
new ValentineModule(),
new KeywordModule(),
2019-05-10 02:55:07 +00:00
new MazeModule(),
2019-05-12 17:09:56 +00:00
new ChartModule(),
2020-08-29 06:52:33 +00:00
new SleepReportModule(),
2020-08-31 11:46:00 +00:00
new NotingModule(),
2020-09-12 10:46:33 +00:00
new PollModule(),
2020-10-31 03:18:42 +00:00
new ReminderModule(),
2019-01-15 17:10:42 +00:00
]);
2018-10-11 06:38:17 +00:00
}).catch(e => {
2019-01-14 15:14:22 +00:00
log(chalk.red('Failed to fetch the account'));
2018-08-11 06:26:25 +00:00
});