김건우

Merge branch 'feature/ranking' into 'master'

Feature/ranking



See merge request !2
Showing 1 changed file with 48 additions and 11 deletions
...@@ -11,6 +11,9 @@ const youtube = new Youtube(youtubeAPI); ...@@ -11,6 +11,9 @@ const youtube = new Youtube(youtubeAPI);
11 const ytdl = require('ytdl-core'); // npm install ytdl-core 11 const ytdl = require('ytdl-core'); // npm install ytdl-core
12 const { getVideoID } = require('ytdl-core'); 12 const { getVideoID } = require('ytdl-core');
13 13
14 +
15 +
16 +
14 //npm install discord.js @discord/opus 필요 17 //npm install discord.js @discord/opus 필요
15 //npm install --save ffmpeg-binaries 필요 18 //npm install --save ffmpeg-binaries 필요
16 19
...@@ -19,7 +22,9 @@ const { getVideoID } = require('ytdl-core'); ...@@ -19,7 +22,9 @@ const { getVideoID } = require('ytdl-core');
19 //로그인 콘솔 출력 22 //로그인 콘솔 출력
20 client.on("ready", () => { 23 client.on("ready", () => {
21 console.log(`Logged in as ${client.user.tag}!`) 24 console.log(`Logged in as ${client.user.tag}!`)
22 - client.user.setPresence({ game: { name: "상메뭐로하지"}, status: "online"}) 25 + client.user.setActivity('도움말은 ~help', {
26 + type : 'PLAYING'
27 + })
23 }); 28 });
24 29
25 30
...@@ -50,6 +55,13 @@ client.on("message", msg => { ...@@ -50,6 +55,13 @@ client.on("message", msg => {
50 55
51 56
52 57
58 +
59 +
60 +
61 +
62 +
63 +
64 +
53 //공부시작 시간 체크 65 //공부시작 시간 체크
54 if (command === "공부시작") { 66 if (command === "공부시작") {
55 var data = String(now.getHours()) +"."+ String(now.getMinutes()); 67 var data = String(now.getHours()) +"."+ String(now.getMinutes());
...@@ -127,24 +139,51 @@ client.on("message", msg => { ...@@ -127,24 +139,51 @@ client.on("message", msg => {
127 //수정 필요 139 //수정 필요
128 //공부시간 순위 140 //공부시간 순위
129 if (command === '순위') { 141 if (command === '순위') {
142 + var studyTimeArr = [];
130 fs.readdir('./data/studyTime', (err, file_list) => { //폴더열기 143 fs.readdir('./data/studyTime', (err, file_list) => { //폴더열기
131 - var fileArr = file_list.toString().split(','); //studyTime 배열 144 + var fileArr = file_list.toString().split(','); //studyTime 파일 배열
145 + var cnt = 0
132 fileArr.forEach((el,i) => { 146 fileArr.forEach((el,i) => {
133 - fs.readFile("./data/studyTime/"+el, 'utf8', function(err, data) { 147 + var data = fs.readFileSync("./data/studyTime/"+el, 'utf8');
134 data = data.slice(0,-1); 148 data = data.slice(0,-1);
135 var timeDiv = data.toString().split(' '); 149 var timeDiv = data.toString().split(' ');
136 - var sumHours = 0; 150 + var sumTime = 0;
137 - var sumMinutes = 0;
138 timeDiv.forEach((j,k) => { // j형식 = ~.@ ( ~는 시, @는 분) 151 timeDiv.forEach((j,k) => { // j형식 = ~.@ ( ~는 시, @는 분)
139 var timeData = j.toString().split('.'); 152 var timeData = j.toString().split('.');
140 - sumHours += Number(timeData[0]); 153 + sumTime += Number(timeData[0])*60;
141 - sumMinutes += Number(timeData[1]); 154 + sumTime += Number(timeData[1]);
142 - });
143 - msg.reply("\n<@" + el.replace('.txt','') + "> 님은 총" + sumHours + "시간 " + sumMinutes + "분 공부하였습니다.")
144 }); 155 });
156 + var tempArr = new Array(2);
157 + tempArr[0] = sumTime;
158 + tempArr[1] = el.replace('.txt','');
159 + studyTimeArr.push(tempArr);
145 }); 160 });
161 +
162 + //순위 출력
163 + studyTimeArr.sort((a, b) => (b[0]+b[1]) - (a[0]+a[1]));
164 + for (var i = 0; i < studyTimeArr.length; i++) {
165 + msg.channel.send((i+1)+"등 <@"+studyTimeArr[i][1]+"> 님 "+parseInt(studyTimeArr[i][0]/60)+"시간 "+studyTimeArr[i][0]%60+"분 공부함.");
166 + }
146 }); 167 });
168 + }//공부시간 순위 end
169 +
170 +
171 +
172 +
173 +
174 + /*
175 + if (command === '순위출력') {
176 + const exampleEmbed = new MessageEmbed()
177 + .setColor('#0099ff')
178 + .setTitle('공부시간 순위')
179 + .setDescription('누가 공부를 제일 많이 했을까요?')
180 + .addField("<@"+studyTimeArr[0][0]+">", String(studyTimeArr[0][1]) + ' ' + String(studyTimeArr[0][2]))
181 + .addField("<@"+studyTimeArr[1][0]+">", String(studyTimeArr[1][1]) + ' ' + String(studyTimeArr[1][2]))
182 + .setTimestamp()
183 + .setFooter('공부시간 순위');
184 + msg.reply(exampleEmbed);
147 } 185 }
186 + */
148 187
149 188
150 189
...@@ -232,8 +271,6 @@ client.on("message", msg => { ...@@ -232,8 +271,6 @@ client.on("message", msg => {
232 271
233 272
234 // 음악재생 273 // 음악재생
235 -
236 -
237 if (command === "음악") { 274 if (command === "음악") {
238 if (msg.member.voice.channel) { 275 if (msg.member.voice.channel) {
239 msg.member.voice.channel.join() 276 msg.member.voice.channel.join()
......