Skip to content

Commit 6a9433f

Browse files
authored
fix cry_pls
1 parent 0783ec1 commit 6a9433f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lib/misc.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,33 +189,39 @@ function cry_pls(str, vars)
189189
for v in inside:gmatch("[^,]+") do -- adds args to array
190190
table.insert(_table, v)
191191
end
192-
local num = vars[tonumber(string.match(str, ">(%d+)"))]
192+
local num = vars[tonumber(string.match(str, ">(%d+)"))] -- gets reference variable
193193
local plural = _table[1] -- default
194-
local checks = { [1] = "=" }
194+
local checks = { [1] = "=" } -- checks 1 by default
195+
local checks1mod = false -- tracks if 1 was modified
195196
if #_table > 1 then
196197
for i = 2, #_table do
197198
local isnum = tonumber(_table[i])
198199
if isnum then
199-
checks[isnum] = ">" .. (_table[i + 1] or "")
200+
if not checks1mod then checks[1] = nil end -- dumb stuff
201+
checks[isnum] = "<" .. (_table[i + 1] or "") -- do less than for custom values
202+
if isnum == 1 then checks1mod = true end
200203
i = i + 1
201204
elseif i == 2 then
202205
checks[1] = "=" .. _table[i]
203-
else
204-
print("Unexpected string: " .. _table[i])
205206
end
206207
end
207208
end
208209
local function fch(str, c)
209210
return string.sub(str, 1, 1) == c -- gets first char and returns boolean
210211
end
211-
for k, v in pairs(checks) do
212-
if fch(v, "=") then
212+
local keys = {}
213+
for k in pairs(checks) do
214+
table.insert(keys, k)
215+
end
216+
table.sort(keys, function(a, b) return a < b end)
217+
for _, k in ipairs(keys) do
218+
if fch(checks[k], "=") then
213219
if math.abs(to_big(num) - k) < to_big(0.001) then
214-
return string.sub(v, 2, -1)
220+
return string.sub(checks[k], 2, -1)
215221
end
216-
elseif fch(v, ">") then
217-
if to_big(num) >= to_big(k - 0.001) then
218-
return string.sub(v, 2, -1)
222+
elseif fch(checks[k], "<") then
223+
if to_big(num) < to_big(k - 0.001) then
224+
return string.sub(checks[k], 2, -1)
219225
end
220226
end
221227
end

0 commit comments

Comments
 (0)