From 5081d03d8224c01df5f3c939f4e9db12afe8f219 Mon Sep 17 00:00:00 2001 From: 9382 Date: Mon, 13 Mar 2023 15:55:00 +0000 Subject: [PATCH 1/4] Automatically encode table bodies in http --- src/modules/http.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/http.lua b/src/modules/http.lua index 63efac6..3b1d753 100644 --- a/src/modules/http.lua +++ b/src/modules/http.lua @@ -13,6 +13,7 @@ local STRAFES_NET_RATELIMIMT = { } local remaining_timeout = 0 local function request(method,url,headers,body,options) + if type(body)=='table' then body=json.encode(body) end local headers,body=http.request(method,url,headers,body,options) local rbody=json.decode(body) or body local rheaders={} -- 2.45.2 From f0cbd286e5bff803e486a56b09799e9eced376a2 Mon Sep 17 00:00:00 2001 From: 9382 Date: Mon, 13 Mar 2023 16:05:35 +0000 Subject: [PATCH 2/4] More in-depth tracebacks upon command failure --- src/main.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.lua b/src/main.lua index 82bca67..14825c3 100644 --- a/src/main.lua +++ b/src/main.lua @@ -66,11 +66,16 @@ client:on('messageCreate', function(message) local command=commands.command_list[cmdName] if command~=nil then if message.guild~=nil then - local s,e=pcall(function() + local tb + local s,e=xpcall(function() command.exec({message=message,args=args,mentions=mentions,t={client,discordia,token}}) + end,function(err) + tb = debug.traceback() + return err end) if not s then message:reply('tripped : '..e:split('/')[#e:split('/')]) + print(e,tb) end end end -- 2.45.2 From 67051b99dae0cf03befd5e6fc1b017a86964a139 Mon Sep 17 00:00:00 2001 From: 9382 Date: Mon, 13 Mar 2023 16:05:53 +0000 Subject: [PATCH 3/4] Improve username-based roblox user grabbing --- src/modules/strafes_net.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/modules/strafes_net.lua b/src/modules/strafes_net.lua index 35bd595..775c86e 100644 --- a/src/modules/strafes_net.lua +++ b/src/modules/strafes_net.lua @@ -260,13 +260,10 @@ function API:GetRobloxInfoFromUserId(USER_ID) end function API:GetRobloxInfoFromUsername(USERNAME) - if not USERNAME then return 'empty id' end - local err, res = parseToURLArgs({username=USERNAME}) - if err then return err end - 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 - local response2 = http_request('GET', ROBLOX_API_URL..'users/'..response.Id, API_HEADER) - return response2 + if not USERNAME then return 'empty username' end + local response,headers = http_request('POST', ROBLOX_API_URL..'usernames/users', API_HEADER, {usernames={USERNAME}}) + if not response.data[1] then return 'invalid username' end + return self:GetRobloxInfoFromUserId(response.data[1].id) end function API:GetRobloxInfoFromDiscordId(DISCORD_ID) -- 2.45.2 From a1470e562bb4ba4cdfd59aab21f4c1fb641ccc19 Mon Sep 17 00:00:00 2001 From: 9382 Date: Mon, 13 Mar 2023 16:24:30 +0000 Subject: [PATCH 4/4] Fix "Last Online" status grabbing --- src/modules/commands/user.lua | 17 +++++++++-------- src/modules/strafes_net.lua | 10 +++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/modules/commands/user.lua b/src/modules/commands/user.lua index 01f96e6..37cf2a1 100644 --- a/src/modules/commands/user.lua +++ b/src/modules/commands/user.lua @@ -58,12 +58,13 @@ commands:Add('user',{},'user ', function(t) local name = user_info.name local displayName = user_info.displayName - -- local onlineStatus_info = API:GetUserOnlineStatus(id) - - -- local LastLocation = onlineStatus_info.LastLocation - -- table.foreach(onlineStatus_info.errors[1],print) - -- local LastOnline = date.fromISO(onlineStatus_info.LastOnline):toSeconds()+(3600*5) - + local onlineStatus_info = API:GetUserOnlineStatus(id) + table.foreach(onlineStatus_info,print) + + local LastLocation = onlineStatus_info.lastLocation + if onlineStatus_info.userPresenceType==2 then LastLocation="Ingame" end + local LastOnline = date.fromISO(onlineStatus_info.lastOnline):toSeconds()+(3600*5) + local badgeRequest = API:GetBadgesAwardedDates(id,Badges) local badgeData = badgeRequest.data @@ -91,8 +92,8 @@ commands:Add('user',{},'user ', function(t) {name='ID',value=id,inline=true}, {name='Account Age',value=accountAge..' days',inline=true}, {name='Created',value='',inline=true}, - -- {name='Last Online',value='',inline=true}, - -- {name='Last Location',value=LastLocation,inline=true}, + {name='Last Online',value='',inline=true}, + {name='Last Location',value=LastLocation,inline=true}, {name='Banned',value=isBanned,inline=true}, {name='Description',value=description,inline=false}, } diff --git a/src/modules/strafes_net.lua b/src/modules/strafes_net.lua index 775c86e..9cbdbbc 100644 --- a/src/modules/strafes_net.lua +++ b/src/modules/strafes_net.lua @@ -7,6 +7,7 @@ local FIVEMAN_API_URL = 'https://api.fiveman1.net/v1/' local ROBLOX_API_URL = 'https://users.roblox.com/v1/' local ROBLOX_API_URL2 = 'https://api.roblox.com/' local ROBLOX_BADGES_API = 'https://badges.roblox.com/v1/' +local ROBLOX_PRESENCE_URL = 'https://presence.roblox.com/v1/' local ROBLOX_THUMBNAIL_URL = 'https://thumbnails.roblox.com/v1/' local ROBLOX_GROUPS_ROLES_URL = 'https://groups.roblox.com/v2/users/%s/groups/roles' @@ -91,6 +92,7 @@ function formatTime(time) -- chatgpt THIS IS FOR SECONDS! NOT MILLISECONDS return string.format("%02d:%02d.%03d", minutes, seconds, milliseconds) end end +function L1Copy(t,b) b=b or {} for x,y in next,t do b[x]=y end return b end -- [[ STRAFESNET API ]] -- @@ -274,10 +276,12 @@ function API:GetRobloxInfoFromDiscordId(DISCORD_ID) return response2 end -function API:GetUserOnlineStatus(USER_ID) -- https://api.roblox.com/users/1455906620/onlinestatus +function API:GetUserOnlineStatus(USER_ID) if not USER_ID then return 'empty id' end - local response,headers = http_request('GET', ROBLOX_API_URL2..'users/'..USER_ID..'/onlinestatus', API_HEADER) - return response,headers + local response1 = http_request('POST', ROBLOX_PRESENCE_URL..'presence/users', API_HEADER, {userIds={USER_ID}}).userPresences[1] --For LastLocation + local response2 = http_request('POST', ROBLOX_PRESENCE_URL..'presence/last-online', API_HEADER, {userIds={USER_ID}}).lastOnlineTimestamps[1] --For a more accurate LastOnline + L1Copy(response2, response1) + return response1 end function API:GetBadgesAwardedDates(USER_ID,BADGE_LIST) -- 2.45.2