tweetbot 0.3.0 → 0.4.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a6ab5c2bf564c197097ea54e74b9bfcb0e38830e0c5b3d4f67f2078f42597d6b
4
+ data.tar.gz: 3ec3eb9860118068290dd03bef1d022b9df099c329c4084ea4841120857e1efb
5
+ SHA512:
6
+ metadata.gz: 24f9a5b02e08e9d3b0b4f2e9331ed7e99b0cecf05a41d2d4868aef29006deee34830237a26064a519ccc673adfc5f4f71f7ec966ce55b68753f4a3018dbafa09
7
+ data.tar.gz: 1b6b5396717edc8e37d8ab86884194ae4a24a635a180b56da56ac3f4849584e2dbbd76d505fe574d347ba160d16e96ad9c0bb7f3c0b671fe817f5360ac37ce89
data/.gitignore CHANGED
@@ -1,4 +1 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
1
+ lib/test.rb
data/.rspec CHANGED
@@ -1 +1,3 @@
1
+ --format documentation
1
2
  --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ tweetbot
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at coreyhaines@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
+
3
+ ruby '2.7.0'
2
4
 
3
5
  # Specify your gem's dependencies in tweetbot.gemspec
4
6
  gemspec
7
+
8
+ gem "rake", "~> 12.0"
9
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tweetbot (0.4.0)
5
+ twitter
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ buftok (0.2.0)
13
+ diff-lcs (1.3)
14
+ domain_name (0.5.20190701)
15
+ unf (>= 0.0.5, < 1.0.0)
16
+ equalizer (0.0.11)
17
+ ffi (1.12.2)
18
+ ffi-compiler (1.0.1)
19
+ ffi (>= 1.0.0)
20
+ rake
21
+ http (4.4.0)
22
+ addressable (~> 2.3)
23
+ http-cookie (~> 1.0)
24
+ http-form_data (~> 2.2)
25
+ http-parser (~> 1.2.0)
26
+ http-cookie (1.0.3)
27
+ domain_name (~> 0.5)
28
+ http-form_data (2.3.0)
29
+ http-parser (1.2.1)
30
+ ffi-compiler (>= 1.0, < 2.0)
31
+ http_parser.rb (0.6.0)
32
+ memoizable (0.4.2)
33
+ thread_safe (~> 0.3, >= 0.3.1)
34
+ multipart-post (2.1.1)
35
+ naught (1.1.0)
36
+ public_suffix (4.0.3)
37
+ rake (12.3.3)
38
+ rspec (3.9.0)
39
+ rspec-core (~> 3.9.0)
40
+ rspec-expectations (~> 3.9.0)
41
+ rspec-mocks (~> 3.9.0)
42
+ rspec-core (3.9.1)
43
+ rspec-support (~> 3.9.1)
44
+ rspec-expectations (3.9.1)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.9.0)
47
+ rspec-mocks (3.9.1)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.9.0)
50
+ rspec-support (3.9.2)
51
+ simple_oauth (0.3.1)
52
+ thread_safe (0.3.6)
53
+ twitter (7.0.0)
54
+ addressable (~> 2.3)
55
+ buftok (~> 0.2.0)
56
+ equalizer (~> 0.0.11)
57
+ http (~> 4.0)
58
+ http-form_data (~> 2.0)
59
+ http_parser.rb (~> 0.6.0)
60
+ memoizable (~> 0.4.0)
61
+ multipart-post (~> 2.0)
62
+ naught (~> 1.0)
63
+ simple_oauth (~> 0.3.0)
64
+ unf (0.1.4)
65
+ unf_ext
66
+ unf_ext (0.0.7.6)
67
+
68
+ PLATFORMS
69
+ ruby
70
+
71
+ DEPENDENCIES
72
+ rake (~> 12.0)
73
+ rspec (~> 3.0)
74
+ tweetbot!
75
+
76
+ RUBY VERSION
77
+ ruby 2.7.0p0
78
+
79
+ BUNDLED WITH
80
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Corey Haines
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,120 @@
1
+ # Tweetbot
2
+
3
+ So you want to write a twitter bot. Use my gem. Then, you can just do this:
4
+
5
+ ```ruby
6
+ load 'twitter_auth.rb'
7
+ require 'tweetbot'
8
+
9
+ bot = TweetBot.configure do |config|
10
+ config.response_frequency = 100
11
+
12
+ config.respond_to_phrase "tweetbot example phrase" do |responses|
13
+ responses << "I am tweetbot!" << "You rang?" << "Pretty cool, thanks for saying hello"
14
+ end
15
+
16
+ config.respond_to_phrase "hey @tweetbot" do |responses|
17
+ responses << "Hey back at ya" << "You rang again?"
18
+ end
19
+
20
+ config.twitter_auth = TwitterAuth::AuthKeys
21
+ end
22
+
23
+ bot.talk
24
+ ```
25
+
26
+ and build a file called twitter_auth.rb that has your keys
27
+
28
+ ```
29
+ module TwitterAuth
30
+ MyName = 'twitter_name'
31
+ ApigeeEnpoint = nil
32
+ def self.use_apigee?
33
+ !ApigeeEnpoint.nil?
34
+ end
35
+ AuthKeys = {
36
+ consumer_key: "key",
37
+ consumer_secret: "secret",
38
+ oauth_token: "token",
39
+ oauth_token_secret: "token_secret"
40
+ }
41
+ end
42
+ ```
43
+
44
+ ## Installation
45
+
46
+ Add this line to your application's Gemfile:
47
+
48
+ ```ruby
49
+ gem 'tweetbot'
50
+ ```
51
+
52
+ And then execute:
53
+
54
+ $ bundle install
55
+
56
+ Or install it yourself as:
57
+
58
+ $ gem install tweetbot
59
+
60
+ ## Usage
61
+
62
+ So you want to write a twitter bot. Use my gem. Then, you can just do this:
63
+
64
+ ```ruby
65
+ load 'twitter_auth.rb'
66
+ require 'tweetbot'
67
+
68
+ bot = TweetBot.configure do |config|
69
+ config.response_frequency = 100
70
+
71
+ config.respond_to_phrase "tweetbot example phrase" do |responses|
72
+ responses << "I am tweetbot!" << "You rang?" << "Pretty cool, thanks for saying hello"
73
+ end
74
+
75
+ config.respond_to_phrase "hey @tweetbot" do |responses|
76
+ responses << "Hey back at ya" << "You rang again?"
77
+ end
78
+
79
+ config.twitter_auth = TwitterAuth::AuthKeys
80
+ end
81
+
82
+ bot.talk
83
+ ```
84
+
85
+ and build a file called twitter_auth.rb that has your keys
86
+
87
+ ```
88
+ module TwitterAuth
89
+ MyName = 'twitter_name'
90
+ ApigeeEnpoint = nil
91
+ def self.use_apigee?
92
+ !ApigeeEnpoint.nil?
93
+ end
94
+ AuthKeys = {
95
+ consumer_key: "key",
96
+ consumer_secret: "secret",
97
+ oauth_token: "token",
98
+ oauth_token_secret: "token_secret"
99
+ }
100
+ end
101
+ ```
102
+
103
+ ## Development
104
+
105
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
106
+
107
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
108
+
109
+ ## Contributing
110
+
111
+ Bug reports and pull requests are welcome on GitHub at https://github.com/coreyhaines/tweetbot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/tweetbot/blob/master/CODE_OF_CONDUCT.md).
112
+
113
+
114
+ ## License
115
+
116
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
117
+
118
+ ## Code of Conduct
119
+
120
+ Everyone interacting in the Tweetbot project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tweetbot/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tweetbot"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -50,8 +50,16 @@ module TweetBot
50
50
  return false
