local args, token = ...
local interop = require "@antiraid/interop"
local img_captcha = require "@antiraid/img_captcha"
local captcha_config = {}
-- Check __stack.users
if __stack._captcha_user_tries == nil then
__stack._captcha_user_tries = {} -- Initialize users table
end
-- Check __stack._captcha_user_tries[args.user.id]
if __stack._captcha_user_tries[args.user.id] == nil then
__stack._captcha_user_tries[args.user.id] = 0 -- Initialize user's try count
end
-- Check if user has reached maximum tries
if __stack._captcha_user_tries[args.user.id] >= 5 then
return { __error = "You have reached the maximum number of tries in this 5 minute window."}
end
-- Basic options
captcha_config.char_count = math.min(7 + __stack._captcha_user_tries[args.user.id], 10) -- Increment the number of characters
captcha_config.filters = {}
setmetatable(captcha_config.filters, interop.array_metatable) -- Filters is an array
captcha_config.viewbox_size = { 280, 160 }
setmetatable(captcha_config.viewbox_size, interop.array_metatable) -- Viewbox size is a tuple
-- Increment the maximum number of tries
__stack._captcha_user_tries[args.user.id] += 1
captcha = img_captcha.new(captcha_config)
return captcha