Advertisement
Terrah

follower

Mar 13th, 2015
1,485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. local TimestampToSec = MOD.TimestampToSec;
  2. local SecondToSpan = MOD.SecondToSpan;
  3.  
  4. local function GetFollowed(user,channel)
  5.  
  6.     local body, code, headers, status;
  7.  
  8.     if user:lower() == channel:lower() then
  9.         body, code, headers, status = MOD.HTTPSGet("https://api.twitch.tv/kraken/channels/"..channel);
  10.     else
  11.         body, code, headers, status = MOD.HTTPSGet("https://api.twitch.tv/kraken/users/"..user.."/follows/channels/"..channel);
  12.     end
  13.  
  14.     if body == nil or body == "" or code ~= 200 then
  15.         return nil;
  16.     end
  17.  
  18.     local raw = JSONDecode(body);
  19.  
  20.     if raw == nil then
  21.         return nil;
  22.     end
  23.  
  24.     if type(raw.created_at) == "string" then
  25.  
  26.         local tbl = {};
  27.         tbl.Followed = raw.created_at;
  28.         tbl.Timestamp = TimestampToSec(raw.created_at);
  29.         tbl.TimeFollowed = os.time()-tbl.Timestamp;
  30.         tbl.FollowedFor = SecondToSpan(tbl.TimeFollowed);
  31.        
  32.         tbl.Followed = tbl.Followed:gsub("T"," ");
  33.         tbl.Followed = tbl.Followed:gsub("Z","");
  34.  
  35.         return tbl;
  36.     else
  37.         return nil;
  38.     end
  39. end
  40.  
  41. MOD.GetFollowData = GetFollowed;
  42.  
  43. return function(msg,usr,chan)
  44.  
  45.     local target = usr;
  46.  
  47.     if UserStatus(usr) == 2 and msg~=nil and msg~="" then
  48.         target = msg;
  49.     end
  50.  
  51.     local data = GetFollowed(target,chan:sub(2));
  52.  
  53.     if data == nil then
  54.         print(target.." is not following " .. chan:sub(2));
  55.     else
  56.         print(target.." followed "..chan:sub(2).." "..data.Followed.." and has been following for "..data.FollowedFor);
  57.     end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement