Advertisement
Guest User

lua - telegram - quotation plugin

a guest
Jan 24th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. function quotation()
  2.     local http = require("socket.http")
  3.     local xml = require("xml")
  4.     local parser = xml.Parser(xml.Parser.Fastest)
  5.     http.TIMEOUT = 5
  6.  
  7.     r, c = http.request("http://developers.agenciaideias.com.br/cotacoes/xml")
  8.     local data = parser:load(r)
  9.  
  10.  
  11.     for k, v in pairs(data[2]) do
  12.         if v[1] ~= nil then
  13.         quotation = v[1]
  14.         quotation = string.gsub(quotation, "%s+", "")
  15.         break
  16.         return "Quotation: R$ "..quotation
  17.         end
  18.     end
  19.  
  20.  
  21.     for x, y in pairs(data) do
  22.         if type(y[1]) ~= "table" then
  23.             if type(y[1]) ~= nil then
  24.             update = y[1]
  25.             update = string.gsub(update, "%s+", "")
  26.             update = string.gsub(update, "-", " ")
  27.             break
  28.             return "Updated: "..update
  29.             end
  30.         end
  31.     end
  32. end
  33.  
  34.  
  35. function run(msg, matches)
  36.     return quotation()
  37. end
  38.  
  39.  
  40. return {
  41.     description = "Shows the dollar quotation",
  42.     usage = "!quotation",
  43.     patterns = {"^!quotation$"},
  44.     run = run
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement