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