51
51
  end
52
52
  matches = tweet_matches?(tweet)
53
+ unless matches
54
+ puts "Tweet does not match"
55
+ return false
56
+ end
53
57
  frequency_check = (rand(100) < self.response_frequency)
54
- matches && frequency_check
58
+ unless frequency_check
59
+ puts "Frequency check failed"
60
+ return false
61
+ end
62
+ true
55
63
  end
56
64
 
57
65
  def rate_limited!
@@ -1,5 +1,4 @@
1
1
  require 'twitter'
2
- require 'tweetstream'
3
2
 
4
3
  if ENV["DEBUG"]
5
4
  module Twitter
@@ -13,52 +12,35 @@ if ENV["DEBUG"]
13
12
  end
14
13
  module TweetBot
15
14
  module Talk
16
- def configure_twitter_auth
17
- Twitter.configure do |config|
15
+ def configure_streaming_twitter
16
+ Twitter::Streaming::Client.new do |config|
18
17
  config.consumer_key = twitter_auth[:consumer_key]
19
18
  config.consumer_secret = twitter_auth[:consumer_secret]
20
- config.oauth_token = twitter_auth[:oauth_token]
21
- config.oauth_token_secret = twitter_auth[:oauth_token_secret]
19
+ config.access_token = twitter_auth[:access_token]
20
+ config.access_token_secret = twitter_auth[:access_token_secret]
22
21
  end
