UNPKG

pupbot-plugin-r6s

Version:

查询彩虹六号战绩

193 lines (167 loc) 6.93 kB
"use strict" const { PupPlugin, segment, http } = require('@pupbot/core') const { version } = require('./package.json') const plugin = new PupPlugin('r6s', version) const https = require('https') //插件被启用调用函数 plugin.onMounted((bot) => { // plugin.onMatch(/^#r6s ?/, msg => { var str_name = msg.raw_message.replace(/^#r6s ?/, '') https.get(`https://r6.tracker.network/profile/pc/${str_name}`, res => { let data = "" res.on("data", d => { data += d.toString() }) res.on("end", () => { var json_out = r6s_page(JSON.parse(data), str_name) var str_out = `player: ${json_out.player_name} 等级:${json_out.level} --本赛季-- 休闲 => kd:${json_out.this_season.Casual.KD} MMR:${json_out.this_season.Casual.MMR} 死斗 => kd:${json_out.this_season.Deathmatch.KD} MMR:${json_out.this_season.Deathmatch.MMR} 排位 => kd:${json_out.this_season.Ranked.KD} MMR:${json_out.this_season.Ranked.MMR} Event => kd:${json_out.this_season.Event.KD} MMR:${json_out.this_season.Event.MMR} --排位-- 最高MMR: ${json_out.rank.bestMMR} 平均MMR: ${json_out.rank.AVGMMR} 获胜场数: ${json_out.rank.WINS} 胜率: ${json_out.rank.WIN_B} KD: ${json_out.rank.KD} 击杀数: ${json_out.rank.KILLS} 常用干员: ${(json_out.rank.top[0]).replace(/[\d\D]+s\//g, '').replace(/.png/g, '')}/${(json_out.rank.top[1]).replace(/[\d\D]+s\//, '').replace(/.png/, '')}/${(json_out.rank.top[2]).replace(/[\d\D]+s\//, '').replace(/.png/, '')}` msg.reply(str_out, true) }) res.on('error', () => { msg.reply("没找到玩家信息\n输入格式:ty+空格+r6s+空格+育碧昵称(区分大小写)", true) }) }) }) }) // R6页面处理 function r6s_page(str_input, str_name) { var json_out = { player_name: str_name,// 昵称 level: '--',// 等级 rank: { bestMMR: '--', // 排位最高MMR AVGMMR: '--', // 赛季排位平均分 WINS: '--',// 排位胜利场数 WIN_B: '--', // 排位胜率 KILLS: '--',// 排位击杀 KD: '--',// 排位KD top: [] }, this_season: { // 本赛季 Ranked: { KD: '--', MMR: '--' }, Deathmatch: { KD: '--', MMR: '--' }, Casual: { KD: '--', MMR: '--' }, Event: { KD: '--', MMR: '--' } } } // var _BODY = str_input// 备份 // 获取本赛季信息 var body = /trn-card__content pt8[\d\D]+trn-card__content pt8/.exec(str_input) body = body[0] .replace(/<\/?span[\/ \w=\-_":;]*>/g, ' ') .replace(/<\/?div[\/ \w=\-_":;]*>\n?/g, ' ') .replace(/[\d\D]+pt8 +pb8">\n?/g, ' ') .replace(/<h2[\d\D]+/g, ' ') .replace(/,/g, '') .replace(/\n *(?=\d)/g, ' ') .replace(/\n *Unranked/g, ' Unranked') .replace(/ KD/g, '') .replace(/ +/g, ' ') .replace(/\n +/g, '\n') .replace(/^ +/g, '') // console.log(body) body = body.split('\n') // body.shift() // 存入 for (var i = 0; i < body.length; i++) { if ((body[i].split(" "))[0] == 'Ranked') { if (/Unranked/.test(body[i])) { json_out.this_season.Ranked.KD = "Unranked" json_out.this_season.Ranked.MMR = "Unranked" } else { json_out.this_season.Ranked.KD = (body[i].split(" "))[1] json_out.this_season.Ranked.MMR = (body[i].split(" "))[2] } } else if ((body[i].split(" "))[0] == 'Deathmatch') { if (/Unranked/.test(body[i])) { json_out.this_season.Deathmatch.KD = "Unranked" json_out.this_season.Deathmatch.MMR = "Unranked" } else { json_out.this_season.Deathmatch.KD = (body[i].split(" "))[1] json_out.this_season.Deathmatch.MMR = (body[i].split(" "))[2] } } else if ((body[i].split(" "))[0] == 'Casual') { if (/Unranked/.test(body[i])) { json_out.this_season.Casual.KD = "Unranked" json_out.this_season.Casual.MMR = "Unranked" } else { json_out.this_season.Casual.KD = (body[i].split(" "))[1] json_out.this_season.Casual.MMR = (body[i].split(" "))[2] } } else if ((body[i].split(" "))[0] == 'Event') { if (/Unranked/.test(body[i])) { json_out.this_season.Event.KD = "Unranked" json_out.this_season.Event.MMR = "Unranked" } else { json_out.this_season.Event.KD = (body[i].split(" "))[1] json_out.this_season.Event.MMR = (body[i].split(" "))[2] } } } // 获取等级 body = /<div class="trn-defstat__name">Level<\/div>\D+\d{1,4}/.exec(str_input) json_out.level = /[0-9]{1,4}/.exec(body[0])[0] // 获取全赛季信息 body = /trn-card__content trn-card--light trn-defstats-flex pt8 pb8[\d\D]+General/.exec(str_input) body = body[0] .replace(/<\/?div[\/ \w=\-_":;]*>\n?/g, ' ') .replace(/<\/?template[\/ \w=\-_"':;]*>\n?/g, ' ') .replace(/<trn-percentilebar :value="[\d]+"><\/trn-percentilebar>\n?/g, ' ') .replace(/<img src="/g, '') .replace(/" style="height: 28px; padding-right: 4px;" title="[\w]+" \/>/g, '') .replace(/,/g, '') .replace(/#[\d]{6,7}\n?/g, '') .replace(/Best +MMR +\d+ +Started +Collecting[\d\D]+/g, '') .replace(/[\d\D]+Best MMR/, 'BestMMR') .replace(/Top +Operators/g, ' ') .replace(/ +/g, ' ') .replace(/\n /g, '\n') .replace(/ %/, '') .replace(/Avg Seasonal MMR/g, 'AVGMMR') // console.log(body) // 存入 body = body.split('\n') for (var i = 0; i < body.length; i++) { if (body[i].startsWith("BestMMR")) { json_out.rank.bestMMR = (body[i].split(' '))[1] } else if (body[i].startsWith("AVGMMR")) { json_out.rank.AVGMMR = (body[i].split(' '))[1] } else if (body[i].startsWith("http")) { json_out.rank.top.push(body[i]) } else if (body[i].startsWith("Wins")) { json_out.rank.WINS = (body[i].split(' '))[1] } else if (body[i].startsWith("Win ")) { json_out.rank.WIN_B = (body[i].split(' '))[1] } else if (body[i].startsWith("Kills")) { json_out.rank.KILLS = (body[i].split(' '))[1] } else if (body[i].startsWith("KD")) { json_out.rank.KD = (body[i].split(' '))[1] } } return json_out } module.exports = { plugin }