removed some prints, fixed time conversion

This commit is contained in:
tommy aka doge 2022-05-07 15:22:03 -04:00
parent 670f166e82
commit faecf94589
3 changed files with 4 additions and 7 deletions

View File

@ -3,7 +3,7 @@ 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)
commands:Add('skill',{},'skill <username|mention|"me"> <game> <style>', function(t)
local args=t.args
local message=t.message
if #args<3 then return message:reply('invalid arguments') end
@ -32,9 +32,7 @@ commands:Add('skill',{},'calculate skill from placement', function(t)
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
@ -75,7 +73,6 @@ commands:Add('skill',{},'calculate skill from placement', function(t)
local file=io.open(txt,'w+')
file:write(msg)
file:close()
print('h')
message:reply({
file=txt,
reference={

View File

@ -12,7 +12,6 @@ local request=function(method,url,headers,params)
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)

View File

@ -42,8 +42,9 @@ API.STATES=STATES
-- use as local err, res = parseToURLArgs(), thanks golang for this idea
function parseToURLArgs(tb) function Err(err) return err, nil end function Ok(res) return nil, res end if not tb then return Err('got nothing') end if type(tb) ~= 'table' then return Err('expected table, got '..type(tb)) end local str = '?' local index = 1 for key, value in pairs(tb) do if index == 1 then str = str..key..'='..t(value) else str = str..'&'..key..'='..t(value) end index = index + 1 end return Ok(str) end
-- fiveman made these (converted to lua from python)
function formatHelper(time, digits) local time = tostring(time)while #time < digits do time = '0'..time end return time end
function formatTime(time) if time > 86400000 then return '>1 day' else local millis = formatHelper(time % 1000, 3) local seconds = formatHelper(r(time / 1000) % 60, 2) local minutes = formatHelper(r(time / (1000 * 60)) % 60, 2) local hours = formatHelper(r(time / (1000 * 60 * 60)) % 24, 2) if hours == '00' then return minutes..':'..seconds..'.'..millis else return hours..':'..minutes..':'..seconds end end end
function format_helper(a,b)a=tostring(a)while#a<b do a='0'..a end;return a end
function formatTime(a)if a>86400000 then return'>1 day'end;local c=format_helper(a%1000,3)local d=format_helper(math.floor(a/1000)%60,2)local e=format_helper(math.floor(a/(1000*60))%60,2)local f=format_helper(math.floor(a/(1000*60*60))%24,2)if f=='00'then return e..':'..d..'.'..c else return f..':'..e..':'..d end end
-- [[ STRAFESNET API ]] --