lib/chatterbot/dsl.rb in chatterbot-0.4.0 vs lib/chatterbot/dsl.rb in chatterbot-0.5.0

- old
+ new

@@ -9,35 +9,35 @@ # # generate a Bot object. if the DSL is being called from a Bot object, just return it # otherwise create a bot and return that def bot return @bot unless @bot.nil? - + # # parse any command-line options and use them to initialize the bot # params = {} - + opts = OptionParser.new opts.banner = "Usage: #{File.basename($0)} [options]" opts.separator "" - opts.separator "Specific options:" - + opts.separator "Specific options:" + opts.on('-d', '--db [ARG]', "Specify a DB connection URI") { |d| ENV["chatterbot_db"] = d } 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('-s', '--since_id [ARG]', "Check for tweets since tweet id #[ARG]") { |s| params[:since_id] = s.to_i } opts.on_tail("-h", "--help", "Show this message") do puts opts exit - end - + end + opts.parse!(ARGV) @bot = Chatterbot::Bot.new(params) end @@ -78,64 +78,74 @@ # presumably an array b end end.flatten end - + # - # specify a bot-specific blacklist of users. accepts an array, or a + # specify a bot-specific blacklist of users. accepts an array, or a # comma-delimited string def blacklist(*args) list = flatten_list_of_strings(args) - + if list.nil? || list.empty? bot.blacklist = [] - else + else bot.blacklist += list end end - + # # specify list of strings we will check when deciding to respond to a tweet or not def exclude(*args) e = flatten_list_of_strings(args) if e.nil? || e.empty? bot.exclude = [] - else + else bot.exclude += e end end - + # # search twitter for the specified terms def search(query, opts = {}, &block) bot.search(query, opts, &block) end - + # # handle replies to the bot def replies(&block) bot.replies(&block) end # # send a tweet def tweet(txt, params = {}, original = nil) bot.tweet(txt, params, original) - end + end # + # retweet + def retweet(id) + bot.retweet(id) + end + + # # reply to a tweet def reply(txt, source) bot.reply(txt, source) end def since_id bot.config[:since_id] end - + def update_config bot.update_config + end + + def db + bot.db end end end include Chatterbot::DSL