setPubCk.js 移到 genshin
This commit is contained in:
parent
d72b1d84d4
commit
d83b4c4f4a
|
@ -1,75 +1,74 @@
|
||||||
import plugin from '../../lib/plugins/plugin.js'
|
import GsCfg from "../model/gsCfg.js"
|
||||||
import GsCfg from '../genshin/model/gsCfg.js'
|
import fs from "node:fs"
|
||||||
import fs from 'node:fs'
|
import lodash from "lodash"
|
||||||
import lodash from 'lodash'
|
import fetch from "node-fetch"
|
||||||
import fetch from 'node-fetch'
|
import YAML from "yaml"
|
||||||
import YAML from 'yaml'
|
import MysInfo from "../model/mys/mysInfo.js"
|
||||||
import MysInfo from '../genshin/model/mys/mysInfo.js'
|
import common from "../../../lib/common/common.js"
|
||||||
import common from '../../lib/common/common.js'
|
|
||||||
|
|
||||||
export class setPubCk extends plugin {
|
export class setPubCk extends plugin {
|
||||||
constructor (e) {
|
constructor (e) {
|
||||||
super({
|
super({
|
||||||
name: '配置',
|
name: "配置",
|
||||||
dsc: '#配置ck',
|
dsc: "#配置ck",
|
||||||
event: 'message',
|
event: "message",
|
||||||
priority: 700,
|
priority: 700,
|
||||||
rule: [
|
rule: [
|
||||||
{
|
{
|
||||||
reg: '^#配置(ck|cookie)$|^#*配置公共查询ck$',
|
reg: "^#配置(ck|cookie)$|^#*配置公共查询ck$",
|
||||||
fnc: 'setPubCk',
|
fnc: "setPubCk",
|
||||||
permission: 'master'
|
permission: "master"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
reg: '^#使用(全部|用户)ck$',
|
reg: "^#使用(全部|用户)ck$",
|
||||||
fnc: 'setUserCk',
|
fnc: "setUserCk",
|
||||||
permission: 'master'
|
permission: "master"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
this.file = './plugins/genshin/config/mys.pubCk.yaml'
|
this.file = "./plugins/genshin/config/mys.pubCk.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 配置公共ck */
|
/** 配置公共ck */
|
||||||
async setPubCk () {
|
async setPubCk () {
|
||||||
/** 设置上下文,后续接收到内容会执行doRep方法 */
|
/** 设置上下文,后续接收到内容会执行doRep方法 */
|
||||||
this.setContext('pubCk')
|
this.setContext("pubCk")
|
||||||
/** 回复 */
|
/** 回复 */
|
||||||
await this.reply('请发送米游社cookie......\n配置后该ck将会加入公共查询池')
|
await this.reply("请发送米游社cookie......\n配置后该ck将会加入公共查询池")
|
||||||
}
|
}
|
||||||
|
|
||||||
async pubCk () {
|
async pubCk () {
|
||||||
let msg = this.e.msg
|
let msg = this.e.msg
|
||||||
|
|
||||||
if (!(/(ltoken|ltoken_v2)/.test(this.e.msg) && /(ltuid|ltmid_v2|account_mid_v2)/.test(this.e.msg))) {
|
if (!(/(ltoken|ltoken_v2)/.test(this.e.msg) && /(ltuid|ltmid_v2|account_mid_v2)/.test(this.e.msg))) {
|
||||||
this.e.reply('cookie错误,请发送正确的cookie')
|
this.e.reply("cookie错误,请发送正确的cookie")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
this.finish('pubCk')
|
this.finish("pubCk")
|
||||||
|
|
||||||
let ck = msg.replace(/#|'|"/g, '')
|
let ck = msg.replace(/#|"|"/g, "")
|
||||||
let param = {}
|
let param = {}
|
||||||
ck.split(';').forEach((v) => {
|
ck.split(";").forEach((v) => {
|
||||||
// cookie_token_v2,ltoken_v2值也可能有=
|
// cookie_token_v2,ltoken_v2值也可能有=
|
||||||
// let tmp = lodash.trim(v).split('=')
|
// let tmp = lodash.trim(v).split("=")
|
||||||
let tmp = lodash.trim(v);
|
let tmp = lodash.trim(v);
|
||||||
let index = tmp.indexOf("=");
|
let index = tmp.indexOf("=");
|
||||||
param[tmp.slice(0,index)] = tmp.slice(index+1);
|
param[tmp.slice(0,index)] = tmp.slice(index+1);
|
||||||
})
|
})
|
||||||
|
|
||||||
this.ck = ''
|
this.ck = ""
|
||||||
lodash.forEach(param, (v, k) => {
|
lodash.forEach(param, (v, k) => {
|
||||||
if (['ltoken', 'ltuid', 'cookie_token', 'account_id', 'cookie_token_v2', 'account_mid_v2', 'ltmid_v2', 'ltoken_v2'].includes(k)) {
|
if (["ltoken", "ltuid", "cookie_token", "account_id", "cookie_token_v2", "account_mid_v2", "ltmid_v2", "ltoken_v2"].includes(k)) {
|
||||||
this.ck += `${k}=${v};`
|
this.ck += `${k}=${v};`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/** 检查ck是否失效 */
|
/** 检查ck是否失效 */
|
||||||
if (!await this.checkCk()) {
|
if (!await this.checkCk()) {
|
||||||
logger.mark(`配置公共cookie错误:${this.checkMsg || 'cookie错误'}`)
|
logger.mark(`配置公共cookie错误:${this.checkMsg || "cookie错误"}`)
|
||||||
await this.e.reply(`配置公共cookie错误:${this.checkMsg || 'cookie错误'}`)
|
await this.e.reply(`配置公共cookie错误:${this.checkMsg || "cookie错误"}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,18 +82,18 @@ export class setPubCk extends plugin {
|
||||||
this.ltuid = userInfo.uid
|
this.ltuid = userInfo.uid
|
||||||
this.ck = `${this.ck}ltuid=${this.ltuid};`
|
this.ck = `${this.ck}ltuid=${this.ltuid};`
|
||||||
} else {
|
} else {
|
||||||
logger.mark(`配置公共cookie错误:${userFullInfo.message || 'cookie错误'}`)
|
logger.mark(`配置公共cookie错误:${userFullInfo.message || "cookie错误"}`)
|
||||||
await this.e.reply(`配置公共cookie错误:${userFullInfo.message || 'cookie错误'}`)
|
await this.e.reply(`配置公共cookie错误:${userFullInfo.message || "cookie错误"}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ckArr = GsCfg.getConfig('mys', 'pubCk') || []
|
let ckArr = GsCfg.getConfig("mys", "pubCk") || []
|
||||||
|
|
||||||
/** 判断是否重复 */
|
/** 判断是否重复 */
|
||||||
for (let ck of ckArr) {
|
for (let ck of ckArr) {
|
||||||
if (ck.includes(this.ltuid)) {
|
if (ck.includes(this.ltuid)) {
|
||||||
await this.e.reply('配置公共cookie错误:该ck已配置')
|
await this.e.reply("配置公共cookie错误:该ck已配置")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,8 +107,8 @@ export class setPubCk extends plugin {
|
||||||
|
|
||||||
/** 检查ck是否可用 */
|
/** 检查ck是否可用 */
|
||||||
async checkCk () {
|
async checkCk () {
|
||||||
let url = 'https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn'
|
let url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn"
|
||||||
let res = await fetch(url, { method: 'get', headers: { Cookie: this.ck } })
|
let res = await fetch(url, { method: "get", headers: { Cookie: this.ck } })
|
||||||
if (!res.ok) return false
|
if (!res.ok) return false
|
||||||
res = await res.json()
|
res = await res.json()
|
||||||
if (res.retcode != 0) {
|
if (res.retcode != 0) {
|
||||||
|
@ -121,22 +120,22 @@ export class setPubCk extends plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取米游社通行证id
|
// 获取米游社通行证id
|
||||||
async getUserInfo (server = 'mys') {
|
async getUserInfo (server = "mys") {
|
||||||
try {
|
try {
|
||||||
const that = this
|
const that = this
|
||||||
let url = {
|
let url = {
|
||||||
mys: 'https://bbs-api.mihoyo.com/user/wapi/getUserFullInfo?gids=2',
|
mys: "https://bbs-api.mihoyo.com/user/wapi/getUserFullInfo?gids=2",
|
||||||
hoyolab: ''
|
hoyolab: ""
|
||||||
}
|
}
|
||||||
let res = await fetch(url[server], {
|
let res = await fetch(url[server], {
|
||||||
method: 'get',
|
method: "get",
|
||||||
headers: {
|
headers: {
|
||||||
Cookie: that.ck,
|
Cookie: that.ck,
|
||||||
Accept: 'application/json, text/plain, */*',
|
Accept: "application/json, text/plain, */*",
|
||||||
Connection: 'keep-alive',
|
Connection: "keep-alive",
|
||||||
Host: 'bbs-api.mihoyo.com',
|
Host: "bbs-api.mihoyo.com",
|
||||||
Origin: 'https://m.bbs.mihoyo.com',
|
Origin: "https://m.bbs.mihoyo.com",
|
||||||
Referer: ' https://m.bbs.mihoyo.com/'
|
Referer: " https://m.bbs.mihoyo.com/"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (!res.ok) return res
|
if (!res.ok) return res
|
||||||
|
@ -153,15 +152,15 @@ export class setPubCk extends plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
async setUserCk () {
|
async setUserCk () {
|
||||||
let set = './plugins/genshin/config/mys.set.yaml'
|
let set = "./plugins/genshin/config/mys.set.yaml"
|
||||||
|
|
||||||
let config = fs.readFileSync(set, 'utf8')
|
let config = fs.readFileSync(set, "utf8")
|
||||||
config = config.replace(/allowUseCookie: [0-1]/g, 'allowUseCookie: 1')
|
config = config.replace(/allowUseCookie: [0-1]/g, "allowUseCookie: 1")
|
||||||
fs.writeFileSync(set, config, 'utf8')
|
fs.writeFileSync(set, config, "utf8")
|
||||||
|
|
||||||
await common.sleep(500)
|
await common.sleep(500)
|
||||||
await MysInfo.initCache(true)
|
await MysInfo.initCache(true)
|
||||||
|
|
||||||
await this.reply('开启成功,用户ck已加入公共查询ck池')
|
await this.reply("开启成功,用户ck已加入公共查询ck池")
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue