mirror of
https://github.com/syuilo/ai.git
synced 2024-12-22 00:11:09 +00:00
リファクタリングなど
This commit is contained in:
parent
c32c871d4d
commit
09fc4291f0
|
@ -49,8 +49,9 @@ export default class 藍 {
|
|||
|
||||
public friends: loki.Collection<FriendDoc>;
|
||||
|
||||
constructor(account: User, ready: (run: Function) => void) {
|
||||
constructor(account: User, modules: Module[]) {
|
||||
this.account = account;
|
||||
this.modules = modules;
|
||||
|
||||
this.log('Lodaing the memory...');
|
||||
|
||||
|
@ -63,7 +64,7 @@ export default class 藍 {
|
|||
this.log(chalk.red(`Failed to load the memory: ${err}`));
|
||||
} else {
|
||||
this.log(chalk.green('The memory loaded successfully'));
|
||||
ready(this.run);
|
||||
this.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -116,6 +117,7 @@ export default class 藍 {
|
|||
// Install modules
|
||||
this.modules.forEach(m => {
|
||||
this.log(`Installing ${chalk.cyan.italic(m.name)}\tmodule...`);
|
||||
m.init(this);
|
||||
const res = m.install();
|
||||
if (res != null) {
|
||||
if (res.mentionHook) this.mentionHooks.push(res.mentionHook);
|
||||
|
|
39
src/index.ts
39
src/index.ts
|
@ -28,7 +28,7 @@ function log(msg: string): void {
|
|||
log(chalk.bold('Ai v1.0'));
|
||||
|
||||
promiseRetry(retry => {
|
||||
log(`Account fetching... (${config.host})`);
|
||||
log(`Account fetching... ${chalk.gray(config.host)}`);
|
||||
return request.post(`${config.apiUrl}/i`, {
|
||||
json: {
|
||||
i: config.i
|
||||
|
@ -37,28 +37,27 @@ promiseRetry(retry => {
|
|||
}, {
|
||||
retries: 3
|
||||
}).then(account => {
|
||||
log(chalk.green(`Account fetched successfully: @${account.username}`));
|
||||
const acct = `@${account.username}`;
|
||||
log(chalk.green(`Account fetched successfully: ${chalk.underline(acct)}`));
|
||||
|
||||
log('Starting AiOS...');
|
||||
|
||||
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();
|
||||
});
|
||||
new 藍(account, [
|
||||
new EmojiModule(),
|
||||
new FortuneModule(),
|
||||
new GuessingGameModule(),
|
||||
new ReversiModule(),
|
||||
new TimerModule(),
|
||||
new DiceModule(),
|
||||
new CoreModule(),
|
||||
new PingModule(),
|
||||
new WelcomeModule(),
|
||||
new ServerModule(),
|
||||
new FollowModule(),
|
||||
new BirthdayModule(),
|
||||
new ValentineModule(),
|
||||
new KeywordModule(),
|
||||
]);
|
||||
}).catch(e => {
|
||||
log(chalk.red('Failed to fetch the account'));
|
||||
});
|
||||
|
|
|
@ -6,9 +6,8 @@ export default abstract class Module {
|
|||
|
||||
protected ai: 藍;
|
||||
|
||||
constructor(ai: 藍) {
|
||||
public init(ai: 藍) {
|
||||
this.ai = ai;
|
||||
this.ai.modules.push(this);
|
||||
}
|
||||
|
||||
public abstract install(): InstallerResult;
|
||||
|
|
|
@ -24,6 +24,8 @@ export default class KeywordModule extends Module {
|
|||
|
||||
@autobind
|
||||
public install() {
|
||||
if (!config.keywordEnabled) return {};
|
||||
|
||||
//#region Init DB
|
||||
this.learnedKeywords = getCollection(this.ai.db, '_keyword_learnedKeywords', {
|
||||
indices: ['userId']
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import chalk from 'chalk';
|
||||
|
||||
export default function(msg: string) {
|
||||
const now = new Date();
|
||||
const date = `${zeroPad(now.getHours())}:${zeroPad(now.getMinutes())}:${zeroPad(now.getSeconds())}`;
|
||||
console.log(`${date} ${msg}`);
|
||||
console.log(`${chalk.gray(date)} ${msg}`);
|
||||
}
|
||||
|
||||
function zeroPad(num: number, length: number = 2): string {
|
||||
|
|
Loading…
Reference in a new issue