diff options
author | Solderpunk <solderpunk@sdf.org> | 2018-12-07 21:17:58 +0000 |
---|---|---|
committer | Solderpunk <solderpunk@sdf.org> | 2018-12-07 21:17:58 +0000 |
commit | e57ced31c8d2569d4e95cfe97bad4f7f2b88f7ef (patch) | |
tree | 25f5a14fc7d625abea84e8f00b5eed5ca0a0a6bb /telem.lua | |
parent | Add support for top-level reply command (outside of ). (diff) |
Store root of BBS directory in a global variable, to allow easily changing it (e.g. for testing).
Diffstat (limited to 'telem.lua')
-rwxr-xr-x | telem.lua | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -9,6 +9,8 @@ path = require("pl.path") string = require("string") table = require("table") +_BBS_ROOT = "/var/bbs/" + bad_topics = {} bad_topics["."] = true bad_topics[".."] = true @@ -29,7 +31,7 @@ end function show_welcome() print("::::::::::: This is telem ver."..telemver.." :::::::::::") - cat_file("/var/bbs/docs/welcome") + cat_file(path.join(_BBS_ROOT, "docs", "welcome")) end function show_prompt() @@ -46,11 +48,11 @@ end function get_threads(board) local threads = {} - for topic in lfs.dir("/var/bbs/boards/"..board) do + for topic in lfs.dir(path.join(_BBS_ROOT, "boards", board)) do if bad_topics[topic] == nil then thread = {} thread.filename = topic - thread.directory = "/var/bbs/boards/"..board.."/"..topic + thread.directory = path.join(_BBS_ROOT, "boards", board, topic) _, _, timestamp, thread.author = string.find(topic, "(%d+)-(%a+)") thread.timestamp = tonumber(timestamp) @@ -104,7 +106,7 @@ function do_board() print("Description?") desc = io.read() -- Create directory - board_dir = path.join("/home/solderpunk/bbs/boards/", board) + board_dir = path.join(_BBS_ROOT, "boards", board) lfs.mkdir(board_dir) -- Write topic file topic_file = path.join(board_dir, "topic") @@ -131,11 +133,11 @@ function do_go() end function do_help() - cat_file("/var/bbs/docs/help") + cat_file(path.join(_BBS_ROOT, "docs", "help")) end function do_help2() - cat_file("/var/bbs/docs/help2") + cat_file(path.join(_BBS_ROOT, "docs", "help2")) end function do_unimplemented() @@ -145,7 +147,7 @@ end function do_list() for _,b in pairs(board_names) do posts = -3 -- Don't want to count "topic" file or "." or ".." - for topic in lfs.dir("/var/bbs/boards/"..b) do + for topic in lfs.dir(path.join(_BBS_ROOT, "boards", b)) do posts = posts +1 end print(string.format("%s [%d posts]", b, posts)) @@ -180,7 +182,7 @@ function do_new() -- Make thread dir timestamp = tostring(os.time()) thread_dir = timestamp .. "-" .. username - thread_path = path.join("/home/solderpunk/bbs/boards/", current_board, thread_dir) + thread_path = path.join(_BBS_ROOT, "boards", current_board, thread_dir) lfs.mkdir(thread_path) -- Write subject file file.write(path.join(thread_path, "subject"), @@ -301,7 +303,7 @@ function do_reply() end function do_rules() - cat_file("/var/bbs/docs/rules") + cat_file(path.join(_BBS_ROOT, "docs", "rules")) end function do_stub() @@ -317,7 +319,7 @@ end show_welcome() boards, board_names = {}, {} -for board in lfs.dir("/var/bbs/boards") do +for board in lfs.dir(path.join(_BBS_ROOT, "boards")) do if string.sub(board, 1, 1) ~= "." then boards[board] = true table.insert(board_names, board) |