-
Notifications
You must be signed in to change notification settings - Fork 3
/
guildScheduledEvent.js
106 lines (87 loc) · 2.78 KB
/
guildScheduledEvent.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
const { MessageEmbed } = require('discord.js');
const client = require('../index');
const transformAndWriteToFile = require('json-to-frontmatter-markdown').default;
const wait = require('node:timers/promises').setTimeout;
client.on('guildScheduledEventCreate', async (guildScheduledEvent) => {
const eventsChannel = client.channels.cache.get('973686987787751534');
const markdownChannel = client.channels.cache.get('1025318437028896778');
let location = '';
let endTime = 'No Scheduled End Time';
const embed = new MessageEmbed()
.setTitle(guildScheduledEvent.name)
.setDescription(guildScheduledEvent.description)
.setColor('GREEN')
.setTimestamp()
.setImage(
`https://cdn.discordapp.com/guild-events/${guildScheduledEvent.id}/${guildScheduledEvent.image}.png?size=2048`
);
if (guildScheduledEvent.entityType !== 'EXTERNAL') {
embed.addField(
'Location',
`${guildScheduledEvent.channel.name} - [Link](https://discordapp.com/channels/427865794467069962/${guildScheduledEvent.channelId})`
);
location = `${guildScheduledEvent.channel.name} - [Link](https://discordapp.com/channels/427865794467069962/${guildScheduledEvent.channelId})`;
} else {
embed.addField(
'Location',
`External - ${guildScheduledEvent.entityMetadata.location}`
);
location = `External - ${guildScheduledEvent.entityMetadata.location}`;
}
embed.addField(
'Start Date and Time',
`${guildScheduledEvent.scheduledStartAt.toLocaleString('en-UK', {
timeZone: 'Europe/London',
})}`,
true
);
if (guildScheduledEvent.scheduledEndAt !== null) {
embed.addField(
'End Date and Time',
`${guildScheduledEvent.scheduledEndAt.toLocaleString('en-UK', {
timeZone: 'Europe/London',
})}`,
true
);
endTime = guildScheduledEvent.scheduledEndAt.toLocaleString('en-UK', {
timeZone: 'Europe/London',
});
}
embed.addField('InviteURL', `${guildScheduledEvent.url}`);
eventsChannel.send({ embeds: [embed] });
transformAndWriteToFile({
frontmatterMarkdown: {
frontmatter: [
{ layout: 'base.html' },
{ tags: 'event' },
{ title: guildScheduledEvent.name },
{
date: guildScheduledEvent.scheduledStartAt
.toISOString()
.substring(0, 10),
},
{ teaser: guildScheduledEvent.description },
],
body: `
# ${guildScheduledEvent.name}
${guildScheduledEvent.description}
## Date and Times
- Start Date and Time: ${guildScheduledEvent.scheduledStartAt.toLocaleString(
'en-UK',
{ timeZone: 'Europe/London' }
)}
- End Date and Time: ${endTime}
## Location:
${location}
## Invite
<a href="${guildScheduledEvent.url}">Invite Link</a>
`,
},
path: `src/markdownOutput`,
fileName: `${guildScheduledEvent.name}.md`,
});
await wait(5000);
markdownChannel.send({
files: [`src/markdownOutput/${guildScheduledEvent.name}.md`],
});
});