chatterbot 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -5
  3. data/Gemfile +9 -17
  4. data/Rakefile +2 -18
  5. data/chatterbot.gemspec +10 -11
  6. data/docs/Gemfile +3 -0
  7. data/docs/README.md +3 -0
  8. data/docs/_config.yml +37 -0
  9. data/docs/_includes/footer.html +3 -0
  10. data/docs/_includes/header.html +4 -0
  11. data/docs/_includes/navigation.html +23 -0
  12. data/docs/_layouts/default.html +98 -0
  13. data/docs/_layouts/page.html +11 -0
  14. data/docs/_posts/.gitkeep +0 -0
  15. data/docs/_site/Gemfile +3 -0
  16. data/docs/_site/advanced.html +476 -0
  17. data/docs/_site/configuration.html +456 -0
  18. data/docs/_site/contributing.html +433 -0
  19. data/docs/_site/css/main.css +58 -0
  20. data/docs/_site/css/syntax.css +61 -0
  21. data/docs/_site/deploying.html +468 -0
  22. data/docs/_site/examples.html +574 -0
  23. data/docs/_site/features.html +497 -0
  24. data/docs/_site/images/01-create-application.png +0 -0
  25. data/docs/_site/images/02-application-permissions.png +0 -0
  26. data/docs/_site/images/03-mobile-number.png +0 -0
  27. data/docs/_site/images/04-access-token.png +0 -0
  28. data/docs/_site/index.html +482 -0
  29. data/docs/_site/javascripts/main.js +1 -0
  30. data/docs/_site/other-tools.html +438 -0
  31. data/docs/_site/params.json +1 -0
  32. data/docs/_site/rdoc.html +428 -0
  33. data/docs/_site/setup.html +500 -0
  34. data/docs/_site/streaming.html +506 -0
  35. data/docs/_site/stylesheets/pygment_trac.css +68 -0
  36. data/docs/_site/stylesheets/stylesheet.css +247 -0
  37. data/docs/_site/tut.html +422 -0
  38. data/docs/_site/twitter-docs.html +428 -0
  39. data/docs/_site/walkthrough.html +463 -0
  40. data/docs/advanced.md +67 -0
  41. data/docs/basics.md +12 -0
  42. data/docs/bin/jekyll-page +109 -0
  43. data/docs/configuration.md +32 -0
  44. data/docs/contributing.md +14 -0
  45. data/docs/css/main.css +58 -0
  46. data/docs/css/syntax.css +61 -0
  47. data/docs/deploying.md +53 -0
  48. data/docs/examples.md +168 -0
  49. data/docs/features.md +88 -0
  50. data/docs/images/01-create-application.png +0 -0
  51. data/docs/images/02-application-permissions.png +0 -0
  52. data/docs/images/03-mobile-number.png +0 -0
  53. data/docs/images/04-access-token.png +0 -0
  54. data/docs/index.md +70 -0
  55. data/docs/javascripts/main.js +1 -0
  56. data/docs/other-tools.md +17 -0
  57. data/docs/params.json +1 -0
  58. data/docs/rdoc.md +6 -0
  59. data/docs/setup.md +84 -0
  60. data/docs/streaming.md +98 -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/examples/streaming_bot.rb +11 -10
  68. data/ext/mkrf_conf.rb +28 -0
  69. data/lib/chatterbot/bot.rb +5 -1
  70. data/lib/chatterbot/config.rb +1 -1
  71. data/lib/chatterbot/home_timeline.rb +1 -1
  72. data/lib/chatterbot/streaming.rb +11 -1
  73. data/lib/chatterbot/version.rb +1 -1
  74. data/spec/spec_helper.rb +1 -4
  75. metadata +71 -122
  76. data/examples/tweet_logger.rb +0 -68
