Skip to content

Commit

Permalink
Fixed same link tweeting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
RagePeanut committed May 3, 2018
1 parent be82f4a commit 2ca140f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Tweem (0.1.4)
# Tweem (0.1.5)
Tweem is a bot that automatically tweets all the resteems and/or recent posts of specified accounts.

## Deploy
Expand Down Expand Up @@ -49,6 +49,7 @@ Here are all the configuration possibilities:
* **stream_nodes:** list of RPC nodes to be used by the app to stream operations (those can be low memory nodes)
* **template:** template for the tweet (explained in 'Create your own template')
* **tweet_retry_timeout:** time in milliseconds to wait for before retrying to tweet if it failed (default: 10000)
* **twitter_handle:** the **Twitter** handle used by the bot, aka your **Twitter** handle (default: 'RagePeanut_')

## Create your own template
**Tweems** aims to be the most configurable sharing bot on the **Steem** blockchain, that's why you can change how your tweets will look by changing their template. Let's take a look at the default template to understand what's happening.
Expand Down
20 changes: 17 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Twit = require('twit');
const steemStream = require('steem');
const steemRequest = require('steem');

const { request_nodes, settings, steem_accounts, stream_nodes, tweet_retry_timeout } = require('./config');
const { request_nodes, settings, steem_accounts, stream_nodes, tweet_retry_timeout, twitter_handle } = require('./config');

const twitter = new Twit({
consumer_key: process.env.CONSUMER_KEY,
Expand Down Expand Up @@ -36,11 +36,15 @@ function stream() {
const op = JSON.parse(operation[1].json);
// Checking if it's a resteem and if it's from one of the specified accounts
if(op[0] === 'reblog' && steem_accounts.resteems.includes(op[1].account)) {
treatOperation(op[1].author, op[1].permlink, op[0]);
isAlreadyTweeted(op[1].author, op[1].permlink)
.then(alreadyTweeted => !alreadyTweeted && treatOperation(op[1].author, op[1].permlink, op[0]))
.catch(err => console.err('Twitter search API error:', err.message));
}
// Checking if it's a post (not a comment) made by one of the specified accounts
} else if(settings.tweet_posts && operation[0] === 'comment' && steem_accounts.posts.includes(operation[1].author) && operation[1].parent_author === '') {
treatOperation(operation[1].author, operation[1].permlink, operation[0]);
isAlreadyTweeted(operation[1].author, operation[1].permlink)
.then(alreadyTweeted => !alreadyTweeted && treatOperation(operation[1].author, operation[1].permlink, operation[0]))
.catch(err => console.error('Twitter search API error:', err.message));
}
});
// If an error occured, add 1 to the index and put it at 0 if it is out of bound
Expand Down Expand Up @@ -70,6 +74,16 @@ function tweet(message) {
});
}

// Checks if the link has already been tweeted in the last 7 days
function isAlreadyTweeted(author, permlink) {
return new Promise((resolve, reject) => {
twitter.get('search/tweets', { q: 'from:' + twitter_handle + ' url:' + author + ' url:' + permlink }, (err, data, response) => {
if(err) return reject(err);
resolve(data.statuses.length > 0);
});
});
}

// Gets the website from which the post has been made if it can view posts
function getWebsite(app, author, permlink, url, tags, body) {
if(!settings.allowed_apps[app]) return null;
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
"https://rpc.steemviz.com",
"https://steemd.minnowsupportproject.org"
],
"tweet_retry_timeout": 10000
"tweet_retry_timeout": 10000,
"twitter_handle": "RagePeanut_"
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tweem",
"version": "0.1.4",
"version": "0.1.5",
"description": "A bot tweeting all the resteems and/or recent posts of specified accounts.",
"main": "app.js",
"scripts": {
Expand Down

0 comments on commit 2ca140f

Please sign in to comment.