-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
99 lines (78 loc) · 3.1 KB
/
bot.js
File metadata and controls
99 lines (78 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const { Client, Intents, MessageEmbed } = require('discord.js');
const token = require("./token.json");
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
});
let request = require(`request`);
let fs = require(`fs`);
function download(url){
request.get(url)
.on('error', console.error)
.pipe(fs.createWriteStream('save.SC2Bank'));
}
// 시간을 불러오는 함수
function addZero(num) {
if (num < 10) {
num = "0" + num;
}
return num;
}
// 시간을 불러오는 함수
function getCurrentTime() {
var date = new Date();
var year = date.getFullYear();
var month = addZero(date.getMonth() + 1);
var day = addZero(date.getDate());
var hour = addZero(date.getHours());
var minute = addZero(date.getMinutes());
var second = addZero(date.getSeconds());
var currentTime = year + "년 " + month + "월 " + day + "일 " + hour + "시 " + minute + "분 " + second +"초";
return currentTime;
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag} || `+new Date());
client.user.setActivity('- help', { type: 'PLAYING' });
});
client.on('messageCreate', msg => {
if (msg.author.bot) return;
if (msg.content == "- help") {
const embed = new MessageEmbed()
.setTitle("ㅡㅡㅡㅡ help list ㅡㅡㅡㅡ")
.setColor('#FFBF00')
.setDescription("help list")
.addField("1. - ranking", " 현재 랭킹 정보를 보여줍니다.")
.addField("2. - time", " 현재 시간 정보를 보여줍니다.");
msg.channel.send({ embeds: [embed] });
/*
reply = 답신
msg.reply("- ranking");
channel.send = 해당 체널에 메시지
msg.channel.send("- ranking");
*/
}
if (msg.content == "- time") {
const embed = new MessageEmbed()
.setTitle("현재 시간")
.setColor('#FFBF00')
.setDescription(getCurrentTime());
msg.channel.send({ embeds: [embed] });
}
if (msg.content == "- rank"){
if(msg.attachments.first()){//checks if an attachment is sent (첨부파일이 있는지 확인)
if(msg.attachments.first().name == "save.SC2Bank"){// attachment file's name = save.SC2Bank (파일 이름이 save.SC2Bank일 때)
download(msg.attachments.first().url);//download attachment file (첨부파일 다운로드)
msg.reply("```cs\n ! 정상적으로 다운로드 되었습니다. ```");
}
else{
msg.reply("```cs\n# error : save.SC2Bank 파일이 아닙니다.\nsave.SC2Bank 파일을 첨부하시면서 댓글달기에 - rank 를 같이 적어 주세요.```");
}
}
else{
msg.reply("```cs\n# error : - rank 를 댓글달기로 같이 입력하지 않았습니다.\nsave.SC2Bank 파일을 첨부하시면서 댓글달기에 - rank 를 같이 적어 주세요.```");
}
}
});
client.login(token.token);