spences10 / twitter-bot-bootstrap

Twitter bot bootstrap :boot: using node and twit :bird:
https://medium.freecodecamp.com/easily-set-up-your-own-twitter-bot-4aeed5e61f7f#.dw898leyj
MIT License
231 stars 104 forks source link

Add user blacklist #127

Closed spences10 closed 1 year ago

spences10 commented 7 years ago

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: 9c9b83b09bb55f77660c868b7d52ae3bff31b20b

danielfsousa commented 7 years ago

I would like to take this one

spences10 commented 7 years ago

Cool, you may want to split the blacklist into a comma separated line, like:

BLACKLIST_USERNAMES=_100DaysOfCode,heroes_bot

Thanks @danielfsousa πŸ‘

spences10 commented 7 years ago

How are you getting on with this @danielfsousa?

spences10 commented 6 years ago

Hey @danielfsousa looks like there's been nothing committed to your fork so I'll open this up for other people interested in doing this.

danielfsousa commented 6 years ago

That's ok @spences10. Sorry for not replying sooner

spences10 commented 6 years ago

Up for grabs now @toxxn πŸ‘

StephenEller86 commented 6 years ago

@spences10

I went ahead and tried to use the #100DaysOfCode Twitter Bot since it seemed like it had the blacklist feature implemented already, however I'm stuck lol, that version of the bot won't deploy and when I just "npm start", it loops but doesn't post.... Maybe ill try your blacklist here haha.

Would I adjust retweet.js and replace this code or would I create a handleretweet.js then adjust retweet.js to include and use the handleretweet.js? Would I need to add a db.js under helpers?

spences10 commented 6 years ago

Hey, just seen this, I don't seem to get notified about these. I answered your question about why the bot won't deploy there, I hope you understand πŸ™ƒ let me know if you need anything clarifying.

So in its simplest form the blacklist is if (blacklist.indexOf(event.screen_name) > -1) where blacklist is the usernames added from the config.

Most of it is detailed in the original post, I'm on mobile now so can't be any more specific at this time.