A Discord webhook tool that fetches a calendar and posts a pretty summary every day.
- Discord Webhook with ID and URL
- Direct URL to the .ics file from a calendar
- MySQL Database with Connection URL
Create a .env file and fill in these details like the .env.sample
file.
Create a message
Table
CREATE TABLE message (
id INT NOT NULL AUTO_INCREMENT,
webhookId INT NOT NULL,
hashValue VARCHAR(256),
PRIMARY KEY(id),
FOREIGN KEY(webhookId) REFERENCES webhook(id) ON DELETE CASCADE
);
Create a webhook
Table
CREATE TABLE webhook (
id INT NOT NULL AUTO_INCREMENT,
discordId BIGINT NOT NULL,
discordToken VARCHAR(512),
calendarPrivateUrl VARCHAR(2048),
calendarPublicUrl VARCHAR(2048),
nickname VARCHAR(256),
primaryColor INT,
PRIMARY KEY(id)
);
Register a webhook
INSERT INTO webhook(discordId, discordToken, calendarPrivateUrl, calendarPublicUrl, nickname, primaryColor)
VALUES(123, "abc",
"https://calendar.url/data.ics",
"https://publiccalendar.url",
"Bot Name",
0xf2c94c);
Create an event in the calendar with one of the following emojis as the prefix. The bot will categorize the events accordingly with the prefixes stripped of them.
HomeworkEmoji = "📘"
ExamEmoji = "📝"
OtherEmoji = "👻"
I would recommend setting a calendar entry to "all day".
The webhook creates a hyperlink if the description contains a URL that redirects to a Discord message.
The bot uses the message
table to store a SHA256 hash value of each message. Every day at 17:00, the bot creates a message, fetches the last hash value, and compares it to the current hash value. If the hash is different, the bot will send the message and store the hash in the database.