Skip to content

Commit

Permalink
fix modified value + add multiple group ids
Browse files Browse the repository at this point in the history
  • Loading branch information
imans777 committed Apr 19, 2020
1 parent 0492644 commit ad53a4c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
8 changes: 6 additions & 2 deletions commands/plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions db/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
8 changes: 7 additions & 1 deletion info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ DB_URL=<DB_URL_COMPETELY>
DB=<DATABASE_NAME>

# the channel id that result of plan service should be published to
PLAN_GROUP_ID=<GROUP_ID>
# there can exist many ids, with _1, _2, ... indexes!
PLAN_GROUP_ID_1=<GROUP_ID>
PLAN_GROUP_ID_2=<GROUP_ID>

0 comments on commit ad53a4c

Please sign in to comment.