2023-03-04 14:30:13 +08:00
|
|
|
|
import plugin from '../../../lib/plugins/plugin.js'
|
|
|
|
|
import fs from 'node:fs'
|
|
|
|
|
import gsCfg from '../model/gsCfg.js'
|
|
|
|
|
import User from '../model/user.js'
|
|
|
|
|
|
|
|
|
|
export class user extends plugin {
|
2024-02-04 09:02:39 +08:00
|
|
|
|
constructor(e) {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
super({
|
|
|
|
|
name: '用户绑定',
|
|
|
|
|
dsc: '米游社ck绑定,游戏uid绑定',
|
|
|
|
|
event: 'message',
|
|
|
|
|
priority: 300,
|
|
|
|
|
rule: [
|
|
|
|
|
{
|
2023-12-22 22:56:11 +08:00
|
|
|
|
reg: '^#?(体力|[Cc](oo)?[Kk](ie)?)帮助',
|
2023-03-04 14:30:13 +08:00
|
|
|
|
fnc: 'ckHelp'
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-12-22 22:56:11 +08:00
|
|
|
|
reg: '^#[Cc](oo)?[Kk](ie)?代码$',
|
2023-03-04 14:30:13 +08:00
|
|
|
|
fnc: 'ckCode'
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-12-22 22:56:11 +08:00
|
|
|
|
reg: '^#绑定[Cc](oo)?[Kk](ie)?$',
|
2023-03-04 14:30:13 +08:00
|
|
|
|
fnc: 'bingCk'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
reg: '(.*)_MHYUUID(.*)',
|
|
|
|
|
event: 'message.private',
|
|
|
|
|
fnc: 'noLogin'
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-12-22 22:56:11 +08:00
|
|
|
|
reg: '^#?(原神|星铁)?我的[Cc](oo)?[Kk](ie)?$',
|
2023-03-04 14:30:13 +08:00
|
|
|
|
event: 'message',
|
|
|
|
|
fnc: 'myCk'
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-12-22 22:56:11 +08:00
|
|
|
|
reg: '^#?(原神|星铁)?删除[Cc](oo)?[Kk](ie)?$',
|
2023-03-04 14:30:13 +08:00
|
|
|
|
fnc: 'delCk'
|
|
|
|
|
},
|
2023-05-28 15:25:23 +08:00
|
|
|
|
{
|
2023-11-23 23:46:33 +08:00
|
|
|
|
reg: '^#?(原神|星铁)?(删除|解绑)(uid|UID)\\s*[0-9]{1,2}$',
|
2023-05-28 15:25:23 +08:00
|
|
|
|
fnc: 'delUid'
|
|
|
|
|
},
|
2023-03-04 14:30:13 +08:00
|
|
|
|
{
|
2024-02-04 09:02:39 +08:00
|
|
|
|
reg: '^#(原神|星铁)?绑定(uid|UID)?\\s*([1-9]|18)[0-9]{8}$',
|
2023-03-04 14:30:13 +08:00
|
|
|
|
fnc: 'bingUid'
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-05-07 03:32:08 +08:00
|
|
|
|
reg: '^#(原神|星铁)?(我的)?(uid|UID)[0-9]{0,2}$',
|
2023-03-04 14:30:13 +08:00
|
|
|
|
fnc: 'showUid'
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-12-22 22:56:11 +08:00
|
|
|
|
reg: '^#\\s*(检查|我的)*[Cc](oo)?[Kk](ie)?(状态)*$',
|
2023-03-04 14:30:13 +08:00
|
|
|
|
fnc: 'checkCkStatus'
|
2023-11-04 04:29:34 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2024-01-10 14:54:20 +08:00
|
|
|
|
reg: '^#(接受)?绑定(主|子)?(用户|账户|账号)(\\[[a-zA-Z0-9_\\-:\\]+\\]){0,2}$',
|
2023-11-04 04:29:34 +08:00
|
|
|
|
fnc: 'bindNoteUser'
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-11-04 05:14:09 +08:00
|
|
|
|
reg: '^#(删除绑定|取消绑定|解除绑定|解绑|删除|取消)(主|子)(用户|账户|账号)$',
|
2023-11-04 04:29:34 +08:00
|
|
|
|
fnc: 'bindNoteUser'
|
2023-03-04 14:30:13 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
this.User = new User(e)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async init() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
/** 加载旧的绑定ck json */
|
2023-06-04 05:03:50 +08:00
|
|
|
|
await this.loadOldData()
|
2023-03-04 14:30:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 接受到消息都会执行一次 */
|
2024-02-04 09:02:39 +08:00
|
|
|
|
accept() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
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)) {
|
|
|
|
|
if (this.e.isGroup) {
|
2023-12-22 22:56:11 +08:00
|
|
|
|
this.reply('请私聊发送Cookie', false, { at: true })
|
2023-03-04 14:30:13 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
this.e.ck = this.e.msg
|
2023-12-22 22:56:11 +08:00
|
|
|
|
this.e.msg = '#绑定Cookie'
|
2023-03-04 14:30:13 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.e.msg == '#绑定uid') {
|
|
|
|
|
this.setContext('saveUid')
|
|
|
|
|
this.reply('请发送绑定的uid', false, { at: true })
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 绑定uid */
|
2024-02-04 09:02:39 +08:00
|
|
|
|
saveUid() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
if (!this.e.msg) return
|
2024-02-04 09:02:39 +08:00
|
|
|
|
let uid = this.e.msg.match(/([1-9]|18)[0-9]{8}/g)
|
2023-03-04 14:30:13 +08:00
|
|
|
|
if (!uid) {
|
|
|
|
|
this.reply('uid输入错误', false, { at: true })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.e.msg = '#绑定' + this.e.msg
|
|
|
|
|
this.bingUid()
|
|
|
|
|
this.finish('saveUid')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 未登录ck */
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async noLogin() {
|
2023-12-22 22:56:11 +08:00
|
|
|
|
this.reply('绑定Cookie失败\n请先【登录米游社】或【登录通行证】再获取Cookie')
|
2023-03-04 14:30:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** #ck代码 */
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async ckCode() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
await this.reply('javascript:(()=>{prompt(\'\',document.cookie)})();')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** ck帮助 */
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async ckHelp() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
let set = gsCfg.getConfig('mys', 'set')
|
2023-12-22 22:56:11 +08:00
|
|
|
|
await this.reply(`Cookie绑定配置教程:${set.cookieDoc}\n获取Cookie后【私聊发送】进行绑定`)
|
2023-03-04 14:30:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 绑定ck */
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async bingCk() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
let set = gsCfg.getConfig('mys', 'set')
|
|
|
|
|
|
|
|
|
|
if (!this.e.ck) {
|
2023-12-22 22:56:11 +08:00
|
|
|
|
await this.reply(`请【私聊】发送米游社Cookie,获取教程:\n${set.cookieDoc}`)
|
2023-03-04 14:30:13 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await this.User.bing()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 删除ck */
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async delCk() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
let msg = await this.User.delCk()
|
|
|
|
|
await this.reply(msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 绑定uid */
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async bingUid() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
await this.User.bingUid()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** #uid */
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async showUid() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
let index = this.e.msg.match(/[0-9]{1,2}/g)
|
|
|
|
|
if (index && index[0]) {
|
|
|
|
|
await this.User.toggleUid(index[0])
|
|
|
|
|
} else {
|
|
|
|
|
await this.User.showUid()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async delUid() {
|
2023-05-28 15:25:23 +08:00
|
|
|
|
let index = this.e.msg.match(/[0-9]{1,2}$/g)
|
|
|
|
|
let uidIdx = index && index[0]
|
|
|
|
|
let game = this.e
|
|
|
|
|
if (uidIdx) {
|
|
|
|
|
await this.User.delUid(uidIdx, game)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-04 14:30:13 +08:00
|
|
|
|
/** 我的ck */
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async myCk() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
if (this.e.isGroup) {
|
|
|
|
|
await this.reply('请私聊查看')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
await this.User.myCk()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 加载旧的绑定ck json */
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async loadOldData() {
|
2023-06-04 05:03:50 +08:00
|
|
|
|
await this.User.loadOldDataV2()
|
|
|
|
|
await this.User.loadOldDataV3()
|
|
|
|
|
await this.User.loadOldUid()
|
2023-03-04 14:30:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 检查用户CK状态 **/
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async checkCkStatus() {
|
2023-03-04 14:30:13 +08:00
|
|
|
|
await this.User.checkCkStatus()
|
|
|
|
|
}
|
2023-11-04 04:29:34 +08:00
|
|
|
|
|
2024-02-04 09:02:39 +08:00
|
|
|
|
async bindNoteUser() {
|
2023-11-04 04:29:34 +08:00
|
|
|
|
await this.User.bindNoteUser()
|
|
|
|
|
}
|
2023-12-22 22:56:11 +08:00
|
|
|
|
}
|