From 0b1a03b5ac9e45c99bb3f2024303221d989c42bc Mon Sep 17 00:00:00 2001
From: tommy aka doge <59783653+dowoge@users.noreply.github.com>
Date: Sat, 10 Sep 2022 18:44:26 -0400
Subject: [PATCH] real

---
 src/modules/commands/skillCalc.lua | 23 +++++++++++++++++------
 src/modules/commands/user.lua      |  2 +-
 src/modules/ordinal.lua            |  4 ++--
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/modules/commands/skillCalc.lua b/src/modules/commands/skillCalc.lua
index 97c34df..7816dfe 100644
--- a/src/modules/commands/skillCalc.lua
+++ b/src/modules/commands/skillCalc.lua
@@ -4,21 +4,28 @@ local commands=require('./../commands.lua')
 function sleep(n) local t = os.clock() while os.clock()-t <= n do end end
 discordia.extensions()
 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 message=t.message
     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 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
+        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')
         local user = API:GetUserFromAny(user,message)
         if type(user)=='string' then return message:reply('```'..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
+        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())
         _G.locked = true
         _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_b=test_b+(count-1)
             end
-            table.sort(times,function(t1,t2)
+            table.sort(times,sort=='skill' and function(t1,t2)
                 return t1.SkillRaw<t2.SkillRaw
+            end or sort=='point' and function(t1,t2)
+                return t1.Points<t2.Points
             end)
             local points = 0
             for _,time in next,times do
                 points = points+time.Points
             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'..
-                        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
                 -- msg = msg..'['..time.Rank..'/'..time.MapCompletionCount..'] '..time.Map..' ('..time.Skill..')\n'
                 local mapStr = API.MAPS[game][time.Map].DisplayName..' ('..time.Map..')'
                 local skill = time.Skill
+                local point = time.Points
                 local rankStr = time.Rank..'/'..time.MapCompletionCount
                 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
             local txt = './skill-'..API.GAMES[game]..'-'..API.STYLES[style]:lower()..'-'..user.name..'.txt'
             local file=io.open(txt,'w+')
diff --git a/src/modules/commands/user.lua b/src/modules/commands/user.lua
index 7fedeaf..bf2dba6 100644
--- a/src/modules/commands/user.lua
+++ b/src/modules/commands/user.lua
@@ -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
     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]
 
diff --git a/src/modules/ordinal.lua b/src/modules/ordinal.lua
index 5837839..5c25a0f 100644
--- a/src/modules/ordinal.lua
+++ b/src/modules/ordinal.lua
@@ -1,9 +1,9 @@
 s=string.sub;t=tonumber
 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
         return n .. o[t(d)]
     else
-        return n .. "th"
+        return n .. 'th'
     end
 end
\ No newline at end of file