Add some comments

This commit is contained in:
syuilo 2019-01-16 02:48:14 +09:00
parent 09fc4291f0
commit eef0e78d7e
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69

View file

@ -49,6 +49,11 @@ export default class 藍 {
public friends: loki.Collection<FriendDoc>; public friends: loki.Collection<FriendDoc>;
/**
*
* @param account 使
* @param modules
*/
constructor(account: User, modules: Module[]) { constructor(account: User, modules: Module[]) {
this.account = account; this.account = account;
this.modules = modules; this.modules = modules;
@ -128,6 +133,10 @@ export default class 藍 {
this.log(chalk.green.bold('Ai am now running!')); this.log(chalk.green.bold('Ai am now running!'));
} }
/**
*
* ()
*/
@autobind @autobind
private async onReceiveMessage(msg: Message): Promise<void> { private async onReceiveMessage(msg: Message): Promise<void> {
this.log(chalk.gray(`<<< An message received: ${chalk.underline(msg.id)}`)); this.log(chalk.gray(`<<< An message received: ${chalk.underline(msg.id)}`));
@ -151,6 +160,9 @@ export default class 藍 {
let reaction = 'love'; let reaction = 'love';
//#region
// コンテキストがあればコンテキストフック呼び出し
// なければそれぞれのモジュールについてフックが引っかかるまで呼び出し
if (context != null) { if (context != null) {
const handler = this.contextHooks[context.module]; const handler = this.contextHooks[context.module];
const res = handler(msg, context.data); const res = handler(msg, context.data);
@ -170,6 +182,7 @@ export default class 藍 {
reaction = res.reaction; reaction = res.reaction;
} }
} }
//#endregion
await delay(1000); await delay(1000);
@ -189,12 +202,18 @@ export default class 藍 {
} }
} }
/**
* 稿
*/
@autobind @autobind
public async post(param: any) { public async post(param: any) {
const res = await this.api('notes/create', param); const res = await this.api('notes/create', param);
return res.createdNote; return res.createdNote;
} }
/**
*
*/
@autobind @autobind
public sendMessage(userId: any, param: any) { public sendMessage(userId: any, param: any) {
return this.api('messaging/messages/create', Object.assign({ return this.api('messaging/messages/create', Object.assign({
@ -202,6 +221,9 @@ export default class 藍 {
}, param)); }, param));
} }
/**
* APIを呼び出します
*/
@autobind @autobind
public api(endpoint: string, param?: any) { public api(endpoint: string, param?: any) {
return request.post(`${config.apiUrl}/${endpoint}`, { return request.post(`${config.apiUrl}/${endpoint}`, {
@ -211,6 +233,14 @@ export default class 藍 {
}); });
}; };
/**
*
* @param module 待ち受けるモジュール名
* @param key
* @param isDm
* @param id ID稿ID
* @param data
*/
@autobind @autobind
public subscribeReply(module: Module, key: string, isDm: boolean, id: string, data?: any) { public subscribeReply(module: Module, key: string, isDm: boolean, id: string, data?: any) {
this.contexts.insertOne(isDm ? { this.contexts.insertOne(isDm ? {
@ -228,6 +258,11 @@ export default class 藍 {
}); });
} }
/**
*
* @param module 解除するモジュール名
* @param key
*/
@autobind @autobind
public unsubscribeReply(module: Module, key: string) { public unsubscribeReply(module: Module, key: string) {
this.contexts.findAndRemove({ this.contexts.findAndRemove({