2
0
mirror of https://github.com/ctrlcvs/xiaoyao-cvs-plugin.git synced 2024-12-22 19:10:53 +08:00

格式化部分内容

This commit is contained in:
ctrlcvs 2023-05-29 21:34:14 +08:00
parent 9ab7a3f5dd
commit 4db9fdf24e
2 changed files with 872 additions and 851 deletions

View File

@ -120,10 +120,10 @@ export async function getCookieMap(cookie) {
*/ */
export function recallMsg(e,r,times){ export function recallMsg(e,r,times){
setTimeout(()=>{ setTimeout(()=>{
if(e?.group?.recallMsg){ if(e?.group?.recallMsg&&r?.message_id){
e?.group?.recallMsg(r.message_id) e?.group?.recallMsg(r?.message_id)
}else if(e?.friend?.recallMsg){ }else if(e?.friend?.recallMsg&&r?.message_id){
e?.friend?.recallMsg(r.message_id) e?.friend?.recallMsg(r?.message_id)
} }
},1000 * times) },1000 * times)
} }

View File

@ -12,6 +12,7 @@ import {
Data Data
} from "../components/index.js"; } from "../components/index.js";
import moment from 'moment' import moment from 'moment'
const _path = process.cwd(); const _path = process.cwd();
const plugin = "xiaoyao-cvs-plugin" const plugin = "xiaoyao-cvs-plugin"
const nameData = ["原神", "崩坏3", "崩坏2", "未定事件簿"]; const nameData = ["原神", "崩坏3", "崩坏2", "未定事件簿"];
@ -72,6 +73,7 @@ export default class user {
} }
return sumData; return sumData;
} }
async getData(type, data = {}, isck = true) { async getData(type, data = {}, isck = true) {
if (isck) { if (isck) {
await this.cookie(this.e) await this.cookie(this.e)
@ -195,9 +197,11 @@ export default class user {
upData upData
} }
} }
async docHelp(type) { async docHelp(type) {
return this.configSign[type.includes("云") ? "cloudDoc" : "cookiesDoc"] return this.configSign[type.includes("云") ? "cloudDoc" : "cookiesDoc"]
} }
async cloudSign() { async cloudSign() {
await this.cloudSeach() await this.cloudSeach()
let res = await this.getData("cloudReward") let res = await this.getData("cloudReward")
@ -220,6 +224,7 @@ export default class user {
Bot.logger.mark(`\n云原神签到用户:${this.e.user_id}:${res.message}\n`) Bot.logger.mark(`\n云原神签到用户:${this.e.user_id}:${res.message}\n`)
return res return res
} }
async cloudSeach() { async cloudSeach() {
let res = await this.getData("cloudGet") let res = await this.getData("cloudGet")
if (res?.retcode == -100) { if (res?.retcode == -100) {
@ -234,6 +239,7 @@ export default class user {
} }
return res; return res;
} }
async bbsSeachSign() { async bbsSeachSign() {
let res = await this.getData("bbsisSign", { let res = await this.getData("bbsisSign", {
name: "原神" name: "原神"
@ -248,6 +254,7 @@ export default class user {
} }
return res; return res;
} }
async getbbsSign(forumData) { async getbbsSign(forumData) {
let message = '', let message = '',
challenge = '', challenge = '',
@ -353,6 +360,7 @@ export default class user {
message message
} }
} }
async signTask(e = "") { async signTask(e = "") {
let mul = e; let mul = e;
//暂不支持多个uid签到 //暂不支持多个uid签到
@ -471,6 +479,7 @@ export default class user {
} }
mysTask = false; mysTask = false;
} }
async cloudTask(e = "") { async cloudTask(e = "") {
let mul = e; let mul = e;
Bot.logger.mark(`云原神签到任务开始`); Bot.logger.mark(`云原神签到任务开始`);
@ -531,6 +540,7 @@ export default class user {
} }
cloudTask = false; cloudTask = false;
} }
countTime(time) { countTime(time) {
let hour = Math.floor((time / 3600) % 24) let hour = Math.floor((time / 3600) % 24)
let min = Math.floor((time / 60) % 60) let min = Math.floor((time / 60) % 60)
@ -541,6 +551,7 @@ export default class user {
if (sec > 0) msg += `${sec}` if (sec > 0) msg += `${sec}`
return msg return msg
} }
async bbsTask(e = "") { async bbsTask(e = "") {
let mul = e; let mul = e;
Bot.logger.mark(`开始米社米币签到任务`); Bot.logger.mark(`开始米社米币签到任务`);
@ -616,6 +627,7 @@ export default class user {
} }
bbsTask = false; bbsTask = false;
} }
async bbsGeetest() { async bbsGeetest() {
if (!this.getToken) return "" if (!this.getToken) return ""
try { try {
@ -635,6 +647,7 @@ export default class user {
} }
return "" return ""
} }
async geetest(data) { async geetest(data) {
if (!this.getToken) return "" if (!this.getToken) return ""
try { try {
@ -651,6 +664,7 @@ export default class user {
} }
return "" return ""
} }
getyunToken(e) { getyunToken(e) {
let file = `${this.yunPath}${e.user_id}.yaml` let file = `${this.yunPath}${e.user_id}.yaml`
try { try {
@ -663,6 +677,7 @@ export default class user {
return "" return ""
} }
} }
async cookie(e) { async cookie(e) {
let { let {
cookie, cookie,
@ -687,20 +702,22 @@ export default class user {
} }
return true; return true;
} }
async getcookiesDoc() { async getcookiesDoc() {
return await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").cookiesDoc return await gsCfg.getfileYaml(`${_path}/plugins/xiaoyao-cvs-plugin/config/`, "config").cookiesDoc
} }
async getCookie(e) { async getCookie(e) {
let skuid, cookie, uid let skuid, cookie, uid
if (isV3) { if (isV3) {
skuid = await gsCfg.getBingCookie(e.user_id); skuid = await gsCfg.getBingCookie(e.user_id);
cookie = skuid?.ck; cookie = skuid?.ck;
uid = skuid?.item; uid = skuid?.item;
if(!uid){ //获取uid为空时进行后续处理获取 (临时处理方式后续会进行解耦以避免这种情况。。待咕中.)s if (!uid && e.user) { //获取uid为空时进行后续处理获取 (临时处理方式后续会进行解耦以避免这种情况。。待咕中.)s
uid=e.user.mainUid[e.isSr?'sr':'gs'] //由于目前只支持原神功能暂时先写死 uid = e.user?.mainUid[e.isSr ? 'sr' : 'gs'] //由于目前只支持原神功能暂时先写死
lodash.mapValues(e.user.mysUsers, function(o) { lodash.mapValues(e.user.mysUsers, function (o) {
if(o.uids[e.isSr?'sr':'gs'].includes(uid)){ if (o.uids[e.isSr ? 'sr' : 'gs'].includes(uid)) {
cookie=o.ck cookie = o.ck
} }
}); });
} }
@ -726,6 +743,7 @@ export default class user {
skuid skuid
} }
} }
async stoken(cookie, e) { async stoken(cookie, e) {
this.e = e; this.e = e;
let datalist = this.getStoken(e.user_id) || {} let datalist = this.getStoken(e.user_id) || {}
@ -756,6 +774,7 @@ export default class user {
} }
return true; return true;
} }
getStoken(userId) { getStoken(userId) {
let file = `${yamlDataUrl}/${userId}.yaml` let file = `${yamlDataUrl}/${userId}.yaml`
try { try {
@ -773,16 +792,17 @@ export default class user {
return {} return {}
} }
} }
async seachUid(data) { async seachUid(data) {
let ltoken = '', v2Sk; let ltoken = '', v2Sk;
if (data?.data) { if (data?.data) {
let res; let res;
if (this.e.sk) { if (this.e.sk) {
if (this.e.sk.get('stoken').includes('v2_')) { if (this.e.sk.get('stoken').includes('v2_')) {
res = await this.getData('getLtoken', { cookies: this.e.raw_message }, false) res = await this.getData('getLtoken', {cookies: this.e.raw_message}, false)
ltoken = res?.data?.ltoken ltoken = res?.data?.ltoken
} else { } else {
v2Sk = await this.getData('getByStokenV2', { headers: { Cookie: this.e.raw_message } }, false) v2Sk = await this.getData('getByStokenV2', {headers: {Cookie: this.e.raw_message}}, false)
} }
this.e.cookie = this.e.cookie =
`ltoken=${this.e.sk?.get('ltoken') || ltoken};ltuid=${this.e.sk?.get('stuid')};cookie_token=${data.data.cookie_token}; account_id=${this.e.sk?.get('stuid')};` `ltoken=${this.e.sk?.get('ltoken') || ltoken};ltuid=${this.e.sk?.get('stuid')};cookie_token=${data.data.cookie_token}; account_id=${this.e.sk?.get('stuid')};`
@ -793,23 +813,23 @@ export default class user {
} else { } else {
this.e.cookie = this.e.original_msg //发送的为cookies this.e.cookie = this.e.original_msg //发送的为cookies
this.cookies = `stuid=${this.e.stuid};stoken=${data?.data?.list[0].token};ltoken=${data?.data?.list[1].token}` this.cookies = `stuid=${this.e.stuid};stoken=${data?.data?.list[0].token};ltoken=${data?.data?.list[1].token}`
res = await this.getData('getLtoken', { cookies: this.cookies }, false) res = await this.getData('getLtoken', {cookies: this.cookies}, false)
v2Sk = await this.getData('getByStokenV2', { headers: { Cookie: this.cookies } }, false) v2Sk = await this.getData('getByStokenV2', {headers: {Cookie: this.cookies}}, false)
} }
let list = [] let list = []
for (let item of ['崩坏星穹铁道', '原神']) { for (let item of ['崩坏星穹铁道', '原神']) {
let result = await this.getData("userGameInfo",this.getDataList(item)[0], false) let result = await this.getData("userGameInfo", this.getDataList(item)[0], false)
if (result?.retcode != 0) { if (result?.retcode != 0) {
continue; continue;
} }
list.push(...result?.data?.list) list.push(...result?.data?.list)
} }
if(list.length==0) return false; if (list.length == 0) return false;
let uids = [] let uids = []
for (let s of list) { for (let s of list) {
let datalist = {} let datalist = {}
let uid = s.game_uid let uid = s.game_uid
uids.push(s.region_name+':'+uid) uids.push(s.region_name + ':' + uid)
datalist[uid] = { datalist[uid] = {
stuid: this.e?.sk?.get('stuid') || this.e.stuid, stuid: this.e?.sk?.get('stuid') || this.e.stuid,
stoken: v2Sk?.data?.token?.token || this.e?.sk?.get('stoken') || data?.data?.list[0].token, stoken: v2Sk?.data?.token?.token || this.e?.sk?.get('stoken') || data?.data?.list[0].token,
@ -818,8 +838,8 @@ export default class user {
uid: uid, uid: uid,
userId: this.e.user_id, userId: this.e.user_id,
is_sign: true, is_sign: true,
region_name:s.region_name, region_name: s.region_name,
region:s.region region: s.region
} }
await gsCfg.saveBingStoken(this.e.user_id, datalist) await gsCfg.saveBingStoken(this.e.user_id, datalist)
} }
@ -864,9 +884,10 @@ export default class user {
return true; return true;
}) })
} }
getDataList(name) { getDataList(name) {
let otherName = lodash.map(this.ForumData,'otherName') let otherName = lodash.map(this.ForumData, 'otherName')
for (let [index,item] of Object.entries(otherName)) { for (let [index, item] of Object.entries(otherName)) {
if (item.includes(name)) { //循环结束未找到的时候返回原数组签到全部 if (item.includes(name)) { //循环结束未找到的时候返回原数组签到全部
return [this.ForumData[index]] return [this.ForumData[index]]
} }