Class: Chatterbot::Bot
- Inherits:
-
Object
- Object
- Chatterbot::Bot
- Includes:
- Blocklist, Client, Config, DirectMessages, Favorite, Followers, Helpers, HomeTimeline, Logging, Profile, Reply, Retweet, Safelist, Search, Tweet, UI, Utils
- Defined in:
- lib/chatterbot/bot.rb
Overview
primary Bot object, includes all the other modules
Constant Summary collapse
- HANDLER_CALLS =
handlers that can use the REST API
[:direct_messages, :home_timeline, :replies, :search]
Constants included from UI
Constants included from Search
Instance Attribute Summary
Attributes included from Client
Attributes included from Config
Attributes included from Safelist
Attributes included from Blocklist
Instance Method Summary collapse
- #after_run ⇒ Object
- #before_run ⇒ Object
- #call_api_immediately? ⇒ Boolean
-
#initialize(params = {}) ⇒ Bot
constructor
Create a new bot.
- #register_handler(method, opts = nil, &block) ⇒ Object
-
#run! ⇒ Object
run the bot with the REST API.
- #screen_name ⇒ Object
Methods included from Helpers
#botname, #botname=, #current_user, #from_user, #replace_variables, #tweet_user
Methods included from Client
#authenticated_user, #base_url, #consumer, #default_opts, #generate_authorize_url, #get_screen_name, #init_client, #login, #request_token, #require_login, #reset!, #reset_client, #reset_since_id, #reset_since_id_counters, #reset_since_id_dm, #reset_since_id_home_timeline, #reset_since_id_reply
Methods included from UI
#ask_yes_no, #deprecated, #display_oauth_error, #get_api_key, #get_oauth_verifier, #green, #red, #send_to_app_creation
Methods included from Followers
Methods included from Reply
Methods included from Favorite
Methods included from Retweet
Methods included from Profile
#profile_text, #profile_website
Methods included from Tweet
Methods included from HomeTimeline
Methods included from DirectMessages
#direct_message, #direct_messages
Methods included from Search
#exclude_retweets, #include_retweets, #search, #skippable_retweet?, #wrap_search_query
Methods included from Logging
Methods included from Config
attr_boolean, attr_since_id, #bot_config, #chatterbot_helper?, #client_params, #config_file, #global_config, #global_config_files, #load_config, #log_dest, #logging?, #max_id_from, #needs_api_key?, #needs_auth_token?, #no_update=, #no_update?, #slurp_file, #update_config?, #working_dir
Methods included from Safelist
#has_safelist?, #on_safelist?, #whitelist
Methods included from Blocklist
#blacklist, #interact_with_user?, #on_blocklist?, #skip_me?, #valid_tweet?
Methods included from Utils
Constructor Details
#initialize(params = {}) ⇒ Bot
Create a new bot. No options for now.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/chatterbot/bot.rb', line 30 def initialize(params={}) if params.has_key?(:name) @botname = params.delete(:name) end @config = load_config(params) @run_count = 0 # # check for command line options # handle resets, etc # at_exit do if !@handlers.empty? && @run_count <= 0 && skip_run? != true run! end raise $! if $! end @handlers = {} end |
Instance Method Details
#after_run ⇒ Object
79 80 81 |
# File 'lib/chatterbot/bot.rb', line 79 def after_run end |
#before_run ⇒ Object
75 76 77 |
# File 'lib/chatterbot/bot.rb', line 75 def before_run @run_count = @run_count + 1 end |
#call_api_immediately? ⇒ Boolean
83 84 85 |
# File 'lib/chatterbot/bot.rb', line 83 def call_api_immediately? true end |
#register_handler(method, opts = nil, &block) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/chatterbot/bot.rb', line 87 def register_handler(method, opts = nil, &block) # @todo raise error if method already defined @handlers[method] = Handler.new(opts, &block) h = @handlers[method] self.send(method, *(h.opts)) do |obj| h.call(obj) end end |
#run! ⇒ Object
run the bot with the REST API
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/chatterbot/bot.rb', line 60 def run! before_run HANDLER_CALLS.each { |c| if (h = @handlers[c]) send(c, *(h.opts)) do |obj| h.call(obj) end end } after_run end |
#screen_name ⇒ Object
53 54 55 |
# File 'lib/chatterbot/bot.rb', line 53 def screen_name @screen_name ||= client.settings.screen_name end |