-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
362 lines (284 loc) · 11.9 KB
/
Copy pathindex.js
File metadata and controls
362 lines (284 loc) · 11.9 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
const botSettings = require("./botsettings.json");
let DB = require('./DB.json');
const Discord = require("discord.js");
const fs = require('fs');
const prefix = botSettings.prefix;
const client = new Discord.Client({disableEveryone: true});
//DB에서 입력한 보스이름 찾기
function findBossName(arr, name) {
return arr.filter(function(item) {
return item.name === name;
})[0];
}
client.on("ready", () => {
console.log(`Bot is ready! ${client.user.username}`);
})
client.on("message", (message) => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
var messageArray = message.content.split(" ");
var command = messageArray[0];
if(!command.startsWith(prefix)) return;
if (command === `${prefix}컷`) {
try {
var now = new Date();
var DateNow = "";
var Hours = now.getHours();
var mins = ('0' + now.getMinutes()).slice(-2);
console.log('현재시간 : ' + ('0' + now.getHours()).slice(-2) + ':' + ('0' + now.getMinutes()).slice(-2) + ':' + ('0' + now.getSeconds()).slice(-2));
var newData = {
"name": messageArray[1],
};
var item = findBossName(DB.raid, newData.name);
var PlusTime = item.plusTime;
var PlusM = item.plusM;
//console.log(PlusTime, PlusM);
//24시가 넘으면 0시부터 계산 + 10시 미만이면 앞에 0을 추가
if ((Number(Hours) + Number(PlusTime)) >= 24) {
if(messageArray[1] == "피닉스") {
if((now.getMinutes() + Number(PlusM)) >= 60) {
mins = ('0' + (now.getMinutes() - 7)).slice(-2);
DateNow = '0' + ((Number(Hours) + Number(PlusTime)) - 23) + mins;
}
else {
mins = now.getMinutes() + Number(PlusM);
DateNow = '0' + ((Number(Hours) + Number(PlusTime)) - 24) + mins;
}
}
else {
DateNow = '0' + ((Number(Hours) + Number(PlusTime)) - 24) + mins;
}
}
else if((Number(Hours) + Number(PlusTime)) < 10){
if(messageArray[1] == "피닉스") {
if((now.getMinutes() + Number(PlusM)) >= 60) {
mins = ('0' + (now.getMinutes() - 7)).slice(-2);
if((Number(Hours) + Number(PlusTime)) >= 9) {
DateNow = ('' + (Number(Hours) + Number(PlusTime) + 1)) + mins;
}
else {
DateNow = ('0' + (Number(Hours) + Number(PlusTime) + 1)) + mins;
}
}
else {
mins = now.getMinutes() + Number(PlusM);
DateNow = ('0' + (Number(Hours) + Number(PlusTime))) + mins;
}
}
else {
DateNow = ('0' + (Number(Hours) + Number(PlusTime))) + mins;
}
}
else {
if(messageArray[1] == "피닉스") {
if((now.getMinutes() + Number(PlusM)) >= 60) {
mins = ('0' + (now.getMinutes() - 7)).slice(-2);
if ((Number(Hours) + Number(PlusTime)) >= 23) {
DateNow = '0' + ((Number(Hours) + Number(PlusTime)) - 23) + mins;
}
else {
DateNow = ('' + (Number(Hours) + Number(PlusTime) + 1)) + mins;
}
}
else {
mins = now.getMinutes() + Number(PlusM);
DateNow = ('' + (Number(Hours) + Number(PlusTime))) + mins;
}
}
else {
DateNow = ('' + (Number(Hours) + Number(PlusTime))) + mins;
}
}
//console.log("계산시간 :",DateNow);
var newData = {
"name": messageArray[1],
"value": DateNow
};
var item = findBossName(DB.raid, newData.name);
item.value = newData.value;
console.log(item);
//정렬
DB.raid.sort(function (a, b) {
return a.value < b.value ? -1 : a.value > b.value ? 1 : 0;
});
message.channel.send(`${messageArray[1]} 컷 체크 완료!`);
//console.log(JSON.stringify(DB.raid, null, 4));
fs.writeFile('./DB.json', JSON.stringify(DB, null, 4), function(err) {
if(err) return console.log(err);
console.log('Save Done');
});
}
catch (e) {
messageArray[2] = 'Undefined';
message.channel.send("오류 : 명령어를 정확히 입력해주세요");
}
}
if(command === `${prefix}수정`){
try {
var newData = {
"name": messageArray[2],
"value": messageArray[1]
};
var item = findBossName(DB.raid, newData.name);
item.value = newData.value;
//정렬
DB.raid.sort(function(a, b){
return a.value < b.value ? -1 : a.value > b.value ? 1 : 0;
});
message.channel.send("수정 체크 완료!");
//console.log(JSON.stringify(messageArray));
console.log(item);
fs.writeFile('./DB.json', JSON.stringify(DB, null, 4), function(err) {
if(err) return console.log(err);
console.log('Save Done');
});
}
catch (e) {
messageArray[2] = 'Undefined';
message.channel.send("오류 : 명령어를 정확히 입력해주세요");
}
}
if (command === `${prefix}뻥`) {
try {
var newData = {
"name": messageArray[1],
};
var item = findBossName(DB.raid, newData.name);
var PlusTime = item.plusTime;
var PlusM = item.plusM;
var listTime = item.value;
var mins = ('0' + Number(listTime)).slice(-2);
// var NewTime_H = Number(listTime).slice(0, -2);
// var NewTime_M = Number(listTime).slice(2);
// console.log("시간:",NewTime_H,"분:",NewTime_M);
var NewTime = Number(listTime) + (Number(PlusTime) * 100);
if(messageArray[1] == "피닉스") {
if((Number(mins) + Number(PlusM)) >= 60) {
NewTime = (Number(NewTime) + 93);
}
else {
NewTime = (Number(NewTime) + 53);
}
}
if(Number(NewTime) >= 2400 && Number(NewTime) < 2410) {
NewTime = '000' + (Number(NewTime) - (24 * 100));
}
else if(Number(NewTime) >= 2410 && Number(NewTime) < 2500) {
NewTime = '00' + (Number(NewTime) - (24 * 100));
}
else if(Number(NewTime) >= 2500) {
NewTime = '0' + (Number(NewTime) - (24 * 100));
}
else if( Number(NewTime) < 1000 ) {
NewTime = '0' + Number(NewTime);
}
console.log(messageArray[1], listTime);
console.log(messageArray[1], NewTime);
var newData = {
"name": messageArray[1],
"value": String(NewTime)
};
var item = findBossName(DB.raid, newData.name);
item.value = newData.value;
//정렬
DB.raid.sort(function (a, b) {
return a.value < b.value ? -1 : a.value > b.value ? 1 : 0;
});
message.channel.send(`${messageArray[1]} 뻥 체크 완료!`);
//console.log(JSON.stringify(DB.raid, null, 4));
fs.writeFile('./DB.json', JSON.stringify(DB, null, 4), function(err) {
if(err) return console.log(err);
console.log('Save Done');
});
}
catch (e) {
messageArray[2] = 'Undefined';
message.channel.send("오류 : 명령어를 정확히 입력해주세요");
}
}
if(command === `${prefix}목록`) {
DB.raid.sort(function(a, b){
return a.value < b.value ? -1 : a.value > b.value ? 1 : 0;
});
const BossArray = [];
for(var i=0; i<25; i++) {
if(DB.raid[i].value !== "x")
BossArray[i] = DB.raid[i].name + (DB.raid[i].name.length == 1 ? "\t\t\t\t" : (DB.raid[i].name.length == 2) ? "\t\t\t" : "\t\t") + DB.raid[i].value
}
message.channel.send(BossArray);
console.log(JSON.stringify(BossArray,null,4));
}
if(command === `${prefix}목록1`) {
DB.raid.sort(function(a, b){
return a.value < b.value ? -1 : a.value > b.value ? 1 : 0;
});
const BossArray = [];
for(var i=0, j=0; i<25; i++) {
if((DB.raid[i].value !== "x") && (DB.raid[i].type == "1")) {
BossArray[j] = DB.raid[i].name + (DB.raid[i].name.length == 1 ? "\t\t\t\t" : (DB.raid[i].name.length == 2) ? "\t\t\t" : "\t\t") + DB.raid[i].value;
j++;
}
}
message.channel.send(BossArray);
console.log(JSON.stringify(BossArray,null,4));
}
if(command === `${prefix}목록2`) {
DB.raid.sort(function(a, b){
return a.value < b.value ? -1 : a.value > b.value ? 1 : 0;
});
const BossArray = [];
for(var i=0, j=0; i<25; i++) {
if((DB.raid[i].value !== "x") && (DB.raid[i].type == "2")) {
BossArray[j] = DB.raid[i].value + (DB.raid[i].name.length == 1 ? " " : (DB.raid[i].name.length == 2) ? " ":" ") + DB.raid[i].name;
j++;
}
}
message.channel.send(BossArray);
console.log(JSON.stringify(BossArray,null,4));
}
if(command === `${prefix}help`){
message.channel.send("-설명\n-명령어 : !컷, !수정, !목록\n-!컷 [보스이름] : !컷 [보스이름] 입력시 그 보스 현재시간과 젠시간을 합산하여 목록에 저장합니다\n- !수정 : !수정 [시간] [보스이름]\nex)!수정 1514 거드\n- '!목록' : 현재 저장된 목록을 보여줌\n'!초기화' : 모든 보스타임을 삭제한다 (완료시 메세지가 서버에만 출력됨 되도록이면 리딩이 아니면 사용금지)\n!뻥 : 현재 목록에 출력되는 시간 + 보스의 리젠주기를 추가합니다");
}
if(command === `${prefix}저장`) {
fs.writeFile('./DB.json', JSON.stringify(DB, null, 4), function(err) {
if(err) return console.log(err);
console.log('Save Done');
})
}
if(command === `${prefix}초기화`) {
for(var i=0; i<25; i++) {
DB.raid[i].value = "x"
}
console.log('초기화 완료');
}
if(command === `${prefix}초기화1`) {
for(var i=0; i<25; i++) {
if(DB.raid[i].type == "1") {
DB.raid[i].value = "x"
}
}
console.log('초기화1 완료');
}
if(command === `${prefix}초기화2`) {
for(var i=0; i<25; i++) {
if(DB.raid[i].type == "2") {
DB.raid[i].value = "x"
}
}
console.log('초기화2 완료');
}
if(command === `${prefix}테스트`) {
if (message.content.startsWith(prefix)) {
message.delete(10); //Supposed to delete message
}
}
// //알림
//var now = new Date();
//var DateNow = "";
//var Hours = (now.getHours() < 10 ? '0' + now.getHours() : now.getHours() );
//var mins = ('0' + now.getMinutes()).slice(-2);
//if ((Number(DB.raid[0].value) - Number(Hours + mins) == 1) && DB.raid[0].name == "개미" ) {
// message.channel.send(`@here ${DB.raid[0].name} 1분전`,{tts: true});
//}
});
client.login(botSettings.token);