mari.js
4.43 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
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js');
const axios = require("axios");
const cheerio = require("cheerio");
module.exports = {
data: new SlashCommandBuilder()
.setName('마리샵')
.setDescription('현재 마리샵과 이전, 전전의 마리샵의 정보를 조회합니다.'),
async execute(interaction) {
const itemInfo = [];
var isMaintainence = false;
await axios.get("https://lostark.game.onstove.com").then(html=>{
const $ = cheerio.load(html.data);
})
const buttonsRow = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId("12time_ago")
.setLabel("전전 마리샵 정보 조회")
.setStyle("SECONDARY")
)
.addComponents(
new MessageButton()
.setCustomId("6time_ago")
.setLabel("이전 마리샵 정보 조회")
.setStyle("SECONDARY")
)
.addComponents(
new MessageButton()
.setCustomId("0time_ago")
.setLabel("현재 마리샵 정보 조회")
.setStyle("SECONDARY")
);
async function getHTML() {
try {
return await axios.get("https://lostark.game.onstove.com/Shop#mari");
} catch (error) {
console.error(error);
}
};
await getHTML().then(html => {
const $ = cheerio.load(html.data);
const bodyList = $("ul.list-items").children("li");
bodyList.each(function(i, elem) {
itemInfo[i] = {
name: $(this).find("span.item-name").text(),
amount: $(this).find("span.amount").text()};
});
return itemInfo;
});
const embed = new MessageEmbed()
.setTitle("마리샵 성장 추천 목록")
.setColor("#FAA8F0")
.setDescription("성장 추천");
for(idx = 0; idx < 6; idx++) {
embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
embed.addField("\u200B", "전투ㆍ생활 추천", false);
for(idx = 18; idx < 24; idx++) {
embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
interaction.reply({ embeds: [embed], components: [buttonsRow], allowedMentions: {repliedUser: false}});
const filter = (interaction) => { return interaction.customId === "12time_ago" || "6time_ago" || "0time_ago" ;};
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000});
collector.on("collect", async (interaction) => {
if(interaction.customId === "12time_ago") {
const embed = new MessageEmbed()
.setTitle("마리샵 성장 추천 목록")
.setColor("#FAA8F0")
.setDescription("성장 추천");
for(idx = 6; idx < 12; idx++) {
embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
embed.addField("\u200B", "전투ㆍ생활 추천", false);
for(idx = 24; idx < 30; idx++) {
embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
interaction.update({ embeds: [embed], components: [buttonsRow], allowedMentions: {repliedUser: false}});
} else if(interaction.customId === "6time_ago"){
const embed = new MessageEmbed()
.setTitle("마리샵 성장 추천 목록")
.setColor("#FAA8F0")
.setDescription("성장 추천");
for(idx = 12; idx < 18; idx++) {
embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
embed.addField("\u200B", "전투ㆍ생활 추천", false);
for(idx = 30; idx < 36; idx++) {
embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
interaction.update({ embeds: [embed], components: [buttonsRow], allowedMentions: {repliedUser: false}});
} else if(interaction.customId === "0time_ago"){
const embed = new MessageEmbed()
.setTitle("마리샵 성장 추천 목록")
.setColor("#FAA8F0")
.setDescription("성장 추천");
for(idx = 0; idx < 6; idx++) {
embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
embed.addField("\u200B", "전투ㆍ생활 추천", false);
for(idx = 18; idx <24; idx++) {
embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
interaction.update({ embeds: [embed], components: [buttonsRow], allowedMentions: {repliedUser: false}});
}
});
},
};