Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coleww/x-to-y
:speaker: tool for making x-to-y bots
https://github.com/coleww/x-to-y
Last synced: 27 days ago
JSON representation
:speaker: tool for making x-to-y bots
- Host: GitHub
- URL: https://github.com/coleww/x-to-y
- Owner: coleww
- Created: 2015-10-08T15:34:17.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-27T02:09:17.000Z (about 7 years ago)
- Last Synced: 2024-10-04T22:34:32.721Z (about 1 month ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/x-to-y
- Size: 10.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
x-to-y
----------------a tool for rapidly scaffolding x-to-y style twitter bots. inspired by [boy2bot](https://twitter.com/boy2bot) by [rainshapes](https://twitter.com/rainshapes), used to power [bot_2_boy](https://twitter.com/bot_2_boy)
[![NPM](https://nodei.co/npm/x-to-y.png)](https://nodei.co/npm/x-to-y/)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
[![Build Status](https://secure.travis-ci.org/coleww/x-to-y.png)](http://travis-ci.org/coleww/x-to-y)### 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!
```