node package manager

x-to-y

x-to-y

a tool for rapidly scaffolding x-to-y style twitter bots. inspired by boy2bot by rainshapes, used to power bot_2_boy

NPM js-standard-style Build Status

EXAMPLE

require('x-to-y')('bot', 'boy', 'en', { consumer_key: 'SPIDERS!!!!', consumer_secret: 'SPIDERS!!!!', access_token: 'SPIDERS!!!!', access_token_secret: 'SPIDERS!!!!'}, ['nononono'])

xToY(x, y, language, twitConfig, ignores)

  • x: the string to search/replace on. Will accept "multiple words"
  • y: the string to replace x with. Will accept "multiple words"
  • language: theoretically this bot should work in any language? 'en' for english, etc.
  • twitConfig: API keys formatted in the ttezel/twit fashion
  • ignores: optional array of words to reject. That way you can reject tweets that would make yr bot unfunny. For example, I have one that searches for "chipotle burrito" as the x, and I put ["bowl"] as the ignores because a burrito bowl is different from a burrito in numerous ways.

call that on a cronjob and yr done! A 1 line bot!

The sauce code is annotated if u want to, oh, i'll just paste the relevant portion here:

  T.get('search/tweets', { q: x, count: 100, result_type: 'recent', lang: lang }, function(err, data, response) { // grab 100 of the most recent tweets with this X in the given language
    var cleaned = data.statuses.map(cleanThisTweetUp).filter(function(t){ // remove usernames, links, hastags, etc.
      return t && !!t.match(x) && iscool(t) // filter out ones that don't actually contain x, or that are not cool
    })
    var toot = pick(cleaned)[0] // pick one at random
    toot = addEnder(cap(toot.replace(new RegExp(x, 'gi'), y))) // replace x with y, capitalize the tweet, and add a period if one is not present
    console.log(toot)
    if (toot.length < 140) { // if y is longer than x, then it is possible to make a too long tweet! that is not good!
      T.post('statuses/update', {status: toot}, function (err, data, response) { // tweet it out to the world!