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
|
//removes (number)remArgsBefore and (number)remArgsAfter from argument array/list
var joinArgs = function (argsList, remArgsBefore, remArgsAfter)
{
var res = "";
for (var i = 0; i < argsList.length; i++)
{
if (i < remArgsBefore)
continue;
if (argsList.length - i <= remArgsAfter)
continue;
res += argsList[i] + " ";
}
return res;
}
// gets the current (weird formated) timestamp
var getTimeStamp = function ()
{
var date_ob = new Date();
var day = addLeadingZero(date_ob.getDate());
var month = addLeadingZero(date_ob.getMonth());
var year = date_ob.getFullYear();
var hours = addLeadingZero(date_ob.getHours());
var minutes = addLeadingZero(date_ob.getMinutes());
var seconds = addLeadingZero(date_ob.getSeconds());
return (year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds);
}
// formats number (n) to 2-digit
var addLeadingZero = function (n)
{
if (n <= 9)
return "0" + n;
return n;
}
var escapeHTML = function (unsafe)
{
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
var chatEmote = function (msg)
{
return msg.replace(":D", "😀")
.replace("O:)", "😇")
.replace("0:)", "😇")
.replace(":)", "🙂")
.replace(":(", "🙁")
.replace(":o", "😮")
.replace(":O", "😲")
.replace(":'(", "😢")
.replace(":')", "🥲")
.replace(":P", "😛");
}
var hasPermission = function (db, username, req, cb)
{
db.account.find({ username: username }, function (err, res)
{
if (res[0].gmlvl >= req)
cb(true);
else
cb(false);
});
}
module.exports = { joinArgs, getTimeStamp, addLeadingZero, escapeHTML, chatEmote, hasPermission };
|