23
- TweetStream.configure do |config|
22
+ end
23
+
24
+ def configure_rest_twitter_client
25
+ Twitter::REST::Client.new do |config|
24
26
  config.consumer_key = twitter_auth[:consumer_key]
25
27
  config.consumer_secret = twitter_auth[:consumer_secret]
26
- config.oauth_token = twitter_auth[:oauth_token]
27
- config.oauth_token_secret = twitter_auth[:oauth_token_secret]
28
- config.auth_method = :oauth
28
+ config.access_token = twitter_auth[:access_token]
29
+ config.access_token_secret = twitter_auth[:access_token_secret]
29
30
  end
30
31
  end
31
32
 
32
33
  def talk
33
- configure_twitter_auth
34
-
35
- if TwitterAuth.use_apigee?
36
- twitter_api_endpoint = if ENV['APIGEE_TWITTER_API_ENDPOINT']
37
- ENV['APIGEE_TWITTER_API_ENDPOINT']
38
- else
39
- # Get this value from Heroku.
40
- # Once you have enabled the addon, boot up the 'heroku console' and run the following:
41
- # puts ENV['APIGEE_TWITTER_API_ENDPOINT']
42
- # this will spit out your correct api endpoint
43
- TwitterAuth::ApigeeEnpoint
44
- end
45
- Twitter.configure do |config|
46
- config.gateway = twitter_api_endpoint
47
- end
48
- end
34
+ client = configure_streaming_twitter
49
35
 
50
36
  bot = self
51
37
 
52
38
  announce_wake_up
53
39
  puts "Listening... #{Time.now}"
54
40
 
55
-
56
- client = TweetStream::Client.new
57
-
58
- ["INT", "TERM", "STOP"].each do |signal|
41
+ ["INT", "TERM"].each do |signal|
59
42
  trap(signal) do
60
43
  puts "Got #{signal}"
61
- client.stop
62
44
  exit!(1)
63
45
  end
64
46
  end
@@ -72,14 +54,9 @@ module TweetBot
72
54
  end
73
55
 
74
56
 
75
- client.on_error do |message|
76
- puts "Error: #{Time.now}"
77
- puts message
78
- end
79
57
 
80
- #EM.defer
81
- #EM::HttpRequest
82
- client.track(*bot.phrases_to_search) do |status|
58
+ client.filter(track: bot.phrases_to_search.join(",")) do |status|
59
+ puts status.text if status.is_a?(Twitter::Tweet)
83
60
  if status.user.screen_name.downcase == TwitterAuth::MyName.downcase
84
61
  puts "#{Time.now} Caught myself saying it"
85
62
  else
@@ -110,12 +87,13 @@ module TweetBot
110
87
  end
111
88
 
112
89
  def send_twitter_message(message, options = {})
113
- Twitter.update message, options
90
+ client = configure_rest_twitter_client
91
+ client.update message, options
114
92
  end
115
93
 
116
94
  def announce_wake_up
117
95
  puts "Waking up to greet the world... #{Time.now}"
118
- # send_twitter_message "Waking up to greet the world... #{Time.now}"
96
+ send_twitter_message "Waking up to greet the world... #{Time.now}"
119
97
  rescue Twitter::Error::Forbidden => ex
120
98
  puts "Twitter Forbidden Error while waking up"
121
99
  puts ex
@@ -1,3 +1,3 @@
1
1
  module Tweetbot
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,26 +1,28 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "tweetbot/version"
1
+ require_relative 'lib/tweetbot/version'
4
2
 
