local lapis = require("lapis") local app = lapis.Application() local config = require("lapis.config").get() members = {{"fynn","https://fynngodau.de"}, {"anton","https://anton.ehrmanntraut.de"}, {"max","https://aaahhh.de"}, {"theresa","https://treimer.dev"}, {"never","https://nevereverever.de"}} members[#members+1] = members[1] math.randomseed(os.time()) app:get("/", function() return 'Welcome to the CUPS (Cool Unique People System) webring
' end) app:get("/embed", function(self) local from = self.params.from if from == nil then return {"cups webring embed needs from defined (.../embed?from=me)"} end return string.format('
', config.host, from, config.host, config.host, config.host, config.host, from, config.host), {layout = false, content_type="text/html"} end) app:get("/random", function(self) rand = math.random(1,#members-1) return {redirect_to=members[rand][2]} end) app:get("/next", function(self) local found for _, elem in ipairs(members) do local name = elem[1] local url = elem[2] if found == true then return {redirect_to=url} end if name == self.params.from then found = true end end if "cups" == self.params.from then rand = math.random(1,#members-1) return {redirect_to=members[rand][2]} end return {redirect_to="/"} end) app:get("/prev", function(self) local found for i=#members, 1, -1 do local name = members[i][1] local url = members[i][2] if found == true then return {redirect_to=url} end if name == self.params.from then found = true end end if "cups" == self.params.from then rand = math.random(1,#members-1) return {redirect_to=members[rand][2]} end return {redirect_to="/"} end) return app