Coder Social home page Coder Social logo

spences10 / twitter-bot-bootstrap Goto Github PK

View Code? Open in Web Editor NEW
230.0 16.0 104.0 11.31 MB

Twitter bot bootstrap :boot: using node and twit :bird:

Home Page: https://medium.freecodecamp.com/easily-set-up-your-own-twitter-bot-4aeed5e61f7f#.dw898leyj

License: MIT License

JavaScript 100.00%
bootstrap twitter node javascript personal twitter-bot-bootstrap twitter-account bot twitter-application twitter-bot

twitter-bot-bootstrap's Introduction

Twitter bot bootstrap

Renovate enabled license Chat

Click to expand TOC

This is a bootstrap for setting up a simple Twitter bot with Node.js using the npm twit module. The bot will retweet what you specify when configuring it. It will also reply to followers with a selection of canned responses.

As a primer for this, there is a great post by @amanhimself on making your own twitter bot, check it out in the Links section. This is an expansion on that with further detail on configuration and deployment with now from Zeit.

Before starting the clock you'll need to set up some accounts if you don't have them already.

What you'll need

  • Twitter account
  • Development environment with Node.js and npm
  • Zeit account

Setup twitter

Set up an application on the Twitter account you want to retweet from via: https://apps.twitter.com/app/new

As an example, I'll configure the old @DroidScott twitter account I have so you can follow along.

Straight forward enough for the twitter application, make sure you add your phone number to your Twitter account before clicking the Create your Twitter application button.

You should now be in the 'Application Management' section where you will need to take note of your keys. You should have your 'Consumer Key (API Key)' and 'Consumer Secret (API Secret)' already available. You'll need to scroll to the bottom of the page and click the Create my access token to get the 'Access Token' and 'Access Token Secret' take note of all four of them as you'll need them when setting up the bot.

Setup development environment

If you don't already have a dev environment with node installed then for a quick-start I'd suggest using Cloud9 you can be up and running in minutes with one of the pre made Node.js environments.

Note that in some regions you will be prompted to enter credit card information to use Cloud9 you will not be charged, there are other options to use like Glitch if you don't have a credit card. For this guide I'm going to be using Cloud9 which is what will be in the images.

Node 8

If you're using a c9 environment then you'll need to upgrade node which I think comes pre-installed at version 6 which will cause some errors with the code in this repository, so we're going to go with version 8 for this, so, in the terminal:

nvm install 8 # install node 8
nvm use 8 # set it to use node 8
nvm alias default 8 # default to 8 so version persists after reboots

nvm stands for Node Version Manager which comes installed by default on c9 machines πŸ‘

Set up the bot

In the project tree for the default c9 node application delete the example project files of client, node_modules, package.json, README.md and server.js. You won't need them, but you can leave them there if you so desire.

In your new Node.js c9 environment go to the terminal and enter:

git clone https://github.com/spences10/twitter-bot-bootstrap

Project structure

The environment project tree will look something like this:

twitter-bot-bootstrap/
β”œβ”€ images
β”œβ”€ node_modules/
β”œβ”€ src/
β”‚  β”œβ”€ api
β”‚  β”‚  β”œβ”€ reply.js
β”‚  β”‚  └─ retweet.js
β”‚  β”œβ”€ bot.js
β”‚  β”œβ”€ config.js
β”‚  └─ rando.js
β”œβ”€ .env
β”œβ”€ .gitignore
β”œβ”€ .snyk
β”œβ”€ CODE_OF_CONDUCT.md
β”œβ”€ CONTRIBUTING.md
β”œβ”€ LICENSE
β”œβ”€ README.md
β”œβ”€ index.js
β”œβ”€ package-lock.json
└─ package.json

Node dependencies

Before configuring the bot we'll need to install the dependencies, cd into the project folder with cd tw* in the terminal this will move you to :~/workspace/twitter-bot-bootstrap (master) $ from the terminal enter:

npm install

This will install all the dependencies listed in the package.json file.

If you get an errors then I suggest installing the dependencies one by one from the package.json file with the same command and the package name at the end:

