ai/src/index.ts

104 lines
3.1 KiB
TypeScript
Raw Normal View History

2019-02-01 16:53:06 +00:00
// AiOS bootstrapper
import process from 'node:process';
2024-01-21 04:27:02 +00:00
import chalk from 'chalk';
import got from 'got';
import promiseRetry from 'promise-retry';
2020-09-19 01:40:44 +00:00
2024-01-21 04:27:02 +00:00
import from './ai.js';
import config from './config.js';
import _log from './utils/log.js';
import pkg from '../package.json' assert { type: 'json' };
2020-08-23 02:31:35 +00:00
2024-01-21 04:27:02 +00:00
import CoreModule from './modules/core/index.js';
import TalkModule from './modules/talk/index.js';
import BirthdayModule from './modules/birthday/index.js';
import ReversiModule from './modules/reversi/index.js';
import PingModule from './modules/ping/index.js';
import EmojiModule from './modules/emoji/index.js';
import EmojiReactModule from './modules/emoji-react/index.js';
import FortuneModule from './modules/fortune/index.js';
import GuessingGameModule from './modules/guessing-game/index.js';
import KazutoriModule from './modules/kazutori/index.js';
import KeywordModule from './modules/keyword/index.js';
import WelcomeModule from './modules/welcome/index.js';
import TimerModule from './modules/timer/index.js';
import DiceModule from './modules/dice/index.js';
import ServerModule from './modules/server/index.js';
import FollowModule from './modules/follow/index.js';
import ValentineModule from './modules/valentine/index.js';
import MazeModule from './modules/maze/index.js';
import ChartModule from './modules/chart/index.js';
import SleepReportModule from './modules/sleep-report/index.js';
import NotingModule from './modules/noting/index.js';
import PollModule from './modules/poll/index.js';
import ReminderModule from './modules/reminder/index.js';
import CheckCustomEmojisModule from './modules/check-custom-emojis/index.js';
import { User } from './misskey/user.js';
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
process.on('uncaughtException', err => {
try {
console.error(`Uncaught exception: ${err.message}`);
console.dir(err, { colors: true, depth: 2 });
} catch { }
});
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
// アカウントをフェッチ
2024-01-21 04:27:02 +00:00
return got.post(`${config.apiUrl}/i`, {
2018-08-11 06:26:25 +00:00
json: {
i: config.i
2018-08-10 17:28:31 +00:00
}
}).json<User>().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(),
new CheckCustomEmojisModule(),
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
});