From b5c2ab5330f176ae3600caa7ad7a4be1cce20ca3 Mon Sep 17 00:00:00 2001 From: Kokomi <102026640+yoimiya-kokomi@users.noreply.github.com> Date: Sun, 28 May 2023 05:30:19 +0800 Subject: [PATCH] =?UTF-8?q?v3.1.0=20=E6=94=AF=E6=8C=81=E5=A4=9AUID?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=EF=BC=8C=E5=8F=AF=E7=BB=91=E5=AE=9A=E5=A4=9A?= =?UTF-8?q?=E4=B8=AAUID=E5=B9=B6=E8=BF=9B=E8=A1=8C=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 9 ++++++--- package.json | 2 +- plugins/genshin/model/db/BaseModel.js | 1 - plugins/genshin/model/mys/NoteUser.js | 5 ++++- plugins/genshin/model/user.js | 24 +++++++++++++----------- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30c3a71..f4931c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ -# 3.1.0 Dev +# 3.1.0 -* !!!暂未完成,会有很多错误,不建议升级!!! * 重构CK与UID管理逻辑 -* 底层对星铁查询进行支持 + * 支持多UID绑定,可绑定多个UID并进行切换 + * 支持原神与星铁UID共存,可针对查询命令分配对应UID + * 新增`#删除uid1`命令,可对`#uid`列表内的绑定UID进行删除 + * 使用sqlite进行ck与uid存储 +* 底层对星铁查询进行支持 **@cvs** # 3.0.2 diff --git a/package.json b/package.json index 27ccf89..bf21ef4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "miao-yunzai", - "version": "3.0.2", + "version": "3.1.0", "author": "Yoimiya-Kokomi, Le-niao", "description": "QQ group Bot", "main": "app.js", diff --git a/plugins/genshin/model/db/BaseModel.js b/plugins/genshin/model/db/BaseModel.js index 45863cb..1dfe33d 100644 --- a/plugins/genshin/model/db/BaseModel.js +++ b/plugins/genshin/model/db/BaseModel.js @@ -18,7 +18,6 @@ export default class BaseModel extends Model { static initDB (model, columns) { let name = model.name - console.log('Model Name', name) name = name.replace(/DB$/, 's') model.init(columns, { sequelize, tableName: name }) model.COLUMNS = columns diff --git a/plugins/genshin/model/mys/NoteUser.js b/plugins/genshin/model/mys/NoteUser.js index 9e62201..3efed5e 100644 --- a/plugins/genshin/model/mys/NoteUser.js +++ b/plugins/genshin/model/mys/NoteUser.js @@ -262,9 +262,12 @@ export default class NoteUser extends BaseModel { if (this.uidMap[gameKey][uid] && this.uidMap[gameKey][uid].type !== 'ck') { lodash.remove(this.uidList[gameKey], (u) => u + '' === uid + '') delete this.uidMap[gameKey][uid] + if (this.mainUid[gameKey] === uid) { + this.mainUid[gameKey] = '' + } } await this.save() - if (this.mainUid[gameKey] === uid) { + if (this.mainUid[gameKey] === '') { this.setMainUid(this.uidList[gameKey][0], game) await this.save() } diff --git a/plugins/genshin/model/user.js b/plugins/genshin/model/user.js index 9750a06..a50e0bb 100644 --- a/plugins/genshin/model/user.js +++ b/plugins/genshin/model/user.js @@ -176,27 +176,25 @@ export default class User extends base { async showUid () { let user = await this.user() let msg = [] - lodash.forEach({ gs: '原神', sr: '星穹铁道' }, (gameName, game) => { + let typeMap = { ck: 'CK Uid', reg: '绑定uid' } + lodash.forEach({ gs: '原神 (#uid)', sr: '星穹铁道 (*uid)' }, (gameName, game) => { let uidList = user.getUidList(game) let currUid = user.getUid(game) + msg.push(`【${gameName}】`) if (uidList.length === 0) { + msg.push(`暂无,通过${game === 'gs' ? '#' : '*'}绑定123456789来绑定UID`) return true } - msg.push(`【${gameName}】`) lodash.forEach(uidList, (ds, idx) => { - let tmp = `${++idx}: ${ds.uid} (${ds.type})` + let tmp = `${++idx}: ${ds.uid} (${typeMap[ds.type]})` if (currUid * 1 === ds.uid * 1) { tmp += ' ☑' } msg.push(tmp) }) }) - if (msg.length > 0) { - msg.unshift('通过【#uid+序号】来切换uid') - await this.e.reply(msg.join('\n')) - } else { - await this.e.reply('尚未绑定UID,发送CK或通过【#绑定123456789】命令来绑定UID') - } + msg.unshift('通过【#uid+序号】来切换uid,【#删除uid+序号】删除uid') + await this.e.reply(msg.join('\n')) } /** 切换uid */ @@ -266,10 +264,14 @@ export default class User extends base { /** 加载V3ck */ async loadOldDataV3 (data) { let dir = './data/MysCookie/' - Data.createDir('./data/MysCookieBak') + Data.createDir('./temp/MysCookieBak') let files = fs.readdirSync(dir).filter(file => file.endsWith('.yaml')) const readFile = promisify(fs.readFile) let promises = [] + if (files.length === 0) { + fs.rmdirSync('./data/MysCookie/') + return + } files.forEach((v) => promises.push(readFile(`${dir}${v}`, 'utf8'))) const res = await Promise.all(promises) let ret = {} @@ -332,7 +334,7 @@ export default class User extends base { } await user.save() if (fs.existsSync(`./data/MysCookie/${qq}.yaml`)) { - fs.rename(`./data/MysCookie/${qq}.yaml`, `./data/MysCookieBak/${qq}.yaml`, (err) => { + fs.rename(`./data/MysCookie/${qq}.yaml`, `./temp/MysCookieBak/${qq}.yaml`, (err) => { if (err) console.log(err) }) }