@@ -0,0 +1,247 @@
1
+ body {
2
+ margin: 0;
3
+ padding: 0;
4
+ background: #151515 url("../images/bkg.png") 0 0;
5
+ color: #eaeaea;
6
+ font: 16px;
7
+ line-height: 1.5;
8
+ font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
9
+ }
10
+
11
+ /* General & 'Reset' Stuff */
12
+
13
+ .container {
14
+ width: 90%;
15
+ max-width: 600px;
16
+ margin: 0 auto;
17
+ }
18
+
19
+ section {
20
+ display: block;
21
+ margin: 0 0 20px 0;
22
+ }
23
+
24
+ h1, h2, h3, h4, h5, h6 {
25
+ margin: 0 0 20px;
26
+ }
27
+
28
+ li {
29
+ line-height: 1.4 ;
30
+ }
31
+
32
+ /* Header, <header>
33
+ header - container
34
+ h1 - project name
35
+ h2 - project description
36
+ */
37
+
38
+ header {
39
+ background: rgba(0, 0, 0, 0.1);
40
+ width: 100%;
41
+ border-bottom: 1px dashed #b5e853;
42
+ padding: 20px 0;
43
+ margin: 0 0 40px 0;
44
+ }
45
+
46
+ header h1 {
47
+ font-size: 30px;
48
+ line-height: 1.5;
49
+ margin: 0 0 0 -40px;
50
+ font-weight: bold;
51
+ font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
52
+ color: #b5e853;
53
+ text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1),
54
+ 0 0 5px rgba(181, 232, 83, 0.1),
55
+ 0 0 10px rgba(181, 232, 83, 0.1);
56
+ letter-spacing: -1px;
57
+ -webkit-font-smoothing: antialiased;
58
+ }
59
+
60
+ header h1:before {
61
+ content: "./ ";
62
+ font-size: 24px;
63
+ }
64
+
65
+ header h2 {
66
+ font-size: 18px;
67
+ font-weight: 300;
68
+ color: #666;
69
+ }
70
+
71
+ #downloads .btn {
72
+ display: inline-block;
73
+ text-align: center;
74
+ margin: 0;
75
+ }
76
+
77
+ /* Main Content
78
+ */
79
+
80
+ #main_content {
81
+ width: 100%;
82
+ -webkit-font-smoothing: antialiased;
83
+ }
84
+ section img {
85
+ max-width: 100%
86
+ }
87
+
88
+ h1, h2, h3, h4, h5, h6 {
89
+ font-weight: normal;
90
+ font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
91
+ color: #b5e853;
92
+ letter-spacing: -0.03em;
93
+ text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1),
94
+ 0 0 5px rgba(181, 232, 83, 0.1),
95
+ 0 0 10px rgba(181, 232, 83, 0.1);
96
+ }
97
+
98
+ #main_content h1 {
99
+ font-size: 30px;
100
+ }
101
+
102
+ #main_content h2 {
103
+ font-size: 24px;
104
+ }
105
+
106
+ #main_content h3 {
107
+ font-size: 18px;
108
+ }
109
+
110
+ #main_content h4 {
111
+ font-size: 14px;
112
+ }
113
+
114
+ #main_content h5 {
115
+ font-size: 12px;
116
+ text-transform: uppercase;
117
+ margin: 0 0 5px 0;
118
+ }
119
+
120
+ #main_content h6 {
121
+ font-size: 12px;
122
+ text-transform: uppercase;
123
+ color: #999;
124
+ margin: 0 0 5px 0;
125
+ }
126
+
127
+ dt {
128
+ font-style: italic;
129
+ font-weight: bold;
130
+ }
131
+
132
+ ul li {
133
+ list-style: none;
134
+ }
135
+
136
+ ul li:before {
137
+ content: ">>";
138
+ font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
139
+ font-size: 13px;
140
+ color: #b5e853;
141
+ margin-left: -37px;
142
+ margin-right: 21px;
143
+ line-height: 16px;
144
+ }
145
+
146
+ blockquote {
147
+ color: #aaa;
148
+ padding-left: 10px;
149
+ border-left: 1px dotted #666;
150
+ }
151
+
152
+ pre {
153
+ background: rgba(0, 0, 0, 0.9);
154
+ border: 1px solid rgba(255, 255, 255, 0.15);
155
+ padding: 10px;
156
+ font-size: 14px;
157
+ color: #b5e853;
158
+ border-radius: 2px;
159
+ -moz-border-radius: 2px;
160
+ -webkit-border-radius: 2px;
161
+ text-wrap: normal;
162
+ overflow: auto;
163
+ overflow-y: hidden;
164
+ }
165
+
166
+ table {
167
+ width: 100%;
168
+ margin: 0 0 20px 0;
169
+ }
170
+
171
+ th {
172
+ text-align: left;
173
+ border-bottom: 1px dashed #b5e853;
174
+ padding: 5px 10px;
175
+ }
176
+
177
+ td {
178
+ padding: 5px 10px;
179
+ }
180
+
181
+ hr {
182
+ height: 0;
183
+ border: 0;
184
+ border-bottom: 1px dashed #b5e853;
185
+ color: #b5e853;
186
+ }
187
+
188
+ /* Buttons
189
+ */
190
+
191
+ .btn {
192
+ display: inline-block;
193
+ background: -webkit-linear-gradient(top, rgba(40, 40, 40, 0.3), rgba(35, 35, 35, 0.3) 50%, rgba(10, 10, 10, 0.3) 50%, rgba(0, 0, 0, 0.3));
194
+ padding: 8px 18px;
195
+ border-radius: 50px;
196
+ border: 2px solid rgba(0, 0, 0, 0.7);
197
+ border-bottom: 2px solid rgba(0, 0, 0, 0.7);
198
+ border-top: 2px solid rgba(0, 0, 0, 1);
199
+ color: rgba(255, 255, 255, 0.8);
200
+ font-family: Helvetica, Arial, sans-serif;
201
+ font-weight: bold;
202
+ font-size: 13px;
203
+ text-decoration: none;
204
+ text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.75);
205
+ box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
206
+ }
207
+
208
+ .btn:hover {
209
+ background: -webkit-linear-gradient(top, rgba(40, 40, 40, 0.6), rgba(35, 35, 35, 0.6) 50%, rgba(10, 10, 10, 0.8) 50%, rgba(0, 0, 0, 0.8));
210
+ }
211
+
212
+ .btn .icon {
213
+ display: inline-block;
214
+ width: 16px;
215
+ height: 16px;
216
+ margin: 1px 8px 0 0;
217
+ float: left;
218
+ }
219
+
220
+ .btn-github .icon {
221
+ opacity: 0.6;
222
+ background: url("../images/blacktocat.png") 0 0 no-repeat;
223
+ }
224
+
225
+ /* Links
226
+ a, a:hover, a:visited
227
+ */
228
+
229
+ a {
230
+ color: #63c0f5;
231
+ text-shadow: 0 0 5px rgba(104, 182, 255, 0.5);
232
+ }
233
+
234
+ /* Clearfix */
235
+
236
+ .cf:before, .cf:after {
237
+ content:"";
238
+ display:table;
239
+ }
240
+
241
+ .cf:after {
242
+ clear:both;
243
+ }
244
+
245
+ .cf {
246
+ zoom:1;
247
+ }
@@ -0,0 +1,22 @@
1
+ ---
2
+ layout: page
3
+ title: "Tips and Tricks"
4
+ category: doc
5
+ published: false
6
+ ---
7
+
8
+ setting profile data
9
+
10
+ resetting since_id/since_id_reply
11
+
12
+ deleting tweets
13
+
14
+ making sure a user is following your bot
15
+
16
+ posting images
17
+
18
+ running multiple searches
19
+
20
+
21
+
22
+
@@ -0,0 +1,6 @@
1
+ ---
2
+ layout: default
3
+ title: "Setup"
4
+ ---
5
+
6
+ setting up your bot!
@@ -0,0 +1,6 @@
1
+ ---
2
+ layout: page
3
+ title: "Twitter API docs"
4
+ category: links
5
+ link: https://dev.twitter.com/rest/public
6
+ ---
@@ -0,0 +1,46 @@
1
+ ---
2
+ layout: page
3
+ title: "Walkthrough"
4
+ category: tut
5
+ ---
6
+
7
+ Make a Twitter account
8
+ ----------------------
9
+
10
+ First thing you'll need to do is create an account for your bot on
11
+ Twitter. That's the easy part.
12
+
13
+ Run the generator
14
+ -----------------
15
+
16
+ Chatterbot comes with a script named `chatterbot-register` which will
17
+ handle two tasks -- it will authorize your bot with Twitter and it
18
+ will generate a skeleton script, which you use to implement your
19
+ actual bot.
20
+
21
+ When you run `chatterbot-register` it will walk you through the
22
+ authorization process. If you prefer, you can do this manually. If
23
+ you'd like to learn more about it, you can read the
24
+ [Authorizing your Bot](setup.html) section.
25
+
26
+ Write your bot
27
+ --------------
28
+
29
+ Chatterbot is written in ruby, but it accepts some very simple
30
+ scripting commands which can handle almost everything you might need
31
+ to do on Twitter. You can get some ideas of things you can do on the
32
+ [Examples](examples.html) page.
33
+
34
+ require 'chatterbot/dsl'
35
+ search("'surely you must be joking'") do |tweet|
36
+ reply "@#{tweet_user(tweet)} I am serious, and don't call me Shirley!", tweet
37
+ end
38
+
39
+ Or, you can create a bot object yourself, extend it if needed, and use it like so:
40
+
41
+ bot = Chatterbot::Bot.new
42
+ bot.search("'surely you must be joking'") do |tweet|
43
+ bot.reply "@#{tweet_user(tweet)} I am serious, and don't call me Shirley!", tweet
44
+ end
45
+
46
+ That's it!
@@ -21,16 +21,7 @@ exclude "http://", "https://"
21
21
 
