Advertisement
psycholyzern

imdb.lua

Jun 28th, 2015
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | None | 0 0
  1. do
  2.  
  3. local function imdb(movie)
  4.   local http = require("socket.http")
  5.   local movie = movie:gsub(' ', '+')
  6.   local url = "http://www.imdbapi.com/?t=" .. movie
  7.   local response, code, headers = http.request(url)
  8.  
  9.   if code ~= 200 then
  10.     return "Error: " .. code
  11.   end
  12.  
  13.   if #response > 0 then
  14.     local r = json:decode(response)
  15.     r['Url'] = "http://imdb.com/title/" .. r.imdbID
  16.     local text = "Title: "..r.Title.."\nRating: "..r.imdbRating.."\nPlot: "..r.Plot.."\nURL: "..r.Url
  17.     return text
  18.   end
  19.   return nil
  20. end
  21.  
  22. local function run(msg, matches)
  23.   return imdb(matches[1])
  24. end
  25.  
  26. return {
  27.   description = "IMDB plugin for telegram",
  28.   usage = "!imdb [movie]",
  29.   patterns = {"^!imdb (.+)"},
  30.   run = run
  31. }
  32.  
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement