Sha256: ebb8c7caa7280dc01add92711336b171d44d801779aab3dc2f1c44dbfabff1ff

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

module Twibot
  @@prompt = false

  def self.prompt=(p)
    @@prompt = f
  end

  module Macros
    def self.included(mod)
      @@bot = nil
    end

    def configure(&blk)
      bot.configure(&blk)
    end

    def message(pattern = nil, options = {}, &blk)
      add_handler(:message, pattern, options, &blk)
    end

    def reply(pattern = nil, options = {}, &blk)
      add_handler(:reply, pattern, options, &blk)
    end

    def tweet(pattern = nil, options = {}, &blk)
      add_handler(:tweet, pattern, options, &blk)
    end

    def twitter
      bot.twitter
    end

    alias_method :client, :twitter

    def post_tweet(msg)
      message = msg.respond_to?(:text) ? msg.text : msg
      puts message
      client.status(:post, message)
    end

    def run?
      !@@bot.nil?
    end

   private
    def add_handler(type, pattern, options, &blk)
      bot.add_handler(type, Twibot::Handler.new(pattern, options, &blk))
    end

    def bot
      return @@bot unless @@bot.nil?

      begin
        @@bot = Twibot::Bot.new nil, true
      rescue Exception
        @@bot = Twibot::Bot.new(Twibot::Config.default << Twibot::CliConfig.new, true)
      end

      @@bot
    end

    def self.bot=(bot)
      @@bot = bot
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
bjeanes-twibot-0.1.6 lib/twibot/macros.rb
bjeanes-twibot-0.1.7 lib/twibot/macros.rb
twibot-0.1.1 lib/twibot/macros.rb
twibot-0.1.0 lib/twibot/macros.rb
twibot-0.1.5 lib/twibot/macros.rb
twibot-0.1.3 lib/twibot/macros.rb
twibot-0.1.2 lib/twibot/macros.rb
twibot-0.1.4 lib/twibot/macros.rb
twibot-0.1.6 lib/twibot/macros.rb