aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolderpunk <solderpunk@sdf.org>2018-12-08 14:36:37 +0000
committerSolderpunk <solderpunk@sdf.org>2018-12-08 14:36:37 +0000
commitee30ef5c4e0ba64b6055863cc1382ae4c1378afe (patch)
tree47648cce8b430f83f5d178d37db7318c383d4728
parentGive various global vars more sensible names and use them more consistently, ... (diff)
General tidy up, get rid of needless global vars, fix bugs from earlier global var refactor.
Diffstat (limited to '')
-rwxr-xr-xtelem.lua66
1 files changed, 28 insertions, 38 deletions
diff --git a/telem.lua b/telem.lua
index a6b149a..cbfee7f 100755
--- a/telem.lua
+++ b/telem.lua
@@ -11,10 +11,6 @@ table = require("table")
_BBS_ROOT = "/var/bbs/"
-bad_topics = {}
-bad_topics["."] = true
-bad_topics[".."] = true
-bad_topics["topic"] = true
-- TODO: This is, obviously, not secure and will need to be updated
username = os.getenv("USER")
@@ -46,29 +42,28 @@ end
function get_threads(board)
local threads = {}
- for topic in lfs.dir(path.join(_BBS_ROOT, "boards", board)) do
- if bad_topics[topic] == nil then
- local thread = {}
- thread.filename = topic
- thread.directory = path.join(_BBS_ROOT, "boards", board, topic)
- _, _, timestamp, thread.author = string.find(topic, "(%d+)-(%g+)")
- thread.timestamp = tonumber(timestamp)
-
- io.input(path.join(thread.directory, "subject"))
- thread.subject = io.read("*line")
- io.input(io.stdin)
-
- local posts = get_posts(thread)
- thread.post_count = #posts
- thread.updated = 0
- for _, post in ipairs(posts) do
- if post.timestamp > thread.updated then
- thread.updated = post.timestamp
- end
+ for threaddir in lfs.dir(path.join(_BBS_ROOT, "boards", board)) do
+ if string.sub(threaddir, 1,1) == "." then goto continue end
+ if threaddir == "topic" then goto continue end
+ local thread = {}
+ thread.directory = path.join(_BBS_ROOT, "boards", board, threaddir)
+ _, _, timestamp, thread.author = string.find(threaddir, "(%d+)-(%g+)")
+ thread.timestamp = tonumber(timestamp)
+
+ io.input(path.join(thread.directory, "subject"))
+ thread.subject = io.read("*line")
+ io.input(io.stdin)
+
+ local posts = get_posts(thread)
+ thread.post_count = #posts
+ thread.updated = 0
+ for _, post in ipairs(posts) do
+ if post.timestamp > thread.updated then
+ thread.updated = post.timestamp
end
- table.insert(threads, thread)
-
end
+ table.insert(threads, thread)
+ ::continue::
end
table.sort(threads, function(x,y) return x.updated > y.updated end)
return threads
@@ -76,18 +71,13 @@ end
function get_posts(thread)
local posts = {}
- for reply in lfs.dir(thread.directory) do
- if string.sub(reply, 1,1) == "." then goto continue end
- if reply == "subject" then goto continue end
+ for postfile in lfs.dir(thread.directory) do
+ if string.sub(postfile, 1,1) == "." then goto continue end
+ if postfile == "subject" then goto continue end
local post = {}
- post.filename = path.join(thread.directory, reply)
- if reply == "original" then
- post.author = thread.author
- post.timestamp = thread.timestamp
- else
- _, _, timestamp, post.author = string.find(reply, "(%d+)-(%a+)")
- post.timestamp = tonumber(timestamp)
- end
+ post.filename = path.join(thread.directory, postfile)
+ _, _, timestamp, post.author = string.find(postfile, "(%d+)-(%a+)")
+ post.timestamp = tonumber(timestamp)
table.insert(posts, post)
::continue::
end
@@ -233,7 +223,7 @@ function do_type_reply()
os.execute("$EDITOR " .. filename)
local timestamp = tostring(os.time())
local newfilename = timestamp .. "-" .. username
- local newpath = path.join(thread.directory, newfilename)
+ local newpath = path.join(current_thread.directory, newfilename)
local ret, str = file.move(filename, newpath)
if not ret then
print(str)
@@ -305,7 +295,7 @@ function do_reply()
return
end
current_thread = current_board_threads[thread_id]
- current_thread_posts = get_posts(thread)
+ current_thread_posts = get_posts(current_thread)
current_post_index = #current_thread_posts
do_type_reply()
end