Here is an example of the dependencies in the package,json file:

  "dependencies": {
    "dotenv": "4.0.0",
    "snyk": "1.31.0",
    "twit": "2.2.5",
    "unique-random-array": "1.0.0"
  }

The npm command to install them all:

npm install --save dotenv twit unique-random-array snyk

Now you can configure the bot. From the terminal enter:

npm init

This will configure the package.json file with your details as desired. Just keep hitting return if you're happy with the defaults.

Make a .env file: make a file named .env do it with the terminal with the following command:

touch .env

This should be at the root of your project directory.

Now you'll need to add your Twitter keys to the .env file. Just input the keys in their corresponding fields and save the file.

The file structure should look as follows:

TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=

QUERY_STRING=my super awesome query string!,google,android

RANDOM_REPLY=Hi @${screenName} thanks for the follow! What are you working on today?|@${screenName} thanks for following! What are you working on today?

RESULT_TYPE=mixed
TWITTER_LANG=en

TWITTER_RETWEET_RATE=.1
TWITTER_SEARCH_COUNT=20

Note that RANDOM_REPLY is split with a pipe | and the QUERY_STRING is split by a comma , this is so that RANDOM_REPLY can have a comma in the reply text.

If you can not find the .env file in the file structure of your c9 project then you will need to enable the Show Hidden Files option. In the file view select the settings cog then tick the Show Hidden Files option if it is not already checked.

Add your API keys to the .env file πŸ”‘

The .env file is where we can configure our bot, here we set what we want to search on, check out the twitter-bot-playground for information on Twitter search.

QUERY_STRING should be what you want to retweet tweets on with the search terms separated with commas. RANDOM_REPLY again is comma separated replies with the ${ScreenName} which is replaced when replying to the follower. TWITTER_RETWEET_RATE is in minutes.

NOTE none of the .env items have quotes '' round them or spaces between the key and the value KEY=value

TWITTER_CONSUMER_KEY=Fw***********P9
TWITTER_CONSUMER_SECRET=TD************Cq
TWITTER_ACCESS_TOKEN=31**************UC
TWITTER_ACCESS_TOKEN_SECRET=r0************S2

QUERY_STRING=mango,horses,"donald -trump -duck"
RANDOM_REPLY=Hi @${screenName} thanks for the follow! What are you working on today?,@${screenName} thanks for following! What are you working on today?

RESULT_TYPE=mixed
TWITTER_LANG=en

TWITTER_RETWEET_RATE=120
TWITTER_SEARCH_COUNT=20

That should be it. Go to the terminal, enter npm start and you should get some output:

Check the Twitter account:

You now have a tweet bot, if you want to have this deployed so it's not just running from your machine or from the c9 machine [which is against their terms of service] then we can go over that next.

Deploy with now

Got your Zeit account set up? Now is the time if not, then install now from the terminal:

npm i -g now

Then now from the terminal and you will be prompted to enter your email, you will be sent a confirmation email, click the link and you're ready to go!

If you take a look at the package.json file in the "scripts" section you see there is one for "deploy" this is the command to deploy the bot to now, so from the terminal:

npm run deploy

This will use all our environment variables we defined within our .env file for use on the now servers.

You will get terminal output with a URL for where your bot is located, click the link and you can watch it get built.

Handy tip

If you want to add this to your own GitHub repo and don't want to share your API keys πŸ”‘ with the world then you should turn off tracking on the .env file. From the terminal enter this git command:

git update-index --assume-unchanged .env

I have added my most used git commands I use in this repo I use it on a daily basis, please feel free to use it.

Links

Credit for the inspiration for this should go to @amanhimself and his posts on creating your own twitter bot.


License

MIT License

Copyright (c) 2017, Scott Spence. All rights reserved.

twitter-bot-bootstrap's People

Contributors

greenkeeper[bot] avatar imgbotapp avatar martiuslim avatar masdc avatar nikkilr88 avatar pabrams avatar renovate-bot avatar serginator avatar spences10 avatar thornjad avatar whaleen avatar wjhurley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitter-bot-bootstrap's Issues