22
22
  blocklist "mean_user, private_user"
23
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
24
+ use_streaming
34
25
 
35
26
  replies do |tweet|
36
27
  favorite tweet
@@ -46,3 +37,13 @@ direct_messages do |tweet|
46
37
  direct_message "got it", tweet.sender
47
38
  end
48
39
 
40
+ favorited do |user, tweet|
41
+ reply "@#{user.screen_name} thanks for the fave!", tweet
42
+ end
43
+
44
+ followed do |user|
45
+ tweet "@#{user.screen_name} just followed me!"
46
+ follow user
47
+ end
48
+
49
+
@@ -0,0 +1,28 @@
1
+ require 'rubygems/dependency_installer'
2
+
3
+ #
4
+ # limit activesupport version if not on ruby 2.2 or higher
5
+ # @see https://www.tiredpixel.com/2014/01/05/curses-conditional-ruby-gem-installation-within-a-gemspec/
6
+ #
7
+
8
+ di = Gem::DependencyInstaller.new
9
+
10
+ begin
11
+ if RUBY_VERSION >= '2.2'
12
+ di.install "activesupport", "~> 4.2.8"
13
+ else
14
+ di.install "activesupport", "< 5.0.0"
15
+ end
16
+ rescue => e
17
+ warn "#{$0}: #{e}"
18
+
19
+ exit!
20
+ end
21
+
22
+
23
+ # https://en.wikibooks.org/wiki/Ruby_Programming/RubyGems#How_to_install_different_versions_of_gems_depending_on_which_version_of_ruby_the_installee_is_using
24
+
25
+ # create dummy rakefile to indicate success
26
+ f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w")
27
+ f.write("task :default\n")
28
+ f.close
@@ -54,6 +54,11 @@ module Chatterbot
54
54
  @handlers = {}
