const request = require('request-promise');
const cheerio = require('cheerio');
const { RichEmbed } = require('discord.js');
async function getRank(args) {
let url = 'http://rank.search.naver.com/rank.js';
let html;
try {
html = await request(url);
} catch (e) {
console.log("error");
return "Error";
}
let json = JSON.parse(html);
let jsonData = json.data[0].data
const Rank_List = [];
for (const key of jsonData) {
Rank_List.push(`${key.rank}위 ${key.keyword}`);
}
const title = ('`네이버 실시간 급상승 TOP 20`');
const Rank_Result = Rank_List.join('\n');
const Result = Rank_Result;
let description = Rank_List;
return new RichEmbed()
.setTitle(title)
.setDescription(description);
}
module.exports = {
name: '!네이버',
description: '',
async execute(message, args) {
let result = null;
if (!args.length) {
result = new RichEmbed()
.setTitle('네이버 실시간 급상승')
.setDescription('`!네이버 실시간` 또는 `!네이버 rank`');
} else {
switch (args[0]) {
case '실시간':
case 's':
case 'rank':
case 'stats':
result = await getRank(args);
break;
default:
result = `\`${args[0]}\` 은(는) 알 수 없는 명령이다`;
break;
}
}
await message.channel.send(result);
},
};