-
Notifications
You must be signed in to change notification settings - Fork 3
/
discord-functions.js
51 lines (44 loc) · 1.53 KB
/
discord-functions.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
const Discord = require('discord.js')
// Sorts and identifies the names of all the events from a list and adds them to the embed.
function parseEvents(eventList, embed) {
eventList.sort(function (a, b) {
var aDate = new Date(a.StartDateTime).getTime(), bDate = new Date(b.StartDateTime).getTime();
return aDate - bDate;
});
eventList.forEach(event => {
const locations = event.Location.split(', ');
var locationArray = [];
locations.forEach(location => {
locationArray.push(location.split('.')[1]);
})
embed.addFields(
{
name: `${event.Name} (${event.Description})`,
value: `Time: ${new Date(event.StartDateTime).toLocaleTimeString().slice(0, -6)}-${new Date(event.EndDateTime).toLocaleTimeString().slice(0, -6)}\nLocation: ${locationArray.join(', ')}`
},
);
});
return embed
};
// Creates a red embed with the addErrorField method to quickly add error info.
// Also you can put in the first field right here.
function buildErrorEmbed(commandName, fieldTitle, fieldValue) {
let outputEmbed = new Discord.EmbedBuilder()
.setTitle(`Error*(s)* with command: \`/${commandName}\``)
.setColor('Red');
outputEmbed.addErrorField = function (errorTitle, errorValue) {
this.addFields({
name: errorTitle,
value: (errorValue) ? errorValue : '\u200b'
});
return this
};
if (fieldTitle) {
outputEmbed = outputEmbed.addErrorField(fieldTitle, fieldValue)
};
return outputEmbed
};
exported = {
parseEvents, buildErrorEmbed
};
module.exports = exported;