Greasy Fork

Le Upboat! xD

Vote on posts on /g/.

目前为 2014-09-06 提交的版本。查看 最新版本

作者
garyoak
评分
0 0 0
版本
0.0.0.2
创建于
2014-09-06
更新于
2014-09-06
大小
16.6 KB
许可证
CC0
适用于

Adds voting to 4chan's /g/.

Backend script for webscript.io platform


-- Voting script
-- 0.0.0.2
-- License: CC0; https://creativecommons.org/publicdomain/zero/1.0/


local thread = request.query.id
local vote = (request.query.vote == "up" and 1) or
(request.query.vote == "down" and -1) or
0
local ip = request.remote_addr

local ip_key = "voted:" .. thread .. ":" .. ip
local vote_key = "score:" .. thread

local voted = false

if not ((vote == 0) or storage[ip_key]) then
if not storage[vote_key] then
storage[vote_key] = 0
end
storage[vote_key] = storage[vote_key] + vote
storage[ip_key] = true
voted = true
end

local response = {voted = (voted and 1 or 0), score = storage[vote_key] or 0}

return json.stringify(response)