Ubuntu

형식: 필요없는 코드 제거 및 자동 정렬

Showing 1 changed file with 44 additions and 46 deletions
1 const fs = require('fs'); 1 const fs = require('fs');
2 const express = require('express'); 2 const express = require('express');
3 const app = express(); 3 const app = express();
4 -const port = 80;
5 4
6 const axios = require('axios'); 5 const axios = require('axios');
7 const cheerio = require('cheerio'); 6 const cheerio = require('cheerio');
...@@ -33,8 +32,7 @@ async function checkData() { ...@@ -33,8 +32,7 @@ async function checkData() {
33 32
34 var today = new Date(); 33 var today = new Date();
35 var dateInfo = `${today.getFullYear()}/${today.getMonth() + 1}/${today.getDate()}`; 34 var dateInfo = `${today.getFullYear()}/${today.getMonth() + 1}/${today.getDate()}`;
36 - if (fakerData.date != dateInfo) 35 + if (fakerData.date != dateInfo) {
37 - {
38 console.log("오래된 데이터입니다. 데이터를 크롤링합니다."); 36 console.log("오래된 데이터입니다. 데이터를 크롤링합니다.");
39 await getData(); 37 await getData();
40 } 38 }
...@@ -228,7 +226,7 @@ function generateQuiz() { ...@@ -228,7 +226,7 @@ function generateQuiz() {
228 var quizO = `${fakerData.name}의 '${fakerData.recentLCK.name}' 모스트 픽은 '${mostList[0].champion}'이다.`; 226 var quizO = `${fakerData.name}의 '${fakerData.recentLCK.name}' 모스트 픽은 '${mostList[0].champion}'이다.`;
229 var quizX = `${fakerData.name}의 '${fakerData.recentLCK.name}' 모스트 픽은 '${mostList[2].champion}'이다.`; 227 var quizX = `${fakerData.name}의 '${fakerData.recentLCK.name}' 모스트 픽은 '${mostList[2].champion}'이다.`;
230 var info = `${fakerData.name}는 '${fakerData.recentLCK.name}'에서 '${mostList[0].champion}'을 가장 많이 플레이했습니다. (${mostList[0].played}게임)`; 228 var info = `${fakerData.name}는 '${fakerData.recentLCK.name}'에서 '${mostList[0].champion}'을 가장 많이 플레이했습니다. (${mostList[0].played}게임)`;
231 - generateOX(quizO,quizX,info); 229 + generateOX(quizO, quizX, info);
232 //#endregion 230 //#endregion
233 231
234 //#region 최근 LCK 승률 비교 ox 232 //#region 최근 LCK 승률 비교 ox
...@@ -242,7 +240,7 @@ function generateQuiz() { ...@@ -242,7 +240,7 @@ function generateQuiz() {
242 quizX = `${fakerData.name}의 '${fakerData.recentLCK.name}' 승률은 LCK 통산 승률보다 높다.`; 240 quizX = `${fakerData.name}의 '${fakerData.recentLCK.name}' 승률은 LCK 통산 승률보다 높다.`;
243 } 241 }
244 info = `${fakerData.recentLCK.name}' 승률 : ${recentWinRate}\nLCK 통산 승률 : ${lckWinRate}`; 242 info = `${fakerData.recentLCK.name}' 승률 : ${recentWinRate}\nLCK 통산 승률 : ${lckWinRate}`;
245 - generateOX(quizO,quizX,info); 243 + generateOX(quizO, quizX, info);
246 //#endregion 244 //#endregion
247 245
248 //#region 최근 LCK KDA 비교 ox 246 //#region 최근 LCK KDA 비교 ox
...@@ -256,7 +254,7 @@ function generateQuiz() { ...@@ -256,7 +254,7 @@ function generateQuiz() {
256 quizX = `${fakerData.name}의 '${fakerData.recentLCK.name}' KDA는 LCK 통산 KDA보다 높다.`; 254 quizX = `${fakerData.name}의 '${fakerData.recentLCK.name}' KDA는 LCK 통산 KDA보다 높다.`;
257 } 255 }
258 info = `${fakerData.recentLCK.name}' KDA : ${recentKDA}\nLCK 통산 KDA : ${lckKDA}`; 256 info = `${fakerData.recentLCK.name}' KDA : ${recentKDA}\nLCK 통산 KDA : ${lckKDA}`;
259 - generateOX(quizO,quizX,info); 257 + generateOX(quizO, quizX, info);
260 //#endregion 258 //#endregion
261 259
262 //#region 최근 LCK 킬관여율 비교 ox 260 //#region 최근 LCK 킬관여율 비교 ox
...@@ -270,28 +268,28 @@ function generateQuiz() { ...@@ -270,28 +268,28 @@ function generateQuiz() {
270 quizX = `${fakerData.name}의 '${fakerData.recentLCK.name}' 킬관여율은 LCK 통산 킬관여율보다 높다.`; 268 quizX = `${fakerData.name}의 '${fakerData.recentLCK.name}' 킬관여율은 LCK 통산 킬관여율보다 높다.`;
271 } 269 }
272 info = `${fakerData.recentLCK.name}' 킬관여율 : ${recentKP}\nLCK 통산 킬관여율 : ${lckKP}`; 270 info = `${fakerData.recentLCK.name}' 킬관여율 : ${recentKP}\nLCK 통산 킬관여율 : ${lckKP}`;
273 - generateOX(quizO,quizX,info); 271 + generateOX(quizO, quizX, info);
274 //#endregion 272 //#endregion
275 273
276 //#region LCK 통산 경기 수 퀴즈 ox 274 //#region LCK 통산 경기 수 퀴즈 ox
277 var lckGames = fakerData.lCK.totalGamePlay * 1; 275 var lckGames = fakerData.lCK.totalGamePlay * 1;
278 - quizO = `${fakerData.name}의 LCK 경기 수는 ${parseInt(lckGames/10)*10} 경기 이상이다.`; 276 + quizO = `${fakerData.name}의 LCK 경기 수는 ${parseInt(lckGames / 10) * 10} 경기 이상이다.`;
279 - quizX = `${fakerData.name}의 LCK 경기 수는 ${parseInt(lckGames/10)*10 + 10} 경기 이상이다.`; 277 + quizX = `${fakerData.name}의 LCK 경기 수는 ${parseInt(lckGames / 10) * 10 + 10} 경기 이상이다.`;
280 info = `${fakerData.name}의 LCK 통산 경기 수 : ${lckGames}`; 278 info = `${fakerData.name}의 LCK 통산 경기 수 : ${lckGames}`;
281 - generateOX(quizO,quizX,info); 279 + generateOX(quizO, quizX, info);
282 //#endregion 280 //#endregion
283 281
284 //#region LCK 경기당 킬 퀴즈 ox 282 //#region LCK 경기당 킬 퀴즈 ox
285 var lckKM = fakerData.lCK.killPerMatch * 1; 283 var lckKM = fakerData.lCK.killPerMatch * 1;
286 quizO = `${fakerData.name}의 LCK 경기 당 킬은 ${parseInt(lckKM)} 킬 이상이다.`; 284 quizO = `${fakerData.name}의 LCK 경기 당 킬은 ${parseInt(lckKM)} 킬 이상이다.`;
287 - quizX = `${fakerData.name}의 LCK 경기 당 킬은 ${parseInt(lckKM)+1} 킬 이상이다.`; 285 + quizX = `${fakerData.name}의 LCK 경기 당 킬은 ${parseInt(lckKM) + 1} 킬 이상이다.`;
288 info = `${fakerData.name}의 LCK 경기 당 킬 : ${lckKM}`; 286 info = `${fakerData.name}의 LCK 경기 당 킬 : ${lckKM}`;
289 generateOX(quizO, quizX, info); 287 generateOX(quizO, quizX, info);
290 //#endregion 288 //#endregion
291 289
292 //#region LCK 경기당 데스 퀴즈 ox 290 //#region LCK 경기당 데스 퀴즈 ox
293 var lckDM = fakerData.lCK.deathPerMatch * 1; 291 var lckDM = fakerData.lCK.deathPerMatch * 1;
294 - quizO = `${fakerData.name}의 LCK 경기 당 데스는 ${parseInt(lckDM)+1} 데스 이하이다.`; 292 + quizO = `${fakerData.name}의 LCK 경기 당 데스는 ${parseInt(lckDM) + 1} 데스 이하이다.`;
295 quizX = `${fakerData.name}의 LCK 경기 당 데스는 ${parseInt(lckDM)} 데스 이하이다.`; 293 quizX = `${fakerData.name}의 LCK 경기 당 데스는 ${parseInt(lckDM)} 데스 이하이다.`;
296 info = `${fakerData.name}의 LCK 경기 당 데스 : ${lckDM}`; 294 info = `${fakerData.name}의 LCK 경기 당 데스 : ${lckDM}`;
297 generateOX(quizO, quizX, info); 295 generateOX(quizO, quizX, info);
...@@ -306,17 +304,17 @@ function generateQuiz() { ...@@ -306,17 +304,17 @@ function generateQuiz() {
306 //#endregion 304 //#endregion
307 305
308 //#region LCK 킬관여율 퀴즈 ox 306 //#region LCK 킬관여율 퀴즈 ox
309 - var lckKP = fakerData.lCK.kP.replace('%','')*1; 307 + var lckKP = fakerData.lCK.kP.replace('%', '') * 1;
310 - quizO = `${fakerData.name}의 LCK 통산 킬관여율은 ${parseInt(lckKP/10)*10}% 이상이다.`; 308 + quizO = `${fakerData.name}의 LCK 통산 킬관여율은 ${parseInt(lckKP / 10) * 10}% 이상이다.`;
311 - quizX = `${fakerData.name}의 LCK 통산 킬관여율은 ${parseInt(lckKP/10)*10 + 10}% 이상이다.`; 309 + quizX = `${fakerData.name}의 LCK 통산 킬관여율은 ${parseInt(lckKP / 10) * 10 + 10}% 이상이다.`;
312 info = `${fakerData.name}의 LCK 통산 킬관여율 : ${lckKP}%`; 310 info = `${fakerData.name}의 LCK 통산 킬관여율 : ${lckKP}%`;
313 generateOX(quizO, quizX, info); 311 generateOX(quizO, quizX, info);
314 //#endregion 312 //#endregion
315 313
316 //#region LCK 승률 퀴즈 ox 314 //#region LCK 승률 퀴즈 ox
317 - var lckWR = fakerData.lCK.winRate.replace('%','')*1; 315 + var lckWR = fakerData.lCK.winRate.replace('%', '') * 1;
318 - quizO = `${fakerData.name}의 LCK 통산 승률은 ${parseInt(lckWR/10)*10}% 이상이다.`; 316 + quizO = `${fakerData.name}의 LCK 통산 승률은 ${parseInt(lckWR / 10) * 10}% 이상이다.`;
319 - quizX = `${fakerData.name}의 LCK 통산 승률은 ${parseInt(lckWR/10)*10 + 10}% 이상이다.`; 317 + quizX = `${fakerData.name}의 LCK 통산 승률은 ${parseInt(lckWR / 10) * 10 + 10}% 이상이다.`;
320 info = `${fakerData.name}의 LCK 통산 승률 : ${lckWR}%`; 318 info = `${fakerData.name}의 LCK 통산 승률 : ${lckWR}%`;
321 generateOX(quizO, quizX, info); 319 generateOX(quizO, quizX, info);
322 //#endregion 320 //#endregion
...@@ -337,7 +335,7 @@ function generateQuiz() { ...@@ -337,7 +335,7 @@ function generateQuiz() {
337 info = `'${rareChampList[champIndex].name}' : ${rareChampList[champIndex].totalGamePlay}게임, ${rareChampList[champIndex].totalWin}승, ${rareChampList[champIndex].kDA}KDA`; 335 info = `'${rareChampList[champIndex].name}' : ${rareChampList[champIndex].totalGamePlay}게임, ${rareChampList[champIndex].totalWin}승, ${rareChampList[champIndex].kDA}KDA`;
338 generateOX(quizO, quizX, info); 336 generateOX(quizO, quizX, info);
339 337
340 - champList.splice(champIndex,1); 338 + champList.splice(champIndex, 1);
341 } 339 }
342 //#endregion 340 //#endregion
343 341
...@@ -418,7 +416,7 @@ app.post('/hook', async function (req, res) { ...@@ -418,7 +416,7 @@ app.post('/hook', async function (req, res) {
418 var message = eventObj.message; 416 var message = eventObj.message;
419 417
420 // request log 418 // request log
421 - console.log('======================', new Date() ,'======================'); 419 + console.log('======================', new Date(), '======================');
422 console.log('[request]', req.body); 420 console.log('[request]', req.body);
423 console.log('[request source] ', eventObj.source); 421 console.log('[request source] ', eventObj.source);
424 console.log('[request message]', eventObj.message); 422 console.log('[request message]', eventObj.message);
...@@ -444,7 +442,7 @@ app.post('/hook', async function (req, res) { ...@@ -444,7 +442,7 @@ app.post('/hook', async function (req, res) {
444 }); 442 });
445 443
446 function sendQuiz(replyToken, id, isInit) { 444 function sendQuiz(replyToken, id, isInit) {
447 - var randomQuiz = quizList[Math.floor(Math.random()*quizList.length)]; 445 + var randomQuiz = quizList[Math.floor(Math.random() * quizList.length)];
448 var quizText = randomQuiz.quiz; 446 var quizText = randomQuiz.quiz;
449 var messages; 447 var messages;
450 users[id].quizAns = randomQuiz.ans; 448 users[id].quizAns = randomQuiz.ans;
...@@ -453,19 +451,19 @@ function sendQuiz(replyToken, id, isInit) { ...@@ -453,19 +451,19 @@ function sendQuiz(replyToken, id, isInit) {
453 if (isInit) { 451 if (isInit) {
454 messages = [ 452 messages = [
455 { 453 {
456 - "type":"text", 454 + "type": "text",
457 - "text":quizText 455 + "text": quizText
458 } 456 }
459 ]; 457 ];
460 } else { 458 } else {
461 messages = [ 459 messages = [
462 { 460 {
463 - "type":"text", 461 + "type": "text",
464 - "text":'정답입니다.' 462 + "text": '정답입니다.'
465 }, 463 },
466 { 464 {
467 - "type":"text", 465 + "type": "text",
468 - "text":quizText 466 + "text": quizText
469 } 467 }
470 ]; 468 ];
471 } 469 }
...@@ -476,10 +474,10 @@ function sendQuiz(replyToken, id, isInit) { ...@@ -476,10 +474,10 @@ function sendQuiz(replyToken, id, isInit) {
476 'Authorization': `Bearer ${TOKEN}` 474 'Authorization': `Bearer ${TOKEN}`
477 }, 475 },
478 json: { 476 json: {
479 - "replyToken":replyToken, 477 + "replyToken": replyToken,
480 "messages": messages 478 "messages": messages
481 } 479 }
482 - },(error, response, body) => { 480 + }, (error, response, body) => {
483 console.log(body) 481 console.log(body)
484 } 482 }
485 ); 483 );
...@@ -499,7 +497,7 @@ function endQuiz(replyToken, id) { ...@@ -499,7 +497,7 @@ function endQuiz(replyToken, id) {
499 isWaitAns = false; 497 isWaitAns = false;
500 sumOfTry++; 498 sumOfTry++;
501 sumOfStreak += users[id].streak; 499 sumOfStreak += users[id].streak;
502 - var averageStreak = sumOfStreak/sumOfTry; 500 + var averageStreak = sumOfStreak / sumOfTry;
503 request.post( 501 request.post(
504 { 502 {
505 url: TARGET_URL, 503 url: TARGET_URL,
...@@ -507,27 +505,27 @@ function endQuiz(replyToken, id) { ...@@ -507,27 +505,27 @@ function endQuiz(replyToken, id) {
507 'Authorization': `Bearer ${TOKEN}` 505 'Authorization': `Bearer ${TOKEN}`
508 }, 506 },
509 json: { 507 json: {
510 - "replyToken":replyToken, 508 + "replyToken": replyToken,
511 - "messages":[ 509 + "messages": [
512 { 510 {
513 - "type":"text", 511 + "type": "text",
514 - "text":"오답입니다." 512 + "text": "오답입니다."
515 }, 513 },
516 { 514 {
517 - "type":"text", 515 + "type": "text",
518 - "text":users[id].quizInfo 516 + "text": users[id].quizInfo
519 }, 517 },
520 { 518 {
521 - "type":"text", 519 + "type": "text",
522 - "text":`${users[id].streak}문제 연속 정답!\n(유저 평균 : ${averageStreak.toFixed(1)}문제)` 520 + "text": `${users[id].streak}문제 연속 정답!\n(유저 평균 : ${averageStreak.toFixed(1)}문제)`
523 }, 521 },
524 { 522 {
525 - "type":"text", 523 + "type": "text",
526 - "text":"퀴즈를 다시 시작하려면 '시작'을 입력해주세요." 524 + "text": "퀴즈를 다시 시작하려면 '시작'을 입력해주세요."
527 } 525 }
528 ] 526 ]
529 } 527 }
530 - },(error, response, body) => { 528 + }, (error, response, body) => {
531 console.log(body) 529 console.log(body)
532 } 530 }
533 ); 531 );
...@@ -535,15 +533,15 @@ function endQuiz(replyToken, id) { ...@@ -535,15 +533,15 @@ function endQuiz(replyToken, id) {
535 533
536 try { 534 try {
537 const option = { 535 const option = {
538 - ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), 536 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'),
539 - key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), 537 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(),
540 - cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), 538 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(),
541 }; 539 };
542 540
543 HTTPS.createServer(option, app).listen(sslport, () => { 541 HTTPS.createServer(option, app).listen(sslport, () => {
544 console.log(`[HTTPS] Server is started on port ${sslport}`); 542 console.log(`[HTTPS] Server is started on port ${sslport}`);
545 }); 543 });
546 - } catch (error) { 544 +} catch (error) {
547 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); 545 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
548 console.log(error); 546 console.log(error);
549 - }
...\ No newline at end of file ...\ No newline at end of file
547 +}
...\ No newline at end of file ...\ No newline at end of file
......