Showing
2 changed files
with
54 additions
and
0 deletions
| 1 | const Discord = require("discord.js") | 1 | const Discord = require("discord.js") |
| 2 | const client = new Discord.Client() | 2 | const client = new Discord.Client() |
| 3 | +var fs = require('fs'); //파일입출력 모듈 | ||
| 4 | +const internal = require("stream"); | ||
| 5 | +var now = new Date(); // 현재날짜 및 시간 객체 | ||
| 3 | 6 | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +//로그인 콘솔 출력 | ||
| 4 | client.on("ready", () => { | 11 | client.on("ready", () => { |
| 5 | console.log(`Logged in as ${client.user.tag}!`) | 12 | console.log(`Logged in as ${client.user.tag}!`) |
| 6 | }) | 13 | }) |
| 7 | 14 | ||
| 15 | + | ||
| 16 | +//명령어 인식 | ||
| 8 | client.on("message", msg => { | 17 | client.on("message", msg => { |
| 18 | + | ||
| 19 | + //테스트 조건문 | ||
| 9 | if (msg.content === "ping") { | 20 | if (msg.content === "ping") { |
| 10 | msg.reply("Pong!") | 21 | msg.reply("Pong!") |
| 11 | } | 22 | } |
| 23 | + if (msg.content === "!현재시간") { | ||
| 24 | + msg.reply(now.getHours() + "시 " + now.getMinutes() + "분"); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + //공부시작 시간 체크 | ||
| 28 | + if (msg.content === "!공부시작") { | ||
| 29 | + var data = String(now.getHours()) +"."+ String(now.getMinutes()); | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + fs.writeFile('data.txt', data, 'utf8', function(error){ // 파일에 data내용 저장 | ||
| 33 | + console.log('write end'); | ||
| 34 | + }); | ||
| 35 | + | ||
| 36 | + msg.reply("공부시작! 열공~ ⁽⁽◝( ˙ ꒳ ˙ )◜⁾⁾"); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + //공부끝 시간 체크 | ||
| 40 | + if (msg.content === "!공부끝") { | ||
| 41 | + fs.readFile('data.txt', 'utf8', function(err, data) { | ||
| 42 | + | ||
| 43 | + var arr = data.split('.'); // arr[0] = 공부시작시간, arr[1] = 공부종료시간 | ||
| 44 | + | ||
| 45 | + //공부시간 계산 | ||
| 46 | + var studyHours = now.getHours() - Number(arr[0]); | ||
| 47 | + if (now.getMinutes() - Number(data[1]) < 0) { | ||
| 48 | + var studyMinutes = 60 + now.getMinutes() - Number(arr[1]); | ||
| 49 | + } | ||
| 50 | + else { | ||
| 51 | + var studyMinutes = now.getMinutes() - Number(arr[1]); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + //공부시간 출력 | ||
| 55 | + msg.reply(studyHours + "시간 " + studyMinutes + "분 공부하였습니다."); | ||
| 56 | + console.log(studyHours + "h " +studyMinutes + "m"); | ||
| 57 | + }); | ||
| 58 | + | ||
| 59 | + | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + | ||
| 12 | }) | 63 | }) |
| 13 | 64 | ||
| 65 | + | ||
| 66 | +//디스코드 봇 토큰 | ||
| 14 | client.login('OTA3OTU2NjY1MTEzMDE4NDA4.YYuuiQ.Rn2yQ9lGPLr_24sky29TWQHLOYA'); | 67 | client.login('OTA3OTU2NjY1MTEzMDE4NDA4.YYuuiQ.Rn2yQ9lGPLr_24sky29TWQHLOYA'); |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment