对星铁命令进行标准化处理,便于后续兼容

This commit is contained in:
Kokomi 2023-05-07 03:32:08 +08:00
parent 195b39212a
commit 097bcb6649
6 changed files with 195 additions and 196 deletions

View File

@ -354,16 +354,17 @@ class PluginsLoader {
for (let val of e.message) {
switch (val.type) {
case 'text':
/** 中文#转为英文 */
val.text = val.text.replace(/|井/g, '#').trim()
if(/星铁|崩坏星穹铁道|铁道|星轨|星穹铁道|\/common\//.test(val.text)){
let msg = (val.text || '').replace(/^\s*[#井#]+\s*/, '#').replace(/^\s*[\\*※]+\s*/, '*').trim()
// 判断是否是星铁命令,若是星铁命令则标准化处理
// e.isSr = true且命令标准化为 #星铁 开头
let srReg = /^#?(\*|星铁|星轨|穹轨|星穹|崩铁|星穹铁道|崩坏星穹铁道|铁道)+/
if (srReg.test(msg)) {
console.log('sr test true')
e.isSr = true
msg = msg.replace(srReg, '#星铁')
}
if (e.msg) {
e.msg += val.text
} else {
e.msg = val.text.trim()
}
e.msg = (e.msg || '') + msg
break
case 'image':
if (!e.img) {
@ -376,11 +377,11 @@ class PluginsLoader {
e.atBot = true
} else if (val.id == e.bot.tiny_id) {
e.atBot = true
/** 多个at 以最后的为准 */
/** 多个at 以最后的为准 */
} else if (val.id) {
e.at = val.id
e.at = val.id
} else {
e.at = val.qq
e.at = val.qq
}
break
case 'file':
@ -692,7 +693,7 @@ class PluginsLoader {
if (e.group_id) {
/** 白名单群 */
if (Array.isArray(other.whiteGroup) && other.whiteGroup.length > 0) {
return other.whiteGroup.includes(Number(e.group_id));
return other.whiteGroup.includes(Number(e.group_id))
}
/** 黑名单群 */
if (Array.isArray(other.blackGroup) && other.blackGroup.length > 0) {

View File

@ -13,7 +13,7 @@ export class dailyNote extends plugin {
event: 'message',
priority: 300,
rule: [{
reg: '^#*(原神|星铁|崩坏星穹铁道|铁道)?(体力|树脂|查询体力)$',
reg: '^#*(原神|星铁)?(体力|树脂|查询体力)$',
fnc: 'note'
}]
})

View File

@ -32,7 +32,7 @@ export class gcLog extends plugin {
fnc: 'logJson'
},
{
reg: '^#*(原神|星铁|崩坏星穹铁道|铁道)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥)池*(记录|祈愿|分析)$',
reg: '^#*(原神|星铁)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥)池*(记录|祈愿|分析)$',
fnc: 'getLog'
},
{
@ -48,7 +48,7 @@ export class gcLog extends plugin {
fnc: 'helpPort'
},
{
reg: '^#*(原神|星铁|崩坏星穹铁道|铁道)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥)池*统计$',
reg: '^#*(原神|星铁)?(抽卡|抽奖|角色|武器|常驻|up|新手|光锥)池*统计$',
fnc: 'logCount'
}
]

View File

@ -42,7 +42,7 @@ export class user extends plugin {
fnc: 'bingUid'
},
{
reg: '^#(我的)?(uid|UID)[0-9]{0,2}$',
reg: '^#(原神|星铁)?(我的)?(uid|UID)[0-9]{0,2}$',
fnc: 'showUid'
},
{

View File

@ -147,78 +147,6 @@ export default class MysUser extends BaseModel {
return false
}
// 为当前MysUser绑定uid
addUid (uid) {
if (lodash.isArray(uid)) {
for (let u of uid) {
this.addUid(u)
}
return true
}
uid = '' + uid
if (/\d{9}/.test(uid) || uid === 'pub') {
if (!this.uids.includes(uid)) {
this.uids.push(uid)
}
}
return true
}
// 初始化当前MysUser缓存记录
async initCache (user) {
if (!this.ltuid || !this.servCache || !this.ck) {
return
}
// 为当前MysUser添加uid查询记录
if (!lodash.isEmpty(this.uids)) {
for (let uid of this.uids) {
if (uid !== 'pub') {
await this.addQueryUid(uid)
// 添加ltuid-uid记录用于判定ltuid绑定个数及自ltuid查询
await this.cache.zAdd(tables.uid, this.ltuid, uid)
}
}
} else {
console.log(`ltuid:${this.ltuid}暂无uid信息请检查...`)
// 公共ck暂无uid信息不添加
if (user?.qq === 'pub') {
return false
}
}
// 缓存ckData供后续缓存使用
// ltuid关系存储到与server无关的cache中方便后续检索
if (this.ckData && this.ckData.ck) {
await this.cache.kSet(tables.ck, this.ltuid, this.ckData)
}
// 缓存qq用于删除ltuid时查找
if (user && user.qq) {
let qq = user.qq === 'pub' ? 'pub' : user.qq * 1
let qqArr = await this.cache.kGet(tables.qq, this.ltuid, true)
if (!lodash.isArray(qqArr)) {
qqArr = []
}
if (!qqArr.includes(qq)) {
qqArr.push(qq)
await this.cache.kSet(tables.qq, this.ltuid, qqArr)
}
}
// 从删除记录中查找并恢复查询记录
let cacheSearchList = await this.servCache.get(tables.del, this.ltuid, true)
// 这里不直接插入,只插入当前查询记录中没有的值
if (cacheSearchList && cacheSearchList.length > 0) {
for (let searchedUid of cacheSearchList) {
// 检查对应uid是否有新的查询记录
if (!await this.getQueryLtuid(searchedUid)) {
await this.addQueryUid(searchedUid)
}
}
}
return true
}
static async eachServ (fn) {
let servs = ['mys', 'hoyolab']
for (let serv of servs) {
@ -238,82 +166,6 @@ export default class MysUser extends BaseModel {
await cache.empty(tables.qq)
}
async disable () {
await this.servCache.zDel(tables.detail, this.ltuid)
logger.mark(`[标记无效ck][ltuid:${this.ltuid}]`)
}
//
//
/**
* 删除缓存, 供User解绑CK时调用
* @param user
* @returns {Promise<boolean>}
*/
async del (user) {
if (user && user.qq) {
let qqList = await this.cache.kGet(tables.qq, this.ltuid, true)
let newList = lodash.pull(qqList, user.qq * 1)
await this.cache.kSet(tables.qq, this.ltuid, newList)
if (newList.length > 0) {
// 如果数组还有其他元素说明该ltuid还有其他绑定不进行缓存删除
return false
}
}
// 将查询过的uid缓存起来以备后续重新绑定时恢复
let uids = await this.getQueryUids()
await this.servCache.set(tables.del, uids)
// 标记ltuid为失效
await this.servCache.zDel(tables.detail, this.ltuid)
await this.cache.zDel(tables.uid, this.ltuid)
await this.cache.kDel(tables.ck, this.ltuid)
await this.cache.kDel(tables.qq, this.ltuid)
logger.mark(`[删除失效ck][ltuid:${this.ltuid}]`)
}
// 删除MysUser用户记录会反向删除User中的记录及绑定关系
async delWithUser () {
// 查找用户
let qqArr = await this.cache.kGet(tables.qq, this.ltuid, true)
if (qqArr && qqArr.length > 0) {
for (let qq of qqArr) {
let user = await NoteUser.create(qq)
if (user) {
// 调用user删除ck
await user.delCk(this.ltuid, false)
}
}
}
await this.del()
}
// 为当前用户添加uid查询记录
async addQueryUid (uid) {
if (uid) {
await this.servCache.zAdd(tables.detail, this.ltuid, uid)
}
}
// 获取当前用户已查询uid列表
async getQueryUids () {
return await this.servCache.zList(tables.detail, this.ltuid)
}
// 根据uid获取查询ltuid
async getQueryLtuid (uid) {
return await this.servCache.zKey(tables.detail, uid)
}
// 检查指定uid是否为当前MysUser所有
async ownUid (uid) {
if (!uid) {
return false
}
let uidArr = await this.cache.zList(tables.uid, this.ltuid) || []
return uid && uidArr.join(',').split(',').includes(uid + '')
}
// 获取用户统计数据
static async getStatData () {
let totalCount = {}
@ -358,13 +210,11 @@ export default class MysUser extends BaseModel {
let count = 0
await MysUser.eachServ(async function (servCache) {
let cks = await servCache.zGetDisableKey(tables.detail)
console.log('cks', cks)
for (let ck of cks) {
if (await servCache.zDel(tables.detail, ck, true)) {
count++
}
let ckUser = await MysUser.create(ck)
console.log('ckUser', ck, ckUser)
if (ckUser) {
await ckUser.delWithUser()
}
@ -462,7 +312,7 @@ export default class MysUser extends BaseModel {
}
for (let val of res.data.list) {
if (/\d{9}/.test(val.game_uid)&&val.game_biz=='hk4e_cn') {
if (/\d{9}/.test(val.game_uid) && val.game_biz === 'hk4e_cn') {
uids.push(val.game_uid + '')
}
}
@ -525,4 +375,151 @@ export default class MysUser extends BaseModel {
msg: 'CK状态正常'
}
}
// 为当前MysUser绑定uid
addUid (uid) {
if (lodash.isArray(uid)) {
for (let u of uid) {
this.addUid(u)
}
return true
}
uid = '' + uid
if (/\d{9}/.test(uid) || uid === 'pub') {
if (!this.uids.includes(uid)) {
this.uids.push(uid)
}
}
return true
}
// 初始化当前MysUser缓存记录
async initCache (user) {
if (!this.ltuid || !this.servCache || !this.ck) {
return
}
// 为当前MysUser添加uid查询记录
if (!lodash.isEmpty(this.uids)) {
for (let uid of this.uids) {
if (uid !== 'pub') {
await this.addQueryUid(uid)
// 添加ltuid-uid记录用于判定ltuid绑定个数及自ltuid查询
await this.cache.zAdd(tables.uid, this.ltuid, uid)
}
}
} else {
console.log(`ltuid:${this.ltuid}暂无uid信息请检查...`)
// 公共ck暂无uid信息不添加
if (user?.qq === 'pub') {
return false
}
}
// 缓存ckData供后续缓存使用
// ltuid关系存储到与server无关的cache中方便后续检索
if (this.ckData && this.ckData.ck) {
await this.cache.kSet(tables.ck, this.ltuid, this.ckData)
}
// 缓存qq用于删除ltuid时查找
if (user && user.qq) {
let qq = user.qq === 'pub' ? 'pub' : user.qq * 1
let qqArr = await this.cache.kGet(tables.qq, this.ltuid, true)
if (!lodash.isArray(qqArr)) {
qqArr = []
}
if (!qqArr.includes(qq)) {
qqArr.push(qq)
await this.cache.kSet(tables.qq, this.ltuid, qqArr)
}
}
// 从删除记录中查找并恢复查询记录
let cacheSearchList = await this.servCache.get(tables.del, this.ltuid, true)
// 这里不直接插入,只插入当前查询记录中没有的值
if (cacheSearchList && cacheSearchList.length > 0) {
for (let searchedUid of cacheSearchList) {
// 检查对应uid是否有新的查询记录
if (!await this.getQueryLtuid(searchedUid)) {
await this.addQueryUid(searchedUid)
}
}
}
return true
}
async disable () {
await this.servCache.zDel(tables.detail, this.ltuid)
logger.mark(`[标记无效ck][ltuid:${this.ltuid}]`)
}
//
/**
* 删除缓存, 供User解绑CK时调用
* @param user
* @returns {Promise<boolean>}
*/
async del (user) {
if (user && user.qq) {
let qqList = await this.cache.kGet(tables.qq, this.ltuid, true)
let newList = lodash.pull(qqList, user.qq * 1)
await this.cache.kSet(tables.qq, this.ltuid, newList)
if (newList.length > 0) {
// 如果数组还有其他元素说明该ltuid还有其他绑定不进行缓存删除
return false
}
}
// 将查询过的uid缓存起来以备后续重新绑定时恢复
let uids = await this.getQueryUids()
await this.servCache.set(tables.del, uids)
// 标记ltuid为失效
await this.servCache.zDel(tables.detail, this.ltuid)
await this.cache.zDel(tables.uid, this.ltuid)
await this.cache.kDel(tables.ck, this.ltuid)
await this.cache.kDel(tables.qq, this.ltuid)
logger.mark(`[删除失效ck][ltuid:${this.ltuid}]`)
}
// 删除MysUser用户记录会反向删除User中的记录及绑定关系
async delWithUser () {
// 查找用户
let qqArr = await this.cache.kGet(tables.qq, this.ltuid, true)
if (qqArr && qqArr.length > 0) {
for (let qq of qqArr) {
let user = await NoteUser.create(qq)
if (user) {
// 调用user删除ck
await user.delCk(this.ltuid, false)
}
}
}
await this.del()
}
// 为当前用户添加uid查询记录
async addQueryUid (uid) {
if (uid) {
await this.servCache.zAdd(tables.detail, this.ltuid, uid)
}
}
// 获取当前用户已查询uid列表
async getQueryUids () {
return await this.servCache.zList(tables.detail, this.ltuid)
}
// 根据uid获取查询ltuid
async getQueryLtuid (uid) {
return await this.servCache.zKey(tables.detail, uid)
}
// 检查指定uid是否为当前MysUser所有
async ownUid (uid) {
if (!uid) {
return false
}
let uidArr = await this.cache.zList(tables.uid, this.ltuid) || []
return uid && uidArr.join(',').split(',').includes(uid + '')
}
}

View File

@ -7,7 +7,7 @@ import MysUser from './mys/MysUser.js'
import MysInfo from './mys/mysInfo.js'
export default class User extends base {
constructor(e) {
constructor (e) {
super(e)
this.model = 'bingCk'
/** 绑定的uid */
@ -22,17 +22,17 @@ export default class User extends base {
}
// 获取当前user实例
async user() {
async user () {
return await MysInfo.getNoteUser(this.e)
}
async resetCk() {
async resetCk () {
let user = await this.user()
await user.initCache()
}
/** 绑定ck */
async bing() {
async bing () {
let user = await this.user()
let set = gsCfg.getConfig('mys', 'set')
@ -69,7 +69,7 @@ export default class User extends base {
/** 检查ck是否失效 */
if (!await this.checkCk(param)) {
logger.mark(`绑定cookie错误${this.checkMsg || 'cookie错误'}`)
logger.mark(`绑定cookie错误1${this.checkMsg || 'cookie错误'}`)
await this.e.reply(`绑定cookie失败${this.checkMsg || 'cookie错误'}`)
return
}
@ -82,7 +82,7 @@ export default class User extends base {
this.ltuid = userInfo.uid
this.ck = `${this.ck}ltuid=${this.ltuid};`
} else {
logger.mark(`绑定cookie错误${userFullInfo.message || 'cookie错误'}`)
logger.mark(`绑定cookie错误2${userFullInfo.message || 'cookie错误'}`)
await this.e.reply(`绑定cookie失败${userFullInfo.message || 'cookie错误'}`)
return
}
@ -116,7 +116,7 @@ export default class User extends base {
msg += '\n【#删除ck】删除当前绑定ck'
}
if (/星穹列车/.test(this.region_name)) {
msg += "\n星穹铁道支持\n功能还在咕咕咕~"
msg += '\n星穹铁道支持\n功能还在咕咕咕~'
}
msg += '\n 支持绑定多个ck'
msg = await common.makeForwardMsg(this.e, ['使用命令说明', msg], '绑定成功:使用命令说明')
@ -125,22 +125,23 @@ export default class User extends base {
}
/** 检查ck是否可用 */
async checkCk(param) {
async checkCk (param) {
let res
for (let type of ['mys', 'hoyolab']) {
let roleRes = await this.getGameRoles(type)
if (roleRes?.retcode === 0) {
res = roleRes
/** 国际服的标记 */
if (type == 'hoyolab' && typeof (param.mi18nLang) === 'string') {
if (type === 'hoyolab' && typeof (param.mi18nLang) === 'string') {
this.ck += ` mi18nLang=${param.mi18nLang};`
}
break
}
if (roleRes.retcode == -100) {
if (roleRes.retcode === -100) {
this.checkMsg = '该ck已失效请重新登录获取'
} else {
this.checkMsg = roleRes.message || 'error'
}
this.checkMsg = roleRes.message || 'error'
}
if (!res) return false
@ -153,13 +154,13 @@ export default class User extends base {
}
//避免同时多个默认展示角色时候只绑定一个
let is_chosen =false
let is_chosen = false
/** 米游社默认展示的角色 */
for (let val of res.data.list) {
if (val.is_chosen&&!is_chosen) {
if (val.is_chosen && !is_chosen) {
this.uid = val.game_uid
this.region_name = val.region_name
is_chosen=true
is_chosen = true
} else {
this.allUid.push({
uid: val.game_uid,
@ -178,17 +179,17 @@ export default class User extends base {
return this.uid
}
async getGameRoles(server = 'mys') {
async getGameRoles (server = 'mys') {
return await MysUser.getGameRole(this.ck, server)
}
// 获取米游社通行证id
async getUserInfo(server = 'mys') {
async getUserInfo (server = 'mys') {
return await MysUser.getUserFullInfo(this.ck, server)
}
/** 保存ck */
getCk() {
getCk () {
let ck = gsCfg.getBingCkSingle(this.e.user_id)
lodash.map(ck, o => {
@ -223,14 +224,14 @@ export default class User extends base {
}
/** 删除绑定ck */
async delCk(uid = '') {
async delCk (uid = '') {
let user = await this.user()
let uids = await user.delCk()
return `绑定cookie已删除,uid:${uids.join(',')}`
}
/** 绑定uid若有ck的话优先使用ck-uid */
async bingUid() {
async bingUid () {
let uid = this.e.msg.match(/[1|2|5-9][0-9]{8}/g)
if (!uid) return
uid = uid[0]
@ -240,7 +241,7 @@ export default class User extends base {
}
/** #uid */
async showUid() {
async showUid () {
let user = await this.user()
if (!user.hasCk) {
await this.e.reply(`当前绑定uid${user.uid || '无'}`, false, { at: true })
@ -255,8 +256,8 @@ export default class User extends base {
if (!region_name.includes(ckData[v].region_name)) {
region_name.push(ckData[v].region_name)
}
});
let count = 0;
})
let count = 0
for (let n of region_name) {
msg.push(n)
for (let i in uids) {
@ -273,7 +274,7 @@ export default class User extends base {
}
/** 切换uid */
async toggleUid(index) {
async toggleUid (index) {
let user = await this.user()
let uidList = user.ckUids
if (index > uidList.length) {
@ -285,7 +286,7 @@ export default class User extends base {
}
/** 加载旧ck */
async loadOldData() {
async loadOldData () {
let file = [
'./data/MysCookie/NoteCookie.json',
'./data/NoteCookie/NoteCookie.json',
@ -340,7 +341,7 @@ export default class User extends base {
}
/** 我的ck */
async myCk() {
async myCk () {
let user = await this.user()
if (!user.hasCk) {
this.e.reply('当前尚未绑定cookie')
@ -353,7 +354,7 @@ export default class User extends base {
}
}
async checkCkStatus() {
async checkCkStatus () {
let user = await this.user()
if (!user.hasCk) {
await this.e.reply(`\n未绑定CK当前绑定uid${user.uid || '无'}`, false, { at: true })
@ -385,15 +386,15 @@ export default class User extends base {
await this.e.reply(cks.join('\n----\n'), false, { at: true })
}
getGuid() {
function S4() {
getGuid () {
function S4 () {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
}
return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4())
}
async userAdmin() {
async userAdmin () {
this.model = 'userAdmin'
await MysInfo.initCache()
let stat = await MysUser.getStatData()