stamp.js
5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');
const puppeteer = require('puppeteer');
const axios = require("axios");
const cheerio = require("cheerio");
module.exports ={
data: new SlashCommandBuilder()
.setName('각인')
.setDescription('클래스별 로아와 상위 10명의 각인 분석 정보를 제공합니다.')
.addStringOption((option) =>
option.setName('클래스')
.setDescription('각인 정보를 알고싶은 직업')
.setRequired(true)),
async execute(interaction){
const class_name = interaction.options.getString('클래스');
let job_number = 0;
let class_number = 0;
switch(class_name){
case '디스트로이어' : job_number = 2; class_number = 2; break;
case '버서커' : job_number = 2; class_number = 3; break;
case '워로드' : job_number = 2; class_number = 4; break;
case '홀리나이트' : job_number = 2; class_number = 5; break;
case '기공사' : job_number = 3; class_number = 2; break;
case '배틀마스터' : job_number = 3; class_number = 3; break;
case '스트라이커' : job_number = 3; class_number = 4; break;
case '인파이터' : job_number = 3; class_number = 5; break;
case '창술사' : job_number = 3; class_number = 6; break;
case '건슬링어' : job_number = 4; class_number = 2; break;
case '데빌헌터' : job_number = 4; class_number = 3; break;
case '블래스터' : job_number = 4; class_number = 4; break;
case '스카우터' : job_number = 4; class_number = 5; break;
case '호크아이' : job_number = 4; class_number = 6; break;
case '바드' : job_number = 5; class_number = 2; break;
case '서머너' : job_number = 5; class_number = 3; break;
case '소서리스' : job_number = 5; class_number = 4; break;
case '아르카나' : job_number = 5; class_number = 5; break;
case '데모닉' : job_number = 6; class_number = 2; break;
case '리퍼' : job_number = 6; class_number = 3; break;
case '블레이드' : job_number = 6; class_number = 4; break;
case '도화가' : job_number = 7; class_number = 2; break;
default: interaction.reply('올바른 직업명을 입력해주세요!'); return;
}
const tempembed = new MessageEmbed()
.setColor('#F7819F')
.setDescription('작업중입니다!(1~2분 가량 소요될 수 있습니다)')
interaction.reply({ embeds: [tempembed], allowedMentions: {repliedUser: false} });
await puppeteer.launch().then(async browser => {
const page = await browser.newPage();
await page.goto('https://loawa.com/rank');
await page.click(`#contents > article > form > div > div:nth-child(${job_number}) > div > div:nth-child(2) > div > label:nth-child(${class_number}) > span`);
await page.waitForSelector('#contents > article > table > tbody > tr:nth-child(20) > td:nth-child(11) > a > svg > path');
await page.waitForTimeout(1000);
let rank_number = 20;
let all_name = [];
for(var i = 1; i < rank_number + 1; i++){
let name = await page.$eval(`#contents > article > table > tbody > tr:nth-child(${i}) > td:nth-child(2) > a`, element => {
return element.textContent;
})
all_name.push(name);
}
page.close();
browser.close();
let all_url = [];
for(i = 0; i< rank_number; i++){
url = 'https://lostark.game.onstove.com/Profile/Character/' + all_name[i];
all_url.push(url);
}
var each_stamp = new Object;
await axios.all(all_url.map((each) => axios.get(encodeURI(each)))).then(axios.spread((...responses) => {
for(i = 0; i < all_url.length; i++){
let $ = cheerio.load(responses[i].data);
$('ul.swiper-slide').children('li').each(function(){
if($(this).find('span').text() in each_stamp){
each_stamp[$(this).find('span').text()] += 1;
} else{
each_stamp[$(this).find('span').text()] = 1;
}
})
}
})).catch(error => {
console.error(error);
})
var each_sortary = [];
for(var name in each_stamp){
each_sortary.push([name, each_stamp[name] * 5]);
}
each_sortary.sort(function(a, b){
return b[1] - a[1];
})
let each_stamp_print = "";
for(i = 0; i < each_sortary.length; i++){
each_stamp_print += each_sortary[i][0] + ': ' + each_sortary[i][1] + '% \n';
}
const stampembed = new MessageEmbed()
.setColor('#F7819F')
.setTitle(class_name)
.setDescription(class_name + '의 상위 20명 각인 정보')
.addFields(
{name: "각인 상세 정보", value: each_stamp_print, inline: true},
{name: "각인 전체 정보", value: '개발중', inline: true}
)
interaction.editReply({ embeds: [stampembed], allowedMentions: {repliedUser: false} });
})
}
}