适配亚服新UID (#364)

This commit is contained in:
Ca(HCO₃)₂ 2024-02-04 09:02:39 +08:00 committed by GitHub
parent 7636951048
commit 14e58fc4ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 176 additions and 154 deletions

View File

@ -46,19 +46,21 @@ export class gcLog extends plugin {
})
this.androidUrl = "https://docs.qq.com/doc/DUWpYaXlvSklmVXlX"
Object.defineProperty(this, "button", { get() {
this.prefix = this.e?.isSr ? "*" : "#"
return segment.button([
{ text: "角色记录", callback: `${this.prefix}角色记录` },
{ text: "角色统计", callback: `${this.prefix}角色统计` },
],[
{ text: "武器记录", callback: `${this.prefix}武器记录` },
{ text: "武器统计", callback: `${this.prefix}武器统计` },
],[
{ text: "常驻记录", callback: `${this.prefix}常驻记录` },
{ text: "常驻统计", callback: `${this.prefix}常驻统计` },
])
}})
Object.defineProperty(this, "button", {
get() {
this.prefix = this.e?.isSr ? "*" : "#"
return segment.button([
{ text: "角色记录", callback: `${this.prefix}角色记录` },
{ text: "角色统计", callback: `${this.prefix}角色统计` },
], [
{ text: "武器记录", callback: `${this.prefix}武器记录` },
{ text: "武器统计", callback: `${this.prefix}武器统计` },
], [
{ text: "常驻记录", callback: `${this.prefix}常驻记录` },
{ text: "常驻统计", callback: `${this.prefix}常驻统计` },
])
}
})
}
async init() {
@ -73,7 +75,7 @@ export class gcLog extends plugin {
accept() {
if (this.e.file) {
let name = this.e.file?.name
if (/(.*)[1-9][0-9]{8}(.*).json/ig.test(name)) {
if (/(.*)([1-9]|18)[0-9]{8}(.*).json/ig.test(name)) {
this.e.msg = "#json文件导入记录"
return true
}

View File

@ -96,7 +96,13 @@ export class takeBirthdayPhoto extends plugin {
}
async getServer(uid) {
switch (String(uid)[0]) {
let uidPrefix = uid.toString()
if (uidPrefix.length == 10) {
uidPrefix = uidPrefix.slice(0, 2)
} else {
uidPrefix = uidPrefix.slice(0, 1)
}
switch (uidPrefix) {
case '1':
case '2':
return 'cn_gf01'
@ -107,6 +113,7 @@ export class takeBirthdayPhoto extends plugin {
case '7':
return 'os_euro'
case '8':
case '18':
return 'os_asia'
case '9':
return 'os_cht'

View File

@ -4,7 +4,7 @@ import gsCfg from '../model/gsCfg.js'
import User from '../model/user.js'
export class user extends plugin {
constructor (e) {
constructor(e) {
super({
name: '用户绑定',
dsc: '米游社ck绑定游戏uid绑定',
@ -42,7 +42,7 @@ export class user extends plugin {
fnc: 'delUid'
},
{
reg: '^#(原神|星铁)?绑定(uid|UID)?\\s*[1-9][0-9]{8}$',
reg: '^#(原神|星铁)?绑定(uid|UID)?\\s*([1-9]|18)[0-9]{8}$',
fnc: 'bingUid'
},
{
@ -66,13 +66,13 @@ export class user extends plugin {
this.User = new User(e)
}
async init () {
async init() {
/** 加载旧的绑定ck json */
await this.loadOldData()
}
/** 接受到消息都会执行一次 */
accept () {
accept() {
if (!this.e.msg) return
// 由于手机端米游社网页可能获取不到ltuid 可以尝试在通行证页面获取login_uid
if (/(ltoken|ltoken_v2)/.test(this.e.msg) && /(ltuid|login_uid|ltmid_v2)/.test(this.e.msg)) {
@ -93,9 +93,9 @@ export class user extends plugin {
}
/** 绑定uid */
saveUid () {
saveUid() {
if (!this.e.msg) return
let uid = this.e.msg.match(/[1|2|3|5-9][0-9]{8}/g)
let uid = this.e.msg.match(/([1-9]|18)[0-9]{8}/g)
if (!uid) {
this.reply('uid输入错误', false, { at: true })
return
@ -106,23 +106,23 @@ export class user extends plugin {
}
/** 未登录ck */
async noLogin () {
async noLogin() {
this.reply('绑定Cookie失败\n请先【登录米游社】或【登录通行证】再获取Cookie')
}
/** #ck代码 */
async ckCode () {
async ckCode() {
await this.reply('javascript:(()=>{prompt(\'\',document.cookie)})();')
}
/** ck帮助 */
async ckHelp () {
async ckHelp() {
let set = gsCfg.getConfig('mys', 'set')
await this.reply(`Cookie绑定配置教程${set.cookieDoc}\n获取Cookie后【私聊发送】进行绑定`)
}
/** 绑定ck */
async bingCk () {
async bingCk() {
let set = gsCfg.getConfig('mys', 'set')
if (!this.e.ck) {
@ -134,18 +134,18 @@ export class user extends plugin {
}
/** 删除ck */
async delCk () {
async delCk() {
let msg = await this.User.delCk()
await this.reply(msg)
}
/** 绑定uid */
async bingUid () {
async bingUid() {
await this.User.bingUid()
}
/** #uid */
async showUid () {
async showUid() {
let index = this.e.msg.match(/[0-9]{1,2}/g)
if (index && index[0]) {
await this.User.toggleUid(index[0])
@ -154,7 +154,7 @@ export class user extends plugin {
}
}
async delUid () {
async delUid() {
let index = this.e.msg.match(/[0-9]{1,2}$/g)
let uidIdx = index && index[0]
let game = this.e
@ -164,7 +164,7 @@ export class user extends plugin {
}
/** 我的ck */
async myCk () {
async myCk() {
if (this.e.isGroup) {
await this.reply('请私聊查看')
return
@ -173,18 +173,18 @@ export class user extends plugin {
}
/** 加载旧的绑定ck json */
async loadOldData () {
async loadOldData() {
await this.User.loadOldDataV2()
await this.User.loadOldDataV3()
await this.User.loadOldUid()
}
/** 检查用户CK状态 **/
async checkCkStatus () {
async checkCkStatus() {
await this.User.checkCkStatus()
}
async bindNoteUser () {
async bindNoteUser() {
await this.User.bindNoteUser()
}
}

View File

@ -182,7 +182,7 @@ export default class ExportLog extends base {
/** json导入抽卡记录 */
async logJson() {
let uid = /[1-9][0-9]{8}/g.exec(this.e.file.name)[0]
let uid = /([1-9]|18)[0-9]{8}/g.exec(this.e.file.name)[0]
let textPath = `${this.path}${this.e.file.name}`
/** 获取文件下载链接 */
let fileUrl = await this.e.friend.getFileUrl(this.e.file.fid)

View File

@ -8,7 +8,7 @@ import { Character, Weapon } from '#miao.models'
/** 配置文件 */
class GsCfg {
constructor () {
constructor() {
this.isSr = false
/** 默认设置 */
this.defSetPath = './plugins/genshin/defSet/'
@ -24,7 +24,7 @@ class GsCfg {
this.ignore = ['mys.pubCk', 'gacha.set', 'bot.help', 'role.name']
}
get element () {
get element() {
return { ...this.getdefSet('element', 'role'), ...this.getdefSet('element', 'weapon') }
}
@ -32,12 +32,12 @@ class GsCfg {
* @param app 功能
* @param name 配置文件名称
*/
getdefSet (app, name) {
getdefSet(app, name) {
return this.getYaml(app, name, 'defSet')
}
/** 用户配置 */
getConfig (app, name) {
getConfig(app, name) {
if (this.ignore.includes(`${app}.${name}`)) {
return this.getYaml(app, name, 'config')
}
@ -51,7 +51,7 @@ class GsCfg {
* @param name 名称
* @param type 默认跑配置-defSet用户配置-config
*/
getYaml (app, name, type) {
getYaml(app, name, type) {
let file = this.getFilePath(app, name, type)
let key = `${app}.${name}`
@ -71,7 +71,7 @@ class GsCfg {
return this[type][key]
}
getFilePath (app, name, type) {
getFilePath(app, name, type) {
if (type == 'defSet') {
return `${this.defSetPath}${app}/${name}.yaml`
} else {
@ -80,7 +80,7 @@ class GsCfg {
}
/** 监听配置文件 */
watch (file, app, name, type = 'defSet') {
watch(file, app, name, type = 'defSet') {
let key = `${app}.${name}`
if (this.watcher[type][key]) return
@ -98,7 +98,7 @@ class GsCfg {
}
/** 读取所有用户绑定的ck */
async getBingCk (game = 'gs') {
async getBingCk(game = 'gs') {
let ck = {}
let ckQQ = {}
let noteCk = {}
@ -126,13 +126,13 @@ class GsCfg {
/**
* 原神角色id转换角色名字
*/
roleIdToName (id) {
roleIdToName(id) {
let char = Character.get(id)
return char?.name || ''
}
/** 原神角色别名转id */
roleNameToID (keyword, isSr) {
roleNameToID(keyword, isSr) {
let char = Character.get(keyword, isSr ? 'sr' : 'gs')
return char?.id || false
}
@ -143,18 +143,18 @@ class GsCfg {
* @param name 名称
* @param isWeapon 是否武器
*/
shortName (name, isWeapon = false) {
shortName(name, isWeapon = false) {
let obj = (isWeapon ? Weapon : Character).get(name)
return obj.abbr || obj.name || ''
}
/** 公共配置ck文件修改hook */
async change_myspubCk () {
async change_myspubCk() {
await MysInfo.initCache()
await MysInfo.initPubCk()
}
getGachaSet (groupId = '') {
getGachaSet(groupId = '') {
let config = this.getYaml('gacha', 'set', 'config')
let def = config.default
if (config[groupId]) {
@ -163,8 +163,8 @@ class GsCfg {
return def
}
getMsgUid (msg) {
let ret = /[1|2|5-9][0-9]{8}/g.exec(msg)
getMsgUid(msg) {
let ret = /([1-9]|18)[0-9]{8}/g.exec(msg)
if (!ret) return false
return ret[0]
}
@ -178,8 +178,8 @@ class GsCfg {
* @return alias 当前别名
* @return uid 游戏uid
*/
getRole (msg, filterMsg = '', isSr = false) {
let alias = msg.replace(/#|老婆|老公|[1|2|3|5-9][0-9]{8}/g, '').trim()
getRole(msg, filterMsg = '', isSr = false) {
let alias = msg.replace(/#|老婆|老公|([1-9]|18)[0-9]{8}/g, '').trim()
if (filterMsg) {
alias = alias.replace(new RegExp(filterMsg, 'g'), '').trim()
}
@ -204,7 +204,7 @@ class GsCfg {
}
cpCfg (app, name) {
cpCfg(app, name) {
if (!fs.existsSync('./plugins/genshin/config')) {
fs.mkdirSync('./plugins/genshin/config')
}
@ -216,7 +216,7 @@ class GsCfg {
}
// 仅供内部调用
_getAbbr () {
_getAbbr() {
if (this[this.isSr ? 'sr_nameID' : 'nameID']) return
this.nameID = new Map()
@ -250,7 +250,7 @@ class GsCfg {
// 仅供内部调用
_roleNameToID (keyword, isSr) {
_roleNameToID(keyword, isSr) {
if (isSr) this.isSr = isSr
if (!isNaN(keyword)) keyword = Number(keyword)
this._getAbbr()
@ -259,8 +259,8 @@ class GsCfg {
}
// 仅供内部调用
_getRole (msg, filterMsg = '', isSr = false) {
let alias = msg.replace(/#|老婆|老公|[1|2|3|5-9][0-9]{8}/g, '').trim()
_getRole(msg, filterMsg = '', isSr = false) {
let alias = msg.replace(/#|老婆|老公|([1-9]|18)[0-9]{8}/g, '').trim()
if (filterMsg) {
alias = alias.replace(new RegExp(filterMsg, 'g'), '').trim()
}
@ -279,46 +279,46 @@ class GsCfg {
}
}
getWeaponDataByWeaponHash (hash) {
getWeaponDataByWeaponHash(hash) {
console.log('gsCfg.getWeaponDataByWeaponHash() 已废弃')
return {}
}
getAllAbbr () {
getAllAbbr() {
console.log('gsCfg.getAllAbbr() 已废弃')
return {}
}
getBingCkSingle (userId) {
getBingCkSingle(userId) {
console.log('gsCfg.getBingCkSingle() 已废弃')
return {}
}
saveBingCk (userId, data) {
saveBingCk(userId, data) {
console.log('gsCfg.saveBingCk() 已废弃')
}
getElementByRoleName (roleName) {
getElementByRoleName(roleName) {
console.log('gsCfg.getElementByRoleName() 已废弃')
return ''
}
getSkillDataByskillId (skillId, roleName) {
getSkillDataByskillId(skillId, roleName) {
console.log('gsCfg.getSkillDataByskillId() 已废弃')
return {}
}
fightPropIdToName (propId) {
fightPropIdToName(propId) {
console.log('gsCfg.fightPropIdToName() 已废弃')
return ''
}
getRoleTalentByTalentId (talentId) {
getRoleTalentByTalentId(talentId) {
console.log('gsCfg.getRoleTalentByTalentId 已废弃')
return {}
}
getAbbr () {
getAbbr() {
console.log('gsCfg.getAbbr() 已经废弃')
}

View File

@ -40,7 +40,7 @@ const tables = {
export default class MysUser extends BaseModel {
constructor (ltuid) {
constructor(ltuid) {
super()
if (!ltuid) {
return false
@ -56,12 +56,12 @@ export default class MysUser extends BaseModel {
// 可传入ltuid、cookie、ck对象来创建MysUser实例
get uid () {
get uid() {
return this.uids?.gs?.[0] || ''
}
// 在仅传入ltuid时必须是之前传入过的才能被识别
static async create (ltuid, db = false) {
static async create(ltuid, db = false) {
ltuid = MysUtil.getLtuid(ltuid)
if (!ltuid) {
return false
@ -71,7 +71,7 @@ export default class MysUser extends BaseModel {
return mys
}
static async forEach (fn) {
static async forEach(fn) {
let dbs = await MysUserDB.findAll()
await Data.forEach(dbs, async (db) => {
let mys = await MysUser.create(db.ltuid, db)
@ -80,7 +80,7 @@ export default class MysUser extends BaseModel {
}
// 根据uid获取查询MysUser
static async getByQueryUid (uid, game = 'gs', onlySelfCk = false) {
static async getByQueryUid(uid, game = 'gs', onlySelfCk = false) {
let servCache = DailyCache.create(uid, game)
// 查找已经查询过的ltuid || 分配最少查询的ltuid
@ -122,7 +122,7 @@ export default class MysUser extends BaseModel {
return false
}
static async eachServ (fn) {
static async eachServ(fn) {
await MysUtil.eachServ(async (serv) => {
await MysUtil.eachGame(async (game) => {
let servCache = DailyCache.create(serv, game)
@ -132,7 +132,7 @@ export default class MysUser extends BaseModel {
}
// 清除当日缓存
static async clearCache () {
static async clearCache() {
await MysUser.eachServ(async function (servCache) {
await servCache.empty(tables.detail)
})
@ -143,7 +143,7 @@ export default class MysUser extends BaseModel {
}
// 获取用户统计数据
static async getStatData () {
static async getStatData() {
let totalCount = {}
let ret = { servs: {} }
await MysUser.eachServ(async function (servCache, serv) {
@ -182,7 +182,7 @@ export default class MysUser extends BaseModel {
* 删除失效用户
* @returns {Promise<number>} 删除用户的个数
*/
static async delDisable () {
static async delDisable() {
let count = 0
await MysUser.eachServ(async function (servCache) {
let cks = await servCache.zGetDisableKey(tables.detail)
@ -204,7 +204,7 @@ export default class MysUser extends BaseModel {
* @param ck 需要检查的CK
* @returns {Promise<boolean|{msg: string, uids: *[], status: number}>}
*/
static async checkCkStatus (ck) {
static async checkCkStatus(ck) {
let uids = []
let err = (msg, status = 2) => {
msg = msg + '\n请退出米游社并重新登录后再次获取CK'
@ -253,7 +253,7 @@ export default class MysUser extends BaseModel {
}
// 不建议使用,为了兼容老数据格式,后续废弃
getCkInfo (game = 'gs') {
getCkInfo(game = 'gs') {
return {
ck: this.ck,
uid: this.getUid(game),
@ -262,7 +262,7 @@ export default class MysUser extends BaseModel {
}
}
getUidData (uid, game = 'gs') {
getUidData(uid, game = 'gs') {
game = this.gameKey(game)
if (!this.hasUid(uid, game)) {
return false
@ -275,21 +275,21 @@ export default class MysUser extends BaseModel {
}
}
hasUid (uid, game = 'gs') {
hasUid(uid, game = 'gs') {
game = this.gameKey(game)
return this.uids[game].includes(uid + '')
}
getUid (game = 'gs') {
getUid(game = 'gs') {
return this.getUids(game)[0]
}
getUids (game = 'gs') {
getUids(game = 'gs') {
let gameKey = this.gameKey(game)
return this.uids[gameKey] || []
}
getUidInfo () {
getUidInfo() {
let ret = []
MysUtil.eachGame((game, gameDs) => {
let uids = this.getUids(game)
@ -304,7 +304,7 @@ export default class MysUser extends BaseModel {
* 刷新mysUser的UID列表
* @returns {Promise<{msg: string, status: number}>}
*/
async reqMysUid () {
async reqMysUid() {
let err = (msg = 'error', status = 1) => {
return { status, msg }
}
@ -344,7 +344,7 @@ export default class MysUser extends BaseModel {
return { status: 0, msg: '' }
}
async getGameRole (serv = 'mys') {
async getGameRole(serv = 'mys') {
let ck = this.ck
let url = {
mys: 'https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie',
@ -359,7 +359,7 @@ export default class MysUser extends BaseModel {
}
// 获取米游社通行证id
async getUserFullInfo (serv = 'mys') {
async getUserFullInfo(serv = 'mys') {
let ck = this.ck
let url = {
mys: 'https://bbs-api.mihoyo.com/user/wapi/getUserFullInfo?gids=2',
@ -381,7 +381,7 @@ export default class MysUser extends BaseModel {
return res
}
getCache (game = 'gs') {
getCache(game = 'gs') {
if (!this.cache) {
this.cache = {}
}
@ -397,7 +397,7 @@ export default class MysUser extends BaseModel {
// 初始化数据
async initDB (db = false) {
async initDB(db = false) {
if (this.db && !db) {
return
}
@ -407,7 +407,7 @@ export default class MysUser extends BaseModel {
}
// 设置ck数据
setCkData (data = {}) {
setCkData(data = {}) {
this.ck = data.ck || this.ck || ''
this.type = data.type || this.type || 'mys'
this.device = data.device || this.device || MysUtil.getDeviceGuid()
@ -418,12 +418,12 @@ export default class MysUser extends BaseModel {
})
}
async save () {
async save() {
await this.db.saveDB(this)
}
// 为当前MysUser绑定uid
addUid (uid, game = 'gs') {
addUid(uid, game = 'gs') {
if (lodash.isArray(uid)) {
for (let u of uid) {
this.addUid(u, game)
@ -431,7 +431,7 @@ export default class MysUser extends BaseModel {
return true
}
uid = '' + uid
if (/\d{9}/.test(uid)) {
if (/\d{9,10}/.test(uid)) {
let gameKey = this.gameKey(game)
let uids = this.uids[gameKey]
if (!uids.includes(uid)) {
@ -441,13 +441,13 @@ export default class MysUser extends BaseModel {
return true
}
hasGame (game = 'gs') {
hasGame(game = 'gs') {
game = this.gameKey(game)
return this.uids[game]?.length > 0
}
// 初始化当前MysUser缓存记录
async initCache () {
async initCache() {
if (!this.ltuid || !this.ck) {
return
}
@ -470,7 +470,7 @@ export default class MysUser extends BaseModel {
return true
}
async disable (game = 'gs') {
async disable(game = 'gs') {
let cache = this.getCache(game)
await cache.zDel(tables.detail, this.ltuid)
logger.mark(`[标记无效ck][game:${game}, ltuid:${this.ltuid}`)
@ -481,7 +481,7 @@ export default class MysUser extends BaseModel {
* 删除缓存, 供User解绑CK时调用
* @returns {Promise<boolean>}
*/
async del () {
async del() {
// TODO 检查一ltuid多绑定的情况
// 将查询过的uid缓存起来以备后续重新绑定时恢复
let self = this
@ -498,7 +498,7 @@ export default class MysUser extends BaseModel {
}
// 删除MysUser用户记录会反向删除User中的记录及绑定关系
async delWithUser (game = 'gs') {
async delWithUser(game = 'gs') {
// 查找用户
let cache = this.getCache(game)
let qqArr = await cache.kGet(tables.qq, this.ltuid, true)
@ -515,7 +515,7 @@ export default class MysUser extends BaseModel {
}
// 为当前用户添加uid查询记录
async addQueryUid (uid, game = 'gs') {
async addQueryUid(uid, game = 'gs') {
if (lodash.isArray(uid)) {
for (let u of uid) {
await this.addQueryUid(u, game)
@ -529,19 +529,19 @@ export default class MysUser extends BaseModel {
}
// 获取当前用户已查询uid列表
async getQueryUids (game = 'gs') {
async getQueryUids(game = 'gs') {
let cache = this.getCache(game)
return await cache.zList(tables.detail, this.ltuid)
}
// 根据uid获取查询ltuid
async getQueryLtuid (uid, game = 'gs') {
async getQueryLtuid(uid, game = 'gs') {
let cache = this.getCache(game)
return await cache.zKey(tables.detail, uid)
}
// 检查指定uid是否为当前MysUser所有
ownUid (uid, game = 'gs') {
ownUid(uid, game = 'gs') {
if (!uid) {
return false
}

View File

@ -13,7 +13,7 @@ export default class MysApi {
* @param isSr 是否星铁
* @param device 设备device_id
*/
constructor (uid, cookie, option = {}, isSr = false, device = '') {
constructor(uid, cookie, option = {}, isSr = false, device = '') {
this.uid = uid
this.cookie = cookie
this.isSr = isSr
@ -30,12 +30,12 @@ export default class MysApi {
}
/* eslint-disable quotes */
get device () {
get device() {
if (!this._device) this._device = `Yz-${md5(this.uid).substring(0, 5)}`
return this._device
}
getUrl (type, data = {}) {
getUrl(type, data = {}) {
let urlMap = this.apiTool.getUrlMap({ ...data, deviceId: this.device })
if (!urlMap[type]) return false
@ -49,9 +49,14 @@ export default class MysApi {
return { url, headers, body }
}
getServer () {
let uid = this.uid
switch (String(uid)[0]) {
getServer() {
let uidPrefix = this.uid.toString()
if (uidPrefix.length == 10) {
uidPrefix = uidPrefix.slice(0, 2)
} else {
uidPrefix = uidPrefix.slice(0, 1)
}
switch (uidPrefix) {
case '1':
case '2':
return this.isSr ? 'prod_gf_cn' : 'cn_gf01' // 官服
@ -62,6 +67,7 @@ export default class MysApi {
case '7':
return this.isSr ? 'prod_official_euro' : 'os_euro' // 欧服
case '8':
case '18':
return this.isSr ? 'prod_official_asia' : 'os_asia' // 亚服
case '9':
return this.isSr ? 'prod_official_cht' : 'os_cht' // 港澳台服
@ -69,7 +75,7 @@ export default class MysApi {
return this.isSr ? 'prod_gf_cn' : 'cn_gf01'
}
async getData (type, data = {}, cached = false) {
async getData(type, data = {}, cached = false) {
if (!this._device_fp && !data?.Getfp) {
this._device_fp = await this.getData('getFp', {
seed_id: this.generateSeed(16),
@ -137,7 +143,7 @@ export default class MysApi {
return res
}
getHeaders (query = '', body = '') {
getHeaders(query = '', body = '') {
const cn = {
app_version: '2.40.1',
User_Agent: `Mozilla/5.0 (Linux; Android 12; ${this.device}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.73 Mobile Safari/537.36 miHoYoBBS/2.40.1`,
@ -169,7 +175,7 @@ export default class MysApi {
}
}
getDs (q = '', b = '') {
getDs(q = '', b = '') {
let n = ''
if (['cn_gf01', 'cn_qd01', 'prod_gf_cn', 'prod_qd_cn'].includes(this.server)) {
n = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs'
@ -182,24 +188,24 @@ export default class MysApi {
return `${t},${r},${DS}`
}
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())
}
cacheKey (type, data) {
cacheKey(type, data) {
return 'Yz:genshin:mys:cache:' + md5(this.uid + type + JSON.stringify(data))
}
async cache (res, cacheKey) {
async cache(res, cacheKey) {
if (!res || res.retcode !== 0) return
redis.setEx(cacheKey, this.cacheCd, JSON.stringify(res))
}
async getAgent () {
async getAgent() {
let proxyAddress = cfg.bot.proxyAddress
if (!proxyAddress) return null
if (proxyAddress === 'http://0.0.0.0:0') return null
@ -221,7 +227,7 @@ export default class MysApi {
return null
}
generateSeed (length = 16) {
generateSeed(length = 16) {
const characters = '0123456789abcdef'
let result = ''
for (let i = 0; i < length; i++) {

View File

@ -8,7 +8,7 @@ import DailyCache from './DailyCache.js'
export default class MysInfo {
static tips = '请先#绑定Cookie\n发送【Cookie帮助】查看配置教程'
constructor (e) {
constructor(e) {
if (e) {
this.e = e
this.userId = String(e.user_id)
@ -33,7 +33,7 @@ export default class MysInfo {
])
}
static async init (e, api) {
static async init(e, api) {
await MysInfo.initCache()
let mysInfo = new MysInfo(e)
@ -55,11 +55,18 @@ export default class MysInfo {
return false
}
if (!['1', '2', '3', '5', '6', '7', '8', '9'].includes(String(mysInfo.uid)[0])) {
let uidPrefix = mysInfo.uid.toString()
if (uidPrefix.length == 10) {
uidPrefix = uidPrefix.slice(0, 2)
} else {
uidPrefix = uidPrefix.slice(0, 1)
}
if (!['1', '2', '3', '5', '6', '7', '8', '18', '9'].includes(uidPrefix)) {
// e.reply('只支持查询国服uid')
return false
}
if (!['6', '7', '8', '9'].includes(String(mysInfo.uid)[0]) && api === 'useCdk') {
if (!['6', '7', '8', '18', '9'].includes(uidPrefix) && api === 'useCdk') {
e.reply('兑换码使用只支持国际服uid')
return false
}
@ -80,7 +87,7 @@ export default class MysInfo {
* @param matchMsgUid 用于判断消息是否为uid数据
* @returns {Promise<string|boolean|*|string>}
*/
static async getUid (e, matchMsgUid = true) {
static async getUid(e, matchMsgUid = true) {
let user = await NoteUser.create(e)
if (e.uid && matchMsgUid) {
/** 没有绑定的自动绑定 */
@ -103,7 +110,7 @@ export default class MysInfo {
}
let matchUid = (msg = '') => {
let ret = /[1235-9][0-9]{8}/g.exec(msg)
let ret = /([1-9]|18)[0-9]{8}/g.exec(msg)
if (!ret) return false
return ret[0]
}
@ -128,7 +135,7 @@ export default class MysInfo {
* @param e
* @returns {Promise<boolean|*>}
*/
static async getSelfUid (e) {
static async getSelfUid(e) {
let { msg = '', at = '' } = e
if (!msg) return false
@ -163,7 +170,7 @@ export default class MysInfo {
* @param option 配置
* @param option.log 是否显示请求日志
*/
static async get (e, api, data = {}, option = {}) {
static async get(e, api, data = {}, option = {}) {
let mysInfo = await MysInfo.init(e, api)
if (!mysInfo.uid || !mysInfo.ckInfo.ck) return false
@ -209,7 +216,7 @@ export default class MysInfo {
* 初始化公共CK
* @returns {Promise<void>}
*/
static async initPubCk () {
static async initPubCk() {
// 初始化公共CK
let pubCount = 0
let pubCks = GsCfg.getConfig('mys', 'pubCk') || []
@ -233,7 +240,7 @@ export default class MysInfo {
* 默认会将用户CK加入查询池
* @returns {Promise<void>}
*/
static async initUserCk () {
static async initUserCk() {
// 初始化用户缓存
let userCount = 0
await MysUser.forEach(async (mys) => {
@ -251,7 +258,7 @@ export default class MysInfo {
* @param clearData 强制初始化时是否清除已有数据 (刷新/重置)
* @returns {Promise<boolean>}
*/
static async initCache (force = false, clearData = false) {
static async initCache(force = false, clearData = false) {
// 检查缓存标记
let cache = DailyCache.create()
if (!force && await cache.get('cache-ready')) {
@ -274,13 +281,13 @@ export default class MysInfo {
return true
}
static async getBingCkUid () {
static async getBingCkUid() {
let res = await GsCfg.getBingCk()
return { ...res.ck }
}
// 获取uid绑定的ck信息
static async checkUidBing (uid, game = 'gs') {
static async checkUidBing(uid, game = 'gs') {
let ckUser = await MysUser.getByQueryUid(uid, game, true)
if (ckUser && ckUser.ck) {
return ckUser
@ -288,12 +295,12 @@ export default class MysInfo {
return false
}
static async delDisable () {
static async delDisable() {
return await MysUser.delDisable()
}
/** 判断绑定ck才能查询 */
checkAuth (api) {
checkAuth(api) {
if (api === 'cookie') {
return true
}
@ -309,7 +316,7 @@ export default class MysInfo {
return false
}
async checkReply () {
async checkReply() {
if (this.e.noTips === true) return
if (!this.uid) {
@ -334,7 +341,7 @@ export default class MysInfo {
* @param onlySelfCk 是否只获取uid自己对应的ck为true则只获取uid对应ck若无则返回为空
* @returns {Promise<string|string|*>} 查询ck获取失败则返回空
*/
async getCookie (game = 'gs', onlySelfCk = false) {
async getCookie(game = 'gs', onlySelfCk = false) {
if (this.ckUser?.ck) return this.ckUser?.ck
let mysUser = await MysUser.getByQueryUid(this.uid, game, onlySelfCk)
@ -353,7 +360,7 @@ export default class MysInfo {
return this.ckUser?.ck
}
async checkCode (res, type, mysApi = {}, data = {}, isTask = false) {
async checkCode(res, type, mysApi = {}, data = {}, isTask = false) {
if (!res) {
if (!isTask) this.e.reply(['米游社接口请求失败,暂时无法查询', this.mysButton])
return false
@ -440,7 +447,7 @@ export default class MysInfo {
}
/** 删除失效ck */
async delCk () {
async delCk() {
if (!this.ckUser) {
return false
}
@ -450,7 +457,7 @@ export default class MysInfo {
}
/** 查询次数满,今日内标记失效 */
async disableToday (game = 'gs') {
async disableToday(game = 'gs') {
/** 统计次数设为超限 */
await this.ckUser.disable(game)
}

View File

@ -13,7 +13,7 @@ import { Player } from '#miao.models'
import { UserGameDB, sequelize } from './db/index.js'
export default class User extends base {
constructor (e) {
constructor(e) {
super(e)
this.model = 'bingCk'
/** 绑定的uid */
@ -28,17 +28,17 @@ export default class User extends base {
}
// 获取当前user实例
async user () {
async user() {
return await NoteUser.create(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')
@ -172,7 +172,7 @@ export default class User extends base {
}
/** 删除绑定ck */
async delCk () {
async delCk() {
let game
if (this.e.game) {
game = this.e.game
@ -196,8 +196,8 @@ export default class User extends base {
}
/** 绑定uid若有ck的话优先使用ck-uid */
async bingUid () {
let uid = this.e.msg.match(/[1|2|3|5-9][0-9]{8}/g)
async bingUid() {
let uid = this.e.msg.match(/([1-9]|18)[0-9]{8}/g)
if (!uid) return
uid = uid[0]
let user = await this.user()
@ -205,7 +205,7 @@ export default class User extends base {
return await this.showUid()
}
async delUid (index) {
async delUid(index) {
let user = await this.user()
let game = this.e
let uidList = user.getUidList(game)
@ -226,7 +226,7 @@ export default class User extends base {
}
/** #uid */
async showUid_bak () {
async showUid_bak() {
let user = await this.user()
let msg = []
let typeMap = { ck: 'CK Uid', reg: '绑定 Uid' }
@ -251,7 +251,7 @@ export default class User extends base {
}
/** #uid */
async showUid () {
async showUid() {
let user = await this.user()
let uids = [{
key: 'gs',
@ -297,7 +297,7 @@ export default class User extends base {
}
/** 切换uid */
async toggleUid (index) {
async toggleUid(index) {
let user = await this.user()
let game = this.e
let uidList = user.getUidList(game)
@ -313,7 +313,7 @@ export default class User extends base {
}
/** 加载V2ck */
async loadOldDataV2 () {
async loadOldDataV2() {
let file = [
'./data/MysCookie/NoteCookie.json',
'./data/NoteCookie/NoteCookie.json',
@ -363,7 +363,7 @@ export default class User extends base {
}
/** 加载V3ck */
async loadOldDataV3 () {
async loadOldDataV3() {
let dir = './data/MysCookie/'
if (!fs.existsSync(dir)) {
return false
@ -395,7 +395,7 @@ export default class User extends base {
}
}
async loadOldUid () {
async loadOldUid() {
// 从DB中导入
await sequelize.query('delete from UserGames where userId is null or data is null', {})
let games = await UserGameDB.findAll()
@ -437,7 +437,7 @@ export default class User extends base {
console.log('load Uid Data Done...')
}
async loadOldData (data) {
async loadOldData(data) {
let count = 0
if (!lodash.isPlainObject(data)) {
return
@ -496,7 +496,7 @@ export default class User extends base {
}
/** 我的ck */
async myCk () {
async myCk() {
let user = await this.user()
if (!user.hasCk) {
this.e.reply(['当前尚未绑定Cookie', segment.button([
@ -510,7 +510,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 })
@ -546,7 +546,7 @@ export default class User extends base {
])], false, { at: true })
}
async userAdmin () {
async userAdmin() {
this.model = 'userAdmin'
await MysInfo.initCache()
let stat = await MysUser.getStatData()
@ -558,7 +558,7 @@ export default class User extends base {
}
}
async bindNoteUser () {
async bindNoteUser() {
let user = await this.user()
let id = user.qq
let { e } = this
@ -616,7 +616,7 @@ export default class User extends base {
e.reply([`此账号将作为子用户,绑定至主用户:${mainId}`,
'成功绑定后此用户输入的命令将视作主用户命令使用主用户的CK与UID等信息',
'如需继续绑定请在5分钟内使用主账户发送以下命令', '',
`#接受绑定子用户[${mainId}][${verify}]`
`#接受绑定子用户[${mainId}][${verify}]`
].join('\n'))
return true
} else {