diff --git a/src/api/bot/core.ts b/src/api/bot/core.ts index b13402dce9ad9f38b73a11a3db3bf4513c3b4f4c..12d1b639e9563b0ed20a2d7dcadb979cd5b73ac5 100644 --- a/src/api/bot/core.ts +++ b/src/api/bot/core.ts @@ -8,6 +8,13 @@ import getUserSummary from '../../common/get-user-summary'; import Othello, { ai as othelloAi } from '../../common/othello'; +const hmm = [ + '?', + 'ãµã…~む...?', + 'ã¡ã‚‡ã£ã¨ä½•è¨€ã£ã¦ã‚‹ã‹ã‚ã‹ã‚‰ãªã„ã§ã™', + '「ヘルプã€ã¨è¨€ã†ã¨åˆ©ç”¨å¯èƒ½ãªæ“作ãŒç¢ºèªã§ãã¾ã™ã‚ˆ' +]; + /** * Botã®é 脳 */ @@ -119,7 +126,7 @@ export default class BotCore extends EventEmitter { return await this.context.greet(); default: - return '?'; + return hmm[Math.floor(Math.random() * hmm.length)]; } } @@ -164,7 +171,7 @@ export default class BotCore extends EventEmitter { public async showUserCommand(q: string): Promise<string | void> { try { - const user = await require('../../endpoints/users/show')({ + const user = await require('../endpoints/users/show')({ username: q.substr(1) }, this.user); @@ -280,11 +287,10 @@ class PostContext extends Context { class GuessingGameContext extends Context { private secret: number; - private try: number; + private history: number[] = []; public async greet(): Promise<string> { this.secret = Math.floor(Math.random() * 100); - this.try = 0; this.emit('updated'); return '0~100ã®ç§˜å¯†ã®æ•°ã‚’当ã¦ã¦ã¿ã¦ãã ã•ã„:'; } @@ -301,16 +307,16 @@ class GuessingGameContext extends Context { return 'æ•´æ•°ã§æŽ¨æ¸¬ã—ã¦ãã ã•ã„。「やã‚ã‚‹ã€ã¨è¨€ã†ã¨ã‚²ãƒ¼ãƒ ã‚’ã‚„ã‚ã¾ã™ã€‚'; } - this.try++; + this.history.push(guess); this.emit('updated'); if (this.secret < guess) { - return `${guess}よりもå°ã•ã„ã§ã™ã`; + return this.history.indexOf(guess) === -1 ? `${guess}よりもå°ã•ã„ã§ã™ã` : `ã‚‚ã†ä¸€åº¦è¨€ã„ã¾ã™ãŒ${guess}よりå°ã•ã„ã§ã™ã‚ˆ`; } else if (this.secret > guess) { - return `${guess}よりも大ãã„ã§ã™ã`; + return this.history.indexOf(guess) === -1 ? `${guess}よりも大ãã„ã§ã™ã` : `ã‚‚ã†ä¸€åº¦è¨€ã„ã¾ã™ãŒ${guess}より大ãã„ã§ã™ã‚ˆ`; } else { this.bot.clearContext(); - return `æ£è§£ã§ã™ðŸŽ‰ (${this.try}回目ã§å½“ã¦ã¾ã—ãŸ)`; + return `æ£è§£ã§ã™ðŸŽ‰ (${this.history.length}回目ã§å½“ã¦ã¾ã—ãŸ)`; } } @@ -319,7 +325,7 @@ class GuessingGameContext extends Context { type: 'guessing-game', content: { secret: this.secret, - try: this.try + history: this.history } }; } @@ -327,7 +333,7 @@ class GuessingGameContext extends Context { public static import(bot: BotCore, data: any) { const context = new GuessingGameContext(bot); context.secret = data.secret; - context.try = data.try; + context.history = data.history; return context; } } @@ -350,7 +356,14 @@ class OthelloContext extends Context { this.bot.clearContext(); return 'オセãƒã‚’ã‚„ã‚ã¾ã—ãŸã€‚'; } - this.othello.setByNumber('black', parseInt(query, 10)); + + const n = parseInt(query, 10); + + if (isNaN(n)) { + return '番å·ã§æŒ‡å®šã—ã¦ãã ã•ã„。「やã‚ã‚‹ã€ã¨è¨€ã†ã¨ã‚²ãƒ¼ãƒ ã‚’ã‚„ã‚ã¾ã™ã€‚'; + } + + this.othello.setByNumber('black', n); const s = this.othello.toString() + '\n\n...(AI)...\n\n'; othelloAi('white', this.othello); if (this.othello.getPattern('black').length === 0) {