5
- Gem::Specification.new do |s|
6
- s.name = "tweetbot"
7
- s.version = Tweetbot::VERSION
8
- s.authors = ["coreyhaines"]
9
- s.email = ["coreyhaines@gmail.com"]
10
- s.homepage = ""
11
- s.summary = %q{Tweetbot makes writing twitter bots twivial!}
12
- s.description = %q{Using tweetbot, you can easily create twitter bots that respond to key phrases that people say on the twitters}
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "tweetbot"
5
+ spec.version = Tweetbot::VERSION
6
+ spec.authors = ["Corey Haines"]
7
+ spec.email = ["coreyhaines@gmail.com"]
13
8
 
14
- s.rubyforge_project = "tweetbot"
9
+ spec.summary = %q{Tweetbot makes writing twitter bots twivial!}
10
+ spec.description = %q{Using tweetbot, you can easily create twitter bots that respond to key phrases that people say on the twitters}
11
+ spec.homepage = "https://github.com/coreyhaines/tweetbot"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
15
14
 
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/coreyhaines/tweetbot"
20
17
 
21
- # specify any dependencies here; for example:
22
- s.add_development_dependency "rspec"
23
- s.add_development_dependency "timecop"
24
- s.add_runtime_dependency "twitter"
25
- s.add_runtime_dependency "tweetstream"
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_runtime_dependency "twitter", "~> 7.0"
26
28
  end
metadata CHANGED
@@ -1,60 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweetbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
- - coreyhaines
7
+ - Corey Haines
9
8
  autorequire:
10
- bindir: bin
9
+ bindir: exe
11
10
  cert_chain: []
12
- date: 2011-12-19 00:00:00.000000000Z
11
+ date: 2020-03-25 00:00:00.000000000 Z
13
12
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &2152535260 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: *2152535260
25
- - !ruby/object:Gem::Dependency
26
- name: timecop
27
- requirement: &2152534840 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *2152534840
36
13
  - !ruby/object:Gem::Dependency
37
14
  name: twitter
38
- requirement: &2152534400 !ruby/object:Gem::Requirement
39
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
40
16
  requirements:
41
- - - ! '>='
17
+ - - "~>"
42
18
  - !ruby/object:Gem::Version
43
- version: '0'
19
+ version: '7.0'
44
20
  type: :runtime
45
21
  prerelease: false
46
- version_requirements: *2152534400
47
- - !ruby/object:Gem::Dependency
48
- name: tweetstream
49
- requirement: &2152533940 !ruby/object:Gem::Requirement
50
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
51
23
  requirements:
52
- - - ! '>='
24
+ - - "~>"
53
25
  - !ruby/object:Gem::Version
54
- version: '0'
55
- type: :runtime
56
- prerelease: false
57
- version_requirements: *2152533940
26
+ version: '7.0'
58
27
  description: Using tweetbot, you can easily create twitter bots that respond to key
59
28
  phrases that people say on the twitters
60
29
  email:
@@ -63,45 +32,46 @@ executables: []
63
32
  extensions: []
64
33
  extra_rdoc_files: []
65
34
  files:
66
- - .gitignore
67
- - .rspec
68
- - .rvmrc
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".ruby-gemset"
38
+ - ".travis.yml"
39
+ - CODE_OF_CONDUCT.md
69
40
  - Gemfile
70
- - README
41
+ - Gemfile.lock
42
+ - LICENSE.txt
43
+ - README.md
71
44
  - Rakefile
72
- - example/run_bot.rb
73
- - example/twitter_auth.rb
45
+ - bin/console
46
+ - bin/setup
74
47
  - lib/tweetbot.rb
75
48
  - lib/tweetbot/bot.rb
76
49
  - lib/tweetbot/talk.rb
77
50
  - lib/tweetbot/version.rb
78
- - spec/tweetbot_config_spec.rb
79
- - spec/tweetbot_spec.rb
80
51
  - tweetbot.gemspec
81
- homepage: ''
82
- licenses: []
52
+ homepage: https://github.com/coreyhaines/tweetbot
53
+ licenses:
54
+ - MIT
55
+ metadata:
56
+ homepage_uri: https://github.com/coreyhaines/tweetbot
57
+ source_code_uri: https://github.com/coreyhaines/tweetbot
83
58
  post_install_message:
84
59
  rdoc_options: []
85
60
  require_paths:
86
61
  - lib
