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

WolferyScripting / WolferyJS / #13

28 Aug 2025 08:28PM UTC coverage: 59.188% (+3.8%) from 55.392%
#13

push

DonovanDMC
0.0.4

88 of 170 branches covered (51.76%)

Branch coverage included in aggregate %.

4608 of 7764 relevant lines covered (59.35%)

1.51 hits per line

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

19.35
/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 { BasicCharacterResponse } from "../util/types.js";
1✔
6
import type { NoteProperties } from "../generated/models/types.js";
1✔
7
import { NoteDefinition } from "../generated/models/definitions.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.options.track.notes) {
×
37
            const m = on ? "resourceOn" : "resourceOff";
×
38
            this[m]("change", this.onChange);
×
39
        }
×
40
    }
×
41

×
42
    get id(): string {
×
43
        return this.rid.slice(this.rid.lastIndexOf(".") + 1);
×
44
    }
×
45

×
46
    /**
×
47
     * Append text to the note for this character. The text will be added on a new line.
×
48
     * @param text The text to append to the note.
×
49
     */
×
50
    async appendText(text: string): Promise<Character> {
×
51
        return this.client.modules.core.getPlayer().then(player => player.appendNote(this.id, text));
×
52
    }
×
53

×
54
    /**
×
55
     * Clear the note for this character.
×
56
     */
×
57
    async clearText(): Promise<null> {
×
58
        await this.setText("");
×
59
        return null;
×
60
    }
×
61

×
62
    /**
×
63
     * Delete this note.
×
64
     */
×
65
    async delete(): Promise<Character> {
×
66
        return this.call<BasicCharacterResponse<"char">>("delete")
×
67
            .then(r => this.api.get<Character>(ResourceIDs.CHARACTER({ id: r.char.id })));
×
68
    }
×
69

×
70
    /** @internal */
×
71
    getOnTextChange(): OnTextChangeFunction | null {
×
72
        return this.onTextChange;
×
73
    }
×
74

×
75
    /** @internal */
×
76
    setOnTextChange(cb: OnTextChangeFunction | null): void {
×
77
        if (this.onTextChange !== null && cb !== null) {
×
78
            throw new Error(`Attempted to overwrite onTextChange for ${this.rid}`);
×
79
        }
×
80
        this.onTextChange = cb;
×
81
    }
×
82

×
83
    /**
×
84
     * Set the note for this character.
×
85
     * @param text The text to set the note to. Provide an empty string to clear.
×
86
     */
×
87
    async setText(text: string): Promise<Character| null> {
×
88
        return this.client.modules.core.getPlayer().then(player => player.setNote(this.id, text));
×
89
    }
×
90
}
×
91

1✔
92
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