ai/src/index.ts

65 lines
1.7 KiB
TypeScript
Raw Normal View History

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';
2018-08-23 08:27:39 +00:00
2018-08-26 21:59:18 +00:00
import CoreModule from './modules/core';
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';
2018-08-11 09:43:50 +00:00
import FortuneModule from './modules/fortune';
import GuessingGameModule from './modules/guessing-game';
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';
2018-08-23 08:27:39 +00:00
2019-01-14 15:14:22 +00:00
import chalk from 'chalk';
2018-08-11 06:26:25 +00:00
import * as request from 'request-promise-native';
const promiseRetry = require('promise-retry');
2018-08-11 03:34:24 +00:00
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
}
log(chalk.bold('Ai v1.0'));
2018-08-23 08:27:39 +00:00
2018-08-11 06:26:25 +00:00
promiseRetry(retry => {
2019-01-15 03:29:11 +00:00
log(`Account fetching... (${config.host})`);
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-14 15:14:22 +00:00
log(chalk.green(`Account fetched successfully: @${account.username}`));
log('Starting AiOS...');
2019-01-15 01:23:54 +00:00
const ai = new (account, run => {
new EmojiModule(ai);
new FortuneModule(ai);
new GuessingGameModule(ai);
new ReversiModule(ai);
new TimerModule(ai);
new DiceModule(ai);
new CoreModule(ai);
new PingModule(ai);
new WelcomeModule(ai);
new ServerModule(ai);
new FollowModule(ai);
new BirthdayModule(ai);
new ValentineModule(ai);
if (config.keywordEnabled) new KeywordModule(ai);
run();
});
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
});