2017-09-25 00:46:58 +03:00
|
|
|
const Core = require("../../discord-bot-core");
|
2017-09-20 02:04:04 +03:00
|
|
|
const FeedData = require("./feed-data.js");
|
2017-09-01 17:51:05 +03:00
|
|
|
|
2017-10-02 01:19:10 +03:00
|
|
|
module.exports = class GuildData extends Core.BaseGuildData {
|
2018-01-27 01:47:23 +02:00
|
|
|
constructor() {
|
|
|
|
super();
|
2017-12-07 03:35:00 +02:00
|
|
|
|
2018-01-27 01:47:23 +02:00
|
|
|
this.feeds = [];
|
2017-12-11 03:05:18 +02:00
|
|
|
|
2018-01-27 01:47:23 +02:00
|
|
|
this.schema({
|
|
|
|
feeds: [FeedData]
|
|
|
|
});
|
|
|
|
}
|
2017-09-20 02:04:04 +03:00
|
|
|
|
2018-01-27 01:47:23 +02:00
|
|
|
cachePastPostedLinks(guild) {
|
|
|
|
return Promise.all(
|
|
|
|
this.feeds
|
|
|
|
.filter(feed => feedIsActive(feed, guild))
|
|
|
|
.map(feed => feed.updatePastPostedLinks(guild).catch(err => null))
|
|
|
|
);
|
|
|
|
}
|
2017-09-20 02:04:04 +03:00
|
|
|
|
2018-01-27 01:47:23 +02:00
|
|
|
checkFeeds(guild) {
|
|
|
|
return Promise.all(
|
|
|
|
this.feeds
|
|
|
|
.filter(feed => feedIsActive(feed, guild))
|
|
|
|
.map(feed => feed.fetchLatest(guild).catch(err => null))
|
|
|
|
);
|
|
|
|
}
|
2017-12-11 03:05:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function feedIsActive(feed, guild) {
|
2018-01-27 01:47:23 +02:00
|
|
|
return guild.channels.get(feed.channelID);
|
2017-12-11 03:05:18 +02:00
|
|
|
}
|