madae the skill thing lol
This commit is contained in:
parent
e6054cd066
commit
670f166e82
23
src/main.lua
23
src/main.lua
@ -213,6 +213,7 @@ local commands=require('./modules/commands.lua')
|
|||||||
local prefix = ','
|
local prefix = ','
|
||||||
local client = discordia.Client()
|
local client = discordia.Client()
|
||||||
_G.client = client
|
_G.client = client
|
||||||
|
_G.locked = false
|
||||||
|
|
||||||
discordia.extensions()
|
discordia.extensions()
|
||||||
|
|
||||||
@ -265,19 +266,23 @@ client:on('messageCreate', function(message)
|
|||||||
local cmdName=args[1]
|
local cmdName=args[1]
|
||||||
table.remove(args,1)
|
table.remove(args,1)
|
||||||
local command=commands.command_list[cmdName]
|
local command=commands.command_list[cmdName]
|
||||||
if command~=nil then
|
if not _G.locked then
|
||||||
if message.guild~=nil then
|
if command~=nil then
|
||||||
local s,e=pcall(function()
|
if message.guild~=nil then
|
||||||
command.exec({message=message,args=args,mentions=mentions,t={client,discordia,token}})
|
local s,e=pcall(function()
|
||||||
end)
|
command.exec({message=message,args=args,mentions=mentions,t={client,discordia,token}})
|
||||||
if not s then
|
end)
|
||||||
message:reply('tripped : '..e:split('/')[#e:split('/')])
|
if not s then
|
||||||
|
message:reply('tripped : '..e:split('/')[#e:split('/')])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
message:reply('i will not let you type in dms!!! 😠')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
message:reply('i will not let you type in dms!!! 😠')
|
message:reply('command does not exist 👎')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
message:reply('command does not exist 👎')
|
message:reply('bot is locked, please wait until it is unlocked')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
14
src/modules/commands/cmds.lua
Normal file
14
src/modules/commands/cmds.lua
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
local discordia=require('discordia')
|
||||||
|
local commands=require('./../commands.lua')
|
||||||
|
discordia.extensions()
|
||||||
|
commands:Add('cmds',{'commands','cmd','help'},'Returns a list of all commands',function(t)
|
||||||
|
local final='```\n'
|
||||||
|
for i,v in pairs(commands.command_list) do
|
||||||
|
local name=v.name
|
||||||
|
local alias=table.concat(v.alias,', ') or 'None'
|
||||||
|
local desc=v.desc
|
||||||
|
final=final..'Name: '..name..'\nDescription: '..desc..'\n'..'Aliases: '..alias..'\n\n'
|
||||||
|
end
|
||||||
|
final=final..'```'
|
||||||
|
t.message:reply(final)
|
||||||
|
end)
|
46
src/modules/commands/map.lua
Normal file
46
src/modules/commands/map.lua
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
local discordia=require('discordia')
|
||||||
|
local API=require('./../strafes_net.lua')
|
||||||
|
local commands=require('./../commands.lua')
|
||||||
|
discordia.extensions()
|
||||||
|
|
||||||
|
commands:Add('map',{},'get map info', function(t)
|
||||||
|
local game = API.GAMES[t.args[1]]
|
||||||
|
local map_name
|
||||||
|
if not game then
|
||||||
|
map_name = table.concat(t.args,' ')
|
||||||
|
else
|
||||||
|
map_name = table.concat(t.args,' ',2)
|
||||||
|
end
|
||||||
|
if not map_name then return t.message:reply('invalid arguments') end
|
||||||
|
if game then
|
||||||
|
if API.MAPS[game][map_name] then
|
||||||
|
local map = API.MAPS[game][map_name]
|
||||||
|
local formatted_message = '```'..
|
||||||
|
'Map: '..map.DisplayName..' ('..API.GAMES[game]..')\n'..
|
||||||
|
'ID: '..map.ID..'\n'..
|
||||||
|
'Creator: '..map.Creator..'\n'..
|
||||||
|
'PlayCount: '..map.PlayCount..'\n'..
|
||||||
|
'Published: '..os.date('%A, %B %d %Y @ %I:%M (%p)',map.Date)..
|
||||||
|
'```'
|
||||||
|
return t.message:reply(formatted_message)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for _,game in next,API.GAMES do
|
||||||
|
if type(tonumber(game)) == 'number' then
|
||||||
|
if API.MAPS[game][map_name] then
|
||||||
|
local map = API.MAPS[game][map_name]
|
||||||
|
local formatted_message = '```'..
|
||||||
|
'Map: '..map.DisplayName..' ('..API.GAMES[game]..')\n'..
|
||||||
|
'ID: '..map.ID..'\n'..
|
||||||
|
'Creator: '..map.Creator..'\n'..
|
||||||
|
'PlayCount: '..map.PlayCount..'\n'..
|
||||||
|
'Published: '..os.date('%A, %B %d %Y @ %I:%M (%p)',map.Date)..
|
||||||
|
'```'
|
||||||
|
return t.message:reply(formatted_message)
|
||||||
|
else
|
||||||
|
return t.message:reply('map not found')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
42
src/modules/commands/maps_init.lua
Normal file
42
src/modules/commands/maps_init.lua
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
local discordia=require('discordia')
|
||||||
|
local API=require('./../strafes_net.lua')
|
||||||
|
discordia.extensions()
|
||||||
|
API.MAPS={}
|
||||||
|
for _,game in next,API.GAMES do
|
||||||
|
if type(tonumber(game)) == 'number' then
|
||||||
|
local maps = {count=0}
|
||||||
|
local res,headers = API:GetMaps(game)
|
||||||
|
local pages = tonumber(headers['Pagination-Count'])
|
||||||
|
maps.count=maps.count+#res
|
||||||
|
for _,v in next,res do
|
||||||
|
maps[v.ID]=v
|
||||||
|
end
|
||||||
|
if pages>1 then
|
||||||
|
for i=2,pages do
|
||||||
|
res,headers = API:GetMaps(game,i)
|
||||||
|
maps.count=maps.count+#res
|
||||||
|
for _,j in next,res do
|
||||||
|
maps[j.ID]=j
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
setmetatable(maps,{__index=function(self,i)
|
||||||
|
if i=='count' then return self.count end
|
||||||
|
if not tonumber(i) then
|
||||||
|
for ix,v in next,self do
|
||||||
|
if type(v)=='table' and v.DisplayName:lower():find(i:lower()) then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif tonumber(i) then
|
||||||
|
for ix,v in next,self do
|
||||||
|
if type(v)=='table' and v.ID==i then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end})
|
||||||
|
API.MAPS[game]=maps
|
||||||
|
print('map init done for game:',API.GAMES[game],'count:',API.MAPS[game].count)
|
||||||
|
end
|
||||||
|
end
|
@ -10,6 +10,8 @@ commands:Add('rank',{},'rank <username|mention|"me"> <game> <style>', function(t
|
|||||||
local user=args[1]
|
local user=args[1]
|
||||||
local game=API.GAMES[args[2]]
|
local game=API.GAMES[args[2]]
|
||||||
local style=API.STYLES[args[3]]
|
local style=API.STYLES[args[3]]
|
||||||
|
if not game then return message:reply('invalid game') end
|
||||||
|
if not style then return message:reply('invalid style') end
|
||||||
if user=='me' then
|
if user=='me' then
|
||||||
local me=message.author
|
local me=message.author
|
||||||
local roblox_user=API:GetRobloxInfoFromDiscordId(me.id)
|
local roblox_user=API:GetRobloxInfoFromDiscordId(me.id)
|
||||||
@ -25,8 +27,9 @@ commands:Add('rank',{},'rank <username|mention|"me"> <game> <style>', function(t
|
|||||||
local roblox_user=API:GetRobloxInfoFromUsername(user)
|
local roblox_user=API:GetRobloxInfoFromUsername(user)
|
||||||
user=roblox_user
|
user=roblox_user
|
||||||
end
|
end
|
||||||
local rank = API:GetRank(user.id,game,style)
|
|
||||||
local sn_info = API:GetUser(user.id)
|
local sn_info = API:GetUser(user.id)
|
||||||
|
if not sn_info.ID then return message:reply('```No data with StrafesNET is associated with that user.```') end
|
||||||
|
local rank = API:GetRank(user.id,game,style)
|
||||||
local rank_string = API:FormatRank(rank.Rank)
|
local rank_string = API:FormatRank(rank.Rank)
|
||||||
local skill = API:FormatSkill(rank.Skill)
|
local skill = API:FormatSkill(rank.Skill)
|
||||||
local formatted_message = '```'..
|
local formatted_message = '```'..
|
||||||
|
92
src/modules/commands/skillCalc.lua
Normal file
92
src/modules/commands/skillCalc.lua
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
local discordia=require('discordia')
|
||||||
|
local API=require('./../strafes_net.lua')
|
||||||
|
local commands=require('./../commands.lua')
|
||||||
|
function sleep(n) local t = os.clock() while os.clock()-t <= n do end end
|
||||||
|
discordia.extensions()
|
||||||
|
commands:Add('skill',{},'calculate skill from placement', function(t)
|
||||||
|
local args=t.args
|
||||||
|
local message=t.message
|
||||||
|
if #args<3 then return message:reply('invalid arguments') end
|
||||||
|
local user=args[1]
|
||||||
|
local game=API.GAMES[args[2]]
|
||||||
|
local style=API.STYLES[args[3]]
|
||||||
|
if not game then return message:reply('invalid game') end
|
||||||
|
if not style then return message:reply('invalid style') end
|
||||||
|
print('getting user')
|
||||||
|
if user=='me' then
|
||||||
|
local me=message.author
|
||||||
|
local roblox_user=API:GetRobloxInfoFromDiscordId(me.id)
|
||||||
|
if not roblox_user.id then return message:reply('```You are not registered with the RoverAPI```') end
|
||||||
|
user=roblox_user
|
||||||
|
elseif user:match('<@%d+>') then
|
||||||
|
local user_id=user:match('<@(%d+)>')
|
||||||
|
local member=message.guild:getMember(user_id)
|
||||||
|
local roblox_user=API:GetRobloxInfoFromDiscordId(member.id)
|
||||||
|
if not roblox_user.id then return message:reply('```You are not registered with the RoverAPI```') end
|
||||||
|
user=roblox_user
|
||||||
|
else
|
||||||
|
local roblox_user=API:GetRobloxInfoFromUsername(user)
|
||||||
|
if not roblox_user.id then return message:reply('```User not found```') end
|
||||||
|
user=roblox_user
|
||||||
|
end
|
||||||
|
local sn_info = API:GetUser(user.id)
|
||||||
|
if not sn_info.ID then return message:reply('```No data with StrafesNET is associated with that user.```') end
|
||||||
|
print('user:',user.id)
|
||||||
|
print('locked bot for this command')
|
||||||
|
_G.locked = true
|
||||||
|
print('getting times')
|
||||||
|
local times = {}
|
||||||
|
local res,rheaders = API:GetUserTimes(user.id,nil,style,game)
|
||||||
|
if #res~=0 then
|
||||||
|
local pages = tonumber(rheaders['Pagination-Count'])
|
||||||
|
for _,v in next,res do
|
||||||
|
table.insert(times,v)
|
||||||
|
end
|
||||||
|
if pages>1 then
|
||||||
|
for i=2,pages do
|
||||||
|
print('getting times page',i)
|
||||||
|
res,rheaders = API:GetUserTimes(user.id,nil,style,game,i)
|
||||||
|
for _,v in next,res do
|
||||||
|
table.insert(times,v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
print('times:',#times)
|
||||||
|
t.message:reply('ETA: '..(math.floor(#times*3/100))..' minutes '..((#times*3)%60)..' seconds (found '..#times..' times out of '..API.MAPS[game].count..' maps)')
|
||||||
|
local i = 1
|
||||||
|
for _,time in next,times do
|
||||||
|
local rank = API:GetTimeRank(time.ID).Rank
|
||||||
|
local count = API:GetMapCompletionCount(time.Map,style)
|
||||||
|
time.Rank = rank
|
||||||
|
time.MapCompletionCount = count
|
||||||
|
time.Skill = API:FormatSkill(1-((rank-1)/tonumber(count)))
|
||||||
|
time.SkillRaw = 1-((rank-1)/tonumber(count))
|
||||||
|
i=i+1
|
||||||
|
end
|
||||||
|
table.sort(times,function(t1,t2)
|
||||||
|
return t1.SkillRaw<t2.SkillRaw
|
||||||
|
end)
|
||||||
|
local msg = ''
|
||||||
|
for _,time in next,times do
|
||||||
|
-- msg = msg..'['..time.Rank..'/'..time.MapCompletionCount..'] '..time.Map..' ('..time.Skill..')\n'
|
||||||
|
msg = msg..API.MAPS[game][time.Map].DisplayName..' ('..time.Map..'): '..time.Skill..' for '..time.Rank..'/'..time.MapCompletionCount..' with '..API:FormatTime(time.Time)..'\n'
|
||||||
|
end
|
||||||
|
local txt = './skill-'..API.GAMES[game]..'-'..API.STYLES[style]:lower()..'-'..user.name..'.txt'
|
||||||
|
local file=io.open(txt,'w+')
|
||||||
|
file:write(msg)
|
||||||
|
file:close()
|
||||||
|
print('h')
|
||||||
|
message:reply({
|
||||||
|
file=txt,
|
||||||
|
reference={
|
||||||
|
message=message,
|
||||||
|
mention=true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
os.remove(txt)
|
||||||
|
_G.locked = false
|
||||||
|
else
|
||||||
|
message:reply('```No times found for that user.```')
|
||||||
|
_G.locked = false
|
||||||
|
end
|
||||||
|
end)
|
@ -1,9 +1,23 @@
|
|||||||
local http = require('coro-http')
|
local http = require('coro-http')
|
||||||
local json = require('json')
|
local json = require('json')
|
||||||
|
function wait(n)c=os.clock t=c()while c()-t<=n do end;end
|
||||||
local request=function(method,url,headers,params)
|
local request=function(method,url,headers,params)
|
||||||
local _,body=http.request(method,url,headers or {{"Content-Type", "application/json"}},params)
|
local headers,body=http.request(method,url,headers or {{"Content-Type", "application/json"}},params)
|
||||||
body=json.decode(body)
|
body=json.decode(body)
|
||||||
return body
|
local rheaders={}
|
||||||
|
for _,t in pairs(headers) do
|
||||||
|
if type(t)=='table' then
|
||||||
|
rheaders[t[1]]=t[2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local remaining = tonumber(rheaders['RateLimit-Remaining'])
|
||||||
|
local reset = tonumber(rheaders['RateLimit-Reset'])
|
||||||
|
print('remaining',remaining,'reset',reset)
|
||||||
|
if remaining and reset then
|
||||||
|
local t = remaining==0 and reset or .38
|
||||||
|
wait(t)
|
||||||
|
end
|
||||||
|
return body,rheaders
|
||||||
end
|
end
|
||||||
|
|
||||||
-- local urlparamencode=function()
|
-- local urlparamencode=function()
|
||||||
|
@ -13,10 +13,11 @@ local r=function(n,nd) return tonumber(string.format('%.' .. (nd or 0) .. 'f', n
|
|||||||
local GAMES={BHOP=1,SURF=2,[1]='bhop',[2]='surf'}
|
local GAMES={BHOP=1,SURF=2,[1]='bhop',[2]='surf'}
|
||||||
local STATES={[0]='Default',[1]='Whitelisted',[2]='Blacklisted',[3]='Pending'}
|
local STATES={[0]='Default',[1]='Whitelisted',[2]='Blacklisted',[3]='Pending'}
|
||||||
local RANKS={'New (1)','Newb (2)','Bad (3)','Okay (4)','Not Bad (5)','Decent (6)','Getting There (7)','Advanced (8)','Good (9)','Great (10)','Superb (11)','Amazing (12)','Sick (13)','Master (14)','Insane (15)','Majestic (16)','Baby Jesus (17)','Jesus (18)','Half God (19)','God (20)'}
|
local RANKS={'New (1)','Newb (2)','Bad (3)','Okay (4)','Not Bad (5)','Decent (6)','Getting There (7)','Advanced (8)','Good (9)','Great (10)','Superb (11)','Amazing (12)','Sick (13)','Master (14)','Insane (15)','Majestic (16)','Baby Jesus (17)','Jesus (18)','Half God (19)','God (20)'}
|
||||||
local STYLES_LIST={'Autohop','Scroll','Sideways','Half-Sideways','W-Only','A-Only','Backwards',}
|
local STYLES_LIST={'Autohop','Scroll','Sideways','Half-Sideways','W-Only','A-Only','Backwards'}
|
||||||
local STYLES={AUTOHOP=1,SCROLL=2,SIDEWAYS=3,HALFSIDEWAYS=4,WONLY=5,AONLY=6,BACKWARDS=7}
|
local STYLES={AUTOHOP=1,SCROLL=2,SIDEWAYS=3,HALFSIDEWAYS=4,WONLY=5,AONLY=6,BACKWARDS=7}
|
||||||
|
|
||||||
setmetatable(STYLES,{__index=function(self,i)
|
setmetatable(STYLES,{__index=function(self,i)
|
||||||
|
if type(i)=='number' then return STYLES_LIST[i] or 'Unknown' end
|
||||||
if i=='a' then i='auto'elseif i=='hsw'then i='half'elseif i=='s'then i='scroll'elseif i=='sw'then i='side'elseif i=='bw'then i='back'end
|
if i=='a' then i='auto'elseif i=='hsw'then i='half'elseif i=='s'then i='scroll'elseif i=='sw'then i='side'elseif i=='bw'then i='back'end
|
||||||
for ix,v in pairs(self) do
|
for ix,v in pairs(self) do
|
||||||
if string.sub(ix:lower(),1,#i):find(i:lower()) then
|
if string.sub(ix:lower(),1,#i):find(i:lower()) then
|
||||||
@ -50,109 +51,120 @@ function formatTime(time) if time > 86400000 then return '>1 day' else local mil
|
|||||||
function API:FormatRank(n) return RANKS[1+math.floor(n*19)] end
|
function API:FormatRank(n) return RANKS[1+math.floor(n*19)] end
|
||||||
-- Get skill percentage from skill point
|
-- Get skill percentage from skill point
|
||||||
function API:FormatSkill(n) return r(n*100,3)..'%' end
|
function API:FormatSkill(n) return r(n*100,3)..'%' end
|
||||||
|
function API:FormatTime(n) return formatTime(n) end
|
||||||
|
|
||||||
-- Time from id.
|
-- Time from id.
|
||||||
function API:GetTime(ID)
|
function API:GetTime(ID)
|
||||||
if not ID then return 'empty id' end
|
if not ID then return 'empty id' end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'time/'..ID, API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'time/'..ID, API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
-- Time rank from id.
|
-- Time rank from id.
|
||||||
function API:GetTimeRank(MAP_ID)
|
function API:GetTimeRank(TIME_ID)
|
||||||
if not MAP_ID then return 'empty id' end
|
if not TIME_ID then return 'empty id' end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'time/'..MAP_ID..'/rank', API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'time/'..TIME_ID..'/rank', API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
-- 10 recent world records.
|
-- 10 recent world records.
|
||||||
function API:GetRecentWrs(STYLE_ID, GAME_ID, WHITELIST_FILTER)
|
function API:GetRecentWrs(STYLE_ID, GAME_ID, WHITELIST_FILTER)
|
||||||
if not STYLE_ID or not GAME_ID then return 'empty id' end
|
if not STYLE_ID or not GAME_ID then return 'empty id' end
|
||||||
local err, res = parseToURLArgs({style=STYLE_ID, game=GAME_ID, whitelist=WHITELIST_FILTER})
|
local err, res = parseToURLArgs({style=STYLE_ID, game=GAME_ID, whitelist=WHITELIST_FILTER})
|
||||||
if err then return err end
|
if err then return err end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'time/recent/wr'..res, API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'time/recent/wr'..res, API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
-- Time by map id. Sorted in ascending order.
|
-- Time by map id. Sorted in ascending order.
|
||||||
function API:GetMapTimes(MAP_ID, STYLE_ID, PAGE)
|
function API:GetMapTimes(MAP_ID, STYLE_ID, PAGE)
|
||||||
if not MAP_ID then return 'empty id' end
|
if not MAP_ID then return 'empty id' end
|
||||||
local err, res = parseToURLArgs({style=STYLE_ID, page=PAGE})
|
local err, res = parseToURLArgs({style=STYLE_ID, page=PAGE})
|
||||||
if err then return err end
|
if err then return err end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'time/map/'..MAP_ID..res, API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'time/map/'..MAP_ID..res, API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
-- Get WR of map.
|
-- Get WR of map.
|
||||||
function API:GetMapWr(MAP_ID, STYLE_ID)
|
function API:GetMapWr(MAP_ID, STYLE_ID)
|
||||||
if not MAP_ID or not STYLE_ID then return 'empty id' end
|
if not MAP_ID or not STYLE_ID then return 'empty id' end
|
||||||
local err, res = parseToURLArgs({style=STYLE_ID})
|
local err, res = parseToURLArgs({style=STYLE_ID})
|
||||||
if err then return err end
|
if err then return err end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'time/map/'..MAP_ID..'/wr'..res, API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'time/map/'..MAP_ID..'/wr'..res, API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
-- Time by user id.
|
-- Time by user id.
|
||||||
function API:GetUserTimes(USER_ID, MAP_ID, STYLE_ID, GAME_ID, PAGE)
|
function API:GetUserTimes(USER_ID, MAP_ID, STYLE_ID, GAME_ID, PAGE)
|
||||||
if not USER_ID then return 'empty id' end
|
if not USER_ID then return 'empty id' end
|
||||||
local err, res = parseToURLArgs({map=MAP_ID, style=STYLE_ID, game=GAME_ID, page=PAGE})
|
local err, res = parseToURLArgs({map=MAP_ID, style=STYLE_ID, game=GAME_ID, page=PAGE})
|
||||||
if err then return err end
|
if err then return err end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'time/user/'..USER_ID..res , API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'time/user/'..USER_ID..res , API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
-- World records by user id.
|
-- World records by user id.
|
||||||
function API:GetUserWrs(USER_ID,GAME_ID,STYLE_ID)
|
function API:GetUserWrs(USER_ID,GAME_ID,STYLE_ID)
|
||||||
if not USER_ID or not GAME_ID or not STYLE_ID then return 'empty id' end
|
if not USER_ID or not GAME_ID or not STYLE_ID then return 'empty id' end
|
||||||
local err, res = parseToURLArgs({game=GAME_ID, style=STYLE_ID})
|
local err, res = parseToURLArgs({game=GAME_ID, style=STYLE_ID})
|
||||||
if err then return err end
|
if err then return err end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'time/user/'..USER_ID..'/wr'..res, API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'time/user/'..USER_ID..'/wr'..res, API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
-- User from id.
|
-- User from id.
|
||||||
function API:GetUser(USER_ID)
|
function API:GetUser(USER_ID)
|
||||||
if not USER_ID then return 'empty id' end
|
if not USER_ID then return 'empty id' end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'user/'..USER_ID, API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'user/'..USER_ID, API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
-- Top ranked players, paged at 50 per page.
|
-- Top ranked players, paged at 50 per page.
|
||||||
function API:GetRanks(STYLE_ID,GAME_ID,PAGE)
|
function API:GetRanks(STYLE_ID,GAME_ID,PAGE)
|
||||||
if not STYLE_ID or not GAME_ID then return 'empty id' end
|
if not STYLE_ID or not GAME_ID then return 'empty id' end
|
||||||
local err, res = parseToURLArgs({style=STYLE_ID, game=GAME_ID, page=PAGE})
|
local err, res = parseToURLArgs({style=STYLE_ID, game=GAME_ID, page=PAGE})
|
||||||
if err then return err end
|
if err then return err end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'rank'..res, API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'rank'..res, API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
-- Get rank of user by their id.
|
-- Get rank of user by their id.
|
||||||
function API:GetRank(USER_ID,GAME_ID,STYLE_ID)
|
function API:GetRank(USER_ID,GAME_ID,STYLE_ID)
|
||||||
if not USER_ID or not STYLE_ID or not GAME_ID then return 'empty id' end
|
if not USER_ID or not STYLE_ID or not GAME_ID then return 'empty id' end
|
||||||
local err, res = parseToURLArgs({style=STYLE_ID, game=GAME_ID})
|
local err, res = parseToURLArgs({style=STYLE_ID, game=GAME_ID})
|
||||||
if err then return err end
|
if err then return err end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'rank/'..USER_ID..res, API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'rank/'..USER_ID..res, API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
-- Get list of maps.
|
-- Get list of maps.
|
||||||
function API:GetMaps(GAME_ID,PAGE)
|
function API:GetMaps(GAME_ID,PAGE)
|
||||||
if not GAME_ID then return 'empty id' end
|
if not GAME_ID then return 'empty id' end
|
||||||
local err, res = parseToURLArgs({game=GAME_ID, page=PAGE})
|
local err, res = parseToURLArgs({game=GAME_ID, page=PAGE})
|
||||||
if err then return err end
|
if err then return err end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'map'..res, API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'map'..res, API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
-- Get map by ID.
|
-- Get map by ID.
|
||||||
function API:GetMap(MAP_ID)
|
function API:GetMap(MAP_ID)
|
||||||
if not MAP_ID then return 'empty id' end
|
if not MAP_ID then return 'empty id' end
|
||||||
local response = http_request('GET', STRAFESNET_API_URL..'map/'..MAP_ID, API_HEADER)
|
local response,headers = http_request('GET', STRAFESNET_API_URL..'map/'..MAP_ID, API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
|
end
|
||||||
|
|
||||||
|
-- [[ CUSTOM ]] --
|
||||||
|
|
||||||
|
function API:GetMapCompletionCount(MAP_ID,STYLE_ID)
|
||||||
|
if not MAP_ID or not STYLE_ID then return 'empty id' end
|
||||||
|
local _,headers = API:GetMapTimes(MAP_ID,STYLE_ID)
|
||||||
|
local pages = headers['Pagination-Count']
|
||||||
|
local res = API:GetMapTimes(MAP_ID,STYLE_ID,pages)
|
||||||
|
return ((pages-1)*200)+#res
|
||||||
end
|
end
|
||||||
|
|
||||||
-- [[ ROBLOX / ROVER AND OTHER APIs ]] --
|
-- [[ ROBLOX / ROVER AND OTHER APIs ]] --
|
||||||
|
|
||||||
function API:GetRobloxInfoFromUserId(USER_ID)
|
function API:GetRobloxInfoFromUserId(USER_ID)
|
||||||
if not USER_ID then return 'empty id' end
|
if not USER_ID then return 'empty id' end
|
||||||
local response = http_request('GET', ROBLOX_API_URL..'users/'..USER_ID, API_HEADER)
|
local response,headers = http_request('GET', ROBLOX_API_URL..'users/'..USER_ID, API_HEADER)
|
||||||
return response
|
return response,headers
|
||||||
end
|
end
|
||||||
|
|
||||||
function API:GetRobloxInfoFromUsername(USERNAME)
|
function API:GetRobloxInfoFromUsername(USERNAME)
|
||||||
if not USERNAME then return 'empty id' end
|
if not USERNAME then return 'empty id' end
|
||||||
local err, res = parseToURLArgs({username=USERNAME})
|
local err, res = parseToURLArgs({username=USERNAME})
|
||||||
if err then return err end
|
if err then return err end
|
||||||
local response = http_request('GET', ROBLOX_API_URL2..'users/get-by-username'..res, API_HEADER)
|
local response,headers = http_request('GET', ROBLOX_API_URL2..'users/get-by-username'..res, API_HEADER)
|
||||||
if not response.Id then return 'no user found' end
|
if not response.Id then return 'no user found' end
|
||||||
local response2 = http_request('GET', ROBLOX_API_URL..'users/'..response.Id, API_HEADER)
|
local response2 = http_request('GET', ROBLOX_API_URL..'users/'..response.Id, API_HEADER)
|
||||||
return response2
|
return response2
|
||||||
@ -160,8 +172,8 @@ end
|
|||||||
|
|
||||||
function API:GetRobloxInfoFromDiscordId(DISCORD_ID)
|
function API:GetRobloxInfoFromDiscordId(DISCORD_ID)
|
||||||
if not DISCORD_ID then return 'empty id' end
|
if not DISCORD_ID then return 'empty id' end
|
||||||
local response = http_request('GET', ROVER_API_URL..'user/'..DISCORD_ID, API_HEADER)
|
local response,headers = http_request('GET', ROVER_API_URL..'user/'..DISCORD_ID, API_HEADER)
|
||||||
if not response.robloxId and response.error then return response.error end
|
if not response.robloxId and response.error then return response,headers.error end
|
||||||
local response2 = http_request('GET', ROBLOX_API_URL..'users/'..response.robloxId, API_HEADER)
|
local response2 = http_request('GET', ROBLOX_API_URL..'users/'..response.robloxId, API_HEADER)
|
||||||
return response2
|
return response2
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user