Add JavaScript scripting: the sysop's own screens, on every terminal

A script (scripts_dir/NAME.js, run by a menu's script:NAME, and logon.js
after each login) draws the BBS's shared screens through ui (menus,
tables, forms, panels, messages, the editor, confirmations), so one
script works on text, RIP and 3270 terminals.  It acts as its caller,
with their access: msg (areas, messages, posting, mail), node (who's
online, node messages, its activity), user, bbs; and keeps JSON values
in data, for everyone or (data.user) for the caller, in the database
(script_data).

goja runs it in strict mode, with no files, network or processes.  A
watchdog stops a script that computes more than two seconds between
screens (the caller's time at a screen is not counted); the caller
hanging up ends a script whatever it catches; failures are logged and
told (to a sysop, with why).  Scripts are compiled once, again when
changed; bbs check refuses scripts that do not compile and menus naming
missing ones.

goja is pinned to its June 2026 commit (the last that builds with Go
1.24; it is changing quickly now).

scripts.sample has one-liners and a poll; both are tested, the
one-liners on a text terminal and on a 3270 (s3270).  That test found
3270 forms broken since the shared screens: the input field began
under its label's last character, whose attribute byte erased it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
This commit is contained in:
Claude committed 2026-10-12 14:52:12 +00:00
1 parent 0cce335b88
commit 1805fcbd13
30 files changed
+1665 -8

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
Sample scripts for scripts_dir: copy them there and give them menu items.
oneliners.js the last lines callers left, and one of yours
poll.js a poll: a vote each, the results as bars
A logon.js there runs after every login, before the menus.
See the wiki's Scripting page for what a script can do.
+33
View File
@@ -0,0 +1,33 @@
// One-liners: the last lines callers left, and one of yours.
//
// A menu item runs it: o = script:oneliners One-liners
// It works on every terminal: text, RIP and 3270.
var MOST = 15; // lines kept
function show() {
var lines = data.get("lines") || [];
var shown = lines.length ? lines.map(function (l) {
return {label: l.who + ":", text: l.text};
}) : ["No one has left a line yet."];
return ui.panel({
title: "One-liners",
lines: shown,
actions: [{id: "add", label: "Add a line", key: "a", pf: 5, short: "Add"}]
});
}
for (;;) {
node.doing("Reading one-liners");
if (show() !== "add") break;
var v = ui.form({
title: "Your one-liner",
fields: [{name: "text", label: "Your line", prompt: "Your line (Enter to give up): ", width: 60}],
submit: "Add"
});
if (!v || !v.text) continue;
var lines = data.get("lines") || [];
lines.push({who: user.name, text: v.text, when: new Date().toISOString()});
data.set("lines", lines.slice(-MOST));
ui.say("Added.", "good");
}
+58
View File
@@ -0,0 +1,58 @@
// A poll: one question, a vote each, the results as bars.
//
// The sysop sets the question from the script itself (S on its screen).
// A menu item runs it: p = script:poll Today's poll
var poll = data.get("poll") || {question: "Which terminal do you call with?",
answers: ["An ANSI terminal", "A Commodore", "A 3270", "Something else"]};
var votes = data.get("votes") || {};
function results() {
var total = 0, i;
for (i = 0; i < poll.answers.length; i++) total += votes[i] || 0;
var lines = [{text: poll.question, tone: "bright"}, ""];
for (i = 0; i < poll.answers.length; i++) {
var n = votes[i] || 0;
lines.push({label: poll.answers[i], text: String(n), bar: total ? n / total : 0});
}
lines.push("", total + (total === 1 ? " vote" : " votes"));
ui.show("Poll results", lines);
}
function vote() {
var c = ui.table({
title: poll.question,
pick: "Your answer",
columns: [{title: "Answer"}],
rows: poll.answers.map(function (a) { return [a]; })
});
if (c.action !== ui.PICK || c.row < 0) return;
votes[c.row] = (votes[c.row] || 0) + 1;
data.set("votes", votes);
data.user.set("voted", poll.question);
ui.say("Your vote is counted.", "good");
}
function setQuestion() {
var v = ui.form({
title: "A new poll",
fields: [{name: "q", label: "Question", width: 70},
{name: "a", label: "Answers", prompt: "Answers (separated by |): ", width: 200}]
});
if (!v || !v.q || !v.a) return;
var answers = v.a.split("|").map(function (s) { return s.trim(); }).filter(Boolean);
if (answers.length < 2) {
ui.say("A poll needs two answers or more.", "bad");
return;
}
poll = {question: v.q, answers: answers};
votes = {};
data.set("poll", poll);
data.set("votes", votes);
ui.say("The new poll is up.", "good");
}
node.doing("At the poll");
if (data.user.get("voted") !== poll.question) vote();
results();
if (user.sysop && ui.confirm("Set a new question?", false)) setQuestion();