Showing
3 changed files
with
60 additions
and
0 deletions
commands/term.js
0 → 100644
1 | +const { SlashCommandBuilder } = require('@discordjs/builders'); | ||
2 | +const { MessageEmbed } = require('discord.js'); | ||
3 | +const fs = require('fs'); | ||
4 | + | ||
5 | +module.exports = { | ||
6 | + data: new SlashCommandBuilder() | ||
7 | + .setName('용어') | ||
8 | + .setDescription('로스트아크 관련 용어정보를 제공합니다.') | ||
9 | + .addStringOption(option => | ||
10 | + option.setName('단어') | ||
11 | + .setDescription('궁금한 단어') | ||
12 | + .setRequired(true)), | ||
13 | + async execute(interaction) { | ||
14 | + const user_term = interaction.options.getString('단어'); | ||
15 | + | ||
16 | + await fs.readFile('./terms/response.json', 'utf-8', (err, respone) => { | ||
17 | + if (err) return console.log(err); | ||
18 | + const terms = JSON.parse(respone); | ||
19 | + | ||
20 | + if(user_term in terms){ | ||
21 | + const termembed = new MessageEmbed() | ||
22 | + .setColor('#FFD700') | ||
23 | + .setTitle('단어 정보 제공') | ||
24 | + .setDescription(`${user_term} : ${terms[user_term]}`) | ||
25 | + interaction.reply({ embeds: [termembed], allowedMentions: {repliedUser: false} }); | ||
26 | + } else{ | ||
27 | + const termembed = new MessageEmbed() | ||
28 | + .setColor('#FFD700') | ||
29 | + .setTitle('단어 정보 제공') | ||
30 | + .setDescription(`${user_term}에 대한 정보가 없어요 ㅠㅠ\n사용자가 많이 입력하는 단어 일수록 정보가 빠르게 추가됩니다!`) | ||
31 | + | ||
32 | + fs.readFile('./terms/request.json', 'utf-8', (err, request) => { | ||
33 | + if (err) return console.log(err); | ||
34 | + let req_terms = JSON.parse(request); | ||
35 | + | ||
36 | + if(user_term in req_terms){ | ||
37 | + req_terms[user_term] += 1; | ||
38 | + let reqtermJsion = JSON.stringify(req_terms); | ||
39 | + fs.writeFile('./terms/request.json', reqtermJsion, (err) => { | ||
40 | + if (err) return console.log(err); | ||
41 | + }) | ||
42 | + }else{ | ||
43 | + req_terms[user_term] = 0; | ||
44 | + let reqtermJsion = JSON.stringify(req_terms); | ||
45 | + fs.writeFile('./terms/request.json', reqtermJsion, (err => { | ||
46 | + if (err) return console.log(err); | ||
47 | + })) | ||
48 | + } | ||
49 | + }) | ||
50 | + interaction.reply({ embeds: [termembed], allowedMentions: {repliedUser: false} }); | ||
51 | + } | ||
52 | + }) | ||
53 | + }, | ||
54 | +}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
terms/request.json
0 → 100644
1 | +{"user_term":0,"temp":1,"회파":0} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment