-
Notifications
You must be signed in to change notification settings - Fork 2
/
util-privacy.js
75 lines (71 loc) · 2.33 KB
/
util-privacy.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
const Database = require('@replit/database')
const db = new Database()
/**
* To route to the resective @function open|isOpen with the message
* based on any @mentions present in the message
* @param {Message} msg Discord Message instantiated the event 'message'
*/
const privacy = async (msg) => {
if (msg.mentions.users.first() === undefined) open(msg)
else isOpen(msg)
}
/**
* To do one out of three things based on the content of the message
* if it is required to change the setting on or off or to just show the current settings
* @param {Message} msg Discord message which created the event 'message'
*/
const open = async (msg) => {
setting = msg.content.split('++privacy')[1].trim()
db.get(msg.author.id + '').then((logs) => {
if (logs) {
msg.react(setting == 'off' ? '🔓' : '🔒')
if (setting == 'off') {
logs.open = true
db.set(msg.author.id + '', logs).then(() =>
msg.reply(
`Your privacy is turned off. Anyone can tag and see your logs`
)
)
} else if (setting == 'on') {
logs.open = false
db.set(msg.author.id + '', logs).then(() =>
msg.reply(
`Your privacy is turned on. No one can tag and check your logs except you`
)
)
} else
msg.reply(
`Your privacy settings are currently ${
logs.open
? `off. Anyone can tag and see your logs`
: `on. No one can tag and check your logs except you`
}`
)
} else
msg.reply(
'Sorry you must start your first log in order to change your privacy settings.'
)
})
}
/**
* To check whether the user tagged in the message content has privacy open or hidden
* @param {Message} msg Discord Message which created the event 'message'
*/
const isOpen = async (msg) => {
user = msg.mentions.users.first()
db.get(user.id + '').then((logs) => {
if (logs) {
if (logs.open)
msg.reply(
`The account of **${user.username}** is open. You can check out their list of logs by \`++list {@mention}\``
)
else
msg.reply(
`Sorry Sir, **${user.username}**'s account is hidden. You cannot check their list.`
)
} else msg.reply(`Sorry mate **${user.username}** is not in our database`)
})
}
module.exports = {
privacy,
}