chatterbot 1.0.2 → 2.0.0.pre

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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/LICENSE.txt +18 -9
  4. data/README.markdown +83 -65
  5. data/bin/chatterbot-register +0 -1
  6. data/chatterbot.gemspec +3 -10
  7. data/examples/class_bot.rb +0 -1
  8. data/examples/echoes_bot.rb +2 -2
  9. data/examples/search_bot.rb +1 -1
  10. data/examples/streaming_bot.rb +21 -15
  11. data/lib/chatterbot.rb +7 -12
  12. data/lib/chatterbot/blocklist.rb +61 -0
  13. data/lib/chatterbot/bot.rb +118 -13
  14. data/lib/chatterbot/client.rb +52 -20
  15. data/lib/chatterbot/config.rb +92 -215
  16. data/lib/chatterbot/config_manager.rb +49 -0
  17. data/lib/chatterbot/direct_messages.rb +46 -0
  18. data/lib/chatterbot/dsl.rb +157 -78
  19. data/lib/chatterbot/followers.rb +4 -0
  20. data/lib/chatterbot/handler.rb +29 -0
  21. data/lib/chatterbot/helpers.rb +14 -3
  22. data/lib/chatterbot/home_timeline.rb +5 -8
  23. data/lib/chatterbot/logging.rb +0 -17
  24. data/lib/chatterbot/profile.rb +0 -1
  25. data/lib/chatterbot/reply.rb +6 -11
  26. data/lib/chatterbot/retweet.rb +2 -6
  27. data/lib/chatterbot/safelist.rb +33 -0
  28. data/lib/chatterbot/search.rb +26 -16
  29. data/lib/chatterbot/skeleton.rb +7 -38
  30. data/lib/chatterbot/streaming.rb +26 -33
  31. data/lib/chatterbot/tweet.rb +0 -1
  32. data/lib/chatterbot/ui.rb +9 -2
  33. data/lib/chatterbot/utils.rb +13 -0
  34. data/lib/chatterbot/version.rb +1 -1
  35. data/spec/blocklist_spec.rb +170 -0
  36. data/spec/bot_spec.rb +83 -8
  37. data/spec/client_spec.rb +61 -7
  38. data/spec/config_manager_spec.rb +59 -0
  39. data/spec/config_spec.rb +33 -158
  40. data/spec/direct_messages_spec.rb +115 -0
  41. data/spec/dsl_spec.rb +95 -53
  42. data/spec/handler_spec.rb +27 -0
  43. data/spec/helpers_spec.rb +7 -11
  44. data/spec/home_timeline_spec.rb +42 -31
  45. data/spec/logging_spec.rb +0 -34
  46. data/spec/reply_spec.rb +10 -34
  47. data/spec/search_spec.rb +65 -6
  48. data/spec/spec_helper.rb +25 -1
  49. data/spec/streaming_spec.rb +56 -58
  50. data/spec/whitelist_spec.rb +10 -10
  51. data/specs.watchr +2 -4
  52. data/templates/skeleton.txt +148 -12
  53. metadata +20 -22
  54. data/bin/chatterbot-blacklist +0 -65
  55. data/bin/chatterbot-status +0 -55
  56. data/examples/loop_bot.rb +0 -44
  57. data/lib/chatterbot/blacklist.rb +0 -61
  58. data/lib/chatterbot/db.rb +0 -79
  59. data/lib/chatterbot/streaming_handler.rb +0 -96
  60. data/lib/chatterbot/whitelist.rb +0 -32
  61. data/spec/blacklist_spec.rb +0 -116
  62. data/spec/db_spec.rb +0 -53
  63. data/spec/streaming_handler_spec.rb +0 -78
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatterbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Mitchell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-27 00:00:00.000000000 Z
11
+ date: 2015-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: oauth
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.4.7
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.4.7
41
41
  - !ruby/object:Gem::Dependency
@@ -196,9 +196,7 @@ description: A ruby framework for writing bots that run on Twitter. Comes with a
196
196
  DSL for easy coding.
197
197
  email: colin@muffinlabs.com
198
198
  executables:
199
- - chatterbot-blacklist
200
199
  - chatterbot-register
201
- - chatterbot-status
202
200
  extensions: []
203
201
  extra_rdoc_files: []
204
202
  files:
@@ -209,50 +207,50 @@ files:
209
207
  - LICENSE.txt
210
208
  - README.markdown
211
209
  - Rakefile
212
- - bin/chatterbot-blacklist
213
210
  - bin/chatterbot-register
214
- - bin/chatterbot-status
215
211
  - chatterbot.gemspec
216
212
  - examples/class_bot.rb
217
213
  - examples/config.yml.example
218
214
  - examples/dsl_test.rb
