twitter_bot_generator 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +10 -47
- data/lib/twitter_bot_generator/templates/Gemfile.erb +2 -1
- data/lib/twitter_bot_generator/templates/README.md.erb +15 -13
- data/lib/twitter_bot_generator/templates/src/test_bot.rb.erb +2 -2
- data/lib/twitter_bot_generator/templates/src/userstream-test_bot.rb.erb +2 -2
- data/lib/twitter_bot_generator/templates/streaming-bot.rb.erb +4 -0
- data/lib/twitter_bot_generator/templates/test/test_bot_test.rb.erb +4 -0
- data/lib/twitter_bot_generator/templates/test/userstream-test_bot_test.rb.erb +9 -0
- data/lib/twitter_bot_generator/templates/userstream-bot.rb.erb +3 -0
- data/lib/twitter_bot_generator/version.rb +1 -1
- data/such_streaming_bot/.gitignore +3 -0
- data/such_streaming_bot/Gemfile +5 -0
- data/such_streaming_bot/Procfile +1 -0
- data/such_streaming_bot/README.md +46 -0
- data/such_streaming_bot/bot.rb +38 -0
- data/such_streaming_bot/lib/greetings.txt +3 -0
- data/such_streaming_bot/spec.rb +9 -0
- data/such_streaming_bot/src/such_streaming_bot.rb +11 -0
- data/such_streaming_bot/test/such_streaming_bot_test.rb +16 -0
- data/such_streaming_bot/test.rb +3 -0
- data/such_test_bot/Gemfile +2 -1
- data/such_test_bot/README.md +15 -13
- data/such_test_bot/src/such_test_bot.rb +2 -2
- data/such_test_bot/test/such_test_bot_test.rb +4 -0
- data/such_userstream_bot/.gitignore +3 -0
- data/such_userstream_bot/Gemfile +5 -0
- data/such_userstream_bot/Procfile +1 -0
- data/such_userstream_bot/README.md +46 -0
- data/such_userstream_bot/bot.rb +31 -0
- data/such_userstream_bot/lib/greetings.txt +3 -0
- data/such_userstream_bot/spec.rb +9 -0
- data/such_userstream_bot/src/such_userstream_bot.rb +11 -0
- data/such_userstream_bot/test/such_userstream_bot_test.rb +21 -0
- data/such_userstream_bot/test.rb +3 -0
- data/test/{generated_default_bot.rb → generated_default_bot_test.rb} +0 -0
- data/test/generated_streaming_bot_test.rb +9 -0
- data/test/generated_userstream_bot_test.rb +9 -0
- data/test/test_helper.rb +15 -21
- metadata +28 -8
- data/test/generated_streaming_bot.rb +0 -9
- data/test/generated_userstream_bot.rb +0 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c3965a6085ac999b9f55d993f35442a4c5cbdbf
|
|
4
|
+
data.tar.gz: c68becc7c37b03eed2ffecf14920ce7f6f8a2fd3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 74c1c635dfed8af6d87cd5893cc8c864d543b0d4257503b62a110aa7e1c7ac3129233999f1d427fe419500df8d4d982f40bddf4339cde7be18e82a0a22e695a8
|
|
7
|
+
data.tar.gz: caa44e2f4e31b9c313d40b8458d65648467dbf7d1a7fc7c420b1fb0547c0461db307d7860df034a2f26ac002e8a3b5e97dcfbbbeae1ad02a7c4a76d88156a6db
|
data/.travis.yml
CHANGED
|
@@ -4,7 +4,7 @@ cache: bundler
|
|
|
4
4
|
rvm:
|
|
5
5
|
- 2.0.0
|
|
6
6
|
|
|
7
|
-
script: 'bundle exec rake
|
|
7
|
+
script: 'bundle exec rake'
|
|
8
8
|
|
|
9
9
|
notifications:
|
|
10
10
|
email:
|
data/README.md
CHANGED
|
@@ -45,65 +45,28 @@ $ ruby spec.rb
|
|
|
45
45
|
HAVE FUN BE SAFE PLAY NICE
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
This will create a skeleton class named YrBotNameSnakeCaseStyleYes, some smokescreen minitest::unit tests, and a variety of other "ruby app on free heroku instance" boiler plate.
|
|
49
|
-
|
|
50
|
-
## Deployment (heroku)
|
|
51
|
-
|
|
52
|
-
Once your bot has been well tested on the command line you'll need to get it out into the world!
|
|
53
|
-
|
|
54
|
-
0. You probably need git and the heroku toolbet installed and also a heroku account.
|
|
55
|
-
0. Make a twitter account for your bot. Give it a photo and header and some biographical information
|
|
56
|
-
0. Go into settings > mobile and add a cell phone number that you can send a text from.
|
|
57
|
-
not all carriers will work :(
|
|
58
|
-
without a mobile number, twitter won't let you get the api keys you need to deploy
|
|
59
|
-
if your mobile number is associated with your personal account, temporarily delete it from that account so you can use it for your bot. Twitter doesn't care.
|
|
60
|
-
0. go to apps.twitter.com and sign in again
|
|
61
|
-
0. click create a new app
|
|
62
|
-
0. fill in the details. just put down the github repo link or twitter page for the bot as website/callback url. no one will ever see this except you.
|
|
63
|
-
0. once your app is created, click "modify app permissions" and set the app to read and write
|
|
64
|
-
0. wait a lil bit for permissions to change.......
|
|
65
|
-
0. click 'generate my access token'
|
|
66
|
-
0. wait a lil bit to get access tokens.....
|
|
67
|
-
0. SUCCESS! copy the access tokens down to a scratch txt file, but make sure not to commit it to source control/git/etc.! That would be bad because these things are secrets.
|
|
68
|
-
0. From the command line:
|
|
69
48
|
|
|
70
|
-
|
|
71
|
-
heroku create
|
|
72
|
-
heroku config:set TWITTER_CONSUMER_KEY=INSERT-YR-SECRETS-HERE
|
|
73
|
-
heroku config:set TWITTER_CONSUMER_SECRET=INSERT-YR-SECRETS-HERE
|
|
74
|
-
heroku config:set TWITTER_ACCESS_TOKEN=INSERT-YR-SECRETS-HERE
|
|
75
|
-
heroku config:set TWITTER_ACCESS_SECRET=INSERT-YR-SECRETS-HERE
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
0. go back to twitter.com and delete yr mobile phone from the bot account. you may also want to disable email notifications as well.
|
|
79
|
-
0. THE MAIN EVENT:
|
|
49
|
+
## Some bots made with this gem
|
|
80
50
|
|
|
81
|
-
|
|
82
|
-
git push heroku master
|
|
83
|
-
heroku ps:scale bot=1
|
|
84
|
-
```
|
|
51
|
+
Make a PR against this repo to add yrs!
|
|
85
52
|
|
|
86
|
-
|
|
53
|
+
[dada bot](https://github.com/coleww/dadabot) tweets simple things related to dadaism
|
|
87
54
|
|
|
88
|
-
|
|
55
|
+
[MiniTest::Warner](https://github.com/coleww/mini_test_warner_bot) tweets more complex phrases, it makes up fake deprecation warnings
|
|
89
56
|
|
|
90
|
-
|
|
57
|
+
[adams song bot](https://github.com/coleww/adams_song_bot) retweets tweets that match lyrics from adams song by blink 182
|
|
91
58
|
|
|
92
|
-
https://github.com/
|
|
59
|
+
[cole_bot](https://github.com/coleww/cole_bot) periodically posts to my personal twitter based on a markov chain made out of things i have tweeted/tumbled/etc.
|
|
93
60
|
|
|
94
|
-
|
|
61
|
+
## More Resources
|
|
95
62
|
|
|
96
|
-
https://github.com/
|
|
63
|
+
Check out the source and deployment notes for these generated [default](https://github.com/coleww/twitter_bot_generator/tree/master/such_test_bot), [streaming](https://github.com/coleww/twitter_bot_generator/tree/master/such_streaming_bot), and [userstream](https://github.com/coleww/twitter_bot_generator/tree/master/such_userstream_bot) example bots.
|
|
97
64
|
|
|
65
|
+
This gem was made for use in the twitter-art-robot-[tutorial](http://github.com/coleww/twitter-art-bot-tutorial) :dancers:
|
|
98
66
|
|
|
67
|
+
It uses [twitter gem by sferik](https://github.com/sferik/twitter) and sometimes [tweetstream](https://github.com/tweetstream/tweetstream) to connect to various parts of twitter, so you can check out their documentations/sources to find other secret tweeting tricks. The twitter api docs are also [...sometimes useful...](https://dev.twitter.com/overview/documentation).
|
|
99
68
|
|
|
100
69
|
## Contribute
|
|
101
70
|
|
|
102
71
|
all kinds of issues in the thing to the upper right! =>
|
|
103
72
|
comment on something if it sounds cool to u
|
|
104
|
-
|
|
105
|
-
To run ALLLLLL the tests:
|
|
106
|
-
|
|
107
|
-
bundle exec rake && bundle exec ruby test/generated_default_bot.rb && bundle exec ruby test/generated_streaming_bot.rb && bundle exec ruby test/generated_userstream_bot.rb
|
|
108
|
-
|
|
109
|
-
If someone could figure out how to get rake to run each of those things, but re-load the generated bot each time, but without changing the generated bot to use "load", that would be rad.
|
|
@@ -11,19 +11,21 @@ A Twitter Bot
|
|
|
11
11
|
|
|
12
12
|
Once your bot has been well tested on the command line you'll need to get it out into the world!
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
* You probably need git and the heroku toolbet installed and also a heroku account.
|
|
15
|
+
* Make a twitter account for your bot. Give it a photo and header and some biographical information
|
|
16
|
+
* Go into settings > mobile and add a cell phone number that you can send a text from.
|
|
17
17
|
not all carriers will work :(
|
|
18
18
|
without a mobile number, twitter won't let you get the api keys you need to deploy
|
|
19
19
|
if your mobile number is associated with your personal account, temporarily delete it from that account so you can use it for your bot. Twitter doesn't care.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
* go to apps.twitter.com and sign in again
|
|
21
|
+
* click create a new app
|
|
22
|
+
* fill in the details. just put down the github repo link or twitter page for the bot as website/callback url. no one will ever see this except you.
|
|
23
|
+
* once your app is created, click "modify app permissions" and set the app to read and write
|
|
24
|
+
* wait a lil bit for permissions to change.......
|
|
25
|
+
* click 'generate my access token'
|
|
26
|
+
* wait a lil bit to get access tokens.....
|
|
27
|
+
* SUCCESS! copy the access tokens down to a scratch txt file, but make sure not to commit it to source control/git/etc.! That would be bad because these things are secrets.
|
|
28
|
+
* From the command line:
|
|
27
29
|
|
|
28
30
|
```
|
|
29
31
|
heroku create
|
|
@@ -33,12 +35,12 @@ heroku config:set TWITTER_ACCESS_TOKEN=INSERT-YR-SECRETS-HERE
|
|
|
33
35
|
heroku config:set TWITTER_ACCESS_SECRET=INSERT-YR-SECRETS-HERE
|
|
34
36
|
```
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
* go back to twitter.com and delete yr mobile phone from the bot account. you may also want to disable email notifications as well.
|
|
39
|
+
* THE MAIN EVENT:
|
|
38
40
|
|
|
39
41
|
```
|
|
40
42
|
git push heroku master
|
|
41
43
|
heroku ps:scale bot=1
|
|
42
44
|
```
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
* go to your bot's page and you should see it's first tweet! Or something?
|
|
@@ -15,8 +15,8 @@ class <%= class_name %>
|
|
|
15
15
|
private
|
|
16
16
|
|
|
17
17
|
def load_txt_file file_name
|
|
18
|
-
home_sweet_home = File.expand_path File.dirname
|
|
19
|
-
ultimate_pathway = File.join home_sweet_home, '
|
|
18
|
+
home_sweet_home = File.expand_path File.dirname(File.dirname(__FILE__))
|
|
19
|
+
ultimate_pathway = File.join home_sweet_home, 'lib', file_name
|
|
20
20
|
(File.readlines ultimate_pathway).map &:strip
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -21,6 +21,10 @@ loop do
|
|
|
21
21
|
begin
|
|
22
22
|
puts "starting search"
|
|
23
23
|
TweetStream::Client.new.sample(language: 'en') do |tweet|
|
|
24
|
+
|
|
25
|
+
# your bot should have a method called matches?(text)
|
|
26
|
+
# if a tweet passes your matcher, the bot retweets it!
|
|
27
|
+
|
|
24
28
|
if <%= class_name %>.matches? tweet.text
|
|
25
29
|
puts "got one!"
|
|
26
30
|
Twitter.retweet tweet.id
|
|
@@ -9,6 +9,10 @@ class Test<%= class_name %> < MiniTest::Test
|
|
|
9
9
|
assert_match /Hello/, <%= class_name %>.generate
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def test_generate_returns_less_than_140
|
|
13
|
+
refute [*0...1000].map { |_| <%= class_name %>.generate }.any?{ |t| t.length > 140 }
|
|
14
|
+
end
|
|
15
|
+
|
|
12
16
|
def test_hides_greetings
|
|
13
17
|
refute_respond_to <%= class_name %>, :greetings
|
|
14
18
|
assert_instance_of String, <%= class_name %>.send(:greetings)[0]
|
|
@@ -9,4 +9,13 @@ class Test<%= class_name %> < MiniTest::Test
|
|
|
9
9
|
assert_match (<%= class_name %>.respond_to 'hello world'), 'dlrow olleh'
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def test_responds_with_less_than_140
|
|
13
|
+
assert_equal false, [*0...1000].map{ |_| <%= class_name %>.respond_to 'hello world' + rand.to_s }.any?{ |t| t.length > 140 }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_responds_with_less_than_140_even_to_greater_than_140
|
|
17
|
+
assert_equal false, [*0...1000].map { |_| <%= class_name %>.respond_to 'hello' * 30 }.any?{ |t| t.length > 140 }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
12
21
|
end
|
|
@@ -18,6 +18,9 @@ TweetStream.configure do |config|
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
TweetStream::Client.new.userstream do |tweet|
|
|
21
|
+
|
|
22
|
+
# your bot should have a method called respond_to(text)
|
|
23
|
+
# when someone tweets @ your bot, it will reply back!
|
|
21
24
|
puts "@#{tweet.user.screen_name} asks: #{tweet.text}"
|
|
22
25
|
begin
|
|
23
26
|
puts (answer = <%= class_name %>.respond_to tweet.text)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bot: ruby bot.rb
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# such_streaming_bot
|
|
2
|
+
A Twitter Bot
|
|
3
|
+
|
|
4
|
+
## Development
|
|
5
|
+
|
|
6
|
+
> bundle install
|
|
7
|
+
> ruby test.rb
|
|
8
|
+
> ruby spec.rb
|
|
9
|
+
|
|
10
|
+
## Deployment (heroku)
|
|
11
|
+
|
|
12
|
+
Once your bot has been well tested on the command line you'll need to get it out into the world!
|
|
13
|
+
|
|
14
|
+
* You probably need git and the heroku toolbet installed and also a heroku account.
|
|
15
|
+
* Make a twitter account for your bot. Give it a photo and header and some biographical information
|
|
16
|
+
* Go into settings > mobile and add a cell phone number that you can send a text from.
|
|
17
|
+
not all carriers will work :(
|
|
18
|
+
without a mobile number, twitter won't let you get the api keys you need to deploy
|
|
19
|
+
if your mobile number is associated with your personal account, temporarily delete it from that account so you can use it for your bot. Twitter doesn't care.
|
|
20
|
+
* go to apps.twitter.com and sign in again
|
|
21
|
+
* click create a new app
|
|
22
|
+
* fill in the details. just put down the github repo link or twitter page for the bot as website/callback url. no one will ever see this except you.
|
|
23
|
+
* once your app is created, click "modify app permissions" and set the app to read and write
|
|
24
|
+
* wait a lil bit for permissions to change.......
|
|
25
|
+
* click 'generate my access token'
|
|
26
|
+
* wait a lil bit to get access tokens.....
|
|
27
|
+
* SUCCESS! copy the access tokens down to a scratch txt file, but make sure not to commit it to source control/git/etc.! That would be bad because these things are secrets.
|
|
28
|
+
* From the command line:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
heroku create
|
|
32
|
+
heroku config:set TWITTER_CONSUMER_KEY=INSERT-YR-SECRETS-HERE
|
|
33
|
+
heroku config:set TWITTER_CONSUMER_SECRET=INSERT-YR-SECRETS-HERE
|
|
34
|
+
heroku config:set TWITTER_ACCESS_TOKEN=INSERT-YR-SECRETS-HERE
|
|
35
|
+
heroku config:set TWITTER_ACCESS_SECRET=INSERT-YR-SECRETS-HERE
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
* go back to twitter.com and delete yr mobile phone from the bot account. you may also want to disable email notifications as well.
|
|
39
|
+
* THE MAIN EVENT:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
git push heroku master
|
|
43
|
+
heroku ps:scale bot=1
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
* go to your bot's page and you should see it's first tweet! Or something?
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require_relative 'src/such_streaming_bot.rb'
|
|
2
|
+
require "twitter"
|
|
3
|
+
require "tweetstream"
|
|
4
|
+
|
|
5
|
+
Twitter.configure do |config|
|
|
6
|
+
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
|
|
7
|
+
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
|
|
8
|
+
config.oauth_token = ENV['TWITTER_OAUTH_TOKEN']
|
|
9
|
+
config.oauth_token_secret = ENV['TWITTER_OAUTH_SECRET']
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
TweetStream.configure do |config|
|
|
13
|
+
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
|
|
14
|
+
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
|
|
15
|
+
config.oauth_token = ENV['TWITTER_OAUTH_TOKEN']
|
|
16
|
+
config.oauth_token_secret = ENV['TWITTER_OAUTH_SECRET']
|
|
17
|
+
config.auth_method = :oauth
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
loop do
|
|
21
|
+
begin
|
|
22
|
+
puts "starting search"
|
|
23
|
+
TweetStream::Client.new.sample(language: 'en') do |tweet|
|
|
24
|
+
|
|
25
|
+
# your bot should have a method called matches?(text)
|
|
26
|
+
# if a tweet passes your matcher, the bot retweets it!
|
|
27
|
+
|
|
28
|
+
if SuchStreamingBot.matches? tweet.text
|
|
29
|
+
puts "got one!"
|
|
30
|
+
Twitter.retweet tweet.id
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
rescue
|
|
34
|
+
puts 'FAILURE'
|
|
35
|
+
ensure
|
|
36
|
+
sleep 300
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative 'src/such_streaming_bot'
|
|
3
|
+
|
|
4
|
+
puts "hello world! ?"
|
|
5
|
+
puts SuchStreamingBot.matches? "hello world!"
|
|
6
|
+
puts "hello canada! ?"
|
|
7
|
+
puts SuchStreamingBot.matches? "hello canada!"
|
|
8
|
+
puts "replace this with meaningful example strings to test yr app!"
|
|
9
|
+
puts SuchStreamingBot.matches? "replace this with meaningful example strings to test yr app!"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require 'minitest/pride'
|
|
3
|
+
|
|
4
|
+
require_relative '../src/such_streaming_bot.rb'
|
|
5
|
+
|
|
6
|
+
class TestSuchStreamingBot < MiniTest::Test
|
|
7
|
+
|
|
8
|
+
def test_matches_hello_world
|
|
9
|
+
assert_equal true, (SuchStreamingBot.matches? 'hello world')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_doesnt_match_hello_canada
|
|
13
|
+
assert_equal false, (SuchStreamingBot.matches? 'hello canada')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
data/such_test_bot/Gemfile
CHANGED
data/such_test_bot/README.md
CHANGED
|
@@ -11,19 +11,21 @@ A Twitter Bot
|
|
|
11
11
|
|
|
12
12
|
Once your bot has been well tested on the command line you'll need to get it out into the world!
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
* You probably need git and the heroku toolbet installed and also a heroku account.
|
|
15
|
+
* Make a twitter account for your bot. Give it a photo and header and some biographical information
|
|
16
|
+
* Go into settings > mobile and add a cell phone number that you can send a text from.
|
|
17
17
|
not all carriers will work :(
|
|
18
18
|
without a mobile number, twitter won't let you get the api keys you need to deploy
|
|
19
19
|
if your mobile number is associated with your personal account, temporarily delete it from that account so you can use it for your bot. Twitter doesn't care.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
* go to apps.twitter.com and sign in again
|
|
21
|
+
* click create a new app
|
|
22
|
+
* fill in the details. just put down the github repo link or twitter page for the bot as website/callback url. no one will ever see this except you.
|
|
23
|
+
* once your app is created, click "modify app permissions" and set the app to read and write
|
|
24
|
+
* wait a lil bit for permissions to change.......
|
|
25
|
+
* click 'generate my access token'
|
|
26
|
+
* wait a lil bit to get access tokens.....
|
|
27
|
+
* SUCCESS! copy the access tokens down to a scratch txt file, but make sure not to commit it to source control/git/etc.! That would be bad because these things are secrets.
|
|
28
|
+
* From the command line:
|
|
27
29
|
|
|
28
30
|
```
|
|
29
31
|
heroku create
|
|
@@ -33,12 +35,12 @@ heroku config:set TWITTER_ACCESS_TOKEN=INSERT-YR-SECRETS-HERE
|
|
|
33
35
|
heroku config:set TWITTER_ACCESS_SECRET=INSERT-YR-SECRETS-HERE
|
|
34
36
|
```
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
* go back to twitter.com and delete yr mobile phone from the bot account. you may also want to disable email notifications as well.
|
|
39
|
+
* THE MAIN EVENT:
|
|
38
40
|
|
|
39
41
|
```
|
|
40
42
|
git push heroku master
|
|
41
43
|
heroku ps:scale bot=1
|
|
42
44
|
```
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
* go to your bot's page and you should see it's first tweet! Or something?
|
|
@@ -15,8 +15,8 @@ class SuchTestBot
|
|
|
15
15
|
private
|
|
16
16
|
|
|
17
17
|
def load_txt_file file_name
|
|
18
|
-
home_sweet_home = File.expand_path File.dirname
|
|
19
|
-
ultimate_pathway = File.join home_sweet_home, '
|
|
18
|
+
home_sweet_home = File.expand_path File.dirname(File.dirname(__FILE__))
|
|
19
|
+
ultimate_pathway = File.join home_sweet_home, 'lib', file_name
|
|
20
20
|
(File.readlines ultimate_pathway).map &:strip
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -9,6 +9,10 @@ class TestSuchTestBot < MiniTest::Test
|
|
|
9
9
|
assert_match /Hello/, SuchTestBot.generate
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def test_generate_returns_less_than_140
|
|
13
|
+
refute [*0...1000].map { |_| SuchTestBot.generate }.any?{ |t| t.length > 140 }
|
|
14
|
+
end
|
|
15
|
+
|
|
12
16
|
def test_hides_greetings
|
|
13
17
|
refute_respond_to SuchTestBot, :greetings
|
|
14
18
|
assert_instance_of String, SuchTestBot.send(:greetings)[0]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bot: ruby bot.rb
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# such_userstream_bot
|
|
2
|
+
A Twitter Bot
|
|
3
|
+
|
|
4
|
+
## Development
|
|
5
|
+
|
|
6
|
+
> bundle install
|
|
7
|
+
> ruby test.rb
|
|
8
|
+
> ruby spec.rb
|
|
9
|
+
|
|
10
|
+
## Deployment (heroku)
|
|
11
|
+
|
|
12
|
+
Once your bot has been well tested on the command line you'll need to get it out into the world!
|
|
13
|
+
|
|
14
|
+
* You probably need git and the heroku toolbet installed and also a heroku account.
|
|
15
|
+
* Make a twitter account for your bot. Give it a photo and header and some biographical information
|
|
16
|
+
* Go into settings > mobile and add a cell phone number that you can send a text from.
|
|
17
|
+
not all carriers will work :(
|
|
18
|
+
without a mobile number, twitter won't let you get the api keys you need to deploy
|
|
19
|
+
if your mobile number is associated with your personal account, temporarily delete it from that account so you can use it for your bot. Twitter doesn't care.
|
|
20
|
+
* go to apps.twitter.com and sign in again
|
|
21
|
+
* click create a new app
|
|
22
|
+
* fill in the details. just put down the github repo link or twitter page for the bot as website/callback url. no one will ever see this except you.
|
|
23
|
+
* once your app is created, click "modify app permissions" and set the app to read and write
|
|
24
|
+
* wait a lil bit for permissions to change.......
|
|
25
|
+
* click 'generate my access token'
|
|
26
|
+
* wait a lil bit to get access tokens.....
|
|
27
|
+
* SUCCESS! copy the access tokens down to a scratch txt file, but make sure not to commit it to source control/git/etc.! That would be bad because these things are secrets.
|
|
28
|
+
* From the command line:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
heroku create
|
|
32
|
+
heroku config:set TWITTER_CONSUMER_KEY=INSERT-YR-SECRETS-HERE
|
|
33
|
+
heroku config:set TWITTER_CONSUMER_SECRET=INSERT-YR-SECRETS-HERE
|
|
34
|
+
heroku config:set TWITTER_ACCESS_TOKEN=INSERT-YR-SECRETS-HERE
|
|
35
|
+
heroku config:set TWITTER_ACCESS_SECRET=INSERT-YR-SECRETS-HERE
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
* go back to twitter.com and delete yr mobile phone from the bot account. you may also want to disable email notifications as well.
|
|
39
|
+
* THE MAIN EVENT:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
git push heroku master
|
|
43
|
+
heroku ps:scale bot=1
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
* go to your bot's page and you should see it's first tweet! Or something?
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require_relative 'src/such_userstream_bot.rb'
|
|
2
|
+
require "twitter"
|
|
3
|
+
require "tweetstream"
|
|
4
|
+
|
|
5
|
+
Twitter.configure do |config|
|
|
6
|
+
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
|
|
7
|
+
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
|
|
8
|
+
config.oauth_token = ENV['TWITTER_OAUTH_TOKEN']
|
|
9
|
+
config.oauth_token_secret = ENV['TWITTER_OAUTH_SECRET']
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
TweetStream.configure do |config|
|
|
13
|
+
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
|
|
14
|
+
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
|
|
15
|
+
config.oauth_token = ENV['TWITTER_OAUTH_TOKEN']
|
|
16
|
+
config.oauth_token_secret = ENV['TWITTER_OAUTH_SECRET']
|
|
17
|
+
config.auth_method = :oauth
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
TweetStream::Client.new.userstream do |tweet|
|
|
21
|
+
|
|
22
|
+
# your bot should have a method called respond_to(text)
|
|
23
|
+
# when someone tweets @ your bot, it will reply back!
|
|
24
|
+
puts "@#{tweet.user.screen_name} asks: #{tweet.text}"
|
|
25
|
+
begin
|
|
26
|
+
puts (answer = SuchUserstreamBot.respond_to tweet.text)
|
|
27
|
+
Twitter.update(answer, :in_reply_to_status_id => tweet.id)
|
|
28
|
+
rescue => e
|
|
29
|
+
puts e
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative 'src/such_userstream_bot'
|
|
3
|
+
|
|
4
|
+
puts "hello world! ?"
|
|
5
|
+
puts SuchUserstreamBot.respond_to "hello world!"
|
|
6
|
+
puts "hello applesauce! ?"
|
|
7
|
+
puts SuchUserstreamBot.respond_to "hello applesauce!"
|
|
8
|
+
puts "replace this with meaningful example strings to test yr app!"
|
|
9
|
+
puts SuchUserstreamBot.respond_to "replace this with meaningful example strings to test yr app!"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require 'minitest/pride'
|
|
3
|
+
|
|
4
|
+
require_relative '../src/such_userstream_bot.rb'
|
|
5
|
+
|
|
6
|
+
class TestSuchUserstreamBot < MiniTest::Test
|
|
7
|
+
|
|
8
|
+
def test_reverses_hello_world
|
|
9
|
+
assert_match (SuchUserstreamBot.respond_to 'hello world'), 'dlrow olleh'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_responds_with_less_than_140
|
|
13
|
+
assert_equal false, [*0...1000].map{ |_| SuchUserstreamBot.respond_to 'hello world' + rand.to_s }.any?{ |t| t.length > 140 }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_responds_with_less_than_140_even_to_greater_than_140
|
|
17
|
+
assert_equal false, [*0...1000].map { |_| SuchUserstreamBot.respond_to 'hello' * 30 }.any?{ |t| t.length > 140 }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require_relative 'test_helper'
|
|
2
|
+
|
|
3
|
+
wipe_such_test_bot! 'streaming'
|
|
4
|
+
TwitterBotGenerator.generate 'such_streaming_bot', '--streaming'
|
|
5
|
+
|
|
6
|
+
puts 'Running the test suite for the generated STREAMING bot'
|
|
7
|
+
Dir.chdir('such_streaming_bot')
|
|
8
|
+
puts load '../such_streaming_bot/test/such_streaming_bot_test.rb'
|
|
9
|
+
Dir.chdir('..')
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require_relative 'test_helper'
|
|
2
|
+
|
|
3
|
+
wipe_such_test_bot! 'userstream'
|
|
4
|
+
TwitterBotGenerator.generate 'such_userstream_bot', '--userstream'
|
|
5
|
+
|
|
6
|
+
puts 'Running the test suite for the generated USERSTREAM bot'
|
|
7
|
+
Dir.chdir('such_userstream_bot')
|
|
8
|
+
puts load '../such_userstream_bot/test/such_userstream_bot_test.rb'
|
|
9
|
+
Dir.chdir('..')
|
data/test/test_helper.rb
CHANGED
|
@@ -5,27 +5,21 @@ Coveralls.wear!
|
|
|
5
5
|
|
|
6
6
|
require_relative "../lib/twitter_bot_generator.rb"
|
|
7
7
|
|
|
8
|
-
def wipe_such_test_bot!
|
|
9
|
-
[
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
def wipe_such_test_bot! type='test'
|
|
9
|
+
["./such_#{type}_bot/Gemfile",
|
|
10
|
+
"./such_#{type}_bot/README.md",
|
|
11
|
+
"./such_#{type}_bot/test.rb",
|
|
12
|
+
"./such_#{type}_bot/Procfile",
|
|
13
|
+
"./such_#{type}_bot/bot.rb",
|
|
14
|
+
"./such_#{type}_bot/spec.rb",
|
|
15
|
+
"./such_#{type}_bot/test/such_#{type}_bot_test.rb",
|
|
16
|
+
"./such_#{type}_bot/lib/greetings.txt",
|
|
17
|
+
"./such_#{type}_bot/src/such_#{type}_bot.rb",
|
|
18
|
+
"./such_#{type}_bot/.gitignore"].each { |file| File.unlink file if File.exists? file }
|
|
19
19
|
|
|
20
|
-
[
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
["./such_#{type}_bot/lib",
|
|
21
|
+
"./such_#{type}_bot/src",
|
|
22
|
+
"./such_#{type}_bot/test",
|
|
23
|
+
"./such_#{type}_bot"].each { |dir| Dir.rmdir dir if Dir.exists? dir}
|
|
24
24
|
true
|
|
25
25
|
end
|
|
26
|
-
|
|
27
|
-
Minitest.after_run do
|
|
28
|
-
# leave behind a default scaffold ALWAYS
|
|
29
|
-
wipe_such_test_bot!
|
|
30
|
-
TwitterBotGenerator.generate 'such_test_bot'
|
|
31
|
-
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: twitter_bot_generator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cole Willsea
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-09-
|
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -131,6 +131,16 @@ files:
|
|
|
131
131
|
- lib/twitter_bot_generator/templates/userstream-bot.rb.erb
|
|
132
132
|
- lib/twitter_bot_generator/templates/userstream-spec.rb.erb
|
|
133
133
|
- lib/twitter_bot_generator/version.rb
|
|
134
|
+
- such_streaming_bot/.gitignore
|
|
135
|
+
- such_streaming_bot/Gemfile
|
|
136
|
+
- such_streaming_bot/Procfile
|
|
137
|
+
- such_streaming_bot/README.md
|
|
138
|
+
- such_streaming_bot/bot.rb
|
|
139
|
+
- such_streaming_bot/lib/greetings.txt
|
|
140
|
+
- such_streaming_bot/spec.rb
|
|
141
|
+
- such_streaming_bot/src/such_streaming_bot.rb
|
|
142
|
+
- such_streaming_bot/test.rb
|
|
143
|
+
- such_streaming_bot/test/such_streaming_bot_test.rb
|
|
134
144
|
- such_test_bot/.gitignore
|
|
135
145
|
- such_test_bot/Gemfile
|
|
136
146
|
- such_test_bot/Procfile
|
|
@@ -141,9 +151,19 @@ files:
|
|
|
141
151
|
- such_test_bot/src/such_test_bot.rb
|
|
142
152
|
- such_test_bot/test.rb
|
|
143
153
|
- such_test_bot/test/such_test_bot_test.rb
|
|
144
|
-
-
|
|
145
|
-
-
|
|
146
|
-
-
|
|
154
|
+
- such_userstream_bot/.gitignore
|
|
155
|
+
- such_userstream_bot/Gemfile
|
|
156
|
+
- such_userstream_bot/Procfile
|
|
157
|
+
- such_userstream_bot/README.md
|
|
158
|
+
- such_userstream_bot/bot.rb
|
|
159
|
+
- such_userstream_bot/lib/greetings.txt
|
|
160
|
+
- such_userstream_bot/spec.rb
|
|
161
|
+
- such_userstream_bot/src/such_userstream_bot.rb
|
|
162
|
+
- such_userstream_bot/test.rb
|
|
163
|
+
- such_userstream_bot/test/such_userstream_bot_test.rb
|
|
164
|
+
- test/generated_default_bot_test.rb
|
|
165
|
+
- test/generated_streaming_bot_test.rb
|
|
166
|
+
- test/generated_userstream_bot_test.rb
|
|
147
167
|
- test/scaffold_generator_test.rb
|
|
148
168
|
- test/test_helper.rb
|
|
149
169
|
- twitter_bot_generator.gemspec
|
|
@@ -172,8 +192,8 @@ signing_key:
|
|
|
172
192
|
specification_version: 4
|
|
173
193
|
summary: Generates a twitter bot template from command line.
|
|
174
194
|
test_files:
|
|
175
|
-
- test/
|
|
176
|
-
- test/
|
|
177
|
-
- test/
|
|
195
|
+
- test/generated_default_bot_test.rb
|
|
196
|
+
- test/generated_streaming_bot_test.rb
|
|
197
|
+
- test/generated_userstream_bot_test.rb
|
|
178
198
|
- test/scaffold_generator_test.rb
|
|
179
199
|
- test/test_helper.rb
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
require_relative 'test_helper'
|
|
2
|
-
|
|
3
|
-
wipe_such_test_bot!
|
|
4
|
-
TwitterBotGenerator.generate 'such_test_bot', '--streaming'
|
|
5
|
-
|
|
6
|
-
puts 'Running the test suite for the generated STREAMING bot'
|
|
7
|
-
Dir.chdir('such_test_bot')
|
|
8
|
-
puts load '../such_test_bot/test/such_test_bot_test.rb'
|
|
9
|
-
Dir.chdir('..')
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
require_relative 'test_helper'
|
|
2
|
-
|
|
3
|
-
wipe_such_test_bot!
|
|
4
|
-
TwitterBotGenerator.generate 'such_test_bot', '--userstream'
|
|
5
|
-
|
|
6
|
-
puts 'Running the test suite for the generated USERSTREAM bot'
|
|
7
|
-
Dir.chdir('such_test_bot')
|
|
8
|
-
puts load '../such_test_bot/test/such_test_bot_test.rb'
|
|
9
|
-
Dir.chdir('..')
|