compass.js
3.84 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
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');
const axios = require("axios");
const cheerio = require("cheerio");
const request = require("request-promise");
module.exports = {
data: new SlashCommandBuilder()
.setName('나침반')
.setDescription('오늘 이용가능한 프로키온의 나침반 스케줄 정보를 조회합니다.'),
async execute(interaction) {
const getHtml = async() => {
try {
return await axios.get("https://www.loawa.com/")
} catch (error){
console.error(error);
}
}
await getHtml()
.then(html => {
const $ = cheerio.load(html.data);
let info_island = [];
let info_contents = [];
let All_contents = ["유령선", "카오스 게이트"];
const $ContentList = $("ul.item-list").children("li.list");
$ContentList.each(function(i, elem){
for(var i = 0; i < All_contents.length; i++){
if($(this).find("h4.item-title span").text() === All_contents[i]){
info_contents.push($(this).find("h4.item-title span").text());
}
}
})
const $Bosscontent = $('div.main-inner-box ul.item-list').children('li'.list);
$Bosscontent.each(function(i, elem){
if($(this).find("h4.item-title").text() == "모아케"){
info_contents.push("필드 보스");
}
})
let content_print = "";
for(var i = 0; i < info_contents.length; i++){
content_print += `${info_contents[i]}\n`;
}
if(!content_print){
content_print = "오늘은 이용가능한 컨텐츠가 없어요";
}
//api 출처: 로학원생
url = "http://152.70.248.4:5000/adventureisland/";
request(url, function(err, res, body){
if(err){
throw err;
}
let island_data = JSON.parse(body);
for(var i = 0; i < island_data.Island.length; i++){
info_island[i] = {
name : island_data.Island[i].Name,
reward : island_data.Island[i].Reward
}
}
}).then(function(){
let island_print = "";
for(var i = 0; i < info_island.length; i++){
let rewardImage = "";
if(info_island[i].reward === "카드"){
rewardImage = "<:cardpack:976389392702791710>"
} else if(info_island[i].reward === "골드"){
rewardImage = "<:golds:976389688132788245>"
} else if(info_island[i].reward === "주화"){
rewardImage = "<:piratecoin:976389403662508092>"
} else if(info_island[i].reward === "실링"){
rewardImage = "<:shillings:976389357558710292>"
}
island_print += `${info_island[i].name}: ${info_island[i].reward} ${rewardImage}\n`;
}
const compassembed = new MessageEmbed()
.setColor('#008B8B')
.setTitle('프로키온의 나침반')
.setDescription(`오늘 이용가능한 컨텐츠 정보`)
.addFields(
{name: "모험섬", value: island_print, inline: true},
{name: "오늘의 콘텐츠", value: content_print, inline: true}
)
interaction.reply({ embeds: [compassembed], allowedMentions: {repliedUser: false} });
})
})
},
};