Sha256: 2b93426864d8bf3196a2bb19714a65752fb44d72e9679932bfa4d73fe3c8270d

Contents?: true

Size: 1.88 KB

Versions: 19

Compression:

Stored size: 1.88 KB

Contents

module Plugins
  class Movie
    include Cinch::Plugin
    include Cinch::Helpers

    enable_acl

    set(
     plugin_name: 'Movie',
     help: 'Movie Plots \nUsage: `?movie <name of movie>`;',
     react_on: :channel
    )

    match /movie (.*)/, method: :find_movie
    def find_movie(m, movie)
      data = query_movie(movie)
      if data && data.response == 'True'
        m.reply "Movie ⊥ #{data.title} (#{data.year}) <#{data.rated}> #{data.plot.to_s.strip[0..800]} [www.imdb.com/title/#{data.imdbid}/]"
      elsif data && data.response == 'False'
        m.reply data.error
      else
        m.reply 'Unable to find movie!'
      end
    end

    private
    def query_movie(m)
      year = m[/:\d+/].gsub(/:/, '') if m[/:\d+/]
      movie = URI.encode(m.gsub(/:\d+/, ''))
      data = JSON.parse(
          # RestClient.get("http://www.omdbapi.com/?t=#{movie}&y=#{year}")
          open("http://www.omdbapi.com/?t=#{movie}&y=#{year}").read
      )
      OpenStruct.new(
          title:       data['Title'],
          year:        data['Year'],
          rated:       data['Rated'],
          released:    data['Released'],
          runtime:     data['Runtime'],
          genre:       data['Genre'],
          director:    data['Director'],
          writer:      data['Writer'],
          actors:      data['Actors'],
          plot:        data['Plot'],
          language:    data['Language'],
          country:     data['Country'],
          awards:      data['Awards'],
          poster:      data['Poster'],
          metascore:   data['Metascore'],
          imdbrating:  data['imdbRating'],
          imdbvotes:   data['imdbVotes'],
          imdbid:      data['imdbID'],
          type:        data['Type'],
          response:    data['Response'],
          error:       data['Error']
      )
    rescue
      nil
    end


  end
end


# AutoLoad
Bot.config.plugins.plugins.push Plugins::Movie

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
zetabot-0.0.19 lib/Zeta/plugins/movie.rb
zetabot-0.0.18 lib/Zeta/plugins/movie.rb
zetabot-0.0.17 lib/Zeta/plugins/movie.rb
zetabot-0.0.16 lib/Zeta/plugins/movie.rb
zetabot-0.0.15 lib/Zeta/plugins/movie.rb
zetabot-0.0.14 lib/Zeta/plugins/movie.rb
zetabot-0.0.13 lib/Zeta/plugins/movie.rb
zetabot-0.0.12 lib/Zeta/plugins/movie.rb
zetabot-0.0.11 lib/Zeta/plugins/movie.rb
zetabot-0.0.10 lib/Zeta/plugins/movie.rb
zetabot-0.0.9 lib/Zeta/plugins/movie.rb
zetabot-0.0.8 lib/Zeta/plugins/movie.rb
zetabot-0.0.7 lib/Zeta/plugins/movie.rb
zetabot-0.0.6 lib/Zeta/plugins/movie.rb
zetabot-0.0.5 lib/Zeta/plugins/movie.rb
zetabot-0.0.4 lib/Zeta/plugins/movie.rb
zetabot-0.0.3 lib/Zeta/plugins/movie.rb
zetabot-0.0.2 lib/Zeta/plugins/movie.rb
zetabot-0.0.1 lib/Zeta/plugins/movie.rb