`Promise.all(...)` runs these simultaneously, yet role depends on the
guild to be created first. This can lead to a race condition. I've
awaited role creation too because the call to `Member.addToGuild(...)`
relies on the role to be created.
The previous PATCH implementation was creating a new template rather
than editing the existing template. This resulted in all requests
failing because it was missing more than one required field.
Resolves: #1281
The `message.message_reference` stores:
1. `message_id`
2. `channel_id`
3. `guild_id`
We use the `message_id` and `channel_id` to `.findOne(...)` Message, and
find the author. If the author is the same as OP, we skip (so replying
to yourself doesn't add you to the mentions array) otherwise, it adds
the author_id to the mentions array.
Resolves: #1247
In a previous PR, I was checking if the `.url` property existed, the
correct fix is to remove any embed that isn't a rich embed
type (non-link).
See also: #1296
Adding `this.events[id]?.()` cleans up the listener. I removed
`opts.cancel()` because with it, the event had issues firing after the
first time.
Resolves: #1242
In a previous commit I was attempting to be clever by only
replacing/removing embeds if necessary. This not only made the logic
more confusing but introduced a bug that would allow for orphaned
embeds when updating the search params of a URL.
This commit will remove all embeds that have a `.url` property and start
fresh. This simplifies the code and eliminates the aforementioned bug.
The `postHandleMessage` function is parsing links and adding them to the
EmbedCache table if necessary. In the previous implementation, message
updates would push to the embeds unconditionally.
This commit parses links from the message and:
1. Normalizes the URLs
- Useful for deduplicating similar URLs
2. Remove embeds with matching normalized URLs
- Leaves all embeds except for ones with a `.url` property matching
the updated message
- This allows embeds to be re-ordered if the URL is moved
3. If no normalized URLs are found, remove all embeds
4. Take the deduplicated + normalized URLs and add an embed to the message and
insert into the EmbedCache table (if necessary)
This enables:
1. Embeds to be re-ordered by re-ordering links
2. Embeds to be removed by removing links
and fixes:
1. Duplicate embeds being attached to a message when edited