forked from DARKCRIME1/xmas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafk.js
100 lines (88 loc) · 5.71 KB
/
afk.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
const Amdi = require('../events');
const {MessageType} = require('@adiwajshing/baileys');
const Config = require('../config');
const Language = require('../language');
const Lang = Language.getString('afk');
var AFK = {
isAfk: false,
reason: false,
lastseen: 0
};
// https://stackoverflow.com/a/37096512
function secondsToHms(d) {
d = Number(d);
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
var s = Math.floor(d % 3600 % 60);
var hDisplay = h > 0 ? h + (h == 1 ? " " + Lang.HOUR + ", " : " " + Lang.HOUR + ", ") : "";
var mDisplay = m > 0 ? m + (m == 1 ? " " + Lang.MINUTE + ", " : " " + Lang.MINUTE + ", ") : "";
var sDisplay = s > 0 ? s + (s == 1 ? " " + Lang.SECOND : " " + Lang.SECOND) : "";
return hDisplay + mDisplay + sDisplay;
}
Amdi.addrex({on: 'text', fromMe: false, deleteCommand: false}, (async (message, match) => {
if (Config.AFKMSG == 'default') {
if (AFK.isAfk && ((!message.jid.includes('-')) || (message.jid.includes('-') &&
(( message.mention !== false && message.mention.length !== 0 ) || message.reply_message !== false)))) {
if (message.jid.includes('-') && (message.mention !== false && message.mention.length !== 0)) {
message.mention.map(async (jid) => {
if (message.client.user.jid.split('@')[0] === jid.split('@')[0]) {
await message.client.sendMessage(message.jid,Lang.AFK_TEXT + '\n' +
(AFK.reason !== false ? '\n*' + Lang.REASON + ':* ```' + AFK.reason + '```' : '') +
(AFK.lastseen !== 0 ? '\n*' + Lang.LAST_SEEN + ':* ```' + secondsToHms(Math.round((new Date()).getTime() / 1000) - AFK.lastseen) + Lang.AGO : ''), MessageType.text, {quoted: message.data});
}
})
} else if (message.jid.includes('-') && message.reply_message !== false) {
if (message.reply_message.jid.split('@')[0] === message.client.user.jid.split('@')[0]) {
await message.client.sendMessage(message.jid,Lang.AFK_TEXT + '\n' +
(AFK.reason !== false ? '\n*' + Lang.REASON + ':* ```' + AFK.reason + '```' : '') +
(AFK.lastseen !== 0 ? '\n*' + Lang.LAST_SEEN + ':* ```' + secondsToHms(Math.round((new Date()).getTime() / 1000) - AFK.lastseen) + Lang.AGO : ''), MessageType.text, {quoted: message.data});
}
} else {
await message.client.sendMessage(message.jid,Lang.AFK_TEXT + '\n' +
(AFK.reason !== false ? '\n*' + Lang.REASON + ':* ```' + AFK.reason + '```' : '') +
(AFK.lastseen !== 0 ? '\n*' + Lang.LAST_SEEN + ':* ```' + secondsToHms(Math.round((new Date()).getTime() / 1000) - AFK.lastseen) + Lang.AGO : ''), MessageType.text, {quoted: message.data});
}
}
}
else {
if (AFK.isAfk && ((!message.jid.includes('-')) || (message.jid.includes('-') &&
(( message.mention !== false && message.mention.length !== 0 ) || message.reply_message !== false)))) {
if (message.jid.includes('-') && (message.mention !== false && message.mention.length !== 0)) {
message.mention.map(async (jid) => {
if (message.client.user.jid.split('@')[0] === jid.split('@')[0]) {
await message.client.sendMessage(message.jid,Config.AFKMSG + '\n' +
(AFK.reason !== false ? '\n*' + Lang.REASON + ':* ```' + AFK.reason + '```' : '') +
(AFK.lastseen !== 0 ? '\n*' + Lang.LAST_SEEN + ':* ```' + secondsToHms(Math.round((new Date()).getTime() / 1000) - AFK.lastseen) + Lang.AGO : ''), MessageType.text, {quoted: message.data});
}
})
} else if (message.jid.includes('-') && message.reply_message !== false) {
if (message.reply_message.jid.split('@')[0] === message.client.user.jid.split('@')[0]) {
await message.client.sendMessage(message.jid,Config.AFKMSG + '\n' +
(AFK.reason !== false ? '\n*' + Lang.REASON + ':* ```' + AFK.reason + '```' : '') +
(AFK.lastseen !== 0 ? '\n*' + Lang.LAST_SEEN + ':* ```' + secondsToHms(Math.round((new Date()).getTime() / 1000) - AFK.lastseen) + Lang.AGO : ''), MessageType.text, {quoted: message.data});
}
} else {
await message.client.sendMessage(message.jid,Config.AFKMSG + '\n' +
(AFK.reason !== false ? '\n*' + Lang.REASON + ':* ```' + AFK.reason + '```' : '') +
(AFK.lastseen !== 0 ? '\n*' + Lang.LAST_SEEN + ':* ```' + secondsToHms(Math.round((new Date()).getTime() / 1000) - AFK.lastseen) + Lang.AGO : ''), MessageType.text, {quoted: message.data});
}
}
}
}));
Amdi.addrex({on: 'online', fromMe: true, deleteCommand: false, deleteCommand: false}, (async (message, match) => {
if (AFK.isAfk && !message.id.startsWith('3EB0')) {
AFK.lastseen = 0;
AFK.reason = false;
AFK.isAfk = false;
await message.client.sendMessage(message.jid,Lang.IM_NOT_AFK,MessageType.text);
}
}));
Amdi.addrex({pattern: 'afk ?(.*)', fromMe: true, deleteCommand: false, deleteCommand: false, desc: Lang.AFK_DESC, dontAddCommandList: true}, (async (message, match) => {
if (!AFK.isAfk) {
AFK.lastseen = Math.round((new Date()).getTime() / 1000);
if (match[1] !== '') { AFK.reason = match[1]; }
AFK.isAfk = true;
await message.client.sendMessage(message.jid,Lang.IM_AFK + (AFK.reason !== false ? ('\n*' + Lang.REASON +':* ```' + AFK.reason + '```') : ''),MessageType.text);
}
}));
module.exports = { secondsToHms };