Cannot assign RetweetID exception occurs intermittently due to invalid random index

Related to #87, but I suspect there's more than one issue causing the same exception so I thought I'd better open a separate issue.

The random index being generated to grab a value from the data.statuses array coming back from bot.get in retweet.js seems to incorrect and sometimes throws exceptions as a result. I think the range of the random number should be based on data.statuses.length (since that's the size of the array we want to index into) instead of param.searchCount, and I don't think we should be adding one. I'll try and submit a PR to resolve this shortly.

Please correct me if I doing anything wrong here - I don't git often.

Enhance follow self fix

Take a look at the Snug's implementation of the bot bootstrap, does a good job with the follow self functionality here: https://github.com/thesnug/thesnugbot/blob/master/src/bot.js

Linking to #16 as it's the same issue it's only after finding thesnugbot that I saw how it could be done.

require('dotenv').config();

module.exports = {
  twitter: {
    username: process.env.TWITTER_USERNAME,
    consumerKey: process.env.TWITTER_CONSUMER_KEY,
    consumerSecret: process.env.TWITTER_CONSUMER_SECRET,
    accessToken: process.env.TWITTER_ACCESS_TOKEN,
    accessTokenSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
    retweet: process.env.TWITTER_RETWEET_RATE,
    favorite: process.env.TWITTER_FAVORITE_RATE
  },
  sentiment: process.env.SENTIMENT
};

beautiful!!

Cannot assign retweeID

I commented on a commit earlier but i'm sending in a issue instead:

Followed the setup instructions several times, but when im trying to start the bot i get the following error message:

"ERRORDERP: Cannot assign retweeID"

It is possible that it is the enviorment i use (C9 web based workspace).

I tried as suggested changing LAN to LANGUAGE in the .env file but to no avail. Other suggested solutions are welcome.

export default?

@MarcL I'm attempting to call a function in bot.js from another module, it's for the search part of the bot.

I can call the function from withing the bot.js module but when I try move it out into it;s own module and then import to the bot I get an error saying it's not a function, here's a quick overview:

Working
bot.js

import Twiter from 'twitter'
import config from './config'
import {
  getFunName,
  rando
} from './helpers/helpers'
import params from './helpers/parameters'

const client = new Twiter(config.twitter)

const tweetNow = async (txt) => {
  try {
    await client.post('statuses/update', { status: txt })
    console.log(txt)
  } catch (err) {
    console.log(err)
  }
}

// tweetNow(getFunName())

// setInterval(() => tweetNow(getFunName()), 1000 * 60 * 2)

const searchResult = async () => {
  let res
  try {
    res = await client.get('search/tweets', params)
    // const randoUser = rando(res.data.statuses).user.scree_name
    // console.log('rando user = ', randoUser)
  } catch (err) {
    console.log('error = ', err)
  }

  // console.log(JSON.stringify(res))
  console.log(rando(res.statuses).user.screen_name)
  console.log(rando(res.statuses).text)
  console.log(rando(res.statuses).id_str)
}

searchResult()

setInterval(() => searchResult(), 1000 * 60 * 2)

tweetNow(getFunName()) and setInterval(() => which are commented out work I'm just concentrating on setting a search working using the same structure so I can them move it out to another module when finished.

Some terminal output from the above code:
image

Not working an attempt to make things modular
bot.js

import Twiter from 'twitter'
import config from './config'
import {
  getFunName,
} from './helpers/helpers'
import { searchResult } from './helpers/search'

const client = new Twiter(config.twitter)

const tweetNow = async (txt) => {
  try {
    await client.post('statuses/update', { status: txt })
    console.log(txt)
  } catch (err) {
    console.log(err)
  }
}

// tweetNow(getFunName())

// setInterval(() => tweetNow(getFunName()), 1000 * 60 * 2)

searchResult()

setInterval(() => searchResult(), 1000 * 5)

search.js

import Twiter from 'twitter'
import config from '../config'
import {
  rando
} from './helpers'
import params from './parameters'

const client = new Twiter(config.twitter)

const searchResult = async () => {
  let res
  try {
    res = await client.get('search/tweets', params)
    // const randoUser = rando(res.data.statuses).user.scree_name
    // console.log('rando user = ', randoUser)
  } catch (err) {
    console.log('error = ', err)
  }

  // console.log(JSON.stringify(res))
  console.log(rando(res.statuses).user.screen_name)
  console.log(rando(res.statuses).text)
  console.log(rando(res.statuses).id_str)
}

export default searchResult()

Terminal output from the above code:
image

So I can use it in bot.js as a function but when I try abstract it out into it's own module it's a no?

Do you have any idea what I'm doing wrong?

Example of making it an npm module

As we were discussing on Twitter, how I'd make the ES6 branch into an exportable module for npm.

So at the moment, package.json has main as index.js which would just start the bot. Instead, export the bot itself.

{
  "name": "twitter-bot-bootstrap",
  "version": "0.0.0-development",
  "description": "twitter bot bootstrap",
  "main": "src/bot.js",
...

Because you're transpiling this with babel, you might want to build the whole project to a build or lib directory instead and reference that but I'll leave that for you to look at if you do. Also don't forget to set the name to the name of your NPM package.

Then update your src/bot.js so that it exports something that I can use if I install your bot NPM package into my project.

import Twit from 'twit'
import config from './config'

class ScottBot {
    constructor(config) {
        this.bot = new Twit(config);
    }

    tweetNow(text) {
        const tweet = {status: text}
        this.bot.post('statuses/update', tweet, (err, data, response) => {
            if (err) {
                console.log('ERROR: ', err)
            }
            console.log('SUCCESS: Replied to Follower')
        }
    }
}

export default ScottBot;

I've rewritten your bot as a class. You don't have to do this. You could export a function which returns you a bot (from new Twit(config)) and then export a 2nd function where you pass that bot through to it perhaps?

if I import your package file, I expect to pull it in and be able to use it:

// We exported with `default` above so I can just import it like this
import ScottBot from 'scotts-twitter-bot';

// Rename this to whatever the config property names are
const twitterConfig = {
    apiKey: 'myAppKey',
    apiSecret: 'myAppSecret'
};

// Initialise the bot that you've kindly built for me
const myBot = new ScottBot(twitterConfig);

// Some point later in my app
myBot.tweetNow('This is my Twitter bot!');

Does that make sense? I've exported something in bot.js which we expose to the package.json file in "main" to tell the importing module (i.e. my code) what to pull in from that export.

Shout tomorrow if it doesn't make sense. Also, there might be typos in the above code. Not tried it! :)

Cheers,
Marc

Invali URL Paramete

Hi Scott,

Amazing bot, thank you for the great guide. I had mine up and running a few days ago made some changes and I managed to break it ):

I've gone with a fresh install as I noticed you updated the README. After I enter in NPM start I get the following output, any suggestions ways you could please recommend on fixing this?

[email protected] start /home/ubuntu/workspace/twitter-bot-bootstrap
node index.js

Something went wrong while SEARCHING...
ERR CAN'T FIND TWEET: { [Error: Missing or invalid url parameter.]
message: 'Missing or invalid url parameter.',
code: 195,
allErrors: [ { code: 195, message: 'Missing or invalid url parameter.' } ],
twitterReply: { errors: [ [Object] ] },
statusCode: 403 }
Something went wrong while SEARCHING...
ERR CAN'T FIND TWEET: { [Error: Missing or invalid url parameter.]
message: 'Missing or invalid url parameter.',
code: 195,
allErrors: [ { code: 195, message: 'Missing or invalid url parameter.' } ],
twitterReply: { errors: [ [Object] ] },
statusCode: 403 }

update: I managed to fix this the only change I made was to remove the spaces from my blocked strings, perhaps the spaces were messing it up.

I can confirm just changed it back and got the same error as above, happy that this solves the issue as it now works. Will Close

Use GraphCool backend

Use GraphCool backend in conjunction with RT on stream so that tweets are not repeatedly tweeted.

flow will be:

  1. match search criteria
  2. check database if tweet text is in there already
  3. if not in db already then retweet

Filter out replies?

First off, thank you for your very detailed guide on setting this up.

I know we can use the query syntax 'from:@username' to retweet tweets from a specific Twitter account, however is there a way to filter those tweets to not retweet replies?

Type Error

Hi I get this output if i try to npm start your code.

/home/ubuntu/workspace/twitter-bot-bootstrap/src/bot.js:175
var index = Math.floor(Math.random() * arr.length);
^

TypeError: Cannot read property 'length' of undefined

Code seems to have errors

This is a great project and learning a lot. I've followed the instructions exactly as they outline, but it does not seem to work.

Can someone please help me figure out why it is not running?

I am getting this output:

0 info it worked if it ends with ok
1 verbose cli [ '/home/ubuntu/.nvm/versions/node/v4.7.3/bin/node',
1 verbose cli   '/home/ubuntu/.nvm/versions/node/v4.7.3/bin/npm',
1 verbose cli   'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart [email protected]
6 info start [email protected]
7 verbose unsafe-perm in lifecycle true
8 info [email protected] Failed to exec start script
9 verbose stack Error: [email protected] start: `node index.js`
9 verbose stack Exit status 1
9 verbose stack     at EventEmitter.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.7.3/lib/node_modules/npm/lib/utils/lifecycle.js:217:16)
9 verbose stack     at emitTwo (events.js:87:13)
9 verbose stack     at EventEmitter.emit (events.js:172:7)
9 verbose stack     at ChildProcess.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.7.3/lib/node_modules/npm/lib/utils/spawn.js:24:14)
9 verbose stack     at emitTwo (events.js:87:13)
9 verbose stack     at ChildProcess.emit (events.js:172:7)
9 verbose stack     at maybeClose (internal/child_process.js:854:16)
9 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:222:5)
10 verbose pkgid [email protected]
11 verbose cwd /home/ubuntu/workspace/twitter-bot-bootstrap
12 error Linux 4.9.17-c9
13 error argv "/home/ubuntu/.nvm/versions/node/v4.7.3/bin/node" "/home/ubuntu/.nvm/versions/node/v4.7.3/bin/npm" "start"
14 error node v4.7.3
15 error npm  v2.15.11
16 error code ELIFECYCLE
17 error [email protected] start: `node index.js`
17 error Exit status 1
18 error Failed at the [email protected] start script 'node index.js'.
18 error This is most likely a problem with the twitter-bot-bootstrap package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error     node index.js
18 error You can get information on how to open an issue for this project with:
18 error     npm bugs twitter-bot-bootstrap
18 error Or if that isn't available, you can get their info via:
18 error
18 error     npm owner ls twitter-bot-bootstrap
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]

