From 7cbdd124fd068bcd3185ae52d2d176a3ecaaad33 Mon Sep 17 00:00:00 2001 From: CoolestDoggo <40402235+CoolestDoggo@users.noreply.github.com> Date: Sat, 10 Sep 2022 18:43:33 -0400 Subject: [PATCH 1/2] Create pb command --- src/modules/commands/pb.lua | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/modules/commands/pb.lua diff --git a/src/modules/commands/pb.lua b/src/modules/commands/pb.lua new file mode 100644 index 0000000..2f14d4a --- /dev/null +++ b/src/modules/commands/pb.lua @@ -0,0 +1,58 @@ +local discordia=require('discordia') +local API=require('./../strafes_net.lua') +local commands=require('./../commands.lua') +local pad = API.Pad + +discordia.extensions() + +-- args: user, game, style, map +commands:Add('pb', {}, 'get placement on map', function(t) + local args = t.args + local message = t.message + + if #args < 4 then return message:reply('invalid arguments') end + + local user = API:GetUserFromAny(args[1]) + local sn_info = API:GetUser(user.id) + local game = API.GAMES[args[2]] + local style = API.STYLES[args[3]] + local map = API.MAPS[game][args[4]] + + -- i love checks + if not game then return message:reply('invalid game') end + if not style then return message:reply('invalid style') end + if not map then return message:reply('invalid map') 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 + + local time = API:GetUserTimes(user.id, map, style, game) + + if not time then return message:reply('idk bruh') end + + local rank = API:GetTimeRank(time.ID).Rank + local count = tonumber(API:GetMapCompletionCount(time.Map, style)) + + if not rank or not count then + rank = 1 + count = 1 + end + + local time_formatted = API:FormatTime(time.Time) + local date = os.date("%x", time.Date) + local placement = rank .. '/' .. count + local points = API:CalculatePoint(rank, count) + + local t_n, d_n, p_n= #time_formatted, 10, math.min(#placement, 10) + + local first_line = pad('Time:', t_n + 1) .. '| ' + .. pad('Date:', d_n + 1) .. '| ' + .. pad('Placement:', p_n + 1) .. '| ' + .. 'Points:' + + local second_line = pad(time_formatted, t_n + 1) .. '| ' + .. pad(date, d_n + 1) .. '| ' + .. pad(placement, p_n + 1) .. '| ' + .. tostring(points) + + return message:reply('```' .. first_line .. '\n' .. second_line .. '```') +end) \ No newline at end of file From 7b4fbf5ee339bad732fd590369604541d284b566 Mon Sep 17 00:00:00 2001 From: tommy aka doge <59783653+dowoge@users.noreply.github.com> Date: Sat, 10 Sep 2022 19:13:31 -0400 Subject: [PATCH 2/2] small changes to make it work --- src/modules/commands/pb.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/commands/pb.lua b/src/modules/commands/pb.lua index 2f14d4a..87120a0 100644 --- a/src/modules/commands/pb.lua +++ b/src/modules/commands/pb.lua @@ -25,7 +25,7 @@ commands:Add('pb', {}, 'get placement on map', function(t) 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 - local time = API:GetUserTimes(user.id, map, style, game) + local time = API:GetUserTimes(user.id, map.ID, style, game)[1] if not time then return message:reply('idk bruh') end @@ -42,7 +42,7 @@ commands:Add('pb', {}, 'get placement on map', function(t) local placement = rank .. '/' .. count local points = API:CalculatePoint(rank, count) - local t_n, d_n, p_n= #time_formatted, 10, math.min(#placement, 10) + local t_n, d_n, p_n= #time_formatted, 8, math.min(#placement, 10) local first_line = pad('Time:', t_n + 1) .. '| ' .. pad('Date:', d_n + 1) .. '| ' @@ -55,4 +55,4 @@ commands:Add('pb', {}, 'get placement on map', function(t) .. tostring(points) return message:reply('```' .. first_line .. '\n' .. second_line .. '```') -end) \ No newline at end of file +end)