1 |
const { notAFK } = require("../commands/afk"); |
2 |
const MessageEmbed = require("./MessageEmbed"); |
3 |
|
4 |
module.exports = class AFKEngine { |
5 |
mention(msg, user, cb, msg1) { |
6 |
app.db.get('SELECT * FROM afk WHERE user_id = ?', [user.id], (err, data) => { |
7 |
if (data) { |
8 |
if (msg1 === undefined) { |
9 |
msg.channel.send({ |
10 |
embeds: [ |
11 |
new MessageEmbed() |
12 |
.setDescription(`**${user.user.tag}** is AFK right now${data.reason.trim() == '' ? '.' : (' for reason: **' + data.reason.replace(/\*/g, '\\*') + '**')}`) |
13 |
] |
14 |
}); |
15 |
} |
16 |
|
17 |
app.db.get('UPDATE afk SET mentions = ? WHERE id = ?', [parseInt(data.mentions) + 1, data.id], (err) => {}); |
18 |
|
19 |
cb(data); |
20 |
} |
21 |
}); |
22 |
|
23 |
} |
24 |
|
25 |
start(msg) { |
26 |
const mention = msg.mentions.members.first(); |
27 |
|
28 |
if (mention) { |
29 |
this.mention(msg, msg.member, data => { |
30 |
if (msg.author.id === data.user_id) { |
31 |
notAFK(msg, data); |
32 |
} |
33 |
}, true); |
34 |
|
35 |
msg.mentions.members.forEach((member) => { |
36 |
this.mention(msg, member, data => { |
37 |
if (msg.author.id === data.user_id) { |
38 |
notAFK(msg, data); |
39 |
} |
40 |
}); |
41 |
}); |
42 |
} |
43 |
else { |
44 |
app.db.get('SELECT * FROM afk WHERE user_id = ?', [msg.author.id], (err, data) => { |
45 |
if (data) { |
46 |
notAFK(msg, data); |
47 |
} |
48 |
}); |
49 |
} |
50 |
} |
51 |
}; |