Skip to content

Commit

Permalink
Finished the blacklist tags feature
Browse files Browse the repository at this point in the history
  • Loading branch information
MattyIce committed Feb 5, 2018
1 parent 1572327 commit 7225d66
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -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
Expand Down Expand Up @@ -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."
}
}
```
Expand All @@ -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:

Expand Down
4 changes: 3 additions & 1 deletion config-example.json
Expand Up @@ -28,6 +28,7 @@
"blacklist_location": "blacklist",
"refund_blacklist": false,
"blacklist_donation_account": "steemcleaners",
"blacklisted_tags": ["nsfw"],
"auto_withdrawal": {
"active": true,
"accounts": [
Expand Down Expand Up @@ -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."
}
}
14 changes: 10 additions & 4 deletions postpromoter.js
Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit 7225d66

Please sign in to comment.