Advertisement
psycholyzern

speedtest.lua

Jul 24th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. -- speedtest-cli must be installed
  2. -- run "pip speedtest-cli" to install
  3.  
  4. local function grab(id)
  5.   if id then
  6.     share = " --share"
  7.   else
  8.     share = ""
  9.   end
  10.  
  11.   local handle = io.popen("speedtest-cli --simple"..share)
  12.   local result = handle:read("*a")
  13.   handle:close()
  14.  
  15.   if id then
  16.     local match = string.match(result, "(https?://[%w-_%.%?%.:/%+=&]+%.(png))")
  17.     if not match then
  18.       return "Not able to grab the result image."
  19.     end
  20.     local file = download_to_file(match)
  21.     local cb_extra = {file_path=file}
  22.     local send = send_photo(id, file, rmtmp_cb, cb_extra)
  23.     print(id, send)
  24.     return
  25.   else
  26.     return result
  27.   end
  28. end
  29.  
  30. local function speed(id)
  31.   if id then
  32.     return grab(id)
  33.   else
  34.     return grab()
  35.   end
  36.  
  37. end
  38.  
  39. local function run(msg, matches)
  40.   if matches[1] == 'share' then
  41.     return speed(get_receiver(msg))
  42.   else
  43.     return speed()
  44.   end
  45. end
  46.  
  47. return {
  48.   description = "",
  49.   usage = "",
  50.   patterns = {
  51.     "^!speed$",
  52.     "^!speed (share)",
  53.     "^!speed (.+)$"
  54.     },
  55.   run = run,
  56.   privileged = true
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement