From b72dc81d6c2f90e6ff5899c36e28c57fc17909df Mon Sep 17 00:00:00 2001 From: n1lsqn Date: Mon, 13 Nov 2023 15:00:16 +0900 Subject: [PATCH] fix --- src/modules/core/index.ts | 74 +++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/src/modules/core/index.ts b/src/modules/core/index.ts index 0e8b659..d138a17 100644 --- a/src/modules/core/index.ts +++ b/src/modules/core/index.ts @@ -60,39 +60,59 @@ export default class extends Module { return true; } - @autobind - private setName(msg: Message): boolean { - if (!msg.text) return false; - if (!msg.text.includes('って呼んで')) return false; - if (msg.text.startsWith('って呼んで')) return false; +@autobind + private setName(msg: Message): boolean { + if (!msg.text) { + console.error("Message text is empty or undefined."); + return false; + } - const name = msg.text.match(/^(.+?)って呼んで/)![1]; + if (!msg.text.includes('って呼んで')) { + console.error("Message text does not include 'って呼んで'."); + return false; + } - if (name.length > 10) { - msg.reply(serifs.core.tooLong); - return true; - } + if (msg.text.startsWith('って呼んで')) { + console.error("Message text starts with 'って呼んで'."); + return false; + } - if (safeForInterpolate(name)) { - msg.reply(serifs.core.invalidName); - return true; - } + const matchResult = msg.text.match(/^(.+?)って呼んで/); - const withSan = titles.some(t => name.endsWith(t)); + if (!matchResult) { + console.error("Name not found in the message text."); + return false; + } - if (withSan) { - msg.friend.updateName(name); - msg.reply(serifs.core.setNameOk(name)); - } else { - msg.reply(serifs.core.san).then(reply => { - this.subscribeReply(msg.userId, reply.id, { - name: name - }); - }); - } + const name = matchResult[1]; - return true; - } + if (name.length > 10) { + console.error("Name length exceeds 10 characters."); + msg.reply(serifs.core.tooLong); + return true; + } + + if (safeForInterpolate(name)) { + console.error("Invalid name."); + msg.reply(serifs.core.invalidName); + return true; + } + + const withSan = titles.some(t => name.endsWith(t)); + + if (withSan) { + msg.friend.updateName(name); + msg.reply(serifs.core.setNameOk(name)); + } else { + msg.reply(serifs.core.san).then(reply => { + this.subscribeReply(msg.userId, reply.id, { + name: name + }); + }); + } + + return true; +} @autobind private modules(msg: Message): boolean {