diff --git a/commands/plan.js b/commands/plan.js index deffafb..b5c32b2 100644 --- a/commands/plan.js +++ b/commands/plan.js @@ -127,8 +127,12 @@ module.exports = (bot) => { replyMarkup: bot.keyboard(replies.main_page, {resize: true}), }).then(() => { return dbQuery.getRemainingStocksForPlan(don["plan_id"]).then(obj => { - return bot.sendMessage(info['plan_group_id'], - decodeURI(getStatement(obj["plan_name"], don['stock'], obj["remaining_stocks"])) + return Promise.all( + info['plan_group_id'].map(group_id => { + return bot.sendMessage(group_id, + decodeURI(getStatement(obj["plan_name"], don['stock'], obj["remaining_stocks"])) + ); + }) ).then(() => { console.log("done"); donations = donations.filter(el => el.user_id !== msg.from.id); diff --git a/db/queries.js b/db/queries.js index 49d7b34..8b33ad7 100644 --- a/db/queries.js +++ b/db/queries.js @@ -93,6 +93,9 @@ class Query { const donated = docs.map(doc => doc.stock).reduce((a, b) => a + b, 0); let stocksLeft = res["stocks"] - donated; + if (res["modified"]) + stocksLeft += res["modified"]; + if (stocksLeft < 0) { return this.deactivatePlan(plan_id).then(r => { return resolve({ diff --git a/info.js b/info.js index 991b3ee..098fde5 100644 --- a/info.js +++ b/info.js @@ -21,7 +21,13 @@ info['proxy'] = process.env.PROXY; info['plan_service'] = process.env.PLAN_SERVICE && process.env.PLAN_SERVICE.toLowerCase() == "true" || false; info['db_url'] = process.env.DB_URL; info['db'] = process.env.DB; -info['plan_group_id'] = process.env.PLAN_GROUP_ID; + +info['plan_group_id'] = [] +const PLAN_BASE = "PLAN_GROUP_ID_" +let i = 1; +for (i; process.env[PLAN_BASE + i]; i++) { + info['plan_group_id'].push(process.env[PLAN_BASE + i]); +} info['fa-ascii'] = { zero: 1776, diff --git a/sample.env b/sample.env index 7af8e7d..d447c4b 100644 --- a/sample.env +++ b/sample.env @@ -37,4 +37,6 @@ DB_URL= DB= # the channel id that result of plan service should be published to -PLAN_GROUP_ID= +# there can exist many ids, with _1, _2, ... indexes! +PLAN_GROUP_ID_1= +PLAN_GROUP_ID_2= \ No newline at end of file