mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
Warnings: shown at the next visit, taken back, and a silence for many
- a warning given while the player is away is kept and shown with the
game's popup once they are next in a room (the latest one)
- unwarn: "Take back latest" in the moderator panel, !unwarn in game and
from the staff window ("xmd")
- config.warningSilence: the Nth warning within some days also silences
(3rd: an hour, 5th: a day, by default)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
627e6f9180
commit
f3983fcf67
8 files changed
+145
-19
No files matched your search
@@ -285,6 +285,10 @@ module.exports = {
|
||||
idleTimeoutMs: 15 * 60000, // the client sends a keep-alive far more often
|
||||
tokenLifetimeDays: 30, // login tokens kept by the launcher's "remember me"
|
||||
maxChatLength: 300,
|
||||
// warnings (lib/moderation.js warn): the Nth one within `days` also
|
||||
// silences the player for that many minutes, [[N, minutes], ...]. a
|
||||
// longer silence already on them stays. steps [] turns it off.
|
||||
warningSilence: {days: 30, steps: [[3, 60], [5, 24 * 60]]},
|
||||
// days typed chat and whispers are kept for the moderator panel's chat
|
||||
// history (lib/chatlog.js); 0 keeps none.
|
||||
chatLogDays: env.AJ_CHAT_LOG_DAYS === undefined ? 30 : Math.max(0, Number(env.AJ_CHAT_LOG_DAYS) || 0),
|
||||
|
||||
+29
-1
@@ -682,7 +682,8 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
|
||||
const reason = WARNINGS.includes(asked) ? asked : "behavior";
|
||||
const note = (WARNINGS.includes(asked) ? rest.slice(1) : rest).join(" ").trim().slice(0, MAX_WARNING);
|
||||
const result = actions.warn(target.account, reason, session.account.username, note);
|
||||
tell(session, `${target.account.username} warned (${reason}): warning ${result.count}.`);
|
||||
tell(session, `${target.account.username} warned (${reason}): warning ${result.count}.`
|
||||
+ (result.silencedMinutes ? ` Silenced for ${result.silencedMinutes} minutes, for that many warnings.` : ""));
|
||||
logged(session, "warn", target, note ? `${reason} · ${note}` : reason);
|
||||
});
|
||||
},
|
||||
@@ -707,6 +708,33 @@ module.exports = ({findOnline, players, watchers, sendItemList, blocks, setHideB
|
||||
});
|
||||
},
|
||||
},
|
||||
// "!unwarn PLAYER": takes back their latest warning (one given by
|
||||
// mistake), online or not.
|
||||
unwarn: {
|
||||
permission: "player.warn",
|
||||
run(session, words) {
|
||||
const account = splitAccount(words);
|
||||
if (!account) {
|
||||
tell(session, words.length ? `No player called ${words.join(" ")}.` : "Use: !unwarn PLAYER");
|
||||
return;
|
||||
}
|
||||
if (account === session.account) {
|
||||
tell(session, "That is you.");
|
||||
return;
|
||||
}
|
||||
if (!roles.outranks(session.account, account)) {
|
||||
tell(session, "Staff of your rank or above are for someone higher up to deal with.");
|
||||
return;
|
||||
}
|
||||
const removed = staffModeration().actions.unwarn(account);
|
||||
if (!removed) {
|
||||
tell(session, `${account.username} has no warnings.`);
|
||||
return;
|
||||
}
|
||||
tell(session, `Took back ${account.username}'s latest warning (${removed.reason}).`);
|
||||
modlog.record(session.account.username, "unwarn (in game)", account.username, removed.reason);
|
||||
},
|
||||
},
|
||||
// "!warnings PLAYER": their latest warnings, online or not.
|
||||
warnings: {
|
||||
permission: "player.warn",
|
||||
|
||||
+64
-7
@@ -4,6 +4,7 @@ const accounts = require("./accounts.js");
|
||||
const achievements = require("./achievements.js");
|
||||
const bans = require("./bans.js");
|
||||
const dens = require("./dens.js");
|
||||
const config = require("../config.js");
|
||||
const {CURRENCIES} = require("./player.js");
|
||||
|
||||
// moderation: kick, ban, silence, clear a den, grant gems, message a player.
|
||||
@@ -29,6 +30,7 @@ const WARNINGS = {
|
||||
};
|
||||
const MAX_WARNINGS_KEPT = 100;
|
||||
const MAX_WARNING_NOTE = 200;
|
||||
const SECONDS_PER_DAY = 86400;
|
||||
|
||||
const now = () => Math.floor(Date.now() / 1000);
|
||||
|
||||
@@ -47,6 +49,21 @@ const banOf = account => {
|
||||
return seconds === 0 ? null : {seconds, reason: account.banReason || bans.NO_REASON, by: account.bannedBy || "", since: account.bannedAt || null};
|
||||
};
|
||||
|
||||
// the warnings an account has had in the last config.warningSilence.days
|
||||
// (all of them when that is 0).
|
||||
const recentWarnings = account => {
|
||||
const days = (config.warningSilence || {}).days || 0;
|
||||
const since = now() - days * SECONDS_PER_DAY;
|
||||
return (account.warnings || []).filter(entry => !days || entry.at >= since).length;
|
||||
};
|
||||
|
||||
// the minutes of silence a warning brings when it is the Nth recent one
|
||||
// (config.warningSilence.steps, [[N, minutes], ...]); 0 for none.
|
||||
const silenceForWarning = count => {
|
||||
const step = ((config.warningSilence || {}).steps || []).find(([warnings]) => warnings === count);
|
||||
return step ? step[1] : 0;
|
||||
};
|
||||
|
||||
const isSilenced = account => account.silencedUntil === PERMANENT || (account.silencedUntil || 0) > now();
|
||||
|
||||
// seconds of silence left, PERMANENT, or 0 when the account may chat.
|
||||
@@ -185,20 +202,47 @@ module.exports = ({findOnline}) => {
|
||||
},
|
||||
|
||||
// a warning: kept on the account (who, when, why and a note for staff),
|
||||
// and shown with the game's own warning popup if they are online.
|
||||
// returns {count, online}, or null for a reason that is not one.
|
||||
// and shown with the game's own warning popup: now if they are in a
|
||||
// room, else once they are next (greet). the Nth warning within
|
||||
// config.warningSilence.days may also silence them for a while; a
|
||||
// longer silence already on them is left alone.
|
||||
// returns {count, online, silencedMinutes}, or null for a reason that
|
||||
// is not one.
|
||||
warn(target, reason, by, note = "") {
|
||||
if (!Object.hasOwn(WARNINGS, reason)) {
|
||||
return null;
|
||||
}
|
||||
target.warnings = [...(target.warnings || []), {at: now(), by, reason, note: String(note).slice(0, MAX_WARNING_NOTE)}]
|
||||
const session = findOnline(target.username);
|
||||
const seen = Boolean(session && session.greeted);
|
||||
target.warnings = [...(target.warnings || []), {at: now(), by, reason, note: String(note).slice(0, MAX_WARNING_NOTE), seen}]
|
||||
.slice(-MAX_WARNINGS_KEPT);
|
||||
accounts.save();
|
||||
const session = findOnline(target.username);
|
||||
if (session) {
|
||||
if (seen) {
|
||||
discipline(session, "fw", WARNINGS[reason]);
|
||||
}
|
||||
return {count: target.warnings.length, online: Boolean(session)};
|
||||
let silencedMinutes = silenceForWarning(recentWarnings(target));
|
||||
const left = silenceRemaining(target);
|
||||
if (silencedMinutes && left !== PERMANENT && left < silencedMinutes * SECONDS_PER_MINUTE) {
|
||||
actions.silence(target, silencedMinutes * SECONDS_PER_MINUTE);
|
||||
}
|
||||
else {
|
||||
silencedMinutes = 0;
|
||||
}
|
||||
return {count: target.warnings.length, online: Boolean(session), silencedMinutes};
|
||||
},
|
||||
|
||||
// takes back their latest warning (one given by mistake). a silence it
|
||||
// brought stays; that is lifted on its own (silence 0). returns the
|
||||
// warning taken back, or null when there is none.
|
||||
unwarn(target) {
|
||||
const list = target.warnings || [];
|
||||
if (!list.length) {
|
||||
return null;
|
||||
}
|
||||
const removed = list[list.length - 1];
|
||||
target.warnings = list.slice(0, -1);
|
||||
accounts.save();
|
||||
return removed;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -207,7 +251,20 @@ module.exports = ({findOnline}) => {
|
||||
const refuse = reply => session => session.sendXt(reply, -1, 0);
|
||||
const handlers = {fk: refuse("fk"), fb: refuse("fb"), fs: refuse("fs"), fm: refuse("fm"), fg: refuse("fg"), fp: refuse("fp"), fc() {}};
|
||||
|
||||
return {handlers, actions, banRemaining, banOf, isSilenced, silenceRemaining, PERMANENT, WARNINGS: Object.keys(WARNINGS)};
|
||||
// the first room has loaded (lib/world.js): a warning given while they
|
||||
// were away is shown now, the latest only (the game has one warning
|
||||
// popup), and all of them count as seen.
|
||||
const greet = session => {
|
||||
const unseen = (session.account.warnings || []).filter(entry => entry.seen === false);
|
||||
if (!unseen.length) {
|
||||
return;
|
||||
}
|
||||
unseen.forEach(entry => { entry.seen = true; });
|
||||
accounts.save();
|
||||
discipline(session, "fw", WARNINGS[unseen[unseen.length - 1].reason] ?? WARNINGS.behavior);
|
||||
};
|
||||
|
||||
return {handlers, actions, greet, banRemaining, banOf, isSilenced, silenceRemaining, PERMANENT, WARNINGS: Object.keys(WARNINGS)};
|
||||
};
|
||||
|
||||
Object.assign(module.exports, {isSilenced, banRemaining, banOf});
|
||||
+14
-2
@@ -144,12 +144,18 @@ const wholeNumber = (value, min, max) => (Number.isInteger(value) && value >= mi
|
||||
const ACTION_PERMISSIONS = {
|
||||
ban: "player.ban", banReason: "player.ban", unban: "player.ban",
|
||||
silence: "chat.silence", unsilence: "chat.silence",
|
||||
kick: "player.kick", message: "player.warn", warn: "player.warn",
|
||||
kick: "player.kick", message: "player.warn", warn: "player.warn", unwarn: "player.warn",
|
||||
rejectName: "player.names", acceptName: "player.names", clearBio: "player.names",
|
||||
banAddress: "address.ban",
|
||||
summon: "player.summon", goto: "player.goto",
|
||||
};
|
||||
|
||||
// minutes as a person would say them: "1 hour", "1 day", "90 minutes".
|
||||
const silenceText = minutes => {
|
||||
const [count, unit] = minutes % 1440 === 0 ? [minutes / 1440, "day"] : minutes % 60 === 0 ? [minutes / 60, "hour"] : [minutes, "minute"];
|
||||
return `${count} ${unit}${count === 1 ? "" : "s"}`;
|
||||
};
|
||||
|
||||
const act = (mod, target, body) => {
|
||||
const {actions, PERMANENT} = world.moderation;
|
||||
const name = target.username;
|
||||
@@ -209,9 +215,15 @@ const act = (mod, target, body) => {
|
||||
if (!result) {
|
||||
return {error: `A warning's reason: ${world.moderation.WARNINGS.join(", ")}.`};
|
||||
}
|
||||
return {ok: `${name} warned (${reason}): warning ${result.count}.${result.online ? "" : " They are offline, so they will not see it."}`,
|
||||
return {ok: `${name} warned (${reason}): warning ${result.count}.${result.online ? "" : " They are offline: they will see it when they next play."}`
|
||||
+ (result.silencedMinutes ? ` That many warnings also silenced them for ${silenceText(result.silencedMinutes)}.` : ""),
|
||||
detail: `${reason}${body.note ? ` · ${String(body.note).slice(0, 200)}` : ""}`};
|
||||
}
|
||||
case "unwarn": {
|
||||
const removed = actions.unwarn(target);
|
||||
return removed ? {ok: `Took back ${name}'s latest warning (${removed.reason}).`, detail: removed.reason}
|
||||
: {error: `${name} has no warnings.`};
|
||||
}
|
||||
case "rejectName":
|
||||
if (target.nameRejected) {
|
||||
return {error: "Already rejected."};
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ const totp = require("./totp.js");
|
||||
const PERMISSIONS = {
|
||||
"player.view": "see players, chat, reports, requests, bans and paintings in the moderator panel",
|
||||
"staff.list": "see which staff are online (!staff)",
|
||||
"player.warn": "warn a player and send them a message (!warn, !warnings, !message)",
|
||||
"player.warn": "warn a player, take a warning back and send them a message (!warn, !unwarn, !warnings, !message)",
|
||||
"player.goto": "go to the room a player is in (!goto)",
|
||||
"chat.silence": "silence and unsilence a player (!silence)",
|
||||
"player.kick": "disconnect a player (!kick)",
|
||||
|
||||
+2
-1
@@ -464,7 +464,7 @@ const sendUserVars = session => {
|
||||
};
|
||||
|
||||
const findOnline = username => online.get(String(username).toLowerCase());
|
||||
const STAFF_WINDOW_COMMANDS = ["warn", "message", "silence", "kick", "summon", "goto", "warnings"];
|
||||
const STAFF_WINDOW_COMMANDS = ["warn", "unwarn", "message", "silence", "kick", "summon", "goto", "warnings"];
|
||||
const MAX_STAFF_WINDOW_WORDS = 3; // username, then a reason, hours or the message (each one field)
|
||||
|
||||
// a custom colour (lib/colours.js) for these four RGB values, made if it is
|
||||
@@ -603,6 +603,7 @@ const handlers = {
|
||||
}
|
||||
buddies.greet(session);
|
||||
minigames.greet(session);
|
||||
moderation.greet(session);
|
||||
// never asked what chat they want filtered: the window is put to
|
||||
// them, this once (the patched client's "xfa").
|
||||
if (!session.account.filter.chosen) {
|
||||
|
||||
+5
-3
@@ -316,6 +316,7 @@
|
||||
</select>
|
||||
<input id="warn-note" maxlength="200" placeholder="Note for staff (optional)" aria-label="Note">
|
||||
<button type="button" data-action="warn">Warn</button></div>
|
||||
<div class="row" style="margin-top:8px"><button type="button" data-action="unwarn">Take back latest</button></div>
|
||||
</div>
|
||||
<div class="action">
|
||||
<h3>Message</h3>
|
||||
@@ -647,7 +648,7 @@
|
||||
const warnings = player.warningList || [];
|
||||
$("warnings-title").hidden = warnings.length === 0;
|
||||
$("player-warnings").replaceChildren(...warnings.map(entry => el("li", [when(entry.at), WARNING_REASONS[entry.reason] || entry.reason,
|
||||
entry.note, entry.by && `by ${entry.by}`].filter(Boolean).join(" · "))));
|
||||
entry.note, entry.by && `by ${entry.by}`, entry.seen === false && "not seen yet"].filter(Boolean).join(" · "))));
|
||||
$("history-title").hidden = player.history.length === 0;
|
||||
$("player-history").replaceChildren(...player.history.map(entry => el("li", [when(entry.at), HISTORY[entry.action] || entry.action,
|
||||
entry.action === "ban" ? (entry.seconds === -1 ? "for good" : duration(entry.seconds)) : "", entry.reason, entry.by && `by ${entry.by}`]
|
||||
@@ -657,7 +658,7 @@
|
||||
const select = username => {
|
||||
selected = username;
|
||||
setStatus($("detail-status"), "");
|
||||
for (const id of ["ban-hours", "ban-reason", "silence-hours", "message-text"]) {
|
||||
for (const id of ["ban-hours", "ban-reason", "silence-hours", "message-text", "warn-note"]) {
|
||||
$(id).value = "";
|
||||
}
|
||||
renderPlayers();
|
||||
@@ -685,6 +686,7 @@
|
||||
const CONFIRM = {
|
||||
banAddress: name => `Ban the address ${name} last signed in from, for good?`,
|
||||
rejectName: name => `Reject the username ${name}? They are signed out and must pick another.`,
|
||||
unwarn: name => `Take back ${name}'s latest warning?`,
|
||||
};
|
||||
|
||||
$("detail").addEventListener("click", async event => {
|
||||
@@ -1159,7 +1161,7 @@
|
||||
const ACTION_PERMISSIONS = {
|
||||
ban: "player.ban", banReason: "player.ban", unban: "player.ban",
|
||||
silence: "chat.silence", unsilence: "chat.silence",
|
||||
kick: "player.kick", message: "player.warn", warn: "player.warn",
|
||||
kick: "player.kick", message: "player.warn", warn: "player.warn", unwarn: "player.warn",
|
||||
rejectName: "player.names", acceptName: "player.names", clearBio: "player.names",
|
||||
banAddress: "address.ban", summon: "player.summon", goto: "player.goto",
|
||||
};
|
||||
|
||||
+26
-4
@@ -195,11 +195,13 @@ const run = async () => {
|
||||
say(mira.client, ann.roomId, "!warnings Ann");
|
||||
assert.match(await nextBox(mira.client), /^Ann has 2 warnings\. Latest: \S+ behavior by Mira; \S+ bullying by Mira \(called names\)$/);
|
||||
// the client's staff window ("xmd"): the same commands, one field each
|
||||
// the third warning in 30 days also silences for an hour (config.warningSilence)
|
||||
mira.client.xt("xmd", ann.roomId, "warn", "Ann", "personal");
|
||||
assert.deepStrictEqual((await ann.client.untilXt("fd")).slice(2, 4), ["fw", "3"]);
|
||||
assert.strictEqual(await nextBox(mira.client), "Ann warned (personal): warning 3.");
|
||||
assert.deepStrictEqual((await ann.client.untilXt("fd")).slice(2, 4), ["fs", "60"]);
|
||||
assert.strictEqual(await nextBox(mira.client), "Ann warned (personal): warning 3. Silenced for 60 minutes, for that many warnings.");
|
||||
mira.client.xt("xmd", ann.roomId, "message", "Ann", "hello there");
|
||||
assert.deepStrictEqual((await ann.client.untilXt("fd")).slice(2, 4), ["fp", "hello there"]);
|
||||
assert.deepStrictEqual((await untilPopup(ann.client, "fp")).slice(2, 4), ["fp", "hello there"]);
|
||||
assert.strictEqual(await nextBox(mira.client), "Shown to Ann.");
|
||||
mira.client.xt("xmd", ann.roomId, "ban", "Ann"); // not one the window has: nothing
|
||||
// and from a player, nothing at all: Ann warns Mira
|
||||
@@ -236,6 +238,25 @@ const run = async () => {
|
||||
const pipPage = (await modPage("/mod/api/player?username=Pip")).data;
|
||||
assert.strictEqual(pipPage.warnings, 1);
|
||||
assert.deepStrictEqual([pipPage.warningList[0].reason, pipPage.warningList[0].note, pipPage.warningList[0].by], ["scamming", "fake trade", "Mira"]);
|
||||
assert.strictEqual(pipPage.warningList[0].seen, true);
|
||||
|
||||
// warnings while away (Ann was disconnected): kept for her next visit;
|
||||
// the fifth in 30 days silences for a day; one is taken back
|
||||
assert.match((await modPage("/mod/api/act", {username: "Ann", action: "warn", reason: "bullying"})).data.ok,
|
||||
/^Ann warned \(bullying\): warning 4\. They are offline: they will see it when they next play\.$/);
|
||||
assert.match((await modPage("/mod/api/act", {username: "Ann", action: "warn", reason: "behavior"})).data.ok,
|
||||
/warning 5\. .*silenced them for 1 day\.$/);
|
||||
assert.strictEqual((await modPage("/mod/api/act", {username: "Ann", action: "unwarn"})).data.ok, "Took back Ann's latest warning (behavior).");
|
||||
const annAway = (await modPage("/mod/api/player?username=Ann")).data;
|
||||
assert.strictEqual(annAway.warnings, 4);
|
||||
assert.strictEqual(annAway.warningList[0].seen, false);
|
||||
const annBack = await arrive("Ann", people.Ann, SAREPIA);
|
||||
assert.deepStrictEqual((await untilPopup(annBack.client, "fw")).slice(2, 4), ["fw", "1"]); // the bullying one
|
||||
assert.strictEqual((await modPage("/mod/api/player?username=Ann")).data.warningList[0].seen, true);
|
||||
say(mira.client, ann.roomId, "!unwarn Ann");
|
||||
assert.strictEqual(await nextBox(mira.client), "Took back Ann's latest warning (bullying).");
|
||||
say(mira.client, ann.roomId, "!unwarn Mira");
|
||||
assert.strictEqual(await nextBox(mira.client), "That is you.");
|
||||
|
||||
// the panel's summon brings Pip to Mira (now in Sarepia)
|
||||
assert.match((await modPage("/mod/api/act", {username: "Pip", action: "summon"})).data.ok || "", /^Pip was brought to /);
|
||||
@@ -244,7 +265,8 @@ const run = async () => {
|
||||
// everything above is in the moderators' log, the in-game ones marked so
|
||||
const log = (await admin("/admin/api/moderators")).data.log.map(entry => `${entry.by} ${entry.action} ${entry.target}`);
|
||||
for (const line of ["Mira summon (in game) Pip", "Hal silence (in game) Pip", "Mira goto (in game) Ann", "Mira warn (in game) Ann",
|
||||
"Mira message (in game) Ann", "Mira kick (in game) Ann", "Mira warn Pip", "Mira summon Pip"]) {
|
||||
"Mira message (in game) Ann", "Mira kick (in game) Ann", "Mira warn Pip", "Mira summon Pip", "Mira warn Ann", "Mira unwarn Ann",
|
||||
"Mira unwarn (in game) Ann"]) {
|
||||
assert.ok(log.includes(line), `missing from the log: ${line}\n${log.join("\n")}`);
|
||||
}
|
||||
|
||||
@@ -256,7 +278,7 @@ const run = async () => {
|
||||
assert.strictEqual(strings[11134], "--Message From Moderator--\n\n");
|
||||
assert.ok(!strings[11135].includes("\\n"));
|
||||
|
||||
for (const {client} of [mira, hal, pip]) {
|
||||
for (const {client} of [mira, hal, pip, annBack]) {
|
||||
client.socket.destroy();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user