Make async

This commit is contained in:
syuilo 2019-01-23 21:49:10 +09:00
parent 29eae273e5
commit e88bffa93c
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
10 changed files with 18 additions and 18 deletions

View file

@ -15,8 +15,8 @@ import getCollection from './utils/get-collection';
import Stream from './stream';
import log from './utils/log';
type MentionHook = (msg: Message) => boolean | HandlerResult;
type ContextHook = (msg: Message, data?: any) => void | HandlerResult;
type MentionHook = (msg: Message) => Promise<boolean | HandlerResult>;
type ContextHook = (msg: Message, data?: any) => Promise<void | HandlerResult>;
export type HandlerResult = {
reaction: string;
@ -165,7 +165,7 @@ export default class 藍 {
// なければそれぞれのモジュールについてフックが引っかかるまで呼び出し
if (context != null) {
const handler = this.contextHooks[context.module];
const res = handler(msg, context.data);
const res = await handler(msg, context.data);
if (res != null && typeof res === 'object') {
reaction = res.reaction;
@ -173,10 +173,10 @@ export default class 藍 {
} else {
let res: boolean | HandlerResult;
this.mentionHooks.some(handler => {
res = handler(msg);
return res === true || typeof res === 'object';
});
for (const handler of this.mentionHooks) {
res = await handler(msg);
if (res === true || typeof res === 'object') break;
}
if (res != null && typeof res === 'object') {
reaction = res.reaction;

View file

@ -21,7 +21,7 @@ export default class extends Module {
}
@autobind
private mentionHook(msg: Message) {
private async mentionHook(msg: Message) {
if (!msg.text) return false;
return (
@ -313,7 +313,7 @@ export default class extends Module {
}
@autobind
private contextHook(msg: Message, data: any) {
private async contextHook(msg: Message, data: any) {
if (msg.text == null) return;
const done = () => {

View file

@ -14,7 +14,7 @@ export default class extends Module {
}
@autobind
private mentionHook(msg: Message) {
private async mentionHook(msg: Message) {
if (msg.text == null) return false;
const query = msg.text.match(/([0-9]+)[dD]([0-9]+)/);

View file

@ -137,7 +137,7 @@ export default class extends Module {
}
@autobind
private mentionHook(msg: Message) {
private async mentionHook(msg: Message) {
if (msg.includes(['顔文字', '絵文字', 'emoji', '福笑い'])) {
const hand = hands[Math.floor(Math.random() * hands.length)];
const face = faces[Math.floor(Math.random() * faces.length)];

View file

@ -13,7 +13,7 @@ export default class extends Module {
}
@autobind
private mentionHook(msg: Message) {
private async mentionHook(msg: Message) {
if (msg.text && msg.includes(['フォロー', 'フォロバ', 'follow me'])) {
if (!msg.user.isFollowing) {
this.ai.api('following/create', {

View file

@ -16,7 +16,7 @@ export default class extends Module {
}
@autobind
private mentionHook(msg: Message) {
private async mentionHook(msg: Message) {
if (msg.includes(['占', 'うらな', '運勢', 'おみくじ'])) {
const date = new Date();
const seed = `${date.getFullYear()}/${date.getMonth()}/${date.getDate()}@${msg.userId}`;

View file

@ -32,7 +32,7 @@ export default class extends Module {
}
@autobind
private mentionHook(msg: Message) {
private async mentionHook(msg: Message) {
if (!msg.includes(['数当て', '数あて'])) return false;
const exist = this.guesses.findOne({
@ -69,7 +69,7 @@ export default class extends Module {
}
@autobind
private contextHook(msg: Message) {
private async contextHook(msg: Message) {
if (msg.text == null) return;
const exist = this.guesses.findOne({

View file

@ -13,7 +13,7 @@ export default class extends Module {
}
@autobind
private mentionHook(msg: Message) {
private async mentionHook(msg: Message) {
if (msg.text && msg.text.includes('ping')) {
msg.reply('PONG!');
return true;

View file

@ -33,7 +33,7 @@ export default class extends Module {
}
@autobind
private mentionHook(msg: Message) {
private async mentionHook(msg: Message) {
if (msg.includes(['リバーシ', 'オセロ', 'reversi', 'othello'])) {
if (config.reversiEnabled) {
msg.reply(serifs.reversi.ok);

View file

@ -14,7 +14,7 @@ export default class extends Module {
}
@autobind
private mentionHook(msg: Message) {
private async mentionHook(msg: Message) {
const secondsQuery = (msg.text || '').match(/([0-9]+)秒/);
const minutesQuery = (msg.text || '').match(/([0-9]+)分/);
const hoursQuery = (msg.text || '').match(/([0-9]+)時間/);