219
215
  - examples/echoes_bot.rb
220
- - examples/loop_bot.rb
221
216
  - examples/search_bot.rb
222
217
  - examples/streaming_bot.rb
223
218
  - examples/tweet_logger.rb
224
219
  - lib/chatterbot.rb
225
- - lib/chatterbot/blacklist.rb
220
+ - lib/chatterbot/blocklist.rb
226
221
  - lib/chatterbot/bot.rb
227
222
  - lib/chatterbot/client.rb
228
223
  - lib/chatterbot/config.rb
229
- - lib/chatterbot/db.rb
224
+ - lib/chatterbot/config_manager.rb
225
+ - lib/chatterbot/direct_messages.rb
230
226
  - lib/chatterbot/dsl.rb
231
227
  - lib/chatterbot/favorite.rb
232
228
  - lib/chatterbot/followers.rb
229
+ - lib/chatterbot/handler.rb
233
230
  - lib/chatterbot/helpers.rb
234
231
  - lib/chatterbot/home_timeline.rb
235
232
  - lib/chatterbot/logging.rb
236
233
  - lib/chatterbot/profile.rb
237
234
  - lib/chatterbot/reply.rb
238
235
  - lib/chatterbot/retweet.rb
236
+ - lib/chatterbot/safelist.rb
239
237
  - lib/chatterbot/search.rb
240
238
  - lib/chatterbot/skeleton.rb
241
239
  - lib/chatterbot/streaming.rb
242
- - lib/chatterbot/streaming_handler.rb
243
240
  - lib/chatterbot/tweet.rb
244
241
  - lib/chatterbot/ui.rb
245
242
  - lib/chatterbot/utils.rb
246
243
  - lib/chatterbot/version.rb
247
- - lib/chatterbot/whitelist.rb
248
- - spec/blacklist_spec.rb
244
+ - spec/blocklist_spec.rb
249
245
  - spec/bot_spec.rb
250
246
  - spec/client_spec.rb
247
+ - spec/config_manager_spec.rb
251
248
  - spec/config_spec.rb
252
- - spec/db_spec.rb
249
+ - spec/direct_messages_spec.rb
253
250
  - spec/dsl_spec.rb
254
251
  - spec/favorite_spec.rb
255
252
  - spec/followers_spec.rb
253
+ - spec/handler_spec.rb
256
254
  - spec/helpers_spec.rb
257
255
  - spec/home_timeline_spec.rb
258
256
  - spec/logging_spec.rb
@@ -262,7 +260,6 @@ files:
262
260
  - spec/search_spec.rb
263
261
  - spec/skeleton_spec.rb
264
262
  - spec/spec_helper.rb
265
- - spec/streaming_handler_spec.rb
266
263
  - spec/streaming_spec.rb
267
264
  - spec/tweet_spec.rb
268
265
  - spec/utils_spec.rb
@@ -271,7 +268,7 @@ files:
271
268
  - templates/skeleton.txt
272
269
  homepage: http://github.com/muffinista/chatterbot
273
270
  licenses:
274
- - WTFPL
271
+ - MIT
275
272
  metadata: {}
276
273
  post_install_message:
277
274
  rdoc_options: []
@@ -284,9 +281,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
284
281
  version: '0'
285
282
  required_rubygems_version: !ruby/object:Gem::Requirement
286
283
  requirements:
287
- - - ">="
284
+ - - ">"
288
285
  - !ruby/object:Gem::Version
289
- version: '0'
286
+ version: 1.3.1
290
287
  requirements: []
291
288
  rubyforge_project: chatterbot
292
289
  rubygems_version: 2.2.2
@@ -294,14 +291,16 @@ signing_key:
294
291
  specification_version: 4
295
292
  summary: A ruby framework for writing Twitter bots
296
293
  test_files:
297
- - spec/blacklist_spec.rb
294
+ - spec/blocklist_spec.rb
298
295
  - spec/bot_spec.rb
299
296
  - spec/client_spec.rb
297
+ - spec/config_manager_spec.rb
300
298
  - spec/config_spec.rb
301
- - spec/db_spec.rb
299
+ - spec/direct_messages_spec.rb
302
300
  - spec/dsl_spec.rb
303
301
  - spec/favorite_spec.rb
304
302
  - spec/followers_spec.rb
303
+ - spec/handler_spec.rb
305
304
  - spec/helpers_spec.rb
306
305
  - spec/home_timeline_spec.rb
307
306
  - spec/logging_spec.rb
@@ -311,7 +310,6 @@ test_files:
311
310
  - spec/search_spec.rb
312
311
  - spec/skeleton_spec.rb
313
312
  - spec/spec_helper.rb
314
- - spec/streaming_handler_spec.rb
315
313
  - spec/streaming_spec.rb
