chatterbot 2.0.0.pre → 2.1.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.
Files changed (96) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +19 -0
  3. data/Gemfile +9 -17
  4. data/README.markdown +27 -34
  5. data/Rakefile +2 -18
  6. data/bin/chatterbot-register +6 -2
  7. data/chatterbot.gemspec +11 -12
  8. data/docs/Gemfile +3 -0
  9. data/docs/README.md +3 -0
  10. data/docs/_config.yml +37 -0
  11. data/docs/_includes/footer.html +3 -0
  12. data/docs/_includes/header.html +4 -0
  13. data/docs/_includes/navigation.html +23 -0
  14. data/docs/_layouts/default.html +98 -0
  15. data/docs/_layouts/page.html +11 -0
  16. data/docs/_posts/.gitkeep +0 -0
  17. data/docs/_site/Gemfile +3 -0
  18. data/docs/_site/advanced.html +465 -0
  19. data/docs/_site/configuration.html +436 -0
  20. data/docs/_site/contributing.html +414 -0
  21. data/docs/_site/css/main.css +58 -0
  22. data/docs/_site/css/syntax.css +61 -0
  23. data/docs/_site/deploying.html +451 -0
  24. data/docs/_site/examples.html +559 -0
  25. data/docs/_site/features.html +496 -0
  26. data/docs/_site/images/01-create-application.png +0 -0
  27. data/docs/_site/images/02-application-permissions.png +0 -0
  28. data/docs/_site/images/03-mobile-number.png +0 -0
  29. data/docs/_site/images/04-access-token.png +0 -0
  30. data/docs/_site/index.html +461 -0
  31. data/docs/_site/javascripts/main.js +1 -0
  32. data/docs/_site/other-tools.html +419 -0
  33. data/docs/_site/params.json +1 -0
  34. data/docs/_site/rdoc.html +409 -0
  35. data/docs/_site/setup.html +491 -0
  36. data/docs/_site/stylesheets/pygment_trac.css +68 -0
  37. data/docs/_site/stylesheets/stylesheet.css +247 -0
  38. data/docs/_site/tut.html +402 -0
  39. data/docs/_site/twitter-docs.html +409 -0
  40. data/docs/_site/walkthrough.html +447 -0
  41. data/docs/advanced.md +62 -0
  42. data/docs/basics.md +12 -0
  43. data/docs/bin/jekyll-page +109 -0
  44. data/docs/configuration.md +32 -0
  45. data/docs/contributing.md +14 -0
  46. data/docs/css/main.css +58 -0
  47. data/docs/css/syntax.css +61 -0
  48. data/docs/deploying.md +47 -0
  49. data/docs/examples.md +120 -0
  50. data/docs/features.md +88 -0
  51. data/docs/images/01-create-application.png +0 -0
  52. data/docs/images/02-application-permissions.png +0 -0
  53. data/docs/images/03-mobile-number.png +0 -0
  54. data/docs/images/04-access-token.png +0 -0
  55. data/docs/index.md +69 -0
  56. data/docs/javascripts/main.js +1 -0
  57. data/docs/other-tools.md +17 -0
  58. data/docs/params.json +1 -0
  59. data/docs/rdoc.md +6 -0
  60. data/docs/setup.md +84 -0
  61. data/docs/stylesheets/pygment_trac.css +68 -0
  62. data/docs/stylesheets/stylesheet.css +247 -0
  63. data/docs/tips.md +22 -0
  64. data/docs/tut.md +6 -0
  65. data/docs/twitter-docs.md +6 -0
  66. data/docs/walkthrough.md +46 -0
  67. data/ext/mkrf_conf.rb +28 -0
  68. data/lib/chatterbot.rb +0 -1
  69. data/lib/chatterbot/bot.rb +7 -63
  70. data/lib/chatterbot/client.rb +6 -12
  71. data/lib/chatterbot/config.rb +2 -2
  72. data/lib/chatterbot/config_manager.rb +7 -1
  73. data/lib/chatterbot/dsl.rb +20 -47
  74. data/lib/chatterbot/home_timeline.rb +1 -2
  75. data/lib/chatterbot/search.rb +26 -3
  76. data/lib/chatterbot/skeleton.rb +1 -3
  77. data/lib/chatterbot/tweet.rb +14 -3
  78. data/lib/chatterbot/ui.rb +88 -20
  79. data/lib/chatterbot/version.rb +1 -1
  80. data/spec/bot_spec.rb +2 -77
  81. data/spec/client_spec.rb +2 -6
  82. data/spec/config_manager_spec.rb +6 -5
  83. data/spec/config_spec.rb +4 -1
  84. data/spec/dsl_spec.rb +10 -35
  85. data/spec/fixtures/update_with_media.png +0 -0
  86. data/spec/search_spec.rb +40 -1
  87. data/spec/spec_helper.rb +1 -4
  88. data/spec/tweet_spec.rb +75 -38
  89. data/templates/skeleton.txt +26 -56
  90. metadata +84 -141
  91. data/.document +0 -5
  92. data/.travis.yml +0 -8
  93. data/examples/streaming_bot.rb +0 -48
  94. data/examples/tweet_logger.rb +0 -68
  95. data/lib/chatterbot/streaming.rb +0 -60
  96. data/spec/streaming_spec.rb +0 -170
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- - 2.1.1
5
- - 2.2.0
6
- - ruby-head
7
- # uncomment this line if your project needs to run something other than `rake`:
8
- # script: bundle exec rspec spec
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- ## This is a very simple working example of a bot using the streaming
4
- ## API. It's basically a copy of echoes_bot.rb, just using streaming.
5
-
6
- #
7
- # require the dsl lib to include all the methods you see below.
8
- #
9
- require 'rubygems'
10
- require 'chatterbot/dsl'
11
-
12
- consumer_secret 'foo'
13
- secret 'bar'
14
- token 'biz'
15
- consumer_key 'bam'
16
-
17
-
18
- puts "Loading echoes_bot.rb using the streaming API"
19
-
20
- exclude "http://", "https://"
21
-
22
- blocklist "mean_user, private_user"
23
-
24
- streaming true
25
-
26
- favorited do |user, tweet|
27
- reply "@#{user.screen_name} thanks for the fave!", tweet
28
- end
29
-
30
- followed do |user|
31
- tweet "@#{user.screen_name} just followed me!"
32
- follow user
33
- end
34
-
35
- replies do |tweet|
36
- favorite tweet
37
-
38
- puts "It's a tweet!"
39
- src = tweet.text.gsub(/@echoes_bot/, "#USER#")
40
- reply src, tweet
41
- end
42
-
43
- direct_messages do |tweet|
44
- puts "well, here i am #{tweet.text}"
45
- puts tweet.inspect
46
- direct_message "got it", tweet.sender
47
- end
48
-
@@ -1,68 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'chatterbot/dsl'
4
-
5
- ##
6
- #
7
- # Simple example of a bot that will log tweets to the
8
- # database. Chatterbot will only log outgoing tweets by default, and
9
- # coding incoming tweet processing seems problematic right now, but
10
- # this is pretty straightforward
11
- #
12
-
13
- #
14
- # Set some date defaults for Sequel
15
- #
16
- Sequel.datetime_class = DateTime
17
- Sequel.default_timezone = :utc
18
-
19
- #
20
- # grab a copy of the db handle
21
- #
22
- db = bot.db
23
-
24
- #
25
- # create a table to hold search results
26
- #
27
- if ! db.tables.include?(:searches)
28
-
29
- #
30
- # if there's other data you want to track, you can add it here
31
- #
32
- db.create_table :searches do
33
- primary_key :id, :type=>Bignum
34
-
35
- String :text
36
- String :from_user
37
- String :from_user_id
38
-
39
- String :to_user
40
- String :to_user_id
41
-
42
- String :in_reply_to_status_id
43
-
44
- DateTime :created_at
45
- end
46
- end
47
-
48
- cols = db[:searches].columns
49
-
50
- #
51
- # run a search
52
- #
53
- search("foo", :lang => "en") do |tweet|
54
-
55
- #
56
- # reject anything from the incoming tweet that doesn't have a
57
- # matching column
58
- #
59
- data = tweet.to_h.delete_if { |k, v|
60
- ! cols.include?(k)
61
- }
62
-
63
- # update timestamp manually -- sequel isn't doing it right
64
- data[:created_at] = Sequel.string_to_datetime(data[:created_at])
65
-
66
- # store to the db!
67
- db[:searches].insert(data)
68
- end
@@ -1,60 +0,0 @@
1
- module Chatterbot
2
-
3
- #
4
- # simple twitter stream handler
5
- module Streaming
6
-
7
- def streaming_tweet_handler
8
- usable_handlers = [:home_timeline, :search]
9
- name, block = @handlers.find { |k, v| usable_handlers.include?(k) }
10
- block
11
- end
12
-
13
- #
14
- # Take the passed in object and call the appropriate bot method
15
- # for it
16
- # @param [Class] object a streaming API object
17
- #
18
- def handle_streaming_object(object)
19
- debug object
20
-
21
- case object
22
- when Twitter::Tweet
23
- if object.user == authenticated_user
24
- debug "skipping #{object} because it's from me"
25
- elsif (h = streaming_tweet_handler) && valid_tweet?(object)
26
- @current_tweet = object
27
- update_since_id(object)
28
-
29
- h.call(object)
30
- @current_tweet = nil
31
- end
32
- when Twitter::Streaming::DeletedTweet
33
- if (h = @handlers[:deleted])
34
- h.call(object)
35
- end
36
- when Twitter::DirectMessage
37
- if object.sender == authenticated_user
38
- debug "skipping DM #{object} because it's from me"
39
- elsif (h = @handlers[:direct_messages])
40
- @current_tweet = object
41
- update_since_id_dm(object)
42
- h.call(object)
43
- @current_tweet = nil
44
- end
45
- when Twitter::Streaming::Event
46
- if object.respond_to?(:source) && object.source == authenticated_user
47
- debug "skipping #{object} because it's from me"
48
- elsif object.name == :follow && (h = @handlers[:followed])
49
- h.call(object.source)
50
- elsif object.name == :favorite && (h = @handlers[:favorited])
51
- h.call(object.source, object.target_object)
52
- end
53
- when Twitter::Streaming::FriendList
54
- debug "got friend list"
55
- end
56
- end
57
-
58
- end
59
- end
60
-
@@ -1,170 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Chatterbot::Streaming" do
4
- let(:bot) { test_bot }
5
- let(:user) { fake_user('user', 100) }
6
- let(:tweet) { fake_tweet(12345) }
7
-
8
-
9
- describe "streaming_tweet_handler" do
10
- before(:each) do
11
- bot.skip_run = true
12
- allow(bot.client).to receive(:user).and_return(user)
13
- end
14
-
15
- it "defaults to home_timeline" do
16
- bot.register_handler(:home_timeline) { @result = :home_timeline }
17
- bot.register_handler(:search, "foo") { @result = :search }
18
-
19
- bot.handle_streaming_object(tweet)
20
- expect(@result).to eql(:home_timeline)
21
- end
22
-
23
- it "will return search" do
24
- bot.register_handler(:search, "foo") { @result = :search }
25
-
26
- bot.handle_streaming_object(tweet)
27
- expect(@result).to eql(:search)
28
- end
29
- end
30
-
31
- describe "handle_streaming_object" do
32
- before(:each) {
33
- bot.skip_run = true
34
- allow(bot.client).to receive(:user).and_return(user)
35
- }
36
-
37
- describe "Twitter::Tweet" do
38
- it "works if no handler" do
39
- bot.handle_streaming_object(tweet)
40
- end
41
-
42
- context "with handler" do
43
- before(:each) do
44
- bot.register_handler(:home_timeline) { |t| @last_object = t }
45
- end
46
-
47
- it "ignores tweets from authenticated user" do
48
- expect(tweet).to receive(:user).and_return(user)
49
- bot.handle_streaming_object(tweet)
50
- expect(@last_object).to be_nil
51
- end
52
-
53
- it "passes to handler" do
54
- bot.handle_streaming_object(tweet)
55
- expect(@last_object).to eql(tweet)
56
- end
57
-
58
- it "ignores tweets from blocklist" do
59
- bot.blocklist = ['chatterbot']
60
- bot.handle_streaming_object(tweet)
61
- expect(@last_object).to be_nil
62
- end
63
-
64
- it "ignores tweets if skip_me is true" do
65
- bot.exclude = ['tweet']
66
- bot.handle_streaming_object(tweet)
67
- expect(@last_object).to be_nil
68
- end
69
- end
70
- end
71
-
72
- describe "Twitter::Streaming::DeletedTweet" do
73
- it "works if no handler" do
74
- obj = Twitter::Streaming::DeletedTweet.new(:id => 1)
75
- bot.handle_streaming_object(obj)
76
- end
77
-
78
- it "passes to handler" do
79
- bot.register_handler(:deleted) { |t| @last_object = t }
80
- obj = Twitter::Streaming::DeletedTweet.new(:id => 1)
81
- bot.handle_streaming_object(obj)
82
- expect(@last_object).to eql(obj)
83
- end
84
- end
85
-
86
- describe "Twitter::DirectMessage" do
87
- it "works if no handler" do
88
- obj = Twitter::DirectMessage.new(:id => 1)
89
- bot.handle_streaming_object(obj)
90
- end
91
-
92
- it "passes to handler" do
93
- bot.register_handler(:direct_messages) { |t| @last_object = t }
94
- obj = Twitter::DirectMessage.new(:id => 1)
95
- bot.handle_streaming_object(obj)
96
- expect(@last_object).to eql(obj)
97
- end
98
- end
99
-
100
- describe "Twitter::Streaming::Event" do
101
- it "ignores events generated by authenticated user" do
102
- event = Twitter::Streaming::Event.new(
103
- :event => :follow,
104
- :source => {:id => user.id, :name => 'name', :screen_name => 'name'},
105
- :target => {:id => user.id, :name => 'name', :screen_name => 'name'})
106
-
107
- bot.register_handler(:followed) { |t| @last_object = t }
108
-
109
- bot.handle_streaming_object(event)
110
- expect(@last_object).to be_nil
111
- end
112
-
113
- describe "follow" do
114
- before(:each) do
115
- @event = Twitter::Streaming::Event.new(
116
- :event => :follow,
117
- :source => {:id => 12345, :name => 'name', :screen_name => 'name'},
118
- :target => {:id => user.id, :name => 'name', :screen_name => 'name'})
119
-
120
- end
121
-
122
- it "works if no handler" do
123
- bot.handle_streaming_object(@event)
124
- expect(@last_object).to be_nil
125
- end
126
-
127
- it "passes to handler" do
128
- bot.register_handler(:followed) { |t| @last_object = t }
129
- bot.handle_streaming_object(@event)
130
- expect(@last_object.class).to be(Twitter::User)
131
- expect(@last_object.id).to be(12345)
132
- end
133
- end
134
-
135
- describe "favorite" do
136
- before(:each) do
137
- @event = Twitter::Streaming::Event.new(
138
- :event => :favorite,
139
- :source => {:id => 12345, :name => 'name', :screen_name => 'name'},
140
- :target => {:id => user.id, :name => 'name', :screen_name => 'name'},
141
- :target_object => {
142
- :from_user => "chatterbot",
143
- :id => 56789,
144
- :text => "I am a tweet!",
145
- :user => { :id => 1, :screen_name => "chatterbot" }
146
- })
147
- end
148
-
149
- it "works if no handler" do
150
- bot.handle_streaming_object(@event)
151
- expect(@last_object).to be_nil
152
- end
153
-
154
- it "passes to handler" do
155
- bot.register_handler(:favorited) { |_, t| @last_object = t }
156
- bot.handle_streaming_object(@event)
157
- expect(@last_object.class).to be(Twitter::Tweet)
158
- expect(@last_object.text).to eq("I am a tweet!")
159
- end
160
- end
161
- end
162
-
163
- describe "Twitter::Streaming::FriendList" do
164
- it "works if no handler" do
165
- obj = Twitter::Streaming::FriendList.new
166
- bot.handle_streaming_object(obj)
167
- end
168
- end
169
- end
170
- end