Retweet functionality broken

Can't seem to get the correct result with several differing ways to re-tweet, I've logged an issue #219 with the package maintainer.

This is probably nothing to do with the package and more likely my rudimentary coding πŸ‘

Update documentation

config.js key values pairs need to reflect what is in the .env file

Refer to #87 for details on how to resolve

An in-range update of snyk is breaking the build 🚨

Version 1.30.1 of snyk just got published.

Branch Build failing 🚨
Dependency snyk
Current Version 1.30.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

snyk is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ bitHound - Dependencies null Details,- ❌ bitHound - Code null Details,- ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 3 commits0.

  • 82bc676 fix: update snyk policy
  • b477852 docs: edit help text re npm & ignore
  • c088b40 docs: remove Node.js caveat we no longer need

false

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Is the bot retweeting

retweetId DERP! Cannot read property 'id_str' of undefined Query String: blockchain professional

An in-range update of snyk is breaking the build 🚨

Version 1.31.0 of snyk just got published.

Branch Build failing 🚨
Dependency snyk
Current Version 1.30.2
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

snyk is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ bitHound - Dependencies null Details
  • ❌ bitHound - Code null Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v1.31.0

<a name"1.31.0">

1.31.0 (2017-05-26)

Features

  • display alerts returned via API calls (9a76dd7b)
