Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function Merge(tbl,tbl2)
- for k,v in ipairs(tbl2.entries)do
- table.insert(tbl.entries,v);
- end
- return tbl;
- end
- local cache = {};
- local function RawLadderRequest(leaguename,entries)
- if cache.request and cache.request == leaguename and cache.tbl and cache.time and (os.time()-cache.time) < 300 then
- return cache.tbl;
- end
- local cnt = 0;
- local request = entries;
- local ladder = false;
- local current = false;
- local actual = entries;
- while(entries>=cnt)do
- if actual> 200 then
- actual= 200;
- elseif actual<=0 then
- break;
- end
- local req = "http://api.pathofexile.com/ladders/"..leaguename:gsub("/","%%2F").."?offset="..tostring(cnt).."&limit="..tostring(actual);
- --print(req);
- cnt = cnt + actual;
- request = request - actual;
- actual = request;
- current = JSONDecode(MOD.HTTPGet(req));
- if not current or current.error~=nil then
- break;
- end
- if(not ladder)then
- ladder = current;
- else
- ladder = Merge(ladder,current);
- end
- if(entries>=ladder.total)then
- break;
- end
- end
- cache.tbl = ladder;
- cache.time = os.time();
- cache.request = leaguename;
- return ladder;
- end
- local function GetLadder(laddersize)
- local league = MOD.GetLeague()
- if not league or league.starts > os.time() then
- return nil;
- end
- local ladder = RawLadderRequest(league.id,laddersize);
- if ladder == nil then
- print("HTTPGet error");
- return nil;
- elseif ladder.error ~= nil then
- print("ERROR: " .. ladder.error.message);
- return nil;
- end
- local entries = ladder.total;
- if(entries>laddersize) then
- entries=laddersize;
- end
- local formatted = {id=league.id,time=league.ends-os.time()};
- for n=1,entries do
- if ladder.entries[n] ~= nil then
- local entry = {dead=ladder.entries[n].dead};
- entry.class = ladder.entries[n].character.class;
- entry.rank = n;
- entry.level = ladder.entries[n].character.level;
- if ladder.entries[n].account.twitch ~= nil then
- entry.name = ladder.entries[n].account.twitch.name:lower();
- entry.twitch = true;
- else
- entry.name = ladder.entries[n].account.name:lower();
- entry.twitch = false;
- end
- table.insert(formatted,entry);
- end
- end
- return formatted;
- end
- local classes = {};
- table.insert(classes,"witch");
- table.insert(classes,"shadow");
- table.insert(classes,"ranger");
- table.insert(classes,"duelist");
- table.insert(classes,"marauder");
- table.insert(classes,"templar");
- table.insert(classes,"scion");
- local function isClass(str)
- local l = str:lower();
- for n=1,#classes do
- if classes[n]==l then
- return true;
- end
- end
- return false;
- end
- local function isNumber(str)
- for n=1,str:len() do
- if str:byte(n) < 48 or str:byte(n) > 57 then
- return false;
- end
- end
- return true;
- end
- local cmd = function(msg,usr,chan)
- if not msg or msg == "" then
- msg = chan:sub(2);
- end
- local laddersize = 400;
- local ladder = GetLadder(laddersize);
- if ladder == nil then
- print("No race is currently running or the race has not yet started!");
- return nil;
- end
- local deadinfo = false;
- local class = false;
- local rank = nil;
- if(isClass(msg))then
- class=true;
- elseif isNumber(msg) then
- rank = math.floor(tonumber(msg));
- if rank > #ladder then
- rank = #ladder;
- elseif rank < 1 then
- rank = 1;
- end
- end
- msg = msg:lower();
- local data = {};
- local first = {};
- for n=1,#ladder do
- local entry = ladder[n];
- if class and entry.class:lower() == msg and not entry.dead then
- msg = entry.name;
- class = false;
- elseif rank ~= nil and n == rank then
- msg = entry.name;
- rank=nil;
- end
- if entry.name == msg and data.rank == nil then
- data.rank = entry.rank;
- data.currentclass = entry.class;
- data.level = entry.level;
- if data[entry.class] == nil then
- data[entry.class] = 0;
- end
- data[entry.class] = data[entry.class] + 1;
- data.classrank = data[entry.class];
- data.dead = entry.dead;
- if data.dead then
- if not deadinfo then
- deadinfo = {};
- deadinfo.Class = entry.class;
- deadinfo.ClassRank = data.classrank;
- deadinfo.Rank = data.rank;
- deadinfo.Level = data.level;
- end
- data.deadrank = data.rank;
- data.rank=nil;
- end
- if first[entry.class] == nil then
- first[entry.class] = entry.name;
- end
- else
- if data[entry.class] == nil then
- data[entry.class] = 0;
- end
- if first[entry.class] == nil then
- first[entry.class] = entry.name;
- end
- data[entry.class] = data[entry.class] + 1;
- end
- end
- if data.deadrank and not data.rank then
- data.rank = data.deadrank;
- end
- if data.currentclass == nil then
- print(msg.." is not in the top "..tostring(laddersize));
- print("Time left: " .. MOD.SecondToSpan(ladder.time));
- else
- print(msg.." is");
- print("#"..tostring(data.classrank));
- print(data.currentclass .. " level " .. tostring(data.level));
- print("#"..tostring(data.rank).." overall");
- if data.dead then
- print("but is however dead raizRip");
- elseif deadinfo then
- print("also has a dead level ".. tostring(deadinfo.Level).. " " ..deadinfo.Class.." at rank #" .. tostring(deadinfo.ClassRank) .. " (#".. tostring(deadinfo.Rank).. " overall) raizRip");
- end
- print("Time left: " .. MOD.SecondToSpan(ladder.time));
- end
- end
- return cmd;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement