Browse Source

Add guild iteration for feed checking

Update default feed check interval to be 10 seconds between guilds
shorten
benji7425 3 years ago
parent
commit
6013b0dcbf
  1. 2
      app/config.json
  2. 26
      app/index.js

2
app/config.json

@ -1,6 +1,6 @@
{
"maxCacheSize": 100,
"feedCheckIntervalSec": 30,
"feedCheckInterval": 10000,
"charLimit": 500,
"viewFeedsPaginationLimit": 10
}

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…
Cancel
Save