Commits

The new version differs by 2 commits.

  • 71bd6c4 test: test the alerts module
  • 9a76dd7 feat: display alerts returned via API calls

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Heroku crashes

Hi there, amazing work and I hope to contribute.

I'm getting the following error with heroku when deployed after a few loops:

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Stopping process with SIGKILL
Process exited with status 137
State changed from starting to crashed

I've followed your guide but can't seem to find the issue

Use external file for search parameters

As with issue spences10/twitter-bot-twit#5 on Twitter bot twit look at using an external file for the configuration of the bot to reduce the need to deploy when a non code element changes a'la search params or other config variables, retweet times etc...

Take a look at: https://github.com/spences10/javascript30/blob/master/src/06%20-%20Type%20Ahead/index.html#L29

const endpoint = 'https://gist.githubusercontent.com/spences10/ceee092f6fed36559036c94682b7a5f7/raw/7a27570759834ee454ee380ca42ebd47dc55e932/arnold_quotes.json'
const quotes = []
// get data from endpoint into array,
// first fetch the data
fetch(endpoint)
  .then(blob => blob.json())
  .then(data => quotes.push(...data))
  
function findMatches(wordToMatch, quotes) {
  return quotes.filter(match => {
    const regex = new RegExp(wordToMatch, 'gi')
    return match.quote.match(regex) || match.movie.match(regex)
  })
}

