Browse Source

Fix links not being properly cached with camo integration

master
benji7425 3 years ago
parent
commit
78eec753f1
  1. 11
      app/index.js
  2. 4
      app/models/feed-data.js

11
app/index.js

@ -24,13 +24,12 @@ client.on("message", message => {
client.guildDataModel.findOne({ guildID: message.guild.id })
.then(guildData => {
if (guildData)
guildData.feeds.forEach(feedData => {
if (message.channel.id === feedData.channelID)
feedData.cachedLinks.push(...GetUrls(message.content));
});
if (guildData) {
guildData.feeds.forEach(feedData =>
message.channel.id === feedData.channelID && feedData.cache(...GetUrls(message.content)));
guildData.save();
}
});
});
client.bootstrap();

4
app/models/feed-data.js

@ -41,7 +41,7 @@ module.exports = class FeedData extends Camo.EmbeddedDocument {
.then(messages => {
/* we want to push the links in oldest first, but discord.js returns messages newest first, so we need to reverse them
* discord.js returns a map, and maps don't have .reverse methods, hence needing to spread the elements into an array first */
[...messages.values()].reverse().forEach(m => this.cachedLinks.push(...GetUrls(m.content)));
[...messages.values()].reverse().forEach(m => this.cache(...GetUrls(m.content)));
resolve();
})
.catch(reject);
@ -72,8 +72,6 @@ module.exports = class FeedData extends Camo.EmbeddedDocument {
const latest = normaliseUrl(articles[0].link);
if (!this.cachedLinks.includes(latest)) {
this.cachedLinks.push(latest);
const channel = guild.channels.get(this.channelID),
role = guild.roles.get(this.roleID);

Loading…
Cancel
Save