316
314
  - spec/tweet_spec.rb
317
315
  - spec/utils_spec.rb
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
-
4
- require 'chatterbot'
5
- require 'optparse'
6
-
7
- include Chatterbot::Helpers
8
- include Chatterbot::Blacklist
9
- include Chatterbot::Config
10
- include Chatterbot::DB
11
- include Chatterbot::Logging
12
-
13
- Chatterbot::from_helper = true
14
-
15
- @display_blacklist = false
16
-
17
- #
18
- # pull in any arguments and set them as env variables
19
- #
20
- opts = OptionParser.new
21
- opts.banner = "Usage: #{File.basename($0)} [options]"
22
-
23
- opts.separator ""
24
- opts.separator "Specific options:"
25
-
26
- opts.on('-d', '--db [ARG]', "Specify a DB connection URI") { |d| ENV["chatterbot_db"] = d }
27
- opts.on('-c', '--config [ARG]', "Specify a config file to use") { |c| ENV["chatterbot_config"] = c }
28
- opts.on('-p', '--print', "Print out the current blacklist") { @display_blacklist = true }
29
- opts.on_tail("-h", "--help", "Show this message") do
30
- puts opts
31
- exit
32
- end
33
-
34
- extra = opts.parse!(ARGV)
35
-
36
- if ! has_db?
37
- puts "You need to specify a db connection!"
38
- exit
39
- end
40
-
41
-
42
- if @display_blacklist
43
- db[:blacklist].each do |u|
44
- puts u.inspect
45
- end
46
-
47
- elsif extra.empty?
48
- #
49
- # iterate through STDIN and add anything to the blacklist. nothing too shiny here.
50
- #
51
- $stdin.each_line do |l|
52
- add_to_blacklist(l.chomp)
53
- end
54
- else
55
- #
56
- # add any users specified on the command-line
57
- #
58
- extra.each do |l|
59
- add_to_blacklist(l.chomp)
60
- end
61
-
62
- end
63
-
64
-
65
-
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
-
4
- require 'chatterbot'
5
- require 'optparse'
6
-
7
- include Chatterbot::Helpers
8
- include Chatterbot::Config
9
- include Chatterbot::DB
10
-
11
- Chatterbot::from_helper = true
12
-
13
- @tweet_count = 5
14
-
15
- #
16
- # pull in any arguments and set them as env variables
17
- #
18
- opts = OptionParser.new
19
- opts.banner = "Usage: #{File.basename($0)} [options]"
20
-
21
- opts.separator ""
22
- opts.separator "Specific options:"
23
-
24
- opts.on('-d', '--db [ARG]', "Specify a DB connection URI") { |d| ENV["chatterbot_db"] = d }
25
- opts.on('-c', '--config [ARG]', "Specify a config file to use") { |c| ENV["chatterbot_config"] = c }
26
- opts.on('-t', '--tweets [ARG]', "How many tweets to display") { |t| @tweet_count = t.to_i }
27
-
28
- opts.on_tail("-h", "--help", "Show this message") do
29
- puts opts
30
- exit
31
- end
32
-
33
- extra = opts.parse!(ARGV)
34
-
35
- #
36
- # will only work if user is tracking tweets in a db
37
- #
38
- if ! has_db?
39
- puts "You need to specify a db connection!"
40
- exit
41
- end
42
-
43
- #
44
- # return total number of tweets sent in last 'days' days
45
- #
46
- def count_for_period(bot, days=1)
47
- db[:tweets].filter(:bot => bot[:id]).filter{created_at > (Time.now - (days*86400))}.count
48
- end
49
-
50
- db[:config].each do |bot|
51
- puts "Tweets from #{bot[:id]} #{[1,7,30].collect{|d| count_for_period(bot, d)}.join("/")}"
52
- db[:tweets].filter(:bot => bot[:id]).order(:created_at.desc).limit(@tweet_count).each do |t|
53
- puts "#{t[:created_at]}: #{t[:txt]} (#{t[:source_tweet]})"
54
- end
55
- end
data/examples/loop_bot.rb DELETED
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #
4
- # simple example of how to run a bot in a loop. if you want to do
5
- # that, you need to call update_config to update the database at the
6
- # end of each iteration -- this will keep you from processing the same
7
- # tweets multiple times
8
- #
9
-
10
-
11
- #
12
- # require the dsl lib to include all the methods you see below.
13
- #
14
- require 'rubygems'
15
- require 'chatterbot/dsl'
16
-
17
- puts "Loading echoes_bot.rb"
18
-
19
- ##
20
- ## If I wanted to exclude some terms from triggering this bot, I would list them here.
21
- ## For now, we'll block URLs to keep this from being a source of spam
22
- ##
23
- exclude "http://"
24
-
25
- blacklist "mean_user, private_user"
26
-
27
- loop do
28
-
29
- puts "run search #{since_id}"
30
- search "twitter" do |tweet|
31
- # here you could do something with a tweet
32
- end
33
-
34
- puts "checking for replies to me"
35
- replies do |tweet|
36
- src = "#USER# it is very nice of you to say that!"
37
- reply src, tweet
38
- end
39
-
40
- # explicitly update our config
41
- update_config
42
-
43
- sleep 1
44
- end
@@ -1,61 +0,0 @@
1
- module Chatterbot
2
-
3
- #
4
- # methods for preventing the bot from spamming people who don't want to hear from it
5
- module Blacklist
6
- attr_accessor :exclude, :blacklist
7
-
8
- # return a list of text strings which we will check for in incoming tweets.
9
- # If the text is listed, we won't use this tweet
10
- def exclude
11
- @exclude || []
12
- end
13
-
14
- # A list of Twitter users that don't want to hear from the bot.
15
- def blacklist
16
- @blacklist || []
17
- end
18
- def blacklist=(b)
19
- @blacklist = b
20
- end
21
-
22
- #
23
- # Based on the text of this tweet, should it be skipped?
24
- def skip_me?(s)
25
- search = s.respond_to?(:text) ? s.text : s
26
- exclude.detect { |e| search.downcase.include?(e) } != nil
27
- end
28
-
29
- #
30
- # Is this tweet from a user on our blacklist?
31
- def on_blacklist?(s)
32
- search = (s.respond_to?(:user) ? from_user(s) : s).downcase
33
- blacklist.any? { |b| search.include?(b.downcase) } ||
34
- on_global_blacklist?(search)
35
- end
36
-
37
- #
38
- # Is this user on our global blacklist?
39
- def on_global_blacklist?(user)
40
- return false if ! has_db?
41
- db[:blacklist].where(:user => user).count > 0
42
- end
43
-
44
- #
45
- # add the specified user to the global blacklist
46
- def add_to_blacklist(user)
47
- user = user.is_a?(Hash) ? user[:from_user] : user
48
-
49
- # don't try and add if we don't have a DB connection, or if the
50
- # user is already on the list
51
- return if ! has_db? || on_global_blacklist?(user)
52
-
53
- # make sure we don't have an @ at the beginning of the username
54
- user.gsub!(/^@/, "")
55
- debug "adding #{user} to blacklist"
56
-
57
- db[:blacklist].insert({ :user => user, :created_at => Time.now }) #
58
- end
59
-
60
- end
61
- end
data/lib/chatterbot/db.rb DELETED
@@ -1,79 +0,0 @@
1
- module Chatterbot
2
-
3
- #
4
- # routines for optionally interacting with a database for logging
5
- # tweets, and storing config data there. Uses Sequel to handle the
6
- # heavy lifing.
7
- module DB
8
- #
9
- # connect to the database, and generate any missing tables
10
- def db
11
- @_db ||= connect_and_validate
12
- end
13
-
14
- #:nocov:
15
- def display_db_config_notice
16
- puts "ERROR: You have specified a DB connection, but you need to install the sequel gem to use it"
17
- end
18
- #:nocov:
19
-
20
- protected
21
-
22
- #
23
- # get a DB object from Sequel
24
- def get_connection
25
- if ! has_sequel? && config.has_key?(:db_uri)
26
- display_db_config_notice
27
- elsif has_sequel?
28
- Sequel.connect(config[:db_uri])
29
- end
30
- end
31
-
32
- #
33
- # try and connect to the DB, and create tables that are missing.
34
- def connect_and_validate
35
- conn = get_connection
36
- return if conn.nil?
37
-
38
- if ! conn.tables.include?(:blacklist)
39
- conn.create_table :blacklist do
40
- String :user, :primary_key => true
41
- DateTime :created_at
42
- end
43
- end
44
-
45
- if ! conn.tables.include?(:tweets)
46
- conn.create_table :tweets do
47
- primary_key :id
48
- String :txt
49
- String :bot
50
- String :user
51
- String :source_id
52
- String :source_tweet
53
-
54
- DateTime :created_at
55
- end
56
- end
57
-
58
- if ! conn.tables.include?(:config)
59
- conn.create_table :config do
60
- String :id, :primary_key => true
61
-
62
- Bignum :since_id
63
- Bignum :since_id_reply
64
-
65
- String :secret
66
- String :token
67
- String :consumer_secret
68
- String :consumer_key
69
-
70
- DateTime :created_at
71
- DateTime :updated_at
72
- end
73
- end
74
-
75
- conn
76
- end
77
-
78
- end
79
- end