aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolderpunk <solderpunk@sdf.org>2018-12-09 09:56:48 +0000
committerSolderpunk <solderpunk@sdf.org>2018-12-09 09:56:48 +0000
commit944e7809f118428dc735664a15ab899fa72c408d (patch)
treed3c22291d0f70e5281c3fe5959fe6cf09cd05c23
parentMake current_board a board table, not just the name of the board. (diff)
Implement 'scan' command.
-rwxr-xr-xtelem.lua46
1 files changed, 45 insertions, 1 deletions
diff --git a/telem.lua b/telem.lua
index e31c9f5..5c303d1 100755
--- a/telem.lua
+++ b/telem.lua
@@ -63,6 +63,7 @@ function update_boards()
board.name = boarddir
board.directory = path.join(_BBS_ROOT, "boards", boarddir)
board.topic = file.read(path.join(board.directory, "topic"))
+ board.last_scanned = 0
boards_by_name[board.name] = board
table.insert(boards, board)
end
@@ -124,6 +125,27 @@ function get_posts(thread)
return posts
end
+function load_scan_times()
+ local scanfile = path.join(_BBS_ROOT, "scans", username ..".scan")
+ local f, err = io.open(scanfile, "r")
+ for line in f:lines() do
+ local _, _, board, scantime = string.find(line, "(%a+):(%d+)")
+ if boards_by_name[board] then
+ boards_by_name[board].last_scanned = tonumber(scantime)
+ end
+ end
+ f:close()
+end
+
+function save_scan_times()
+ local scanfile = path.join(_BBS_ROOT, "scans", username ..".scan")
+ local f, err = io.open(scanfile, "w")
+ for _, board in ipairs(boards) do
+ f:write(board.name .. ":" .. tostring(board.last_scanned) .. "\n")
+ end
+ f:close()
+end
+
-- Commands
function do_board()
@@ -230,6 +252,9 @@ function do_messages()
end
-- Separator
print(string.rep("-",79))
+ -- Update scan times
+ current_board.last_scanned = os.time()
+ save_scan_times()
end
function do_new()
@@ -267,6 +292,24 @@ function do_new()
print("Post submitted.")
end
+function do_scan()
+ for _, board in ipairs(boards) do
+ io.write("Scanning " .. stringx.ljust(board.name,20))
+ local threads = get_threads(board)
+ local updated_threads = 0
+ for _, thread in ipairs(threads) do
+ if thread.updated > board.last_scanned then
+ updated_threads = updated_threads + 1
+ end
+ end
+ if updated_threads == 0 then
+ print("No new posts")
+ else
+ print(tostring(updated_threads) .. " threads updated!")
+ end
+ end
+end
+
-- The "type" command is implemented using multiple functions
-- do_type is the entry point, which runs a command dispatch loop that
-- runs various do_type_xxx functions.
@@ -421,6 +464,7 @@ cat_file(path.join(_BBS_ROOT, "docs", "welcome"))
-- Initialise global vars representing BBS state
update_boards()
+load_scan_times()
-- Build dispatch table mapping chars to functions
dispatch = {}
@@ -433,7 +477,7 @@ dispatch["t"] = do_type
dispatch["?"] = do_help2
dispatch["!"] = do_rules
dispatch["w"] = do_who
-dispatch["s"] = do_unimplemented
+dispatch["s"] = do_scan
dispatch["="] = do_unimplemented
dispatch["M"] = do_unimplemented
dispatch["n"] = do_new