feat: complete Ancestor quote bot with production-ready Docker support

This commit is contained in:
unfunny
2026-09-13 14:14:38 -04:00
parent f2016da05a
commit fe7351a7dc
1145 changed files with 30890 additions and 97684 deletions

View File

@@ -1,4 +1,14 @@
import _defineProperty from "@babel/runtime/helpers/defineProperty";
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isTimestampInDuration = exports.getBeaconInfoIdentifier = exports.BeaconEvent = exports.Beacon = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _contentHelpers = require("../content-helpers");
var _utils = require("../utils");
var _typedEventEmitter = require("./typed-event-emitter");
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
@@ -14,11 +24,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { parseBeaconContent, parseBeaconInfoContent } from "../content-helpers.js";
import { sortEventsByLatestContentTimestamp } from "../utils.js";
import { TypedEventEmitter } from "./typed-event-emitter.js";
export let BeaconEvent = /*#__PURE__*/function (BeaconEvent) {
let BeaconEvent = /*#__PURE__*/function (BeaconEvent) {
BeaconEvent["New"] = "Beacon.new";
BeaconEvent["Update"] = "Beacon.update";
BeaconEvent["LivenessChange"] = "Beacon.LivenessChange";
@@ -26,29 +32,31 @@ export let BeaconEvent = /*#__PURE__*/function (BeaconEvent) {
BeaconEvent["LocationUpdate"] = "Beacon.LocationUpdate";
return BeaconEvent;
}({});
export const isTimestampInDuration = (startTimestamp, durationMs, timestamp) => timestamp >= startTimestamp && startTimestamp + durationMs >= timestamp;
exports.BeaconEvent = BeaconEvent;
const isTimestampInDuration = (startTimestamp, durationMs, timestamp) => timestamp >= startTimestamp && startTimestamp + durationMs >= timestamp;
// beacon info events are uniquely identified by
// `<roomId>_<state_key>`
export const getBeaconInfoIdentifier = event => `${event.getRoomId()}_${event.getStateKey()}`;
exports.isTimestampInDuration = isTimestampInDuration;
const getBeaconInfoIdentifier = event => `${event.getRoomId()}_${event.getStateKey()}`;
// https://github.com/matrix-org/matrix-spec-proposals/pull/3672
export class Beacon extends TypedEventEmitter {
exports.getBeaconInfoIdentifier = getBeaconInfoIdentifier;
class Beacon extends _typedEventEmitter.TypedEventEmitter {
constructor(rootEvent) {
super();
_defineProperty(this, "roomId", void 0);
this.rootEvent = rootEvent;
(0, _defineProperty2.default)(this, "roomId", void 0);
// beaconInfo is assigned by setBeaconInfo in the constructor
// ! to make tsc believe it is definitely assigned
_defineProperty(this, "_beaconInfo", void 0);
_defineProperty(this, "_isLive", void 0);
_defineProperty(this, "livenessWatchTimeout", void 0);
_defineProperty(this, "_latestLocationEvent", void 0);
_defineProperty(this, "clearLatestLocation", () => {
(0, _defineProperty2.default)(this, "_beaconInfo", void 0);
(0, _defineProperty2.default)(this, "_isLive", void 0);
(0, _defineProperty2.default)(this, "livenessWatchTimeout", void 0);
(0, _defineProperty2.default)(this, "_latestLocationEvent", void 0);
(0, _defineProperty2.default)(this, "clearLatestLocation", () => {
this._latestLocationEvent = undefined;
this.emit(BeaconEvent.LocationUpdate, this.latestLocationState);
});
this.rootEvent = rootEvent;
this.roomId = this.rootEvent.getRoomId();
this.setBeaconInfo(this.rootEvent);
}
@@ -71,7 +79,7 @@ export class Beacon extends TypedEventEmitter {
return this._beaconInfo;
}
get latestLocationState() {
return this._latestLocationEvent && parseBeaconContent(this._latestLocationEvent.getContent());
return this._latestLocationEvent && (0, _contentHelpers.parseBeaconContent)(this._latestLocationEvent.getContent());
}
get latestLocationEvent() {
return this._latestLocationEvent;
@@ -128,13 +136,14 @@ export class Beacon extends TypedEventEmitter {
* Emits BeaconEvent.LocationUpdate
*/
addLocations(beaconLocationEvents) {
var _validLocationEvents$;
// discard locations for beacons that are not live
if (!this.isLive) {
return;
}
const validLocationEvents = beaconLocationEvents.filter(event => {
const content = event.getContent();
const parsed = parseBeaconContent(content);
const parsed = (0, _contentHelpers.parseBeaconContent)(content);
if (!parsed.uri || !parsed.timestamp) return false; // we won't be able to process these
const {
timestamp
@@ -145,14 +154,14 @@ export class Beacon extends TypedEventEmitter {
// ignore positions older than our current latest location
!this.latestLocationState || timestamp > this.latestLocationState.timestamp);
});
const latestLocationEvent = validLocationEvents.sort(sortEventsByLatestContentTimestamp)?.[0];
const latestLocationEvent = (_validLocationEvents$ = validLocationEvents.sort(_utils.sortEventsByLatestContentTimestamp)) === null || _validLocationEvents$ === void 0 ? void 0 : _validLocationEvents$[0];
if (latestLocationEvent) {
this._latestLocationEvent = latestLocationEvent;
this.emit(BeaconEvent.LocationUpdate, this.latestLocationState);
}
}
setBeaconInfo(event) {
this._beaconInfo = parseBeaconInfoContent(event.getContent());
this._beaconInfo = (0, _contentHelpers.parseBeaconInfoContent)(event.getContent());
this.checkLiveness();
}
checkLiveness() {
@@ -170,4 +179,5 @@ export class Beacon extends TypedEventEmitter {
}
}
}
exports.Beacon = Beacon;
//# sourceMappingURL=beacon.js.map