Add listen on port for zeit deployment

This is a straightforward change adding a listen on port to the bot so that it completes deployment to zeit's now;

Details of the change:

bot.js needs to have the following added to the very top of the file:

// listen on port so now.sh likes it
const { createServer } = require('http')

And this at the very bottom of the file add:

// This will allow the bot to run on now.sh
const server = createServer((req, res) => {
  res.writeHead(302, {
    Location: `https://twitter.com/${config.twitterConfig.username}`
  })
  res.end()
})

server.listen(3000)

Unhandled rejection Error - Sometimes - on Retweet

Hi, love the bot... works great and I've been able to customize it to interact with Microsoft's QnA. However, every now and then I get the following error message on Retweets:

Unhandled rejection Error: Twit: Params object is missing a required parameter for this request: id

Not sure if that's a twit module problem or the twitter-bot. I can't seem to make it go away or figure out why the id param is missing.

This doesn't happen on all retweets... which is even more confusing...

More confusing is that I get Errorderp: Retweet! and then Success and the tweet... but it doesn't post to Twitter.

I'm running the bot currently from cloud9, npm v8.9.1, twit v2.2.9

When ever I run "git clone https://github.com/spences10/twitter-bot-bootstrap" I seem to be missing the folder "helpers" and the files within

As the title suggests, I run ""git clone https://github.com/spences10/twitter-bot-bootstrap"" and all seems to work ok, however the folder "helpers" with files <sentiment.js> & <strings.js> are missing.

This seems to hinder my install as even after following each step after and entering "npm run" nothing is retweeted on my feed.

This is the message I receive after an "NPM RUN"

davebryantlu:~/workspace/twitter-bot-bootstrap (master) $ npm run
Lifecycle scripts included in twitter-bot-bootstrap:
start
node index.js
test
snyk test && standard && node index.js
prepublish
npm run snyk-protect

available via npm run-script:
snyk-protect
snyk protect
deploy
now -E
davebryantlu:~/workspace/twitter-bot-bootstrap (master) $

Any idea where I have gone wrong ?

Use data.length

Use data.length for the upper bound of the random number used, if there is a small result set then the random number will probably not be in the range of param.searchCount

const rando = Math.floor(Math.random() * param.searchCount) + 1

not retweeting/fave latest

couple things

awsome bot btw.

How to remove the thank you on new follower without breaking it ?
Also how to define a handle rather than hashtag ? Its hit or miss on reading the users handle @username

Hidden files are hidden

A user commented on the Medium post that they were really stuck on the .env file part as it's hidden by default with c9.

Something I was completely unaware of but I'll add them in there as it is causing frustration for a lot of users.

Also add in that WARN can be ignored when doing npm install

Follower reply functionality triggers on wrong event

