Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TimestampToSec = MOD.TimestampToSec;
- local SecondToSpan = MOD.SecondToSpan;
- local function GetFollowed(user,channel)
- local body, code, headers, status;
- if user:lower() == channel:lower() then
- body, code, headers, status = MOD.HTTPSGet("https://api.twitch.tv/kraken/channels/"..channel);
- else
- body, code, headers, status = MOD.HTTPSGet("https://api.twitch.tv/kraken/users/"..user.."/follows/channels/"..channel);
- end
- if body == nil or body == "" or code ~= 200 then
- return nil;
- end
- local raw = JSONDecode(body);
- if raw == nil then
- return nil;
- end
- if type(raw.created_at) == "string" then
- local tbl = {};
- tbl.Followed = raw.created_at;
- tbl.Timestamp = TimestampToSec(raw.created_at);
- tbl.TimeFollowed = os.time()-tbl.Timestamp;
- tbl.FollowedFor = SecondToSpan(tbl.TimeFollowed);
- tbl.Followed = tbl.Followed:gsub("T"," ");
- tbl.Followed = tbl.Followed:gsub("Z","");
- return tbl;
- else
- return nil;
- end
- end
- MOD.GetFollowData = GetFollowed;
- return function(msg,usr,chan)
- local target = usr;
- if UserStatus(usr) == 2 and msg~=nil and msg~="" then
- target = msg;
- end
- local data = GetFollowed(target,chan:sub(2));
- if data == nil then
- print(target.." is not following " .. chan:sub(2));
- else
- print(target.." followed "..chan:sub(2).." "..data.Followed.." and has been following for "..data.FollowedFor);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement