-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathutils.js
105 lines (104 loc) · 3.84 KB
/
utils.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
// const bot = require('./bot');
const Discord = require('discord.js');
const guilds = require("./data/guilds.json");
const sqlite3 = require('sqlite3').verbose();
exports.logChannel = (bot, guildID, colour, event, user, moderator, reason, timeString, other, thumbnail) => {
if (!guildID) return console.log(`guildID is not defined!`);
// identify the logger channel
let logChannel = (bot.guilds.get(guildID)).channels.get(guilds[guildID].logChannelID)
// check if other supplied
if (!other || other == '') { var other = '' } // check for a user parameter
if (user) {
var userString = `**Target:** ${user} (${user.tag})`
var user_id = `ID: ${user.id}`
var icon = user.displayAvatarURL
}
if (!user || user == '') {
var userString = ''
var user_id = ''
}
// check if there is a moderator parameter
if (moderator) {
var moderatorString = `\n**Moderator:** ${moderator} (${moderator.tag})`
if (!user) { var icon = moderator.user.displayAvatarURL }
}
if (!moderator || moderator == '') {
var moderatorString = ''
if (!user) { var icon = bot.displayAvatarURL }
}
// check for reason
if (reason) { var reasonString = `\n**Reason:** ${reason}` }
if (!reason || reason == '') { var reasonString = '' }
// check for timeString
if (!timeString || timeString == '') { var timeString = '' }
// check if other supplied
if (!other || other == '') { var other = '' }
// do the actual embed
try {
logChannel.send({
embed: new Discord.RichEmbed()
.setDescription(`**Target:** ${user} (${user.tag})${moderatorString}${reasonString}${timeString}${other}`)
.setFooter(`ID: ${user.id}`)
.setAuthor(event, user.displayAvatarURL)
.setTimestamp()
.setThumbnail(thumbnail)
.setColor(colour)
})
}
catch (error) {
if (!guildID) return console.log(`LoggerERR: No guildID given!`)
if (!logChannel) return console.log(`LoggerERR: No logchannel defined for this guild!`)
else console.log(error)
}
}
exports.randomSelection = (choices) => {
return choices[Math.floor(Math.random() * choices.length)];
}
exports.warning = async (bot, guildID, userID, moderatorID, string, severity, callback) => {
// create warnings table if it doesn't exist
function createtable(cb) {
db.run(`CREATE TABLE IF NOT EXISTS warnings
(warn_id integer PRIMARY KEY,
guild_id text,
user_id text,
moderator_id text,
warn_str text,
severity integer,
date integer)`,
(err) => {
if (err) {
cb(err.message)
}
else {
console.log(`Warnings table opened/created successfully.`);
cb(null)
}
})
}
// perform the insertion
function insertwarning(guildID, userID, moderatorID, string, severity, cb) {
db.run(
"INSERT INTO warnings (guild_id, user_id, moderator_id, warn_str, severity, date) VALUES(?,?,?,?,?,?)",
[guildID, userID, moderatorID, string, severity, Date.now()],
function (err) {
if (err) {
cb(err.message, null)
}
else {
console.log(`Warning insertion successful. Warning ID: ${this.lastID}`);
cb(null, this.lastID)
}
})
}
createtable((err) => {
if (err) return console.log(err);
insertwarning(guildID, userID, moderatorID, string, severity, (err, result) => {
if (err) {
console.log(err);
callback(err, null)
return
}
else callback(err, result)
})
})
}