-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogging.js
57 lines (48 loc) · 1.67 KB
/
logging.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
const fs = require('fs');
var config = require("./config");
function _blackListLogging(blackListedUser, blackListedBy)
{
let log = "[" + getTime() + "] : User " + blackListedUser + " was blacklisted by " + blackListedBy + "\r\n";
addToLog(log);
}
function _unblackListLogging(blackListedUser, blackListedBy)
{
let log = "[" + getTime() + "] : User " + blackListedUser + " was unblacklisted by " + blackListedBy + "\r\n";
addToLog(log);
}
function _purgeLogging(num, message)
{
let log = "[" + getTime() + "] : User " + message.author.username + " purged " + num + " messages from " + message.channel.name + ".\r\n";
addToLog(log);
}
function _blackListedUserAccessAttempt(message, command)
{
let log = "[" + getTime() + "] : Blacklisted user " + message.author.username + " tried to call " + command + " function from " + message.channel.name + ".\r\n";
addToLog(log);
}
function _generalCommandLogging(message, command)
{
let log = "[" + getTime() + "] : User " + message.author.username + " called `" + command.toLowerCase() + "` function from " + message.channel.name + ".\r\n";
addToLog(log);
}
//Adds to the log file, file destination editable in config
function addToLog(log)
{
fs.appendFile(config.logFileName, log, function(err) {
if(err) {
return console.log(err);
}
});
}
//Gets syetem time and formats like '[2018-09-16 01:26:14]'
function getTime()
{
return new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
}
module.exports = {
blackListLogging: _blackListLogging,
unblackListLogging: _unblackListLogging,
purgeLogging: _purgeLogging,
blackListedUserAccessAttempt: _blackListedUserAccessAttempt,
generalCommandLogging: _generalCommandLogging
};