/
EventSubChannelChatMessageEvent.ts
228 lines (197 loc) · 6.28 KB
/
EventSubChannelChatMessageEvent.ts
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import { Enumerable } from '@d-fischer/shared-utils';
import { type ApiClient, type HelixUser } from '@twurple/api';
import { checkRelationAssertion, DataObject, rawDataSymbol, rtfm } from '@twurple/common';
import { type EventSubChatMessagePart } from './common/EventSubChatMessage.external';
import { type EventSubChannelChatMessageEventData } from './EventSubChannelChatMessageEvent.external';
/**
* An EventSub event representing a notification being sent to a channel's chat.
*/
@rtfm<EventSubChannelChatMessageEvent>('eventsub-base', 'EventSubChannelChatMessageEvent', 'broadcasterId')
export class EventSubChannelChatMessageEvent extends DataObject<EventSubChannelChatMessageEventData> {
/** @internal */ @Enumerable(false) protected readonly _client: ApiClient;
/** @internal */
constructor(data: EventSubChannelChatMessageEventData, client: ApiClient) {
super(data);
this._client = client;
}
/**
* The type of the message.
*/
get messageType(): string {
return this[rawDataSymbol].message_type;
}
/**
* The ID of the broadcaster.
*/
get broadcasterId(): string {
return this[rawDataSymbol].broadcaster_user_id;
}
/**
* The name of the broadcaster.
*/
get broadcasterName(): string {
return this[rawDataSymbol].broadcaster_user_login;
}
/**
* The display name of the broadcaster.
*/
get broadcasterDisplayName(): string {
return this[rawDataSymbol].broadcaster_user_name;
}
/**
* Gets more information about the broadcaster.
*/
async getBroadcaster(): Promise<HelixUser> {
return checkRelationAssertion(await this._client.users.getUserById(this[rawDataSymbol].broadcaster_user_id));
}
/**
* The ID of the chatter.
*/
get chatterId(): string {
return this[rawDataSymbol].chatter_user_id;
}
/**
* The name of the chatter.
*/
get chatterName(): string {
return this[rawDataSymbol].chatter_user_login;
}
/**
* The display name of the chatter.
*/
get chatterDisplayName(): string {
return this[rawDataSymbol].chatter_user_name;
}
/**
* Gets more information about the chatter.
*/
async getChatter(): Promise<HelixUser> {
return checkRelationAssertion(await this._client.users.getUserById(this[rawDataSymbol].chatter_user_id));
}
/**
* The color of the chatter, or null if they didn't choose a color.
*/
get color(): string | null {
return this[rawDataSymbol].color || null;
}
/**
* The badges the chatter has.
*
* The returned object contains the badge names as keys and the badge versions as the respective values.
*/
get badges(): Record<string, string> {
return Object.fromEntries(this[rawDataSymbol].badges.map(badge => [badge.set_id, badge.id]));
}
/**
* Checks whether the chatter has the specified badge.
*
* @param name The name of the badge to check.
*/
hasBadge(name: string): boolean {
return this[rawDataSymbol].badges.some(badge => badge.set_id === name);
}
/**
* Gets the badge info for a specified badge, or null if the badge does not exist.
*
* @param name The name of the badge to get info for.
*/
getBadgeInfo(name: string): string | null {
return this[rawDataSymbol].badges.find(badge => badge.set_id === name)?.info ?? null;
}
/**
* The ID of the notification message.
*/
get messageId(): string {
return this[rawDataSymbol].message_id;
}
/**
* The text that was sent with the notification, e.g. the resub message or announcement text.
*/
get messageText(): string {
return this[rawDataSymbol].message.text;
}
/**
* The text that was sent with the notification, structured into pre-parsed parts.
*/
get messageParts(): EventSubChatMessagePart[] {
return this[rawDataSymbol].message.fragments;
}
/**
* The ID of the message that this message is a reply to, or `null` if it's not a reply.
*/
get parentMessageId(): string | null {
return this[rawDataSymbol].reply?.parent_message_id ?? null;
}
/**
* The text of the message that this message is a reply to, or `null` if it's not a reply.
*/
get parentMessageText(): string | null {
return this[rawDataSymbol].reply?.parent_message_body ?? null;
}
/**
* The ID of the user that wrote the message that this message is a reply to, or `null` if it's not a reply.
*/
get parentMessageUserId(): string | null {
return this[rawDataSymbol].reply?.parent_user_id ?? null;
}
/**
* The name of the user that wrote the message that this message is a reply to, or `null` if it's not a reply.
*/
get parentMessageUserName(): string | null {
return this[rawDataSymbol].reply?.parent_user_login ?? null;
}
/**
* The display name of the user that wrote the message that this message is a reply to, or `null` if it's not a reply.
*/
get parentMessageUserDisplayName(): string | null {
return this[rawDataSymbol].reply?.parent_user_name ?? null;
}
/**
* The ID of the message that is the thread starter of this message, or `null` if it's not a reply.
*/
get threadMessageId(): string | null {
return this[rawDataSymbol].reply?.thread_message_id ?? null;
}
/**
* The ID of the user that wrote the thread starter message of this message, or `null` if it's not a reply.
*/
get threadMessageUserId(): string | null {
return this[rawDataSymbol].reply?.thread_user_id ?? null;
}
/**
* The name of the user that wrote the thread starter message of this message, or `null` if it's not a reply.
*/
get threadMessageUserName(): string | null {
return this[rawDataSymbol].reply?.thread_user_login ?? null;
}
/**
* The display name of the user that wrote the thread starter message of this message, or `null` if it's not a reply.
*/
get threadMessageUserDisplayName(): string | null {
return this[rawDataSymbol].reply?.thread_user_name ?? null;
}
/**
* Whether the message is a cheer.
*/
get isCheer(): boolean {
return Boolean(this[rawDataSymbol].cheer);
}
/**
* The number of bits cheered with this message.
*/
get bits(): number {
return this[rawDataSymbol].cheer?.bits ?? 0;
}
/**
* Whether the message represents a redemption of a custom channel points reward.
*/
get isRedemption(): boolean {
return Boolean(this[rawDataSymbol].channel_points_custom_reward_id);
}
/**
* The ID of the redeemed reward, or `null` if the message does not represent a redemption.
*/
get rewardId(): string | null {
return this[rawDataSymbol].channel_points_custom_reward_id ?? null;
}
}