-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
255 lines (238 loc) · 9.61 KB
/
index.js
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
require('dotenv').config();
const Discord = require('discord.js');
const bot = new Discord.Client();
const fs = require('fs');
const PREFIX = '!'; // Prefix used to invoke commands
const TOKEN = process.env.TOKEN;
const TOKEN2 = process.env.NitraToken;
const servUser = process.env.ID2;
const servID = process.env.ID1;
const { isNull } = require('util');
const mongoose = require('mongoose');
const allUsers = [];
const axios = require('axios');
const path = require('path');
var moment = require('moment-timezone');
var data = [];
var data2 = [];
var tRef = 0;
var feedStart = Boolean;
var readline = require('readline');
const { createSecureServer } = require('http2');
const { triggerAsyncId } = require('async_hooks');
const { toASCII } = require('punycode');
var phrase1 = ">) killed by ";
var phrase2 = " is connected (";
var phrase3 = ") has been disconnected";
var today = new Date();
bot.on('message', async message=> {
let args = message.content.substring(PREFIX.length).split(" ");
//const ausername = message.author.username;
//const auserId = message.member.id;
//const guildId = message.guild.id;
//const guildName = message.guild.name;
//const tuserId = Discord.User.id;
//const members = message.guild.members.cache;
switch(args[0]){
// Clear Messages (Owner and Admin Perms Only )
case 'clear':
if (!message.member.roles.cache.some(r => r.name === "Admin")) return message.channel.send('YOU DO NOT HAVE THE REQUIRED PERMISSIONS') .then (message => message.delete({ timeout: 5000, }));
if (!args[1]) return message.reply('Error, please define number of messages to clear') .then (msg => msg.delete(5000))
if (args[1] > 50) return message.channel.send('The max number of messages you can delete is 50') .then (msg => msg.delete(5000))
if (isNaN(args[1])) return message.channel.send('You must use a number!') .then (msg => msg.delete(5000))
message.channel.bulkDelete(args[1])
break;
//Start K1llFeed (Owner and Admin perms only)
case 'k1llfeed':
if (!args[1]) return message.channel.send("Missing Server Argument!").then (message => message.delete({ timeout: 5000, }));
if (args[1] === 'PAUSE') {
if (!message.member.roles.cache.some(r => r.name === "Admin")) return message.channel.send('YOU DO NOT HAVE THE REQUIRED PERMISSIONS') .then (message => message.delete({ timeout: 5000, }));
feedStart = false;
return;
}
if (args[1] === 'RESUME') {
if (!message.member.roles.cache.some(r => r.name === "Admin")) return message.channel.send('YOU DO NOT HAVE THE REQUIRED PERMISSIONS') .then (message => message.delete({ timeout: 5000, }));
feedStart = true;
return;
}
if (args[1] === 'START'){
if (!message.member.roles.cache.some(r => r.name === "Admin")) return message.channel.send('YOU DO NOT HAVE THE REQUIRED PERMISSIONS') .then (message => message.delete({ timeout: 5000, }));
feedStart = true;
setInterval(function() {
if (feedStart === true) {
axios.get('https://api.nitrado.net/ping')
.then((res) => {
if(res.status >= 200 && res.status < 300) {
async function downloadFile () {
// This function will request file that will contain download link for log
const url1 = 'https://api.nitrado.net/services/'
const url2 = '/gameservers/file_server/download?file=/games/'
const url3 = '/noftp/dayzxb/config/DayZServer_X1_x64.ADM'
const filePath = path.resolve('./logs', 'serverlog.ADM')
const writer = fs.createWriteStream(filePath)
const response = await axios.get(url1+`${servID}`+url2+`${servUser}`+url3,{ responseType: 'stream', headers: {'Authorization' : 'Bearer '+`${TOKEN2}`, 'Accept': 'application/octet-stream'}})
response.data.pipe(writer)
return new Promise((resolve, reject) => {
writer.on('finish', resolve)
writer.on('error', reject)
})
}
downloadFile();
}
})
.catch(function (error) {
console.log(error);
});
// Create a readable stream in order to parse log download link form file
var rl = readline.createInterface({
input: fs.createReadStream('./logs/serverlog.ADM')
});
//Handle Stream events ---> data, end, and error// This will request download link and write result to new file
rl.on('line', function (line) {
const newURL = line.substr(44,91);
axios.get(newURL)
.then((res) => {
const _log = res.data;
fs.writeFile('./logs/log.ADM', _log, 'utf-8', (err) =>{
if (err) throw err;
console.log('Log Saved!')
})
})
});
rl.on('close', function() {
return data;
})
rl.on('error', function(err) {
console.log(err.stack);
});
// Create new readable stream// This will read new log file in order to parse k1llfeed data.
var rl = readline.createInterface({
input: fs.createReadStream('./logs/log.ADM')
});
//Handle Stream events ---> data, end, and error// parses data for each line then passes data.
rl.on('line', function (line) {
if (line.includes(phrase1, 0)) {
data.push(line.split(/[|"'<>()]/));
}
});
rl.on('close', function() {
return data;
})
rl.on('error', function(err) {
console.log(err.stack);
});
if (data) {
for(let i = 0; i < data.length; i++){
data2.push(data[i]);
for ( val of data2){
if (val[15]){
var f0 = val[0].toString();
var f1 = val[10].toString();
var f2 = val[2].toString();
var f3 = val[15].toString();
let f0a = f0.split(":")
let dt = new Date();
function getDate() {
dt.setHours(f0a[0]);
dt.setMinutes(f0a[1]);
dt.setSeconds(f0a[2]);
dt.toLocaleString();
}
getDate();
data2.splice(0, data2.length);
let dt0 = Math.round(dt.getTime() / 1000);
console.log(dt0);
if(dt0 != tRef && dt0 > tRef) {
const attachment = new Discord.MessageAttachment('./images/crown.png', 'crown.png');
const embed = new Discord.MessageEmbed()
.attachFiles(attachment)
.setThumbnail('attachment://crown.png')
.setColor(0xDD0000)
.setTitle('K1llFeed Notification')
.setDescription(`${f0} **${f1}** Killed **${f2}** ${f3} `)
message.channel.send(embed).then (message => message.delete({ timeout: 180000, }));
tRef = dt0;
}
}else if (val[13] && !val[15]) {
var f0 = val[0].toString();
var f1 = val[8].toString();
var f2 = val[2].toString();
var f3 = val[13].toString();
let f0a = f0.split(":");
let dt = new Date();
function getDate() {
dt.setHours(f0a[0]);
dt.setMinutes(f0a[1]);
dt.setSeconds(f0a[2]);
dt.toLocaleString();
}
getDate();
data2.splice(0, data2.length);
let dt0 = Math.round(dt.getTime() / 1000);
if(dt0 != tRef && dt0 > tRef) {
const attachment = new Discord.MessageAttachment('./images/crown.png', 'crown.png');
const embed = new Discord.MessageEmbed()
.attachFiles(attachment)
.setThumbnail('attachment://crown.png')
.setColor(0xDD0000)
.setTitle('K1llFeed Notification')
.setDescription(`${f0} **${f1}** Killed **${f2}** ${f3} `)
message.channel.send(embed).then (message => message.delete({ timeout: 180000, }));
tRef = dt0;
}
}else if (val[7] && !val[9]) {
console.log("Stupid NPC's!");
}else {
var f0 = val[0].toString();
var f1 = val[2].toString();
var f2 = val[9].toString();
let f0a = f0.split(":");
let dt = new Date();
function getDate() {
dt.setHours(f0a[0]);
dt.setMinutes(f0a[1]);
dt.setSeconds(f0a[2]);
dt.toLocaleString();
}
getDate();
data2.splice(0, data2.length);
let dt0 = Math.round(dt.getTime() / 1000);
if(dt0 != tRef && dt0 > tRef) {
const attachment = new Discord.MessageAttachment('./images/crown.png', 'crown.png');
const embed = new Discord.MessageEmbed()
.attachFiles(attachment)
.setThumbnail('attachment://crown.png')
.setColor(0xDD0000)
.setTitle('K1llFeed Notification')
.setDescription(`${f0} **${f1}** was ${f2}`)
message.channel.send(embed).then (message => message.delete({ timeout: 180000, }));
tRef = dt0;
}
}
}
}
}else {
console.log('No Change!');
data2.splice(0, data.length);
data.splice(0, data.length);
console.log("Program Ended");
}
}else {
console.log("K1llfeed Paused!");
return;
}
data.splice(0, data.length);
data2.splice(0, data2.length);
}, 10000);
}
break;
}
})
//Login Discord Bot
bot.login(TOKEN);
bot.on('ready', () => {
console.info(`Logged in as ${bot.user.tag}!`);
})
bot.on('ready', () => {
console.log('K1llfeed is Active!');
})