Method: Chatterbot::DSL#bot

Defined in:
lib/chatterbot/dsl.rb

#botObject

generate a Bot object. if the DSL is being called from a Bot object, just return it otherwise create a bot and return that



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/chatterbot/dsl.rb', line 159

def bot
  return @bot unless @bot.nil?

  @bot_command = nil
  
  #
  # parse any command-line options and use them to initialize the bot
  #
  params = {}

  #:nocov:
  opts = OptionParser.new

  opts.banner = "Usage: #{File.basename($0)} [options]"

  opts.separator ""
  opts.separator "Specific options:"


  opts.on('-c', '--config [ARG]', "Specify a config file to use")    { |c| ENV["chatterbot_config"] = c }
  opts.on('-t', '--test', "Run the bot without actually sending any tweets") { params[:debug_mode] = true }
  opts.on('-v', '--verbose', "verbose output to stdout")    { params[:verbose] = true }
  opts.on('--dry-run', "Run the bot in test mode, and also don't update the database")    { params[:debug_mode] = true ; params[:no_update] = true }

  opts.on('-r', '--reset', "Reset your bot to ignore old tweets") {
    @bot_command = :reset_since_id_counters
  }

  opts.on('--profile [ARG]', "get/set your bot's profile text") { |p| 
    @bot_command = :profile_text
    @bot_command_args = [ p ]
  }

  opts.on('--website [ARG]', "get/set your bot's profile URL") { |u| 
    @bot_command = :profile_website
    @bot_command_args = [ u ]
  }
  
  opts.on_tail("-h", "--help", "Show this message") do
    puts opts
    exit
  end

  opts.parse!(ARGV)
  #:nocov:

  @bot = Chatterbot::Bot.new(params)
  if @bot_command != nil
    @bot.skip_run = true
    result = @bot.send(@bot_command, *@bot_command_args)
    puts result
  end

  @bot
end