Skip to content

Commit

Permalink
feat: optional delete subscribes on send err
Browse files Browse the repository at this point in the history
  • Loading branch information
fengkx committed Oct 4, 2019
1 parent a6048f5 commit b26f7d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ module.exports = {
process.env.RSSBOT_UA ||
`Mozilla/5.0 NodeRSSBot v${version}(https://github.com/fengkx/NodeRSSBot)`,
not_send: process.env.NOT_SEND || false, // just for debug use
concurrency: process.env.RSSBOT_CONCURRENCY || 200
concurrency: process.env.RSSBOT_CONCURRENCY || 200,
delete_on_err_send: process.env.DELETE_ON_ERR_SEND || true // block and chat not found
};
10 changes: 7 additions & 3 deletions utils/send.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const SUBSCRIBES = require('../proxies/subscribes');
const logger = require('./logger');
const sanitize = require('./sanitize');
const config = require('../config');

module.exports = async (bot, toSend, feed) => {
const subscribers = await SUBSCRIBES.getSubscribersByFeedId(feed.feed_id);
Expand Down Expand Up @@ -36,11 +37,14 @@ module.exports = async (bot, toSend, feed) => {
disable_web_page_preview: true
});
} catch (e) {
// bot was blocked or chat is deleted
logger.error(e.description);
const re = new RegExp('chat not found');
if (re.test(e.description)) {
const re = new RegExp(
'chat not found|bot was blocked by the user'
);
if (config.delete_on_err_send && re.test(e.description)) {
logger.error(`delete all subscribes for user ${userId}`);
// SUBSCRIBES.deleteSubscribersByUserId(userId);
SUBSCRIBES.deleteSubscribersByUserId(userId);
}
}
});
Expand Down

0 comments on commit b26f7d9

Please sign in to comment.