Add guild iteration for feed checking
Update default feed check interval to be 10 seconds between guilds
This commit is contained in:
parent
78eec753f1
commit
8dfbab0122
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"maxCacheSize": 100,
|
||||
"feedCheckIntervalSec": 30,
|
||||
"feedCheckInterval": 10000,
|
||||
"charLimit": 500,
|
||||
"viewFeedsPaginationLimit": 10
|
||||
}
|
26
app/index.js
26
app/index.js
|
@ -4,18 +4,26 @@ const GuildData = require("./models/guild-data.js");
|
|||
// @ts-ignore
|
||||
const Config = require("./config.json");
|
||||
|
||||
const guildsIterator = (function* () {
|
||||
while (true) {
|
||||
if (client.guilds.size === 0)
|
||||
yield null;
|
||||
else
|
||||
for (let i = 0; i < client.guilds.size; i++)
|
||||
yield [...client.guilds.values()][i];
|
||||
}
|
||||
})();
|
||||
|
||||
const token = require("../" + process.argv[2]).token,
|
||||
dataFile = process.argv[3];
|
||||
|
||||
const client = new Core.Client(token, dataFile, __dirname + "/commands", GuildData);
|
||||
|
||||
client.on("beforeLogin", () => {
|
||||
setInterval(() => checkFeedsInGuilds(), Config.feedCheckIntervalSec * 1000);
|
||||
});
|
||||
client.on("beforeLogin", () =>
|
||||
setInterval(doGuildIteration, Config.feedCheckInterval));
|
||||
|
||||
client.on("ready", () => {
|
||||
parseLinksInGuilds()
|
||||
.then(() => checkFeedsInGuilds());
|
||||
parseLinksInGuilds().then(doGuildIteration);
|
||||
});
|
||||
|
||||
client.on("message", message => {
|
||||
|
@ -35,10 +43,10 @@ client.on("message", message => {
|
|||
client.bootstrap();
|
||||
|
||||
//INTERNAL FUNCTIONS//
|
||||
function checkFeedsInGuilds() {
|
||||
client.guildDataModel.find().then(guildDatas =>
|
||||
guildDatas.forEach(guildData =>
|
||||
guildData.checkFeeds(client.guilds.get(guildData.guildID))));
|
||||
function doGuildIteration() {
|
||||
const guild = guildsIterator.next().value;
|
||||
guild && client.guildDataModel.findOne({ guildID: guild.id })
|
||||
.then(guildData => guildData && guildData.checkFeeds(guild));
|
||||
}
|
||||
|
||||
function parseLinksInGuilds() {
|
||||
|
|
Loading…
Reference in New Issue