From 7225d66a88a1724468b0e1906f5a2195a62bad25 Mon Sep 17 00:00:00 2001 From: Matt Rosen Date: Mon, 5 Feb 2018 11:11:20 -0500 Subject: [PATCH] Finished the blacklist tags feature --- README.md | 6 +++++- config-example.json | 4 +++- postpromoter.js | 14 ++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5963436..a5ccf69 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Then set the following options in config.json: "blacklist_location": "blacklist", // The location of the blacklist file containing one blacklisted Steem account name per line "refund_blacklist": true, // Whether or not to refund blacklisted users' bids "blacklist_donation_account": "steemcleaners", // If "refund_blacklist" is false, then this will send all bids from blacklisted users to the specified account as a donation + "blacklisted_tags": ["nsfw", "other-tag"], // List of post tags that are not allowed by the bot. Bids for posts with one or more tags in this list will be refunded "auto_withdrawal": { "active": true, // Activate the auto withdrawal function (will withdraw all accepted currencies) "accounts": [ // List of accounts to receive daily withdrawals and the amount to send to each @@ -78,7 +79,8 @@ Then set the following options in config.json: "blacklist_no_refund": "Bid is invalid - The author of this post is on the blacklist.", "blacklist_donation": "Bid from blacklisted user sent as a donation. Thank you!", "flag_refund": "Refund for invalid bid: {amount} - This post has been flagged by one or more spam / abuse indicator accounts.", - "flag_no_refund": "Bid is invalid - This post has been flagged by one or more spam / abuse indicator accounts." + "flag_no_refund": "Bid is invalid - This post has been flagged by one or more spam / abuse indicator accounts.", + "blacklist_tag": "Bid is invalid - This post contains the [{tag}] tag which is not allowed by this bot." } } ``` @@ -99,6 +101,8 @@ Additionally you can add a list of "flag_signal_accounts" which means that if an $ nodejs postpromoter.js ``` +This will run the process in the foreground which is not recommended. We recommend using a tool such as [PM2](http://pm2.keymetrics.io/) to run the process in the background as well as providing many other great features. + ## API Setup If you would like to use the API functionality set the "api.enabled" setting to "true" and choose a port. You can test if it is working locally by running: diff --git a/config-example.json b/config-example.json index ac047c6..3e250fe 100644 --- a/config-example.json +++ b/config-example.json @@ -28,6 +28,7 @@ "blacklist_location": "blacklist", "refund_blacklist": false, "blacklist_donation_account": "steemcleaners", + "blacklisted_tags": ["nsfw"], "auto_withdrawal": { "active": true, "accounts": [ @@ -61,6 +62,7 @@ "blacklist_no_refund": "Bid is invalid - The author of this post is on the blacklist.", "blacklist_donation": "Bid from blacklisted/flagged user sent as a donation. Thank you!", "flag_refund": "Refund for invalid bid: {amount} - This post has been flagged by one or more spam / abuse indicator accounts.", - "flag_no_refund": "Bid is invalid - This post has been flagged by one or more spam / abuse indicator accounts." + "flag_no_refund": "Bid is invalid - This post has been flagged by one or more spam / abuse indicator accounts.", + "blacklist_tag": "Bid is invalid - This post contains the [{tag}] tag which is not allowed by this bot." } } diff --git a/postpromoter.js b/postpromoter.js index 112d279..5b180f4 100644 --- a/postpromoter.js +++ b/postpromoter.js @@ -380,8 +380,13 @@ function checkPost(memo, amount, currency, sender, retries) { if (config.blacklisted_tags && config.blacklisted_tags.length > 0 && result.json_metadata && result.json_metadata != '') { var tags = JSON.parse(result.json_metadata).tags; - if (tags && tags.find(t => config.blacklisted_tags.indexOf(t))) { - // TODO: send refund + if (tags && tags.length > 0) { + var tag = tags.find(t => config.blacklisted_tags.indexOf(t) >= 0); + + if(tag) { + refund(sender, amount, currency, 'blacklist_tag', 0, tag); + return; + } } } @@ -525,7 +530,7 @@ function saveDelegators() { }); } -function refund(sender, amount, currency, reason, retries) { +function refund(sender, amount, currency, reason, retries, data) { if(!retries) retries = 0; @@ -541,6 +546,7 @@ function refund(sender, amount, currency, reason, retries) { memo = memo.replace(/{currency}/g, currency); memo = memo.replace(/{min_bid}/g, config.min_bid); memo = memo.replace(/{max_bid}/g, config.max_bid); + memo = memo.replace(/{tag}/g, data); var days = Math.floor(config.max_post_age / 24); var hours = (config.max_post_age % 24); @@ -553,7 +559,7 @@ function refund(sender, amount, currency, reason, retries) { // Try again on error if(retries < 2) - setTimeout(function() { refund(sender, amount, currency, reason, retries + 1) }, (Math.floor(Math.random() * 10) + 3) * 1000); + setTimeout(function() { refund(sender, amount, currency, reason, retries + 1, data) }, (Math.floor(Math.random() * 10) + 3) * 1000); else utils.log('============= Refund failed three times for: @' + sender + ' ==============='); } else {