87
62
  required_ruby_version: !ruby/object:Gem::Requirement
88
- none: false
89
63
  requirements:
90
- - - ! '>='
64
+ - - ">="
91
65
  - !ruby/object:Gem::Version
92
- version: '0'
66
+ version: 2.7.0
93
67
  required_rubygems_version: !ruby/object:Gem::Requirement
94
- none: false
95
68
  requirements:
96
- - - ! '>='
69
+ - - ">="
97
70
  - !ruby/object:Gem::Version
98
71
  version: '0'
99
72
  requirements: []
100
- rubyforge_project: tweetbot
101
- rubygems_version: 1.8.10
73
+ rubygems_version: 3.1.2
102
74
  signing_key:
103
- specification_version: 3
75
+ specification_version: 4
104
76
  summary: Tweetbot makes writing twitter bots twivial!
105
- test_files:
106
- - spec/tweetbot_config_spec.rb
107
- - spec/tweetbot_spec.rb
77
+ test_files: []
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.2@tweetbot
data/README DELETED
@@ -1,39 +0,0 @@
1
- So you want to write a twitter bot. Use my gem. Then, you can just do this:
2
-
3
- load 'twitter_auth.rb'
4
- require 'tweetbot'
5
-
6
- bot = TweetBot.configure do |config|
7
- config.response_frequency = 100
8
-
9
- config.respond_to_phrase "tweetbot example phrase" do |responses|
10
- responses << "I am tweetbot!" << "You rang?" << "Pretty cool, thanks for saying hello"
11
- end
12
-
13
- config.respond_to_phrase "hey @tweetbot" do |responses|
14
- responses << "Hey back at ya" << "You rang again?"
15
- end
16
-
17
- config.twitter_auth = TwitterAuth::AuthKeys
18
- end
19
-
20
- bot.talk
21
-
22
- and build a file called twitter_auth.rb that has your keys
23
-
24
- module TwitterAuth
25
- MyName = 'twitter_name'
26
- ApigeeEnpoint = nil
27
- def self.use_apigee?
28
- !ApigeeEnpoint.nil?
29
- end
30
- AuthKeys = {
31
- consumer_key: "key",
32
- consumer_secret: "secret",
33
- oauth_token: "token",
34
- oauth_token_secret: "token_secret"
35
- }
36
- end
37
-
38
-
39
- Abstracting out the apigee stuff, don't worry. Just leave it like that for now.
@@ -1,19 +0,0 @@
1
- load 'twitter_auth.rb'
2
- require 'tweetbot'
3
-
4
- bot = TweetBot.configure do |config|
5
- config.response_frequency = 100
6
-
7
- config.respond_to_phrase "tweetbot example phrase" do |responses|
8
- responses << "I am tweetbot!" << "You rang?" << "Pretty cool, thanks for saying hello"
9
- end
10
-
11
- config.respond_to_phrase "hey @tweetbot" do |responses|
12
- responses << "Hey back at ya" << "You rang again?"
13
- end
14
-
15
- config.twitter_auth = TwitterAuth::AuthKeys
16
- end
17
-
18
- bot.talk
19
-
@@ -1,13 +0,0 @@
1
- module TwitterAuth
2
- MyName = 'twitter_name'
3
- ApigeeEnpoint = nil
4
- def self.use_apigee?
5
- !ApigeeEnpoint.nil?
6
- end
7
- AuthKeys = {
8
- consumer_key: "key",
9
- consumer_secret: "secret",
10
- oauth_token: "token",
11
- oauth_token_secret: "token_secret"
12
- }
13
- end
@@ -1,134 +0,0 @@
1
- require_relative '../lib/tweetbot'
2
- module Twitter
3
- end
4
- module TweetStream
5
- end
6
-
7
- describe "configuring tweetbot with a config block" do
8
- class DummyAuth
9
- attr_accessor :consumer_key, :consumer_secret, :oauth_token,
10
- :oauth_token_secret, :auth_method
11
- end
12
-
13
- before do
14
- Twitter.stub(:configure)
15
- TweetStream.stub(:configure)
16
- end
17
-
18
- context "configuring with twitter authentication" do
19
- it "configures twitter with the oauth keys" do
20
- auth = DummyAuth.new
21
- bot = TweetBot.configure do |bot|
22
- bot.twitter_auth = {
23
- consumer_key: "ckey",
24
- consumer_secret: "csecret",
25
- oauth_token: "token",
26
- oauth_token_secret: "tokensecret"
27
- }
28
- end
29
- Twitter.stub(:configure).and_yield auth
30
- bot.configure_twitter_auth
31
- auth.consumer_key.should == "ckey"
32
- auth.consumer_secret.should == "csecret"
33
- auth.oauth_token.should == "token"
34
- auth.oauth_token_secret.should == "tokensecret"
35
- end
36
- it "configures tweetstream with the oauth keys" do
37
- auth = DummyAuth.new
38
- bot = TweetBot.configure do |bot|
39
- bot.twitter_auth = {
40
- consumer_key: "ckey",
41
- consumer_secret: "csecret",
42
- oauth_token: "token",
43
- oauth_token_secret: "tokensecret"
44
- }
45
- end
46
- TweetStream.stub(:configure).and_yield auth
47
- bot.configure_twitter_auth
48
- auth.consumer_key.should == "ckey"
49
- auth.consumer_secret.should == "csecret"
50
- auth.oauth_token.should == "token"
51
- auth.oauth_token_secret.should == "tokensecret"
52
- end
53
- end
54
-
55
- context "configuring twice" do
56
- it "uses the same bot" do
57
- bot1 = TweetBot.configure do |bot|
58
- bot.response_frequency = 4
59
- end
60
-
61
- bot2 = TweetBot.configure do |bot|
62
- bot.response_frequency = 10
63
- end
64
-
65
- bot1.should be(bot2)
66
- bot1.response_frequency.should == 10
67
- end
68
- end
69
-
70
- context "configuring frequency" do
71
- let(:bot) do
72
- TweetBot.configure do |bot|
73
- bot.response_frequency = 4
74
- end
75
- end
76
-
77
- it "saves the response_frequency" do
78
- bot.response_frequency.should == 4
79
- end
80
- end
81
-
82
- context "configuring responses" do
83
- let(:bot) do
84
- TweetBot.configure do |bot|
85
- bot.respond_to_phrase "code and coffee" do |responses|
86
- responses << "good times" << "bad times"
87
- end
88
- end
89
- end
90
-
91
- it "saves the response given in block" do
92
- bot.responses_for("code and coffee").should =~ ["good times", "bad times"]
93
- end
94
- end
95
-
96
- context "configuring a status captured block" do
97
- let(:statuses) { [] }
98
- let(:bot) do
99
- TweetBot.configure do |bot|
100
- bot.on_status_captured "positivember" do |status|
101
- statuses << status.text
102
- end
103
- end
104
- end
105
-
106
- it "adds the phrase to the phrases to search" do
107
- bot.phrases_to_search.should include("positivember")
108
- end
109
-
110
- context "status text contains the phrase" do
111
- it "calls the block" do
112
- status = stub(text: "Yeah #positivember")
113
- bot.alert_status_captured(status)
114
- statuses.should include("Yeah #positivember")
115
- end
116
- end
117
-
118
- context "status text does not contain the phrase" do
119
- it "does not call the block" do
120
- status = stub(text: "negativity")
121
- bot.alert_status_captured(status)
122
- statuses.should be_empty
123
- end
124
- end
125
- end
126
-
127
- context "without a configure block" do
128
- it "returns a bot that I can use" do
129
- bot = TweetBot.configure
130
- bot.response_frequency = 4
131
- bot.response_frequency.should == 4
132
- end
133
- end
134
- end
@@ -1,136 +0,0 @@
1
- require_relative '../lib/tweetbot'
2
- require 'timecop'
3
-
4
-
5
- describe TweetBot::Bot do
6
- let(:bot) { TweetBot::Bot.new }
7
- let(:tweet) { stub(:text => "hello world", :user => stub(:screen_name => "fun_person")) }
8
-
9
- before do
10
- bot.add_responses_for_phrase "hello world", "and hello to you"
11
- end
12
-
13
- after do
14
- Timecop.return
15
- end
16
-
17
-
18
- describe "#phrases_to_search" do
19
- it "returns the phrases that have responses associated with them" do
20
- bot.add_responses_for_phrase "good night", ""
21
- bot.phrases_to_search.should == ["hello world", "good night"]
22
- end
23
- end
24
-
25
- describe "#tweet_matches?" do
26
- before do
27
- bot.add_responses_for_phrase "the night", "a dark night"
28
- end
29
- it "looks to see if any phrases match the tweet" do
30
- tweet.stub(:text) { "the night" }
31
- bot.tweet_matches?(tweet).should be_true
32
- tweet.stub(:text) { "the day" }
33
- bot.tweet_matches?(tweet).should be_false
34
- end
35
-
36
- it "compares case-insensitive" do
37
- tweet.stub(:text) { "The Night"}
38
- bot.tweet_matches?(tweet).should be_true
39
- end
40
-
41
- it "matches if anywhere in text" do
42
- tweet.stub(:text) { "It is cold The Night"}
43
- bot.tweet_matches?(tweet).should be_true
44
- end
45
- end
46
-
47
- describe "#response_for" do
48
- it "replies to the user" do
49
- tweet.user.stub(:screen_name) { "corey" }
50
- bot.response_for(tweet).should =~ /^@corey/
51
- end
52
-
53
- it "uses responses associated with phrase" do
54
- bot.add_responses_for_phrase("good morning", "morning response")
55
- bot.add_responses_for_phrase("good night", "night response")
56
-
57
- tweet.stub(:text) { "good morning" }
58
- bot.response_for(tweet).should =~ /morning response/
59
- tweet.stub(:text) { "good night" }
60
- bot.response_for(tweet).should =~ /night response/
61
- end
62
-
63
- it "uses a random phrase from the responses" do
64
- tweet.stub(:text) { "good morning" }
65
- bot.add_responses_for_phrase("good morning", "response 1", "response 2")
66
- responses = (1..20).map do
67
- bot.response_for(tweet)
68
- end
69
- responses.reject! {|response| response =~ /response 1/}
70
- responses.should_not be_empty
71
- responses.reject! {|response| response =~ /response 2/}
72
- responses.should be_empty
73
- end
74
-
75
- it "uses responses if phrase appears anywhere in tweet (case-insensitive)" do
76
- bot.add_responses_for_phrase("good afternoon", "afternoon response")
77
- tweet.stub(:text) { "this is a Good Afternoon" }
78
- bot.response_for(tweet).should =~ /afternoon response/
79
- end
80
- end
81
-
82
- describe "#should_i_respond_to?" do
83
- before do
84
- bot.stub(:rand) { 1 }
85
- bot.stub(:tweet_matches?) { true }
86
- end
87
-
88
- context "Under rate limit" do
89
- let(:now) { Time.now }
90
- let(:status) { stub }
91
- before do
92
- Timecop.freeze(now)
93
- bot.rate_limited!
94
- end
95
-
96
- it "won't allow response for 1 hour" do
97
- bot.should_i_respond_to?(status).should be_false
98
- Timecop.travel(now + 60 * 59) do
99
- bot.should_i_respond_to?(status).should be_false
100
- end
101
- end
102
-
103
- it "will allow response after an hour" do
104
- Timecop.travel(now + 3600) do
105
- bot.should_i_respond_to?(status).should be_true
106
- end
107
- end
108
- end
109
-
110
- it "only responds if rand is less than response_frequency" do
111
- bot.response_frequency = 30
112
- bot.stub(:rand) { 29 }
113
- bot.should_i_respond_to?(stub).should be_true
114
- bot.stub(:rand) { 30 }
115
- bot.should_i_respond_to?(stub).should be_false
116
- bot.stub(:rand) { 31 }
117
- bot.should_i_respond_to?(stub).should be_false
118
- end
119
-
120
- it "only responds if phrase matches" do
121
- bot.stub(:tweet_matches?) { true }
122
- bot.should_i_respond_to?(stub).should be_true
123
- bot.stub(:tweet_matches?) { false }
124
- bot.should_i_respond_to?(stub).should be_false
125
- end
126
- end
127
-
128
- describe "#respond_to_phrase" do
129
- it "stores the given responses" do
130
- bot.respond_to_phrase "morning fun" do |responses|
131
- responses << "evening delight" << "afternoon rockets"
132
- end
133
- bot.responses_for_tweet(stub(:text => "morning fun")).should =~ ["evening delight", "afternoon rockets"]
134
- end
135
- end
136
- end