mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-19 01:27:51 -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
+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});
|
||||
Reference in new issue
Block a user