forked from SlavyanDesu/BocchiBot
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathafk.js
109 lines (102 loc) · 2.13 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
100
101
102
103
104
105
106
107
108
109
const fs = require('fs-extra')
/**
* Add AFK user.
* @param {string} userId
* @param {string} time
* @param {string} reason
* @param {object} _dir
*/
const addAfkUser = (userId, time, reason, _dir) => {
const obj = { id: userId, time: time, reason: reason }
_dir.push(obj)
fs.writeFileSync('./database/user/afk.json', JSON.stringify(_dir))
}
/**
* Check if user is on AFK state.
* @param {string} userId
* @param {object} _dir
* @returns {boolean}
*/
const checkAfkUser = (userId, _dir) => {
let status = false
Object.keys(_dir).forEach((i) => {
if (_dir[i].id === userId) {
status = true
}
})
return status
}
/**
* Get user AFK reason.
* @param {string} userId
* @param {object} _dir
* @returns {string}
*/
const getAfkReason = (userId, _dir) => {
let position = null
Object.keys(_dir).forEach((i) => {
if (_dir[i].id === userId) {
position = i
}
})
if (position !== null) {
return _dir[position].reason
}
}
/**
* Get user AFK time.
* @param {string} userId
* @param {object} _dir
* @returns {string}
*/
const getAfkTime = (userId, _dir) => {
let position = null
Object.keys(_dir).forEach((i) => {
if (_dir[i].id === userId) {
position = i
}
})
if (position !== null) {
return _dir[position].time
}
}
/**
* Get user AFK ID.
* @param {string} userId
* @param {object} _dir
* @returns {string}
*/
const getAfkId = (userId, _dir) => {
let position = null
Object.keys(_dir).forEach((i) => {
if (_dir[i].id === userId) {
position = i
}
})
if (position !== null) {
return _dir[position].id
}
}
/**
* Get user AFK index position.
* @param {string} userId
* @param {object} _dir
* @returns {number}
*/
const getAfkPosition = (userId, _dir) => {
let position = null
Object.keys(_dir).forEach((i) => {
if (_dir[i].id === userId) {
position = i
}
})
return position
}
module.exports = {
addAfkUser,
checkAfkUser,
getAfkReason,
getAfkTime,
getAfkId,
getAfkPosition
}