|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -const { Events } = require('../../../util/Constants'); |
4 | | -const textBasedChannelTypes = ['dm', 'text', 'news']; |
5 | | - |
6 | | -module.exports = (client, { d: data }) => { |
7 | | - const channel = client.channels.cache.get(data.channel_id); |
8 | | - const user = client.users.cache.get(data.user_id); |
9 | | - const timestamp = new Date(data.timestamp * 1000); |
10 | | - |
11 | | - if (channel && user) { |
12 | | - if (!textBasedChannelTypes.includes(channel.type)) { |
13 | | - client.emit(Events.WARN, `Discord sent a typing packet to a ${channel.type} channel ${channel.id}`); |
14 | | - return; |
15 | | - } |
16 | | - |
17 | | - if (channel._typing.has(user.id)) { |
18 | | - const typing = channel._typing.get(user.id); |
19 | | - |
20 | | - typing.lastTimestamp = timestamp; |
21 | | - typing.elapsedTime = Date.now() - typing.since; |
22 | | - client.clearTimeout(typing.timeout); |
23 | | - typing.timeout = tooLate(channel, user); |
24 | | - } else { |
25 | | - const since = new Date(); |
26 | | - const lastTimestamp = new Date(); |
27 | | - channel._typing.set(user.id, { |
28 | | - user, |
29 | | - since, |
30 | | - lastTimestamp, |
31 | | - elapsedTime: Date.now() - since, |
32 | | - timeout: tooLate(channel, user), |
33 | | - }); |
34 | | - |
35 | | - /** |
36 | | - * Emitted whenever a user starts typing in a channel. |
37 | | - * @event Client#typingStart |
38 | | - * @param {Channel} channel The channel the user started typing in |
39 | | - * @param {User} user The user that started typing |
40 | | - */ |
41 | | - client.emit(Events.TYPING_START, channel, user); |
42 | | - } |
43 | | - } |
| 3 | +module.exports = (client, packet) => { |
| 4 | + client.actions.TypingStart.handle(packet.d); |
44 | 5 | }; |
45 | | - |
46 | | -function tooLate(channel, user) { |
47 | | - return channel.client.setTimeout(() => { |
48 | | - channel._typing.delete(user.id); |
49 | | - }, 10000); |
50 | | -} |
0 commit comments