Advertisement
psycholyzern

DownUp.lua

Jul 14th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. do
  2.  
  3. function custom_func(cb_extra, success, result)
  4.   if success then
  5.     local start_time = cb_extra[2]
  6.     local file_path = cb_extra[3].file_path
  7.     local end_time = os.time()
  8.     local elapsed_time = os.difftime(end_time,start_time)
  9.     local message = "Elapsed Time: "..os.difftime(end_time,start_time).." second(s)"
  10.     send_msg(cb_extra[1], message, ok_cb, false)
  11.  
  12.     if file_path ~= nil then
  13.       os.remove(file_path)
  14.       print("Deleted: "..file_path)
  15.     end
  16.   end
  17. end
  18.  
  19. local function DownUp(receiver, url, ext)
  20.   local start_time = os.time()
  21.   local file = download_to_file(url)
  22.   local cb_extra = {file_path=file}
  23.   print('send_file')
  24.  
  25.   send_file(receiver, file, custom_func, {receiver, start_time, cb_extra})
  26.  
  27. end
  28.  
  29. local function run(msg,matches)
  30.   DownUp(get_receiver(msg), matches[1], matches[2])
  31. end
  32.  
  33. return {
  34.   description = "Download and reupload requested file ",
  35.   usage = "",
  36.   patterns = {
  37.     "!download (https?://[%w-_%.%?%.:/%+=&]+%.(.*))$"
  38.   },
  39.   run = run,
  40.   hide = true,
  41.   privileged = true
  42. }
  43.  
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement