forked from saacki/isacbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
65 lines (54 loc) · 1.87 KB
/
helper.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
/******************************
Variables & Libs
*******************************/
const moment = require("moment");
const config = require('./config').production;
const pool = config.getPool();
var Hashids = require('hashids/cjs');
/******************************
Helper Functions
*******************************/
module.exports = {
// Print to console with timestamp prefix
isAdmin: function(member) {
if ( member.hasPermission('ADMINISTRATOR') ||
member.hasPermission('MANAGE_CHANNELS') ||
// member.roles.cache.find(roles => roles.name === "Admin") ||
Object.keys(config.adminIDs).includes(member.id) )
return true;
else
return false;
},
// Print to console with timestamp prefix
printStatus: function(text) {
console.log( "[" + moment().format() + "] " + text );
},
logCommands: async function(message) {
let insertId = 0;
await pool.query("INSERT INTO commands (command, user_id, username, server_id, date_added) VALUES (?, ?, ?, ?, ?)", [message.content, message.author.id, message.author.username, message.guild.id, moment().format('YYYY-M-D HH:mm:ss')])
.then(function(res){
if( res.insertId > 0 ) {
let hashid = new Hashids('ISAC_BOT', 6, 'abcdefghijklmnopqrstuvwxyz'); // pad to length 10
pool.query("UPDATE commands SET hash = ? WHERE id = ?", [ hashid.encode(res.insertId), res.insertId ]);
insertId = res.insertId;
}
})
.catch(function(error){
console.log(error);
console.log(message);
});
return insertId;
},
saveLogCommandResult: function(id, data) {
if(id > 0) {
data = JSON.stringify(data);
pool.query("UPDATE commands SET result = ? WHERE id = ?", [data, id]);
}
},
owner: function(member) {
if ( Object.keys(config.adminIDs).includes(member.id) )
return true;
else
return false;
},
}