This commit is contained in:
tommy aka doge 2022-09-10 18:44:26 -04:00
parent 7924ee4d8c
commit 0b1a03b5ac
3 changed files with 20 additions and 9 deletions

View File

@ -4,21 +4,28 @@ local commands=require('./../commands.lua')
function sleep(n) local t = os.clock() while os.clock()-t <= n do end end function sleep(n) local t = os.clock() while os.clock()-t <= n do end end
discordia.extensions() discordia.extensions()
local pad = API.Pad local pad = API.Pad
commands:Add('skill',{},'skill <username|mention|"me"> <game> <style>', function(t) commands:Add('skill',{},'skill <username|mention|"me"> <game> <style> <sort?=skill|point>', function(t)
local args=t.args local args=t.args
local message=t.message local message=t.message
if not _G.locked then if not _G.locked then
if #args<3 then return message:reply('invalid arguments') end if #args<3 then return message:reply('usage: `skill <username|mention|"me"> <game> <style> <sort?="skill"|"point">`') end
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 game then return message:reply('invalid game') end
if not style then return message:reply('invalid style') end if not style then return message:reply('invalid style') end
local sort = args[4]
if type(sort)=='string' and sort:lower()~='skill' and sort:lower()~='point' then
return message:reply('invalid sort option, valid options are "skill" or "point"')
elseif sort==nil then
sort = 'skill'
end
print('getting user') print('getting user')
local user = API:GetUserFromAny(user,message) local user = API:GetUserFromAny(user,message)
if type(user)=='string' then return message:reply('```'..user..'```') end if type(user)=='string' then return message:reply('```'..user..'```') end
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 if not sn_info.ID then return message:reply('```No data with StrafesNET is associated with that user.```') end
if sn_info.State==2 then return message:reply('```This user is currently blacklisted```') end
print(user.name,user.id,API.GAMES[game],API.STYLES[style]:lower()) print(user.name,user.id,API.GAMES[game],API.STYLES[style]:lower())
_G.locked = true _G.locked = true
_G.current = {name=user.name,game=API.GAMES[game],style=API.STYLES[style]:lower()} _G.current = {name=user.name,game=API.GAMES[game],style=API.STYLES[style]:lower()}
@ -58,24 +65,28 @@ commands:Add('skill',{},'skill <username|mention|"me"> <game> <style>', function
test_a=test_a+(count-rank) test_a=test_a+(count-rank)
test_b=test_b+(count-1) test_b=test_b+(count-1)
end end
table.sort(times,function(t1,t2) table.sort(times,sort=='skill' and function(t1,t2)
return t1.SkillRaw<t2.SkillRaw return t1.SkillRaw<t2.SkillRaw
end or sort=='point' and function(t1,t2)
return t1.Points<t2.Points
end) end)
local points = 0 local points = 0
for _,time in next,times do for _,time in next,times do
points = points+time.Points points = points+time.Points
end end
local msg = 'Average Skill: '..API:FormatSkill(math.clamp(s,0,1))..'\n'.. local skillFinal = (test_a)/(test_b-1)
local msg = 'Average Skill: '..API:FormatSkill(math.clamp(skillFinal,0,1))..'\n'..
'Points: '..points..'\n'.. 'Points: '..points..'\n'..
pad(API,'Map',50)..' | '..pad(API,'Skill',7)..' | '.. pad(API,'Placement',14)..' | Time\n\n' pad(API,'Map',50)..' | '..pad(API,'Points')..' | '..pad(API,'Skill',7)..' | '.. pad(API,'Placement',14)..' | Time\n\n'
for _,time in next,times do for _,time in next,times do
-- msg = msg..'['..time.Rank..'/'..time.MapCompletionCount..'] '..time.Map..' ('..time.Skill..')\n' -- msg = msg..'['..time.Rank..'/'..time.MapCompletionCount..'] '..time.Map..' ('..time.Skill..')\n'
local mapStr = API.MAPS[game][time.Map].DisplayName..' ('..time.Map..')' local mapStr = API.MAPS[game][time.Map].DisplayName..' ('..time.Map..')'
local skill = time.Skill local skill = time.Skill
local point = time.Points
local rankStr = time.Rank..'/'..time.MapCompletionCount local rankStr = time.Rank..'/'..time.MapCompletionCount
local timeStr = API:FormatTime(time.Time) local timeStr = API:FormatTime(time.Time)
msg = msg.. pad(API,mapStr,50)..' | '..pad(API,skill,7)..' | '.. pad(API,rankStr,14)..' | '..timeStr..'\n' msg = msg.. pad(API,mapStr,50)..' | '..pad(API,point)..' | '..pad(API,skill,7)..' | '.. pad(API,rankStr,14)..' | '..timeStr..'\n'
end end
local txt = './skill-'..API.GAMES[game]..'-'..API.STYLES[style]:lower()..'-'..user.name..'.txt' local txt = './skill-'..API.GAMES[game]..'-'..API.STYLES[style]:lower()..'-'..user.name..'.txt'
local file=io.open(txt,'w+') local file=io.open(txt,'w+')

View File

@ -49,7 +49,7 @@ commands:Add('user',{},'user <username|mention|"me">', function(t)
-- for a,b in next,onlineStatus_info do onlineStatus_info[a]=tostring(b)end -- for a,b in next,onlineStatus_info do onlineStatus_info[a]=tostring(b)end
local LastLocation = onlineStatus_info.LastLocation local LastLocation = onlineStatus_info.LastLocation
local LastOnline = date.fromISO(onlineStatus_info.LastOnline):toSeconds() local LastOnline = date.fromISO(onlineStatus_info.LastOnline):toSeconds()+(3600*5)
local userThumbnail = API:GetUserThumbnail(user_info.id).data[1] local userThumbnail = API:GetUserThumbnail(user_info.id).data[1]

View File

@ -1,9 +1,9 @@
s=string.sub;t=tonumber s=string.sub;t=tonumber
return function(n) return function(n)
local o, d = {"st", "nd", "rd"}, s(n, -1) local o, d = {'st', 'nd', 'rd'}, s(n, -1)
if t(d) > 0 and t(d) <= 3 and s(n,-2) ~= 11 and s(n,-2) ~= 12 and s(n,-2) ~= 13 then if t(d) > 0 and t(d) <= 3 and s(n,-2) ~= 11 and s(n,-2) ~= 12 and s(n,-2) ~= 13 then
return n .. o[t(d)] return n .. o[t(d)]
else else
return n .. "th" return n .. 'th'
end end
end end