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

u-wave / core / 13129773810

04 Feb 2025 06:37AM UTC coverage: 85.093% (+0.02%) from 85.077%
13129773810

push

github

web-flow
deps: bump nock from 13.5.6 to 14.0.0 (#686)

Bumps [nock](https://github.com/nock/nock) from 13.5.6 to 14.0.0.
- [Release notes](https://github.com/nock/nock/releases)
- [Changelog](https://github.com/nock/nock/blob/main/CHANGELOG.md)
- [Commits](https://github.com/nock/nock/compare/v13.5.6...v14.0.0)

---
updated-dependencies:
- dependency-name: nock
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

936 of 1113 branches covered (84.1%)

Branch coverage included in aggregate %.

9984 of 11720 relevant lines covered (85.19%)

90.69 hits per line

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

89.03
/src/plugins/chat.js
1
import { randomUUID } from 'node:crypto';
1✔
2
import routes from '../routes/chat.js';
1✔
3
import { now } from '../utils/sqlite.js';
1✔
4

1✔
5
/**
1✔
6
 * @typedef {import('../schema.js').UserID} UserID
1✔
7
 * @typedef {import('../schema.js').User} User
1✔
8
 * @typedef {object} ChatOptions
1✔
9
 * @prop {number} maxLength
1✔
10
 */
1✔
11

1✔
12
/** @type {ChatOptions} */
1✔
13
const defaultOptions = {
1✔
14
  maxLength: 300,
1✔
15
};
1✔
16

1✔
17
class Chat {
144✔
18
  #uw;
144✔
19

144✔
20
  /** @type {ChatOptions} */
144✔
21
  #options;
144✔
22

144✔
23
  /**
144✔
24
   * @param {import('../Uwave.js').default} uw
144✔
25
   * @param {Partial<ChatOptions>} [options]
144✔
26
   */
144✔
27
  constructor(uw, options = {}) {
144✔
28
    this.#uw = uw;
144✔
29

144✔
30
    this.#options = {
144✔
31
      ...defaultOptions,
144✔
32
      ...options,
144✔
33
    };
144✔
34
  }
144✔
35

144✔
36
  /**
144✔
37
   * @param {User} user
144✔
38
   * @param {number} duration - Duration in seconds
144✔
39
   * @param {{ moderator: User }} options
144✔
40
   */
144✔
41
  async mute(user, duration, options) {
144✔
42
    const { db } = this.#uw;
1✔
43

1✔
44
    const expiresAt = new Date(Date.now() + duration * 1000);
1✔
45
    await db.insertInto('mutes')
1✔
46
      .values({
1✔
47
        userID: user.id,
1✔
48
        moderatorID: options.moderator.id,
1✔
49
        expiresAt,
1✔
50
      })
1✔
51
      .execute();
1✔
52

1✔
53
    this.#uw.publish('chat:mute', {
1✔
54
      moderatorID: options.moderator.id,
1✔
55
      userID: user.id,
1✔
56
      duration,
1✔
57
    });
1✔
58
  }
1✔
59

144✔
60
  /**
144✔
61
   * @param {User} user
144✔
62
   * @param {{ moderator: User }} options
144✔
63
   */
144✔
64
  async unmute(user, options) {
144✔
65
    const { db } = this.#uw;
×
66

×
67
    await db.updateTable('mutes')
×
68
      .where('userID', '=', user.id)
×
69
      .where('expiresAt', '>', now)
×
70
      .set({ expiresAt: now, updatedAt: now })
×
71
      .execute();
×
72

×
73
    this.#uw.publish('chat:unmute', {
×
74
      moderatorID: options.moderator.id,
×
75
      userID: user.id,
×
76
    });
×
77
  }
×
78

144✔
79
  /**
144✔
80
   * @param {User} user
144✔
81
   * @private
144✔
82
   */
144✔
83
  async isMuted(user) {
144✔
84
    const { db } = this.#uw;
6✔
85

6✔
86
    const mute = await db.selectFrom('mutes')
6✔
87
      .where('userID', '=', user.id)
6✔
88
      .where('expiresAt', '>', now)
6✔
89
      .selectAll()
6✔
90
      .executeTakeFirst();
6✔
91

6✔
92
    return mute ?? null;
6✔
93
  }
6✔
94

144✔
95
  /**
144✔
96
   * @param {string} message
144✔
97
   * @private
144✔
98
   */
144✔
99
  truncate(message) {
144✔
100
    return message.slice(0, this.#options.maxLength);
6✔
101
  }
6✔
102

144✔
103
  /**
144✔
104
   * @param {User} user
144✔
105
   * @param {string} message
144✔
106
   */
144✔
107
  async send(user, message) {
144✔
108
    if (await this.isMuted(user)) {
6!
109
      return;
×
110
    }
×
111

6✔
112
    this.#uw.publish('chat:message', {
6✔
113
      id: randomUUID(),
6✔
114
      userID: user.id,
6✔
115
      message: this.truncate(message),
6✔
116
      timestamp: Date.now(),
6✔
117
    });
6✔
118
  }
6✔
119

144✔
120
  /**
144✔
121
   * @param {{ id: string } | { userID: UserID } | {}} filter
144✔
122
   * @param {{ moderator: User }} options
144✔
123
   */
144✔
124
  delete(filter, options) {
144✔
125
    const deletion = {
6✔
126
      filter: typeof filter === 'string' ? { id: filter } : filter,
6!
127
      moderatorID: options.moderator.id,
6✔
128
    };
6✔
129

6✔
130
    this.#uw.publish('chat:delete', deletion);
6✔
131
  }
6✔
132
}
144✔
133

1✔
134
/**
1✔
135
 * @param {import('../Uwave.js').default} uw
1✔
136
 * @param {Partial<ChatOptions>} [options]
1✔
137
 */
1✔
138
async function chat(uw, options = {}) {
144✔
139
  uw.chat = new Chat(uw, options);
144✔
140
  uw.httpApi.use('/chat', routes());
144✔
141
}
144✔
142

1✔
143
export default chat;
1✔
144
export { Chat };
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