-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobalfunctions.js
More file actions
132 lines (128 loc) · 4.77 KB
/
globalfunctions.js
File metadata and controls
132 lines (128 loc) · 4.77 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const {categorySchema, suggestionSchema, templateEmbed} = require("./constants.js")
const {dbClient} = require("./mongodb.js")
const makeMsgLink = (msgID, categoryID, serverID) => {
return "[Jump](https://discord.com/channels/" + serverID + "/" + categoryID + "/" + msgID + ")"
}
module.exports = {
translateCategoryName(name) {
if (name.includes("_")) {
return name.split("_").join(" ")
} else if (name.includes("-")) {
return name.split("-").join(" ")
} else {
return name
}
},
createNewEntry(section, desc, msgID, user) {
let entry = Object.create(suggestionSchema)
entry.section = section
entry.description = desc
entry.messageID = msgID
entry.user = user
return entry
},
makeNewEntry(msg, title, id, category, serverID) {
let messageObject = {}
messageObject[serverID] = id
let entry = Object.create(categorySchema)
entry.embedMessage = msg
entry.categoryTitle = title
entry.messageID = messageObject
entry.category = category
return entry
},
checkAliases(aliasList, input) {
let returnVal = false
aliasList.map(val => val == input).filter(val => val == true)[0] ? (returnVal = true) : (returnVal = false)
return returnVal
},
linkEmbedConstructor(msg) {
var objURL = ""
msg.map(val => val.includes("https://") && val.includes("attachments") ? objURL = val : undefined)
return {url: objURL}
},
timeToMS(time){
switch(time.split("")[time.length-1]){
case "h":
return parseInt(time.split("h")[0]) * 360 * 1000
case "m":
return parseInt(time.split("m")[0]) * 60 * 1000
default:
return parseInt(time.split("s")[0]) * 1000
}
},
logAction(user, id, action, msg, category){
let logEntry = {
color: 0x33998c,
title: action + " Action",
fields: [
{
name: user + " (" + id + ") has made a change in `" + category + "`",
value: '**Old Message:**\n ```' + msg + "```",
},
],
footer: {
text: 'Skyblock Guides',
icon_url: "https://i.imgur.com/184jyne.png",
},
timestamp: new Date()
}
return logEntry
},
embedCharCount(embed) {
let msg;
embed.embedMessage == undefined ? msg = embed : msg = embed.embedMessage
var charCount = msg.title.length
msg.fields.map(val => {
charCount += (val.name.length + val.value.length)
})
return charCount
},
channelID(channel){
return channel.split("").slice(2,channel.length-1).join("")
},
commandHelpEmbed(name, alias, time, example, result) {
return {
color: 0x4ea8de,
title: `${name}`,
fields: [
{
name: 'Aliases',
value: `${alias.join(", ")}`,
},
{
name: 'Example',
value: `${example}\n\u200b${result}`
},
],
footer: {
text: 'Skyblock Guides',
icon_url: "https://i.imgur.com/184jyne.png",
},
timestamp: time
}
},
escapeRegex(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
},
makeMsgLink: makeMsgLink,
async tableOfContents(category, guildID) {
let listEmbed = Object.create(templateEmbed)
listEmbed.fields = [{name: "_ _", value: "_ _" }]
let categoryCollection = dbClient.db("skyblockGuide").collection("Guides")
let categoryList = await categoryCollection.find({"category": category}).toArray()
let serverInfo = dbClient.db("skyblockGuide").collection("Settings")
let findServer = await serverInfo.find({"serverID": guildID}).toArray()
let categoryID, msgLink = ""
category === "Skyblock" ? categoryID = findServer[0].sbGuideChannelID : categoryID = findServer[0].dGuideChannelID
findServer[0].sbGuideChannelID == "None" || findServer[0].dGuideChannelID == "None" ? msgLink = "_ _" : msgLink = makeMsgLink(val.messageID[guildID], categoryID, guildID)
categoryList.map(val => listEmbed.fields.push({name: val.categoryTitle, value: msgLink}))
//When there is no guide channel, list the category titles without a message link
listEmbed.timestamp = new Date()
listEmbed.title = "Table of Contents -- " + category
return listEmbed
},
msToDay(time){
return (((time/1000)/60)/60)/24
}
}