Skip to content

Commit 89e3a35

Browse files
authored
Merge pull request #943 from bliporg/0.1.24
0.1.24
2 parents 0252d89 + ec3e818 commit 89e3a35

19 files changed

+1128
-651
lines changed

bundle/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"APIHost": "https://api.cu.bzh:443",
3-
"GameServerTag": "ace96e81",
4-
"Version": "0.1.23",
3+
"GameServerTag": "f809f0cb",
4+
"Version": "0.1.26",
55
"Commit": "",
66
"Deps": {
77
"libluau": {

bundle/images/icon-play-white.png

1.72 KB
Loading

lua/modules/.luacheckrc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ return {
2727
"CollisionGroups",
2828
"Data",
2929
"AI",
30-
"Server"
30+
"Server",
3131
},
3232

3333
read_globals = {
@@ -71,6 +71,7 @@ return {
7171
"Type",
7272
"URL",
7373
"World",
74-
"math.clamp"
75-
}
74+
"math.clamp",
75+
"typeof",
76+
},
7677
}

lua/modules/api.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,18 @@ mod.aiChatCompletions = function(messages, temperatureOrCb, cb)
10271027
local headers = {}
10281028
headers["Content-Type"] = "application/json"
10291029

1030+
-- AI can insert annotations which can be empty arrays.
1031+
-- The JSON encoder encodes those empty arrays as `{}` instead of `[]`
1032+
-- and that is not valid for the API.
1033+
-- Ommiting them is ok though so setting them to nil fixes the issue.
1034+
for _, m in messages do
1035+
if m.annotations then
1036+
if #m.annotations == 0 then
1037+
m.annotations = nil
1038+
end
1039+
end
1040+
end
1041+
10301042
local body = {}
10311043
body.model = "gpt-4o-mini"
10321044
body.messages = messages
@@ -1089,6 +1101,22 @@ end
10891101

10901102
-- Badges
10911103

1104+
local function badgeFixFields(badge)
1105+
if badge.userDidUnlock ~= nil then
1106+
badge.unlocked = badge.userDidUnlock
1107+
badge.userDidUnlock = nil
1108+
else
1109+
badge.unlocked = false
1110+
end
1111+
if badge.userUnlockedAt ~= nil then
1112+
badge.unlockedAt = badge.userUnlockedAt
1113+
badge.userUnlockedAt = nil
1114+
end
1115+
if badge.rarity == nil then
1116+
badge.rarity = 0
1117+
end
1118+
end
1119+
10921120
-- Callback signature: cb(error, badges)
10931121
mod.listBadgesForWorld = function(_, worldId, cb)
10941122
local url = mod.kApiAddr .. "/worlds/" .. worldId .. "/badges"
@@ -1097,6 +1125,24 @@ mod.listBadgesForWorld = function(_, worldId, cb)
10971125
return cb(mod:error(res.StatusCode, "status code: " .. res.StatusCode))
10981126
end
10991127
local badges = JSON:Decode(res.Body)
1128+
for _, badge in badges do
1129+
badgeFixFields(badge)
1130+
end
1131+
cb(nil, badges)
1132+
end)
1133+
return req
1134+
end
1135+
1136+
mod.listBadgesForUser = function(_, userID, cb)
1137+
local url = mod.kApiAddr .. "/users/" .. userID .. "/badges"
1138+
local req = HTTP:Get(url, function(res)
1139+
if res.StatusCode ~= 200 then
1140+
return cb(mod:error(res.StatusCode, "status code: " .. res.StatusCode))
1141+
end
1142+
local badges = JSON:Decode(res.Body)
1143+
for _, badge in badges do
1144+
badgeFixFields(badge)
1145+
end
11001146
cb(nil, badges)
11011147
end)
11021148
return req

0 commit comments

Comments
 (0)