55
55
  end
56
56
 
57
+ def screen_name
58
+ @screen_name ||= client.settings.screen_name
59
+ end
60
+
61
+
57
62
  #
58
63
  # determine the right API to use and run the bot
59
64
  #
@@ -113,7 +118,6 @@ module Chatterbot
113
118
 
114
119
  HANDLER_CALLS.each { |c|
115
120
  if (h = @handlers[c])
116
- puts "calling #{c} #{h.opts.inspect}"
117
121
  send(c, *(h.opts)) do |obj|
118
122
  h.call(obj)
119
123
  end
@@ -212,7 +212,7 @@ module Chatterbot
212
212
  :consumer_key => ENV["chatterbot_consumer_key"],
213
213
  :consumer_secret => ENV["chatterbot_consumer_secret"],
214
214
  :access_token => ENV["chatterbot_access_token"],
215
- :access_token_secret => ENV["chatterbot_access_secret"]
215
+ :access_token_secret => ENV["chatterbot_access_secret"] || ENV["chatterbot_access_token_secret"]
216
216
  }.delete_if { |k, v| v.nil? }.merge(slurp_file(config_file) || {})
217
217
  end
218
218
 
@@ -7,7 +7,7 @@ module Chatterbot
7
7
  # handle the bots timeline
8
8
  def home_timeline(*args, &block)
9
9
  return unless require_login
10
- debug "check for home_timeline tweets since #{since_id}"
10
+ debug "check for home_timeline tweets since #{since_id_home_timeline}"
11
11
 
12
12
  opts = {
13
13
  :since_id => since_id_home_timeline,
@@ -7,7 +7,17 @@ module Chatterbot
7
7
  def streaming_tweet_handler
8
8
  usable_handlers = [:home_timeline, :search]
9
9
  name, block = @handlers.find { |k, v| usable_handlers.include?(k) }
10
- block
10
+
11
+ if block.nil? && ( block = @handlers[:replies] )
12
+ debug "No default handler, wrapping the replies handler"
13
+ return Proc.new { |tweet|
14
+ if tweet.text =~ /^@#{bot.screen_name}/i
15
+ block.call(tweet)
16
+ end
17
+ }
18
+ end
19
+
20
+ block
11
21
  end
12
22
 
13
23
  #