The string configured in RANDOM_REPLY in the .env file is being tweeted by my bot at its own account, for some reason. I can't tell what the exact trigger is - I thought it was when I followed someone else, but it doesn't seem to always trigger when I do that. It's definitely not triggering on someone else following me, because I haven't gained any new followers, yet the tweet is appearing.

Random replies syntax error

Hi Scott,

Found a little issue with the Readme. The syntax given for the RANDOM_REPLY var is shown as separated with commas, just like the QUERY_STRING var above it. However, after this failing to work I noticed that on line 6 of reply.js, the split is defined with a pipe |, not a comma. I think this is an intelligent choice, as it's likely you might want a comma in your reply string, but that means in the Readme, this:

RANDOM_REPLY=Hi @${screenName} thanks for the follow! What are you working on today?,@${screenName} thanks for following! What are you working on today?

Should be:

RANDOM_REPLY=Hi @${screenName} thanks for the follow! What are you working on today?|@${screenName} thanks for following! What are you working on today?

An in-range update of snyk is breaking the build 🚨

Version 1.30.0 of snyk just got published.

Branch Build failing 🚨
Dependency snyk
Current Version 1.29.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

snyk is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ

Status Details - βœ… **bitHound - Dependencies** No failing dependencies. [Details](https://www.bithound.io/github/spences10/twitter-bot-bootstrap/b66b2b93d8058a6793c680910119452b130c3a42/dependencies/npm?status=passing),- βœ… **bitHound - Code** No failing files. [Details](https://www.bithound.io/github/spences10/twitter-bot-bootstrap/b66b2b93d8058a6793c680910119452b130c3a42/files?status=passing),- ❌ **continuous-integration/travis-ci/push** The Travis CI build failed [Details](https://travis-ci.org/spences10/twitter-bot-bootstrap/builds/228737298?utm_source=github_status&utm_medium=notification)

Release Notes v1.30.0

<a name"1.30.0">

1.30.0 (2017-05-04)

Features

  • double-dash argument as last option in arg line (8291ec1e)
Commits

The new version differs by 1 commits0.

  • 8291ec1 feat: double-dash argument as last option in arg line

false

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Add user blacklist

Add a user blacklist to the Twitterbot bootstrap 🏴

I have similar functionality in another bot where the blacklist is configured in a .env file and you can use a comma-separated list in the .env file, like so:

BLACKLIST_USERNAMES=_100DaysOfCode,heroes_bot

Then use something along the same lines as what is here:

const addTweet = require('./dbAddTweet')
const checkTweet = require('./dbCheckTweet')

const retweet = require('../api/retweet')
const config = require('../config')

const handleRetweet = (event) => {
  const blacklist = config.twitterConfig.blacklist.split(',')
  // all teh debugs!!
  console.log('====================')
  console.log('BLACKLIST USERS: ', blacklist)
  console.log('EVENT USER NAME: ', event.user.screen_name)
  console.log('INDEX OF NAME IN BLACKLIST: ', blacklist.indexOf(event.user.screen_name))
  console.log('====================')
  if (
    event.lang != config.twitterConfig.language ||
    !event.in_reply_to_status_id ||
    blacklist.indexOf(event.screen_name) > -1
  ) {
    return
  } else {
    // console.log(JSON.stringify(event.lang))
    // console.log(JSON.stringify(event))
    checkTweet(event).then((data) => {
      let count = data.length
      if (!count >= 0) {
        addTweet(event)
        // retweet
        retweet(event)
      }
    })
  }
}

The code for this is located here: https://github.com/spences10/twitter-bot-twit/blob/ee6d1e4bef3e37af84c1eccec2a12337513e165a/src/helpers/dbHandleRetweet.js#L1-L33

Ideally, this would be checked before (re)tweeting so it should go somewhere like @nikkilr88's last commit, here: 9c9b83b

Missing .env file

Hi there,

This is the first bit of code I've touched in my entire life so please be gentle, and apologies in advance if this is dumb/answered somewhere else.

I can't seem to find the .env file to input my twitter credentials for the life of me. Yes, I showed "hidden files" and even tried searching for it using the Navigation tab.

Help?

Thank you thank you thank you in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.