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