-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Expand file tree
/
Copy pathMessageCall.ts
More file actions
68 lines (60 loc) · 1.86 KB
/
MessageCall.ts
File metadata and controls
68 lines (60 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import type { APIMessageCall } from 'discord-api-types/v10';
import { Structure } from '../Structure.js';
import { dateToDiscordISOTimestamp } from '../utils/optimization.js';
import { kEndedTimestamp } from '../utils/symbols.js';
import type { Partialize } from '../utils/types.js';
export class MessageCall<Omitted extends keyof APIMessageCall | '' = 'ended_timestamp'> extends Structure<
APIMessageCall,
Omitted
> {
/**
* The template used for removing data from the raw data stored for each MessageCall.
*
* @remarks This template has defaults, if you want to remove additional data and keep the defaults,
* use `Object.defineProperties`. To override the defaults, set this value directly.
*/
public static override DataTemplate: Partial<APIMessageCall> = {
set ended_timestamp(_: string) {},
};
protected [kEndedTimestamp]: number | null = null;
/**
* @param data - The raw data received from the API for the message call
*/
public constructor(data: Partialize<APIMessageCall, Omitted>) {
super(data);
this.optimizeData(data);
}
/**
* {@inheritDoc Structure.optimizeData}
*
* @internal
*/
protected override optimizeData(data: Partial<APIMessageCall>) {
if (data.ended_timestamp) {
this[kEndedTimestamp] = Date.parse(data.ended_timestamp);
}
}
/**
* The timestamp this call ended at, or `null` if it didn't end yet
*/
public get endedTimestamp() {
return this[kEndedTimestamp];
}
/**
* The time the call ended at, or `null` if it didn't end yet
*/
public get endedAt() {
const endedTimestamp = this.endedTimestamp;
return endedTimestamp ? new Date(endedTimestamp) : null;
}
/**
* {@inheritDoc Structure.toJSON}
*/
public override toJSON() {
const clone = super.toJSON();
if (this[kEndedTimestamp]) {
clone.ended_timestamp = dateToDiscordISOTimestamp(new Date(this[kEndedTimestamp]));
}
return clone;
}
}