남우성

Merge branch 'feature/mari' into develop

1 +const { SlashCommandBuilder } = require('@discordjs/builders');
2 +const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js');
3 +const axios = require("axios");
4 +const cheerio = require("cheerio");
5 +
6 +module.exports = {
7 + data: new SlashCommandBuilder()
8 + .setName('마리샵')
9 + .setDescription('현재 마리샵과 이전, 전전의 마리샵의 정보를 조회합니다.'),
10 + async execute(interaction) {
11 + const itemInfo = [];
12 + var isMaintainence = false;
13 + await axios.get("https://lostark.game.onstove.com").then(html=>{
14 + const $ = cheerio.load(html.data);
15 + })
16 + const buttonsRow = new MessageActionRow()
17 + .addComponents(
18 + new MessageButton()
19 + .setCustomId("12time_ago")
20 + .setLabel("전전 마리샵 정보 조회")
21 + .setStyle("SECONDARY")
22 + )
23 + .addComponents(
24 + new MessageButton()
25 + .setCustomId("6time_ago")
26 + .setLabel("이전 마리샵 정보 조회")
27 + .setStyle("SECONDARY")
28 + )
29 + .addComponents(
30 + new MessageButton()
31 + .setCustomId("0time_ago")
32 + .setLabel("현재 마리샵 정보 조회")
33 + .setStyle("SECONDARY")
34 + );
35 + async function getHTML() {
36 + try {
37 + return await axios.get("https://lostark.game.onstove.com/Shop#mari");
38 + } catch (error) {
39 + console.error(error);
40 + }
41 + };
42 + await getHTML().then(html => {
43 + const $ = cheerio.load(html.data);
44 + const bodyList = $("ul.list-items").children("li");
45 + bodyList.each(function(i, elem) {
46 + itemInfo[i] = {
47 + name: $(this).find("span.item-name").text(),
48 + amount: $(this).find("span.amount").text()};
49 + });
50 + return itemInfo;
51 + });
52 +
53 + const embed = new MessageEmbed()
54 + .setTitle("마리샵 성장 추천 목록")
55 + .setColor("#FAA8F0")
56 + .setDescription("성장 추천");
57 + for(idx = 0; idx < 6; idx++) {
58 + embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
59 + embed.addField("\u200B", "전투ㆍ생활 추천", false);
60 + for(idx = 18; idx < 24; idx++) {
61 + embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
62 + interaction.reply({ embeds: [embed], components: [buttonsRow], allowedMentions: {repliedUser: false}});
63 +
64 + const filter = (interaction) => { return interaction.customId === "12time_ago" || "6time_ago" || "0time_ago" ;};
65 + const collector = interaction.channel.createMessageComponentCollector({ filter, time: 60000});
66 + collector.on("collect", async (interaction) => {
67 + if(interaction.customId === "12time_ago") {
68 + const embed = new MessageEmbed()
69 + .setTitle("마리샵 성장 추천 목록")
70 + .setColor("#FAA8F0")
71 + .setDescription("성장 추천");
72 + for(idx = 6; idx < 12; idx++) {
73 + embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
74 + embed.addField("\u200B", "전투ㆍ생활 추천", false);
75 + for(idx = 24; idx < 30; idx++) {
76 + embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
77 + interaction.update({ embeds: [embed], components: [buttonsRow], allowedMentions: {repliedUser: false}});
78 + } else if(interaction.customId === "6time_ago"){
79 + const embed = new MessageEmbed()
80 + .setTitle("마리샵 성장 추천 목록")
81 + .setColor("#FAA8F0")
82 + .setDescription("성장 추천");
83 + for(idx = 12; idx < 18; idx++) {
84 + embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
85 + embed.addField("\u200B", "전투ㆍ생활 추천", false);
86 + for(idx = 30; idx < 36; idx++) {
87 + embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
88 + interaction.update({ embeds: [embed], components: [buttonsRow], allowedMentions: {repliedUser: false}});
89 + } else if(interaction.customId === "0time_ago"){
90 + const embed = new MessageEmbed()
91 + .setTitle("마리샵 성장 추천 목록")
92 + .setColor("#FAA8F0")
93 + .setDescription("성장 추천");
94 + for(idx = 0; idx < 6; idx++) {
95 + embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
96 + embed.addField("\u200B", "전투ㆍ생활 추천", false);
97 + for(idx = 18; idx <24; idx++) {
98 + embed.addField(`${(itemInfo[idx]).name}`, `${(itemInfo[idx]).amount}<:bluecrystal:952747773097295932>`, true); }
99 + interaction.update({ embeds: [embed], components: [buttonsRow], allowedMentions: {repliedUser: false}});
100 + }
101 + });
102 + },
103 +};
...\ No newline at end of file ...\ No newline at end of file