Sha256: b55ce81f39f3e4374271b9047bf12957c6ef671d7602487fd5535531c37edb90

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

require 'twitter'

module Cinch
  module Plugins
    class Tweet
      include Cinch::Plugin

      match /t ?([^ ]*)?( ?.*)/

      set :plugin_name, 'tweet'
      set :help, <<EOT
Tweet makes the bot can query twittter API
.t search <term> : searches the public timelines
EOT

=begin
  Twitter.configure do |c|
    c.consumer_key = @bot.config.options.cogconf['tweet']['consumer_key']
    c.consumer_secret = @bot.config.options.cogconf['tweet']['consumer_secret']
    c.oauth_token = @bot.config.options.cogconf['tweet']['oauth_token']
    c.oauth_token_secret = @bot.config.options.cogconf['tweet']['oauth_token_secret']
  end
=end

      def new(bot)
        @bot = bot
      end

      def exec(command,args)
        back = ''
        #back += "command: #{command} / args: #{args}\n"
        begin
          case command
          when 'search'
            Twitter.search(args, { :lang => 'en', :rpp => '3' }).each do|status|
              back += status.full_text + "\n"
            end
          else
            back += Twitter.send(command,args.split(','))
          end
        rescue Exception => e
          back += "Bad request\n"
          back += e.inspect
        end
        return back
      end

      def execute(m,command,args)
        m.reply(exec(command,args.strip))
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cogbot-0.1.0 plugins/tweet.rb
cogbot-0.0.3 plugins/tweet.rb
cogbot-0.0.2 plugins/tweet.rb