• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WolferyScripting / WolferyJS / #17

01 Sep 2025 09:19PM UTC coverage: 63.335% (+3.5%) from 59.799%
#17

push

DonovanDMC
0.0.6

95 of 253 branches covered (37.55%)

Branch coverage included in aggregate %.

7592 of 11884 relevant lines covered (63.88%)

1.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.22
/lib/models/Note.ts
1
import type Character from "./Character.js";
1✔
2
import BaseModel from "./BaseModel.js";
1✔
3
import type WolferyJS from "../WolferyJS.js";
1✔
4
import ResourceIDs from "../generated/ResourceIDs.js";
1✔
5
import type { NoteProperties } from "../generated/models/types.js";
1✔
6
import { NoteDefinition } from "../generated/models/definitions.js";
1✔
7
import type Commands from "../util/commands.js";
1✔
8
import { Properties, type ResClient } from "resclient-ts";
1✔
9

1✔
10
export type OnTextChangeFunction = (note: Note, char: Character, text: string, oldText: string) => void;
1✔
11
declare interface Note extends BaseModel, NoteProperties {}
1✔
12
// do not edit the first line of the class comment
1✔
13
/**
1✔
14
 * A note on a character.
1✔
15
 * @resourceID {@link ResourceIDs.NOTE | NOTE}
1✔
16
 */
1✔
17
class Note extends BaseModel implements NoteProperties {
×
18
    private onChange = this._onChange.bind(this);
×
19
    private onTextChange!: OnTextChangeFunction | null;
×
20
    constructor(client: WolferyJS, api: ResClient, rid: string) {
×
21
        super(client, api, rid, { definition: NoteDefinition });
×
22
        Properties.of(this)
×
23
            .readOnly("onChange")
×
24
            .writable("onTextChange", null);
×
25
    }
×
26

×
27
    private async _onChange(data: Partial<NoteProperties>): Promise<void> {
×
28
        if (data.text !== undefined && this.onTextChange) {
×
29
            const char = await this.char.get();
×
30
            this.onTextChange(this, char, this.text, data.text);
×
31
        }
×
32
    }
×
33

×
34
    protected override async _listen(on: boolean): Promise<void> {
×
35
        await super._listen(on);
×
36
        if (this.client.anyTracked("notes")) {
×
37
            const m = on ? "resourceOn" : "resourceOff";
×
38
            this[m]("change", this.onChange);
×
39
        }
×
40
    }
×
41

×
42
    get charId(): string {
×
43
        return ResourceIDs.NOTE.parts(this.rid).char;
×
44
    }
×
45

×
46
    get id(): string {
×
47
        // no individual id
×
48
        return this.charId;
×
49
    }
×
50

×
51
    get playerId(): string {
×
52
        return ResourceIDs.NOTE.parts(this.rid).player;
×
53
    }
×
54

×
55
    /**
×
56
     * Append text to the note for this character. The text will be added on a new line.
×
57
     * @param text The text to append to the note.
×
58
     * @playerRequired
×
59
     * @calls {@link PlayerCommands.appendNote} > {@link WolferyJS.getChar}
×
60
     */
×
61
    async appendText(text: string): Promise<Character> {
×
62
        return this.client.commands.player.appendNote(this.playerId, this.charId, text)
×
63
            .then(r => this.client.getChar(r.id));
×
64
    }
×
65

×
66
    /**
×
67
     * Clear the note for this character.
×
68
     * @playerRequired
×
69
     * @calls {@link set}
×
70
     */
×
71
    async clearText(): Promise<Character> {
×
72
        return this.set({ text: "" });
×
73
    }
×
74

×
75
    /**
×
76
     * Delete this note.
×
77
     * @playerRequired
×
78
     * @calls {@link PlayerCommands.deleteNote} > {@link WolferyJS.getChar}
×
79
     */
×
80
    async delete(): Promise<Character> {
×
81
        return this.client.commands.player.deleteNote(this.playerId, this.charId)
×
82
            .then(r => this.client.getChar(r.id));
×
83
    }
×
84

×
85
    /** @internal */
×
86
    getOnTextChange(): OnTextChangeFunction | null {
×
87
        return this.onTextChange;
×
88
    }
×
89

×
90
    /**
×
91
     * Set the note for this character.
×
92
     * @param options The options to set.
×
93
     * @playerRequired
×
94
     * @calls {@link PlayerCommands.setNote} > {@link WolferyJS.getChar}
×
95
     */
×
96
    async set(options: Commands.Player.SetNoteOptions): Promise<Character> {
×
97
        return this.client.commands.player.setNote(this.playerId, this.charId, options)
×
98
            .then(r => this.client.getChar(r.id));
×
99
    }
×
100

×
101
    /** @internal */
×
102
    setOnTextChange(cb: OnTextChangeFunction | null): void {
×
103
        if (this.onTextChange !== null && cb !== null) {
×
104
            throw new Error(`Attempted to overwrite onTextChange for ${this.rid}`);
×
105
        }
×
106
        this.onTextChange = cb;
×
107
    }
×
108
}
×
109

1✔
110
export default Note;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc