From 37f94bc0c193c3b1112ec28c519b7e558a543234 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 21 Jan 2024 14:21:48 +0900 Subject: [PATCH] :v: --- package.json | 8 ++++++-- src/friend.ts | 15 +++++++++++++++ src/modules/core/index.ts | 2 +- src/modules/maze/gen-maze.ts | 2 +- src/modules/maze/render-maze.ts | 2 +- src/modules/reversi/index.ts | 13 ++++++++++++- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 2fdeb73..950d452 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "type": "module", "main": "./built/index.js", "scripts": { - "start": "node ./built", + "start": "nodemon ./built", "build": "tspc", "test": "jest" }, @@ -23,6 +23,7 @@ "lokijs": "1.5.12", "memory-streams": "0.1.3", "misskey-reversi": "0.0.5", + "nodemon": "3.0.3", "promise-retry": "2.0.1", "random-seed": "0.3.0", "reconnecting-websocket": "4.4.0", @@ -68,5 +69,8 @@ "^@/(.+)": "/src/$1", "^#/(.+)": "/test/$1" } - } + }, + "nodemonConfig": { + "ignore": ["memory.json"] + } } diff --git a/src/friend.ts b/src/friend.ts index 30ddef8..1ac199e 100644 --- a/src/friend.ts +++ b/src/friend.ts @@ -15,6 +15,7 @@ export type FriendDoc = { perModulesData?: any; married?: boolean; transferCode?: string; + reversiStrength?: number | null; }; export default class Friend { @@ -154,6 +155,20 @@ export default class Friend { this.save(); } + @bindThis + public updateReversiStrength(strength: number | null) { + if (strength == null) { + this.doc.reversiStrength = null; + this.save(); + return; + } + + if (strength < 0) strength = 0; + if (strength > 5) strength = 5; + this.doc.reversiStrength = strength; + this.save(); + } + @bindThis public save() { this.ai.friends.update(this.doc); diff --git a/src/modules/core/index.ts b/src/modules/core/index.ts index feafdac..6fba045 100644 --- a/src/modules/core/index.ts +++ b/src/modules/core/index.ts @@ -66,7 +66,7 @@ export default class extends Module { if (!msg.text.includes('って呼んで')) return false; if (msg.text.startsWith('って呼んで')) return false; - const name = msg.text.match(/^(.+?)って呼んで/)![1]; + const name = msg.text.match(/^(.+?)って呼んで/g)![1]; if (name.length > 10) { msg.reply(serifs.core.tooLong); diff --git a/src/modules/maze/gen-maze.ts b/src/modules/maze/gen-maze.ts index 050f0ad..fa074b7 100644 --- a/src/modules/maze/gen-maze.ts +++ b/src/modules/maze/gen-maze.ts @@ -1,4 +1,4 @@ -import * as gen from 'random-seed'; +import gen from 'random-seed'; import { CellType } from './maze.js'; const cellVariants = { diff --git a/src/modules/maze/render-maze.ts b/src/modules/maze/render-maze.ts index 9e2b064..60177ba 100644 --- a/src/modules/maze/render-maze.ts +++ b/src/modules/maze/render-maze.ts @@ -1,4 +1,4 @@ -import * as gen from 'random-seed'; +import gen from 'random-seed'; import { createCanvas } from 'canvas'; import { CellType } from './maze.js'; diff --git a/src/modules/reversi/index.ts b/src/modules/reversi/index.ts index 2838fd8..987d0dc 100644 --- a/src/modules/reversi/index.ts +++ b/src/modules/reversi/index.ts @@ -54,6 +54,10 @@ export default class extends Module { if (config.reversiEnabled) { msg.reply(serifs.reversi.ok); + if (msg.includes(['接待'])) { + msg.friend.updateReversiStrength(0); + } + this.ai.api('reversi/match', { userId: msg.userId }); @@ -85,6 +89,13 @@ export default class extends Module { @bindThis private onReversiGameStart(game: any) { + let strength = 4; + const friend = this.ai.lookupFriend(game.user1Id !== this.ai.account.id ? game.user1Id : game.user2Id)!; + if (friend != null) { + strength = friend.doc.reversiStrength ?? 4; + friend.updateReversiStrength(null); + } + this.log(`enter reversi game room: ${game.id}`); // ゲームストリームに接続 @@ -102,7 +113,7 @@ export default class extends Module { id: 'strength', type: 'radio', label: '強さ', - value: 4, + value: strength, items: [{ label: '接待', value: 0