@sdeck/youtube 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1792 @@
1
+ // @bun
2
+ // src/actions.ts
3
+ import { setting as setting2 } from "@sdeck/plugin";
4
+
5
+ // src/api.ts
6
+ import { createHash, randomBytes } from "crypto";
7
+ import { OAuthError } from "@sdeck/plugin";
8
+ var SCOPES = ["https://www.googleapis.com/auth/youtube.force-ssl"];
9
+ var GOOGLE = {
10
+ authorize: "https://accounts.google.com/o/oauth2/v2/auth",
11
+ oauth: "https://oauth2.googleapis.com",
12
+ api: "https://www.googleapis.com/youtube/v3"
13
+ };
14
+
15
+ class SignedOut extends Error {
16
+ constructor(message = "Sign in to YouTube from the plugin's settings") {
17
+ super(message);
18
+ }
19
+ }
20
+
21
+ class YouTubeError extends Error {
22
+ status;
23
+ reason;
24
+ constructor(status, reason, message) {
25
+ super(message);
26
+ this.status = status;
27
+ this.reason = reason;
28
+ }
29
+ }
30
+
31
+ class QuotaError extends YouTubeError {
32
+ constructor(ownApp) {
33
+ super(403, "quotaExceeded", ownApp ? "your app has used up YouTube's limit for today" : "sdeck has used up YouTube's limit for today; an app of your own has a limit of its own");
34
+ }
35
+ }
36
+ var QUOTA = new Set(["quotaExceeded", "dailyLimitExceeded"]);
37
+ var MESSAGES = {
38
+ liveStreamingNotEnabled: "live streaming is not turned on for this channel (see YouTube Studio)",
39
+ redundantTransition: "YouTube is already doing that",
40
+ invalidTransition: "YouTube does not allow that at this point of the stream",
41
+ errorStreamInactive: "YouTube receives no video yet: start streaming in OBS or your encoder first",
42
+ liveChatDisabled: "chat is turned off for this stream",
43
+ liveChatEnded: "the chat of this stream has ended",
44
+ insufficientPermissions: "Sign in to YouTube again, and allow everything it asks for",
45
+ ACCESS_TOKEN_SCOPE_INSUFFICIENT: "Sign in to YouTube again, and allow everything it asks for",
46
+ accessNotConfigured: "turn on the YouTube Data API v3 for your app in the Google Cloud console"
47
+ };
48
+ var page = (message) => new Response(`<!doctype html><meta charset="utf-8"><title>sdeck</title><p>${message}</p>`, {
49
+ headers: { "content-type": "text/html; charset=utf-8" }
50
+ });
51
+
52
+ class YouTubeClient {
53
+ #options;
54
+ #endpoints;
55
+ #access;
56
+ #renewing;
57
+ #era = 0;
58
+ constructor(options) {
59
+ this.#options = options;
60
+ this.#endpoints = options.endpoints ?? GOOGLE;
61
+ }
62
+ get signedIn() {
63
+ return this.#options.tokens.get() !== undefined;
64
+ }
65
+ async signIn() {
66
+ const app = this.#options.app();
67
+ if (app)
68
+ return this.#signInWithOwnApp(app);
69
+ const { url, tokens } = await this.#options.broker.start();
70
+ let cancelled = false;
71
+ const done = tokens.then(async (tokens) => {
72
+ if (cancelled)
73
+ throw new Error("sign-in cancelled");
74
+ await this.#begin(tokens);
75
+ });
76
+ return {
77
+ url,
78
+ done,
79
+ cancel: () => {
80
+ cancelled = true;
81
+ }
82
+ };
83
+ }
84
+ #signInWithOwnApp(app, timeoutMs = 300000) {
85
+ const verifier = randomBytes(64).toString("base64url");
86
+ const state = randomBytes(16).toString("base64url");
87
+ let closed = false;
88
+ let finish = () => {};
89
+ const done = new Promise((resolve, reject) => {
90
+ finish = (error) => error ? reject(error) : resolve();
91
+ });
92
+ const close = (error) => {
93
+ if (closed)
94
+ return;
95
+ closed = true;
96
+ clearTimeout(timer);
97
+ setTimeout(() => server.stop(), 100);
98
+ finish(error);
99
+ };
100
+ const server = Bun.serve({
101
+ hostname: "127.0.0.1",
102
+ port: 0,
103
+ fetch: async (request) => {
104
+ const { pathname, searchParams } = new URL(request.url);
105
+ if (pathname !== "/")
106
+ return new Response("not found", { status: 404 });
107
+ if (closed || searchParams.get("state") !== state) {
108
+ return new Response("wrong state", { status: 400 });
109
+ }
110
+ const code = searchParams.get("code");
111
+ if (!code) {
112
+ const said = searchParams.get("error");
113
+ close(new Error(said === "access_denied" ? "YouTube was not allowed" : `Google: ${said}`));
114
+ return page("sdeck was not given access. You can close this tab.");
115
+ }
116
+ try {
117
+ await this.#begin(await this.#ask(app, {
118
+ grant_type: "authorization_code",
119
+ code,
120
+ redirect_uri: redirect,
121
+ code_verifier: verifier
122
+ }));
123
+ close();
124
+ return page("sdeck is connected to YouTube. You can close this tab.");
125
+ } catch (error) {
126
+ close(error);
127
+ return page("Signing in failed. See the plugin's settings in sdeck.");
128
+ }
129
+ }
130
+ });
131
+ const redirect = `http://127.0.0.1:${server.port}`;
132
+ const timer = setTimeout(() => close(new Error("signing in took too long")), timeoutMs);
133
+ const url = new URL(this.#endpoints.authorize);
134
+ url.search = new URLSearchParams({
135
+ client_id: app.clientId,
136
+ response_type: "code",
137
+ redirect_uri: redirect,
138
+ scope: SCOPES.join(" "),
139
+ state,
140
+ code_challenge_method: "S256",
141
+ code_challenge: createHash("sha256").update(verifier).digest("base64url"),
142
+ access_type: "offline",
143
+ prompt: "consent"
144
+ }).toString();
145
+ return { url: url.href, done, cancel: () => close(new Error("sign-in cancelled")) };
146
+ }
147
+ async signOut() {
148
+ const token = this.#options.tokens.get();
149
+ this.#forget();
150
+ await this.#options.tokens.set(undefined);
151
+ if (!token)
152
+ return;
153
+ await fetch(`${this.#endpoints.oauth}/revoke`, {
154
+ method: "POST",
155
+ body: new URLSearchParams({ token }),
156
+ signal: AbortSignal.timeout(1e4)
157
+ }).catch(() => {});
158
+ }
159
+ async request(method, path, query = {}, body) {
160
+ const url = new URL(`${this.#endpoints.api}${path}`);
161
+ for (const [key, value] of Object.entries(query))
162
+ url.searchParams.set(key, value);
163
+ for (let attempt = 0;; attempt++) {
164
+ const token = await this.#token();
165
+ const response = await fetch(url, {
166
+ method,
167
+ headers: {
168
+ authorization: `Bearer ${token}`,
169
+ ...body !== undefined && { "content-type": "application/json" }
170
+ },
171
+ ...body !== undefined && { body: JSON.stringify(body) },
172
+ signal: AbortSignal.timeout(15000)
173
+ });
174
+ const answer = await response.json().catch(() => {
175
+ return;
176
+ }) ?? {};
177
+ if (response.ok)
178
+ return answer;
179
+ if (response.status === 401 && attempt === 0) {
180
+ if (this.#access?.token === token)
181
+ this.#access = undefined;
182
+ continue;
183
+ }
184
+ const error = answer.error ?? {};
185
+ const reason = error.errors?.[0]?.reason ?? "";
186
+ if (QUOTA.has(reason))
187
+ throw new QuotaError(this.#options.app() !== undefined);
188
+ throw new YouTubeError(response.status, reason, MESSAGES[reason] ?? (error.message?.replace(/<[^>]*>/g, "") || `YouTube answered ${response.status}`));
189
+ }
190
+ }
191
+ async list(path, query) {
192
+ const { items } = await this.request("GET", path, query);
193
+ return Array.isArray(items) ? items : [];
194
+ }
195
+ #forget() {
196
+ this.#era++;
197
+ this.#access = undefined;
198
+ this.#renewing = undefined;
199
+ }
200
+ async#begin(tokens) {
201
+ if (!tokens.refreshToken)
202
+ throw new Error("Google gave no lasting access; sign in again");
203
+ this.#forget();
204
+ await this.#keep(tokens);
205
+ }
206
+ async#keep(tokens) {
207
+ if (tokens.refreshToken)
208
+ await this.#options.tokens.set(tokens.refreshToken);
209
+ this.#access = { token: tokens.accessToken, expires: tokens.expiresAt - 60000 };
210
+ return tokens.accessToken;
211
+ }
212
+ async#token() {
213
+ if (this.#access && Date.now() < this.#access.expires)
214
+ return this.#access.token;
215
+ if (!this.#renewing) {
216
+ const renewing = this.#renew().finally(() => {
217
+ if (this.#renewing === renewing)
218
+ this.#renewing = undefined;
219
+ });
220
+ this.#renewing = renewing;
221
+ }
222
+ return this.#renewing;
223
+ }
224
+ async#renew() {
225
+ const era = this.#era;
226
+ const refresh = this.#options.tokens.get();
227
+ if (!refresh)
228
+ throw new SignedOut;
229
+ const app = this.#options.app();
230
+ let tokens;
231
+ try {
232
+ tokens = app ? await this.#ask(app, { grant_type: "refresh_token", refresh_token: refresh }) : await this.#options.broker.refresh(refresh);
233
+ } catch (error) {
234
+ if (!(error instanceof OAuthError) || error.code !== "invalid_grant")
235
+ throw error;
236
+ if (era === this.#era) {
237
+ this.#forget();
238
+ await this.#options.tokens.set(undefined);
239
+ }
240
+ throw new SignedOut("The YouTube sign-in expired: sign in again");
241
+ }
242
+ if (era !== this.#era)
243
+ throw new SignedOut;
244
+ return this.#keep(tokens);
245
+ }
246
+ async#ask(app, fields) {
247
+ const response = await fetch(`${this.#endpoints.oauth}/token`, {
248
+ method: "POST",
249
+ body: new URLSearchParams({
250
+ ...fields,
251
+ client_id: app.clientId,
252
+ ...app.clientSecret && { client_secret: app.clientSecret }
253
+ }),
254
+ signal: AbortSignal.timeout(15000)
255
+ });
256
+ const body = await response.json().catch(() => ({}));
257
+ if (!response.ok || !body.access_token) {
258
+ if (body.error === "invalid_grant" || body.error === "unauthorized_client") {
259
+ throw new OAuthError("Google no longer accepts this sign-in", "invalid_grant");
260
+ }
261
+ if (body.error === "invalid_client") {
262
+ throw new Error("Google does not accept the client ID and secret of your app; check them");
263
+ }
264
+ throw new Error(`Google: ${body.error_description ?? body.error ?? response.status}`);
265
+ }
266
+ return {
267
+ accessToken: body.access_token,
268
+ expiresAt: Date.now() + (body.expires_in ?? 3600) * 1000,
269
+ ...body.refresh_token && { refreshToken: body.refresh_token }
270
+ };
271
+ }
272
+ }
273
+
274
+ // src/model.ts
275
+ var text = (value) => typeof value === "string" ? value : "";
276
+ var part = (value, name) => value?.[name];
277
+ var maybe = (value) => value === undefined || value === null || value === "" || !Number.isFinite(Number(value)) ? undefined : Number(value);
278
+ var count = (value) => maybe(value) ?? 0;
279
+ var OFFLINE = {
280
+ live: false,
281
+ id: "",
282
+ title: "",
283
+ chatId: "",
284
+ startedAt: 0,
285
+ viewers: 0,
286
+ likes: undefined,
287
+ views: 0
288
+ };
289
+ function parseStream(video) {
290
+ const details = part(video, "liveStreamingDetails");
291
+ if (!video || details?.actualEndTime)
292
+ return OFFLINE;
293
+ const statistics = part(video, "statistics");
294
+ return {
295
+ live: true,
296
+ id: text(video.id),
297
+ title: text(part(video, "snippet")?.title),
298
+ chatId: text(details?.activeLiveChatId),
299
+ startedAt: Date.parse(text(details?.actualStartTime)) || 0,
300
+ viewers: count(details?.concurrentViewers),
301
+ likes: maybe(statistics?.likeCount),
302
+ views: count(statistics?.viewCount)
303
+ };
304
+ }
305
+ function parseBroadcast(raw) {
306
+ const snippet = part(raw, "snippet");
307
+ const details = part(raw, "contentDetails");
308
+ return {
309
+ id: text(raw?.id),
310
+ title: text(snippet?.title),
311
+ status: text(part(raw, "status")?.lifeCycleStatus),
312
+ at: Date.parse(text(snippet?.actualStartTime) || text(snippet?.scheduledStartTime)) || 0,
313
+ streamId: text(details?.boundStreamId),
314
+ preview: part(details, "monitorStream")?.enableMonitorStream === true
315
+ };
316
+ }
317
+ var newestLive = (broadcasts) => broadcasts.filter((b) => b.status === "live").sort((a, b) => b.at - a.at)[0];
318
+ var HEALTH = { good: "Good", ok: "OK", bad: "Bad", noData: "No data" };
319
+ var SEVERITY = ["info", "warning", "error"];
320
+ var isActive = (stream) => part(stream, "status")?.streamStatus === "active";
321
+ function parseHealth(streams) {
322
+ const health = part(part(streams.find(isActive), "status"), "healthStatus");
323
+ if (!streams.some(isActive))
324
+ return { receiving: false, name: "Offline", problem: "" };
325
+ const issues = (Array.isArray(health?.configurationIssues) ? health.configurationIssues : []).map((issue) => ({
326
+ rank: SEVERITY.indexOf(text(issue?.severity)),
327
+ reason: text(issue?.reason) || text(issue?.description)
328
+ })).filter(({ rank }) => rank > 0).sort((a, b) => b.rank - a.rank);
329
+ return {
330
+ receiving: true,
331
+ name: HEALTH[text(health?.status)] ?? "No data",
332
+ problem: issues[0]?.reason ?? ""
333
+ };
334
+ }
335
+ function parseChannel(raw) {
336
+ const statistics = part(raw, "statistics");
337
+ return {
338
+ id: text(raw?.id),
339
+ name: text(part(raw, "snippet")?.title),
340
+ subscribers: count(statistics?.subscriberCount),
341
+ views: count(statistics?.viewCount),
342
+ videos: count(statistics?.videoCount),
343
+ uploads: text(part(part(raw, "contentDetails"), "relatedPlaylists")?.uploads)
344
+ };
345
+ }
346
+ function newestVideo(videos) {
347
+ const at = (video) => Date.parse(text(part(video, "snippet")?.publishedAt)) || 0;
348
+ const video = videos.filter((v) => part(v, "status")?.privacyStatus === "public" && part(v, "snippet")?.liveBroadcastContent === "none").sort((a, b) => at(b) - at(a))[0];
349
+ if (!video)
350
+ return;
351
+ const statistics = part(video, "statistics");
352
+ return {
353
+ id: text(video.id),
354
+ title: text(part(video, "snippet")?.title),
355
+ views: count(statistics?.viewCount),
356
+ likes: maybe(statistics?.likeCount),
357
+ comments: maybe(statistics?.commentCount)
358
+ };
359
+ }
360
+ function newAtTop(items, known) {
361
+ const end = items.findIndex((item) => known.has(item.id));
362
+ return items.slice(0, end < 0 ? items.length : end).reverse();
363
+ }
364
+ var parseSubscriber = (raw) => {
365
+ const who = part(raw, "subscriberSnippet");
366
+ return { id: text(who?.channelId), user: text(who?.title), channelId: text(who?.channelId) };
367
+ };
368
+ function parseComment(raw) {
369
+ const snippet = part(raw, "snippet");
370
+ const comment = part(part(snippet, "topLevelComment"), "snippet");
371
+ const id = text(raw?.id);
372
+ const videoId = text(snippet?.videoId);
373
+ return {
374
+ id,
375
+ user: text(comment?.authorDisplayName),
376
+ channelId: text(part(comment, "authorChannelId")?.value),
377
+ text: text(comment?.textOriginal) || text(comment?.textDisplay),
378
+ videoId,
379
+ url: `https://www.youtube.com/watch?v=${videoId}&lc=${id}`
380
+ };
381
+ }
382
+ function formatDuration(seconds) {
383
+ const s = Math.max(0, Math.floor(seconds));
384
+ const two = (n) => String(n).padStart(2, "0");
385
+ const hours = Math.floor(s / 3600);
386
+ const minutes = Math.floor(s % 3600 / 60);
387
+ return hours > 0 ? `${hours}:${two(minutes)}:${two(s % 60)}` : `${minutes}:${two(s % 60)}`;
388
+ }
389
+ var CHAPTER = /^(?:\d+:)?\d{1,2}:\d{2}\s/;
390
+ var chapterSeconds = (line) => (line.split(/\s/)[0] ?? "").split(":").reduce((sum, n) => sum * 60 + Number(n), 0);
391
+ function addChapter(description, line) {
392
+ const lines = description.split(`
393
+ `);
394
+ const last = lines.findLastIndex((l) => CHAPTER.test(l));
395
+ if (last < 0) {
396
+ const before = description.trimEnd();
397
+ return `${before}${before && `
398
+
399
+ `}0:00 Start
400
+ ${line}`;
401
+ }
402
+ const at = chapterSeconds(line);
403
+ const later = lines.findIndex((l) => CHAPTER.test(l) && chapterSeconds(l) > at);
404
+ return lines.toSpliced(later < 0 ? last + 1 : later, 0, line).join(`
405
+ `);
406
+ }
407
+ function removeChapter(description, line) {
408
+ const lines = description.split(`
409
+ `);
410
+ const at = lines.lastIndexOf(line);
411
+ if (at < 0)
412
+ return description;
413
+ const rest = lines.toSpliced(at, 1);
414
+ const others = rest.filter((l) => CHAPTER.test(l));
415
+ return others.length === 1 && others[0] === "0:00 Start" ? rest.filter((l) => l !== "0:00 Start").join(`
416
+ `).trimEnd() : rest.join(`
417
+ `);
418
+ }
419
+ var RANKS = ["everyone", "member", "moderator", "owner"];
420
+ var hasRole = (mine, wanted) => RANKS.indexOf(mine) >= RANKS.indexOf(wanted);
421
+ function commandWords(message, command) {
422
+ const wanted = command.trim().toLowerCase();
423
+ const said = message.trim();
424
+ if (!wanted || !said.toLowerCase().startsWith(wanted))
425
+ return;
426
+ const rest = said.slice(wanted.length);
427
+ return rest === "" || /^\s/.test(rest) ? rest.trim() : undefined;
428
+ }
429
+ function parsePoll(raw) {
430
+ const metadata = part(part(part(raw, "snippet"), "pollDetails"), "metadata");
431
+ const options = (Array.isArray(metadata?.options) ? metadata.options : []).map((o) => ({
432
+ text: text(o?.optionText),
433
+ votes: count(o?.tally)
434
+ }));
435
+ const most = Math.max(0, ...options.map((o) => o.votes));
436
+ const best = options.filter((o) => o.votes === most);
437
+ return {
438
+ id: text(raw?.id),
439
+ question: text(metadata?.questionText),
440
+ options,
441
+ votes: options.reduce((sum, o) => sum + o.votes, 0),
442
+ winner: most > 0 && best.length === 1 ? best[0]?.text ?? "" : ""
443
+ };
444
+ }
445
+ function person(raw) {
446
+ const who = part(raw, "authorDetails");
447
+ return {
448
+ user: text(who?.displayName),
449
+ channelId: text(who?.channelId),
450
+ messageId: text(raw?.id)
451
+ };
452
+ }
453
+ var details = (raw, name) => part(part(raw, "snippet"), name);
454
+ var money = (raw) => ({
455
+ amount: count(raw?.amountMicros) / 1e6,
456
+ currency: text(raw?.currency),
457
+ amountText: text(raw?.amountDisplayString)
458
+ });
459
+ var CHAT = {
460
+ textMessageEvent: (raw) => {
461
+ const who = part(raw, "authorDetails");
462
+ const role = who?.isChatOwner ? "owner" : who?.isChatModerator ? "moderator" : who?.isChatSponsor ? "member" : "everyone";
463
+ return { ...person(raw), message: text(details(raw, "textMessageDetails")?.messageText), role };
464
+ },
465
+ superChatEvent: (raw) => {
466
+ const chat = details(raw, "superChatDetails");
467
+ return { ...person(raw), ...money(chat), message: text(chat?.userComment), sticker: false };
468
+ },
469
+ superStickerEvent: (raw) => {
470
+ const sticker = details(raw, "superStickerDetails");
471
+ const message = text(part(sticker, "superStickerMetadata")?.altText);
472
+ return { ...person(raw), ...money(sticker), message, sticker: true };
473
+ },
474
+ newSponsorEvent: (raw) => {
475
+ const member = details(raw, "newSponsorDetails");
476
+ return {
477
+ ...person(raw),
478
+ level: text(member?.memberLevelName),
479
+ upgrade: member?.isUpgrade === true
480
+ };
481
+ },
482
+ memberMilestoneChatEvent: (raw) => {
483
+ const member = details(raw, "memberMilestoneChatDetails");
484
+ return {
485
+ ...person(raw),
486
+ level: text(member?.memberLevelName),
487
+ months: count(member?.memberMonth),
488
+ message: text(member?.userComment)
489
+ };
490
+ },
491
+ membershipGiftingEvent: (raw) => {
492
+ const gift = details(raw, "membershipGiftingDetails");
493
+ return {
494
+ ...person(raw),
495
+ total: count(gift?.giftMembershipsCount),
496
+ level: text(gift?.giftMembershipsLevelName)
497
+ };
498
+ },
499
+ giftEvent: (raw) => {
500
+ const gift = details(raw, "giftDetails");
501
+ return {
502
+ ...person(raw),
503
+ gift: text(gift?.giftName),
504
+ jewels: count(gift?.jewelsAmount),
505
+ combo: count(gift?.comboCount)
506
+ };
507
+ },
508
+ pollEvent: (raw) => {
509
+ const { question, winner, votes } = parsePoll(raw);
510
+ return {
511
+ question,
512
+ winner,
513
+ votes,
514
+ closed: details(raw, "pollDetails")?.status === "closed"
515
+ };
516
+ }
517
+ };
518
+
519
+ // src/chat.ts
520
+ var REMEMBERED = 5000;
521
+ var OVER = new Set(["liveChatEnded", "liveChatDisabled", "liveChatNotFound"]);
522
+ var QUOTA_PAUSE_MS = 15 * 60000;
523
+ var pause = (ms, signal) => new Promise((resolve) => {
524
+ if (signal.aborted)
525
+ return resolve();
526
+ const done = () => {
527
+ clearTimeout(timer);
528
+ signal.removeEventListener("abort", done);
529
+ resolve();
530
+ };
531
+ const timer = setTimeout(done, ms);
532
+ signal.addEventListener("abort", done, { once: true });
533
+ });
534
+ async function readChat(options) {
535
+ const { client, chatId, everyMs, onEvent, onError, signal, retryMs = 5000 } = options;
536
+ const seen = new Set;
537
+ let pageToken = "";
538
+ let first = true;
539
+ let failures = 0;
540
+ while (!signal.aborted) {
541
+ let waitMs;
542
+ try {
543
+ const answer = await client.request("GET", "/liveChat/messages", {
544
+ liveChatId: chatId,
545
+ part: "id,snippet,authorDetails",
546
+ maxResults: "2000",
547
+ ...pageToken && { pageToken }
548
+ });
549
+ if (signal.aborted)
550
+ return;
551
+ failures = 0;
552
+ for (const item of Array.isArray(answer.items) ? answer.items : []) {
553
+ const snippet = item.snippet;
554
+ const type = String(snippet?.type);
555
+ if (!Object.hasOwn(CHAT, type))
556
+ continue;
557
+ const gift = snippet?.giftDetails?.comboCount ?? "";
558
+ const poll = snippet?.pollDetails?.status ?? "";
559
+ const key = `${item.id}:${gift}:${poll}`;
560
+ if (seen.has(key))
561
+ continue;
562
+ seen.add(key);
563
+ if (seen.size > REMEMBERED)
564
+ seen.delete(seen.values().next().value);
565
+ if (!first)
566
+ onEvent({ type, item });
567
+ }
568
+ first = false;
569
+ if (typeof answer.nextPageToken === "string")
570
+ pageToken = answer.nextPageToken;
571
+ if (answer.offlineAt)
572
+ return;
573
+ waitMs = Math.max(everyMs(), Number(answer.pollingIntervalMillis) || 0);
574
+ } catch (error) {
575
+ if (signal.aborted)
576
+ return;
577
+ if (error instanceof YouTubeError && OVER.has(error.reason))
578
+ return;
579
+ onError(error);
580
+ if (error instanceof SignedOut)
581
+ return;
582
+ if (error instanceof YouTubeError && error.reason === "pageTokenInvalid") {
583
+ pageToken = "";
584
+ first = true;
585
+ }
586
+ waitMs = error instanceof QuotaError ? QUOTA_PAUSE_MS : Math.min(retryMs * 2 ** failures++, 60000);
587
+ }
588
+ await pause(waitMs, signal);
589
+ }
590
+ }
591
+
592
+ // src/looks.ts
593
+ import { iconLook } from "@sdeck/schema";
594
+ var category = "YouTube";
595
+ var slots = ["key", "sensor"];
596
+ var BACKGROUND = "#181818";
597
+ var RED = "#ff0033";
598
+ var CORAL = "#ff5c6c";
599
+ var MUTED = "#aaaaaa";
600
+ var key = (icon, caption = "") => iconLook({ icon, caption, background: BACKGROUND, color: CORAL });
601
+ var short = (path) => `{{${path} == null ? "" : ${path} >= 1000000 ? fmt(${path} / 1000000, 2) + "M" : ${path} >= 100000 ? fmt(${path} / 1000, 0) + "K" : fmt(${path}, 0, ",")}}`;
602
+
603
+ // src/plugin.ts
604
+ import { createPlugin, Permissions, Shared, setting } from "@sdeck/plugin";
605
+ import { z } from "zod";
606
+ var plugin = createPlugin({
607
+ id: "@sdeck/youtube",
608
+ name: "YouTube",
609
+ version: "1.0.1",
610
+ description: "Run your YouTube channel: go live, chat, polls, ads, markers and goals, with live values and triggers.",
611
+ permissions: [Permissions.network],
612
+ settings: {
613
+ clientId: setting.text("Client ID of your own app", {
614
+ description: "To use an app of your own instead of sdeck's, with a daily limit of its own. Sign in again after changing it.",
615
+ validate: z.string().trim().regex(/\.apps\.googleusercontent\.com$/, "should end in .apps.googleusercontent.com")
616
+ }),
617
+ clientSecret: setting.secret("Client secret of your own app"),
618
+ chatSeconds: setting.number("Seconds between looks at the chat", {
619
+ default: 10,
620
+ min: 3,
621
+ max: 120,
622
+ description: "For triggers. Each look costs 5 of the 10,000 units an app has a day: every 10 seconds is enough for 5\xBD hours, every 20 for 11."
623
+ })
624
+ }
625
+ });
626
+ var TOKEN = "refreshToken";
627
+ function running() {
628
+ if (!plugin.context)
629
+ throw new Error("the YouTube plugin is off");
630
+ return plugin.context;
631
+ }
632
+ var youtube = new YouTubeClient({
633
+ app: () => {
634
+ const { clientId = "", clientSecret = "" } = plugin.context?.settings() ?? {};
635
+ const id = clientId.trim();
636
+ return id ? { clientId: id, clientSecret: clientSecret.trim() } : undefined;
637
+ },
638
+ broker: {
639
+ start: () => running().oauth.start("youtube", { scopes: SCOPES }),
640
+ refresh: (token) => running().oauth.refresh("youtube", token)
641
+ },
642
+ tokens: {
643
+ get: () => plugin.context?.secrets.get(TOKEN),
644
+ set: async (token) => {
645
+ await plugin.context?.secrets.set(TOKEN, token);
646
+ }
647
+ }
648
+ });
649
+ var trouble = false;
650
+ function report(error) {
651
+ if (error) {
652
+ trouble = true;
653
+ plugin.context?.status(error.message, error instanceof SignedOut ? "info" : "error");
654
+ } else if (trouble) {
655
+ trouble = false;
656
+ plugin.context?.status("Signed in to YouTube", "ok");
657
+ }
658
+ }
659
+ var refreshers = new Set;
660
+ function polled(everyMs, readNow) {
661
+ let again = () => {};
662
+ const shared = new Shared((emit) => {
663
+ let stopped = false;
664
+ let timer;
665
+ let latest = 0;
666
+ const tick = async () => {
667
+ clearTimeout(timer);
668
+ const mine = ++latest;
669
+ let value;
670
+ let waitMs;
671
+ try {
672
+ value = await readNow();
673
+ if (stopped || mine !== latest)
674
+ return;
675
+ report();
676
+ } catch (error) {
677
+ if (stopped || mine !== latest)
678
+ return;
679
+ report(error);
680
+ if (error instanceof QuotaError)
681
+ waitMs = QUOTA_PAUSE_MS;
682
+ }
683
+ timer = setTimeout(tick, waitMs ?? everyMs(value));
684
+ emit(value);
685
+ };
686
+ const mine = () => void tick();
687
+ again = mine;
688
+ refreshers.add(mine);
689
+ mine();
690
+ return () => {
691
+ stopped = true;
692
+ clearTimeout(timer);
693
+ refreshers.delete(mine);
694
+ again = () => {};
695
+ };
696
+ });
697
+ return { shared, refresh: () => again() };
698
+ }
699
+ async function readStream(known = "") {
700
+ const read = async (id) => parseStream((await youtube.list("/videos", { part: "snippet,statistics,liveStreamingDetails", id }))[0]);
701
+ if (known) {
702
+ const stream = await read(known);
703
+ if (stream.live)
704
+ return stream;
705
+ }
706
+ const found = await youtube.list("/liveBroadcasts", {
707
+ part: "id,snippet,status",
708
+ broadcastStatus: "active",
709
+ broadcastType: "all",
710
+ maxResults: "50"
711
+ });
712
+ const live = newestLive(found.map(parseBroadcast));
713
+ return live ? read(live.id) : OFFLINE;
714
+ }
715
+ var stream = polled((now) => now?.live ? 30000 : 60000, () => readStream(stream.shared.last?.id));
716
+ async function liveStream() {
717
+ const known = stream.shared.last;
718
+ const now = known?.live ? known : await readStream();
719
+ if (!now.live)
720
+ throw new Error("this only works while you are live");
721
+ return now;
722
+ }
723
+ async function liveChat() {
724
+ const { chatId } = await liveStream();
725
+ if (!chatId)
726
+ throw new Error("chat is turned off for this stream");
727
+ return chatId;
728
+ }
729
+ async function readChannel() {
730
+ const [own] = await youtube.list("/channels", {
731
+ part: "snippet,statistics,contentDetails",
732
+ mine: "true"
733
+ });
734
+ if (!own)
735
+ throw new Error("this Google account has no YouTube channel");
736
+ return parseChannel(own);
737
+ }
738
+ var channel = polled(() => 5 * 60000, readChannel);
739
+ var readEncoders = () => youtube.list("/liveStreams", { part: "id,status", mine: "true", maxResults: "50" });
740
+ var health = polled(() => 30000, async () => parseHealth(await readEncoders()));
741
+ var ownChannel = async () => channel.shared.last ?? await readChannel();
742
+ var video = polled(() => 5 * 60000, async () => {
743
+ const { uploads } = await ownChannel();
744
+ const items = await youtube.list("/playlistItems", {
745
+ part: "contentDetails",
746
+ playlistId: uploads,
747
+ maxResults: "15"
748
+ });
749
+ const ids = items.map((item) => item.contentDetails?.videoId);
750
+ if (ids.length === 0)
751
+ return;
752
+ return newestVideo(await youtube.list("/videos", { part: "snippet,statistics,status", id: ids.join(",") }));
753
+ });
754
+ var subscribers = polled(() => 2 * 60000, async () => {
755
+ const found = await youtube.list("/subscriptions", {
756
+ part: "subscriberSnippet",
757
+ myRecentSubscribers: "true",
758
+ maxResults: "50"
759
+ });
760
+ return found.map(parseSubscriber).filter(({ id }) => id);
761
+ });
762
+ var comments = polled(() => 2 * 60000, async () => {
763
+ const { id } = await ownChannel();
764
+ const found = await youtube.list("/commentThreads", {
765
+ part: "snippet",
766
+ allThreadsRelatedToChannelId: id,
767
+ order: "time",
768
+ maxResults: "50"
769
+ });
770
+ return found.map(parseComment).filter(({ channelId }) => channelId !== id);
771
+ });
772
+ var restartChat = () => {};
773
+ var chat = new Shared((emit) => {
774
+ let reading;
775
+ const stopReading = () => {
776
+ reading?.stop.abort();
777
+ reading = undefined;
778
+ };
779
+ const follow = (now) => {
780
+ if (!now || now.chatId === (reading?.id ?? ""))
781
+ return;
782
+ stopReading();
783
+ if (!now.chatId)
784
+ return;
785
+ const stop = new AbortController;
786
+ reading = { id: now.chatId, stop };
787
+ readChat({
788
+ client: youtube,
789
+ chatId: now.chatId,
790
+ everyMs: () => (plugin.context?.settings().chatSeconds ?? 10) * 1000,
791
+ onEvent: emit,
792
+ onError: report,
793
+ signal: stop.signal
794
+ }).then(() => {
795
+ if (!stop.signal.aborted)
796
+ stream.refresh();
797
+ });
798
+ };
799
+ restartChat = stopReading;
800
+ const stopFollowing = stream.shared.listen(follow);
801
+ follow(stream.shared.last);
802
+ return () => {
803
+ stopFollowing();
804
+ stopReading();
805
+ restartChat = () => {};
806
+ };
807
+ });
808
+ var signingIn;
809
+ function startOver() {
810
+ restartChat();
811
+ for (const refresh of [...refreshers])
812
+ refresh();
813
+ }
814
+ var signIn = plugin.command({
815
+ id: "sign-in",
816
+ name: "Sign in",
817
+ description: "Opens Google in your browser to allow access.",
818
+ run: async (context) => {
819
+ signingIn?.cancel();
820
+ const started = await youtube.signIn();
821
+ signingIn = started;
822
+ context.status("Allow access in the browser", "info");
823
+ started.done.then(() => {
824
+ trouble = false;
825
+ context.status("Signed in to YouTube", "ok");
826
+ startOver();
827
+ }, (error) => {
828
+ if (signingIn === started)
829
+ context.status(error.message, "error");
830
+ });
831
+ return started.url;
832
+ }
833
+ });
834
+ var signOut = plugin.command({
835
+ id: "sign-out",
836
+ name: "Sign out",
837
+ run: async (context) => {
838
+ signingIn?.cancel();
839
+ signingIn = undefined;
840
+ await youtube.signOut();
841
+ startOver();
842
+ context.status("Signed out", "info");
843
+ }
844
+ });
845
+ var isSignedIn = () => youtube.signedIn;
846
+ function stopAll() {
847
+ signingIn?.cancel();
848
+ signingIn = undefined;
849
+ }
850
+
851
+ // src/state.ts
852
+ import { following } from "@sdeck/plugin";
853
+ var { boolean, number, string } = plugin.state;
854
+ var live = boolean("live", "Live", { start: following(stream.shared, (s) => s.live) });
855
+ var viewers = number("viewers", "Viewers", {
856
+ start: following(stream.shared, (s) => s.viewers)
857
+ });
858
+ var uptime = string("uptime", "Time live", {
859
+ description: "Such as 1:02:05; empty while offline.",
860
+ start: (set) => {
861
+ const update = () => {
862
+ const now = stream.shared.last;
863
+ set(now && (now.live ? formatDuration((Date.now() - now.startedAt) / 1000) : ""));
864
+ };
865
+ const stop = stream.shared.listen(update);
866
+ update();
867
+ const timer = setInterval(update, 1000);
868
+ return () => {
869
+ stop();
870
+ clearInterval(timer);
871
+ };
872
+ }
873
+ });
874
+ var title = string("title", "Stream title", {
875
+ description: "Empty while offline.",
876
+ start: following(stream.shared, (s) => s.title)
877
+ });
878
+ var likes = number("likes", "Likes of the stream", {
879
+ start: following(stream.shared, (s) => s.likes)
880
+ });
881
+ var views = number("views", "Views of the stream", {
882
+ description: "Everyone who watched so far.",
883
+ start: following(stream.shared, (s) => s.views)
884
+ });
885
+ var url = string("url", "Link to the stream", {
886
+ description: "Empty while offline.",
887
+ start: following(stream.shared, (s) => s.live ? `https://youtu.be/${s.id}` : "")
888
+ });
889
+ var healthName = string("health", "Stream health", {
890
+ description: "Good, OK, Bad or No data; Offline when YouTube receives no video.",
891
+ start: following(health.shared, (h) => h.name)
892
+ });
893
+ var healthProblem = string("healthProblem", "Stream problem", {
894
+ description: "The worst one YouTube sees, or empty.",
895
+ start: following(health.shared, (h) => h.problem)
896
+ });
897
+ var subscriberCount = number("subscribers", "Subscribers", {
898
+ description: "YouTube rounds it down to three digits.",
899
+ start: following(channel.shared, (c) => c.subscribers)
900
+ });
901
+ var channelViews = number("channelViews", "Views of the channel", {
902
+ start: following(channel.shared, (c) => c.views)
903
+ });
904
+ var channelVideos = number("videos", "Public videos", {
905
+ start: following(channel.shared, (c) => c.videos)
906
+ });
907
+ var latestSubscriber = string("latestSubscriber", "Newest subscriber", {
908
+ description: "Of those who show their subscriptions to everyone.",
909
+ start: following(subscribers.shared, (s) => s[0]?.user ?? "")
910
+ });
911
+ var videoTitle = string("videoTitle", "Newest video: title", {
912
+ start: following(video.shared, (v) => v.title)
913
+ });
914
+ var videoViews = number("videoViews", "Newest video: views", {
915
+ start: following(video.shared, (v) => v.views)
916
+ });
917
+ var videoLikes = number("videoLikes", "Newest video: likes", {
918
+ start: following(video.shared, (v) => v.likes)
919
+ });
920
+ var videoComments = number("videoComments", "Newest video: comments", {
921
+ start: following(video.shared, (v) => v.comments)
922
+ });
923
+ var state = [
924
+ live,
925
+ viewers,
926
+ uptime,
927
+ title,
928
+ likes,
929
+ views,
930
+ url,
931
+ healthName,
932
+ healthProblem,
933
+ subscriberCount,
934
+ channelViews,
935
+ channelVideos,
936
+ latestSubscriber,
937
+ videoTitle,
938
+ videoViews,
939
+ videoLikes,
940
+ videoComments
941
+ ];
942
+
943
+ // src/actions.ts
944
+ var atMost = (length) => (text) => [...text].length > length ? `cannot be longer than ${length} letters` : undefined;
945
+ var plain = (length) => (text) => /[<>]/.test(text) ? "cannot have < or > in it" : atMost(length)(text);
946
+ var caption = setting2.text("Caption", { appearance: true });
947
+ async function upcoming() {
948
+ const found = await youtube.list("/liveBroadcasts", {
949
+ part: "id,snippet,status,contentDetails",
950
+ broadcastStatus: "upcoming",
951
+ broadcastType: "all",
952
+ maxResults: "50"
953
+ });
954
+ return found.map(parseBroadcast).sort((a, b) => a.at - b.at);
955
+ }
956
+ var transition = (id, to) => youtube.request("POST", "/liveBroadcasts/transition", {
957
+ id,
958
+ broadcastStatus: to,
959
+ part: "id,status"
960
+ });
961
+ async function reaches(id, status, signal) {
962
+ for (let i = 0;i < 20; i++) {
963
+ const [now] = await youtube.list("/liveBroadcasts", { part: "id,status", id });
964
+ if (now && parseBroadcast(now).status === status)
965
+ return true;
966
+ await pause(3000, signal);
967
+ if (signal.aborted)
968
+ throw new Error("stopped");
969
+ }
970
+ return false;
971
+ }
972
+ var goLive = plugin.action({
973
+ id: "go-live",
974
+ name: "Go live",
975
+ description: "Starts a stream you set up in YouTube Studio, once your encoder sends video. Not needed for streams that start by themselves.",
976
+ category,
977
+ icon: "podcast",
978
+ slots,
979
+ settings: {
980
+ broadcast: setting2.text("Stream", {
981
+ source: "broadcasts",
982
+ placeholder: "The next one",
983
+ description: "Its title."
984
+ })
985
+ },
986
+ run: async ({ settings, signal }) => {
987
+ const wanted = settings.broadcast.trim().toLowerCase();
988
+ const planned = (await upcoming()).filter((b) => !wanted || b.title.toLowerCase() === wanted);
989
+ if (planned.length === 0) {
990
+ throw new Error(wanted ? `no stream called "${settings.broadcast}" is planned` : "no stream is planned: set one up in YouTube Studio first");
991
+ }
992
+ const receiving = new Set((await readEncoders()).filter(isActive).map(({ id }) => id));
993
+ const next = planned.find((b) => receiving.has(b.streamId));
994
+ if (!next) {
995
+ throw new Error("YouTube receives no video for it yet: start streaming in OBS or your encoder first");
996
+ }
997
+ if (next.preview && next.status !== "testing") {
998
+ if (next.status !== "testStarting")
999
+ await transition(next.id, "testing");
1000
+ if (!await reaches(next.id, "testing", signal)) {
1001
+ throw new Error("YouTube's preview did not start; try again");
1002
+ }
1003
+ }
1004
+ await transition(next.id, "live");
1005
+ await reaches(next.id, "live", signal);
1006
+ stream.refresh();
1007
+ return { result: `https://youtu.be/${next.id}`, label: `Go live: ${next.title}` };
1008
+ },
1009
+ look: () => key("lucide/podcast", `{{${live.key} ? "Live" : "Go live"}}`)
1010
+ });
1011
+ var endStream = plugin.action({
1012
+ id: "end-stream",
1013
+ name: "End the stream",
1014
+ description: "This cannot be undone: put it on a hold or a double press.",
1015
+ category,
1016
+ icon: "circle-stop",
1017
+ slots,
1018
+ run: async () => {
1019
+ const { id } = await liveStream();
1020
+ await transition(id, "complete");
1021
+ stream.refresh();
1022
+ return { label: "End the stream" };
1023
+ },
1024
+ look: () => key("lucide/circle-stop", "End")
1025
+ });
1026
+ var broadcasts = plugin.source("broadcasts", async () => {
1027
+ const titles = new Set((await upcoming()).map(({ title }) => title));
1028
+ return [...titles].map((title) => ({ value: title, label: title }));
1029
+ });
1030
+ var KEPT = {
1031
+ snippet: [
1032
+ "title",
1033
+ "description",
1034
+ "tags",
1035
+ "categoryId",
1036
+ "defaultLanguage",
1037
+ "defaultAudioLanguage"
1038
+ ],
1039
+ status: [
1040
+ "privacyStatus",
1041
+ "embeddable",
1042
+ "license",
1043
+ "publicStatsViewable",
1044
+ "selfDeclaredMadeForKids",
1045
+ "containsSyntheticMedia"
1046
+ ]
1047
+ };
1048
+ var editing = Promise.resolve();
1049
+ function edit(id, part, change) {
1050
+ const next = editing.catch(() => {}).then(async () => {
1051
+ const [video] = await youtube.list("/videos", { part, id });
1052
+ if (!video)
1053
+ throw new Error("the video is gone");
1054
+ const now = video[part];
1055
+ const same = Object.entries(now).filter(([name]) => KEPT[part].includes(name));
1056
+ const changed = { ...Object.fromEntries(same), ...change(now) };
1057
+ await youtube.request("PUT", "/videos", { part }, { id, [part]: changed });
1058
+ return now;
1059
+ });
1060
+ editing = next;
1061
+ return next;
1062
+ }
1063
+ var update = plugin.action({
1064
+ id: "update",
1065
+ name: "Change title or description",
1066
+ description: "Of the stream that is live.",
1067
+ category,
1068
+ icon: "pencil",
1069
+ slots,
1070
+ settings: {
1071
+ title: setting2.text("Title", { placeholder: "Leave it as it is", validate: plain(100) }),
1072
+ description: setting2.text("Description", {
1073
+ placeholder: "Leave it as it is",
1074
+ multiline: true,
1075
+ validate: plain(5000)
1076
+ }),
1077
+ caption
1078
+ },
1079
+ run: async ({ settings }) => {
1080
+ const title = settings.title.trim();
1081
+ const description = settings.description.trim();
1082
+ if (!title && !description)
1083
+ throw new Error("enter a title or a description");
1084
+ const { id } = await liveStream();
1085
+ const set = async (to) => {
1086
+ const before = await edit(id, "snippet", () => ({
1087
+ ...title && { title: to.title ?? "" },
1088
+ ...description && { description: to.description ?? "" }
1089
+ }));
1090
+ stream.refresh();
1091
+ return before;
1092
+ };
1093
+ const before = await set({ title, description });
1094
+ return { label: title || "Description", undo: () => set(before) };
1095
+ },
1096
+ look: (s) => key("lucide/pencil", s.caption)
1097
+ });
1098
+ var PRIVACY = { public: "Public", unlisted: "Unlisted", private: "Private" };
1099
+ var PRIVACY_ICONS = { public: "globe", unlisted: "link", private: "lock" };
1100
+ var privacy = plugin.action({
1101
+ id: "privacy",
1102
+ name: "Who can watch",
1103
+ description: "Makes the stream that is live public, unlisted or private.",
1104
+ category,
1105
+ icon: "globe",
1106
+ slots,
1107
+ settings: { to: setting2.select("Make it", PRIVACY) },
1108
+ run: async ({ settings }) => {
1109
+ const { id } = await liveStream();
1110
+ const set = (privacyStatus) => edit(id, "status", () => ({ privacyStatus }));
1111
+ const { privacyStatus } = await set(settings.to);
1112
+ const label = `${PRIVACY[settings.to]} stream`;
1113
+ if (!privacyStatus || privacyStatus === settings.to)
1114
+ return { label };
1115
+ return { label, undo: () => set(privacyStatus) };
1116
+ },
1117
+ look: (s) => key(`lucide/${PRIVACY_ICONS[s.to]}`, PRIVACY[s.to])
1118
+ });
1119
+ var marker = plugin.action({
1120
+ id: "marker",
1121
+ name: "Mark this moment",
1122
+ description: "Adds the time to the stream's description, where YouTube makes a chapter of it. Its result is the time.",
1123
+ category,
1124
+ icon: "bookmark",
1125
+ slots,
1126
+ settings: {
1127
+ text: setting2.text("Name", { default: "Highlight", required: true, validate: plain(100) }),
1128
+ back: setting2.number("Seconds ago", {
1129
+ default: 0,
1130
+ min: 0,
1131
+ max: 600,
1132
+ description: "For what you only know was good once it is over."
1133
+ })
1134
+ },
1135
+ run: async ({ settings }) => {
1136
+ const { id, startedAt } = await liveStream();
1137
+ const time = formatDuration(Math.max(1, (Date.now() - startedAt) / 1000 - settings.back));
1138
+ const line = `${time} ${settings.text.trim().replace(/\s+/g, " ")}`;
1139
+ await edit(id, "snippet", ({ description = "" }) => {
1140
+ const longer = addChapter(description, line);
1141
+ if ([...longer].length > 5000)
1142
+ throw new Error("the stream's description is full");
1143
+ return { description: longer };
1144
+ });
1145
+ const undo = () => edit(id, "snippet", ({ description = "" }) => ({
1146
+ description: removeChapter(description, line)
1147
+ }));
1148
+ return { result: time, label: `Mark ${time}`, undo };
1149
+ },
1150
+ look: () => key("lucide/bookmark")
1151
+ });
1152
+ var ad = plugin.action({
1153
+ id: "ad",
1154
+ name: "Play an ad",
1155
+ description: "Your channel and the stream have to be monetized.",
1156
+ category,
1157
+ icon: "badge-dollar-sign",
1158
+ slots,
1159
+ settings: {
1160
+ length: setting2.select("Length", [
1161
+ { value: "30", label: "30 seconds" },
1162
+ { value: "60", label: "1 minute" },
1163
+ { value: "90", label: "1\xBD minutes" },
1164
+ { value: "120", label: "2 minutes" },
1165
+ { value: "180", label: "3 minutes" }
1166
+ ])
1167
+ },
1168
+ run: async ({ settings }) => {
1169
+ const { id } = await liveStream();
1170
+ const body = { cueType: "cueTypeAd", durationSecs: Number(settings.length) };
1171
+ await youtube.request("POST", "/liveBroadcasts/cuepoint", { id }, body);
1172
+ return { label: `Ad, ${settings.length} s` };
1173
+ },
1174
+ look: (s) => key("lucide/badge-dollar-sign", `${s.length} s`)
1175
+ });
1176
+ async function post(chatId, snippet) {
1177
+ const { id } = await youtube.request("POST", "/liveChat/messages", { part: "snippet" }, { snippet: { liveChatId: chatId, ...snippet } });
1178
+ return String(id ?? "");
1179
+ }
1180
+ var say = (chatId, messageText) => post(chatId, { type: "textMessageEvent", textMessageDetails: { messageText } });
1181
+ var deleteMessage = (id) => youtube.request("DELETE", "/liveChat/messages", { id });
1182
+ var message = plugin.action({
1183
+ id: "message",
1184
+ name: "Send a chat message",
1185
+ category,
1186
+ icon: "message-square",
1187
+ slots,
1188
+ settings: {
1189
+ text: setting2.text("Message", { multiline: true, required: true, validate: atMost(200) }),
1190
+ caption
1191
+ },
1192
+ run: async ({ settings }) => {
1193
+ const id = await say(await liveChat(), settings.text.trim());
1194
+ return { label: "Chat message", ...id && { undo: () => deleteMessage(id) } };
1195
+ },
1196
+ look: (s) => key("lucide/message-square", s.caption)
1197
+ });
1198
+ var removeMessage = plugin.action({
1199
+ id: "delete-message",
1200
+ name: "Delete a chat message",
1201
+ description: "For a workflow that a chat message starts.",
1202
+ category,
1203
+ icon: "message-square-x",
1204
+ slots,
1205
+ settings: {
1206
+ message: setting2.text("Message ID", { default: "{{event.messageId}}", required: true })
1207
+ },
1208
+ run: async ({ settings }) => {
1209
+ await deleteMessage(settings.message.trim());
1210
+ return { label: "Delete message" };
1211
+ },
1212
+ look: () => key("lucide/message-square-x")
1213
+ });
1214
+ var block = plugin.action({
1215
+ id: "block",
1216
+ name: "Time out or hide someone",
1217
+ description: "For a workflow that a chat message starts. Hiding can be undone, a timeout ends by itself.",
1218
+ category,
1219
+ icon: "user-x",
1220
+ slots,
1221
+ settings: {
1222
+ channel: setting2.text("Their channel ID", {
1223
+ default: "{{event.channelId}}",
1224
+ required: true
1225
+ }),
1226
+ how: setting2.select("What to do", {
1227
+ temporary: "Time out",
1228
+ permanent: "Hide from the channel"
1229
+ }),
1230
+ seconds: setting2.number("Seconds", {
1231
+ default: 300,
1232
+ min: 1,
1233
+ max: 86400,
1234
+ visibleIf: { how: "temporary" }
1235
+ })
1236
+ },
1237
+ run: async ({ settings }) => {
1238
+ const { how, seconds } = settings;
1239
+ const channelId = settings.channel.trim();
1240
+ if (!/^UC[\w-]{22}$/.test(channelId)) {
1241
+ throw new Error("a channel ID starts with UC and has 24 letters");
1242
+ }
1243
+ const snippet = {
1244
+ liveChatId: await liveChat(),
1245
+ type: how,
1246
+ bannedUserDetails: { channelId },
1247
+ ...how === "temporary" && { banDurationSeconds: seconds }
1248
+ };
1249
+ const { id } = await youtube.request("POST", "/liveChat/bans", { part: "snippet" }, { snippet });
1250
+ if (how === "temporary")
1251
+ return { label: `Timeout, ${seconds} s` };
1252
+ const undo = () => youtube.request("DELETE", "/liveChat/bans", { id: String(id) });
1253
+ return { label: "Hide someone", ...id !== undefined && { undo } };
1254
+ },
1255
+ look: (s) => key(s.how === "temporary" ? "lucide/timer" : "lucide/user-x")
1256
+ });
1257
+ var answer = (label, required = false) => setting2.text(label, { required, validate: atMost(35) });
1258
+ var closePoll = async (id) => parsePoll(await youtube.request("POST", "/liveChat/messages/transition", {
1259
+ id,
1260
+ status: "closed",
1261
+ part: "id,snippet"
1262
+ }));
1263
+ var startPoll = plugin.action({
1264
+ id: "poll",
1265
+ name: "Start a poll",
1266
+ description: "In the chat of your stream. Only one can run at a time.",
1267
+ category,
1268
+ icon: "chart-bar",
1269
+ slots,
1270
+ settings: {
1271
+ question: setting2.text("Question", { required: true, validate: atMost(100) }),
1272
+ first: answer("Answer 1", true),
1273
+ second: answer("Answer 2", true),
1274
+ third: answer("Answer 3"),
1275
+ fourth: answer("Answer 4"),
1276
+ caption
1277
+ },
1278
+ run: async ({ settings }) => {
1279
+ const { first, second, third, fourth } = settings;
1280
+ const questionText = settings.question.trim();
1281
+ const options = [first, second, third, fourth].map((text) => ({ optionText: text.trim() })).filter(({ optionText }) => optionText);
1282
+ const id = await post(await liveChat(), {
1283
+ type: "pollEvent",
1284
+ pollDetails: { metadata: { questionText, options } }
1285
+ });
1286
+ return { label: `Poll: ${questionText}`, ...id && { undo: () => closePoll(id) } };
1287
+ },
1288
+ look: (s) => key("lucide/chart-bar", s.caption)
1289
+ });
1290
+ var endPoll = plugin.action({
1291
+ id: "end-poll",
1292
+ name: "End the poll",
1293
+ description: "Its result is the answer that won, or nothing for a draw.",
1294
+ category,
1295
+ icon: "circle-check-big",
1296
+ slots,
1297
+ settings: { tell: setting2.boolean("Write the winner in chat") },
1298
+ run: async ({ settings }) => {
1299
+ const chatId = await liveChat();
1300
+ const { activePollItem } = await youtube.request("GET", "/liveChat/messages", {
1301
+ liveChatId: chatId,
1302
+ part: "id,snippet",
1303
+ maxResults: "200"
1304
+ });
1305
+ const { id } = parsePoll(activePollItem);
1306
+ if (!id)
1307
+ throw new Error("no poll is running");
1308
+ const { winner, question, votes } = await closePoll(id);
1309
+ if (settings.tell && winner) {
1310
+ await say(chatId, `${question} ${winner} (${votes} ${votes === 1 ? "vote" : "votes"})`);
1311
+ }
1312
+ return { result: winner, label: winner ? `Poll: ${winner}` : "End the poll" };
1313
+ },
1314
+ look: () => key("lucide/circle-check-big", "End poll")
1315
+ });
1316
+ var controls = [
1317
+ goLive,
1318
+ endStream,
1319
+ marker,
1320
+ message,
1321
+ startPoll,
1322
+ endPoll,
1323
+ ad,
1324
+ update,
1325
+ privacy,
1326
+ block,
1327
+ removeMessage
1328
+ ];
1329
+
1330
+ // src/displays.ts
1331
+ import { setting as setting3 } from "@sdeck/plugin";
1332
+ import {
1333
+ captionLayer,
1334
+ iconLayer,
1335
+ iconSize,
1336
+ meterLayer,
1337
+ rectLayer,
1338
+ surface,
1339
+ textLayer
1340
+ } from "@sdeck/schema";
1341
+ var slots2 = ["key", "window"];
1342
+ var LIVE = live.key;
1343
+ var OFF = `!${LIVE}`;
1344
+ function statusWindow() {
1345
+ const pill = { x: 4, y: 14, width: 19, height: 36 };
1346
+ const subscribers = subscriberCount.key;
1347
+ const known = `${OFF} && ${subscribers} != null`;
1348
+ return {
1349
+ background: surface(BACKGROUND),
1350
+ layers: [
1351
+ rectLayer("badge", { frame: pill, fill: RED, radius: 6, visible: LIVE }),
1352
+ textLayer("live", "LIVE", { size: 13, frame: pill, visible: LIVE }),
1353
+ iconLayer("eye", "lucide/eye", {
1354
+ color: CORAL,
1355
+ frame: { x: 27, y: 15, width: 9, height: 34 },
1356
+ visible: LIVE
1357
+ }),
1358
+ textLayer("viewers", short(viewers.key), {
1359
+ size: 21,
1360
+ align: "left",
1361
+ frame: { x: 37.5, y: 10, width: 32, height: 44 },
1362
+ visible: LIVE
1363
+ }),
1364
+ textLayer("uptime", uptime.template, {
1365
+ size: 15,
1366
+ color: MUTED,
1367
+ align: "right",
1368
+ frame: { x: 69, y: 10, width: 27, height: 44 },
1369
+ visible: LIVE
1370
+ }),
1371
+ textLayer("title", title.template, {
1372
+ size: 13,
1373
+ color: MUTED,
1374
+ align: "left",
1375
+ frame: { x: 4, y: 58, width: 92, height: 32 },
1376
+ visible: LIVE
1377
+ }),
1378
+ iconLayer("logo", "si/SiYoutube", {
1379
+ color: RED,
1380
+ frame: { x: 19, y: 18, width: 17, height: 64 },
1381
+ visible: OFF
1382
+ }),
1383
+ textLayer("offline", "Offline", {
1384
+ size: 20,
1385
+ align: "left",
1386
+ frame: { x: 41, y: 12, width: 55, height: 44 },
1387
+ visible: known
1388
+ }),
1389
+ textLayer("offline-alone", "Offline", {
1390
+ size: 20,
1391
+ align: "left",
1392
+ frame: { x: 41, y: 20, width: 55, height: 60 },
1393
+ visible: `${OFF} && ${subscribers} == null`
1394
+ }),
1395
+ textLayer("subscribers", `${short(subscribers)} subscribers`, {
1396
+ size: 13,
1397
+ color: MUTED,
1398
+ align: "left",
1399
+ frame: { x: 41, y: 54, width: 55, height: 32 },
1400
+ visible: known
1401
+ })
1402
+ ]
1403
+ };
1404
+ }
1405
+ var status = plugin.action({
1406
+ id: "status",
1407
+ name: "Stream status",
1408
+ description: "Whether you are live, with viewers and the time since it started.",
1409
+ category,
1410
+ icon: "radio",
1411
+ slots: slots2,
1412
+ display: true,
1413
+ look: (_, slot) => {
1414
+ if (slot === "window")
1415
+ return statusWindow();
1416
+ const pill = { x: 22, y: 13, width: 56, height: 22 };
1417
+ return {
1418
+ background: surface(BACKGROUND),
1419
+ layers: [
1420
+ rectLayer("badge", { frame: pill, fill: RED, radius: 6, visible: LIVE }),
1421
+ textLayer("live", "LIVE", { size: 13, frame: pill, visible: LIVE }),
1422
+ textLayer("viewers", short(viewers.key), {
1423
+ size: 25,
1424
+ frame: { x: 0, y: 38, width: 100, height: 30 },
1425
+ visible: LIVE
1426
+ }),
1427
+ textLayer("uptime", uptime.template, {
1428
+ size: 13,
1429
+ color: MUTED,
1430
+ frame: { x: 0, y: 69, width: 100, height: 20 },
1431
+ visible: LIVE
1432
+ }),
1433
+ iconLayer("logo", "si/SiYoutube", { color: MUTED, size: iconSize(true), visible: OFF }),
1434
+ captionLayer("offline", "Offline", { color: MUTED, visible: OFF })
1435
+ ]
1436
+ };
1437
+ }
1438
+ });
1439
+ var goal = setting3.number("Goal", {
1440
+ default: 0,
1441
+ min: 0,
1442
+ description: "Shows a bar that fills up. 0 for none.",
1443
+ appearance: true
1444
+ });
1445
+ function countLook(slot, options) {
1446
+ const { icon, path, unit, goal } = options;
1447
+ const count = short(path);
1448
+ const wide = slot === "window";
1449
+ const row = wide ? { row: "line" } : {};
1450
+ return {
1451
+ background: surface(BACKGROUND),
1452
+ layers: [
1453
+ iconLayer("icon", icon, {
1454
+ color: CORAL,
1455
+ size: wide ? goal > 0 ? 40 : 50 : goal > 0 ? 38 : 44,
1456
+ ...row
1457
+ }),
1458
+ textLayer("label", count, { size: wide ? goal > 0 ? 20 : 26 : 18, ...row }),
1459
+ ...wide ? [textLayer("unit", unit, { color: MUTED, size: 14, ...row })] : [],
1460
+ ...goal > 0 ? [
1461
+ meterLayer("goal", `${path} == null ? 0 : min(100, 100 * ${path} / ${goal})`, {
1462
+ color: RED
1463
+ })
1464
+ ] : []
1465
+ ]
1466
+ };
1467
+ }
1468
+ var subscribers2 = plugin.action({
1469
+ id: "subscribers",
1470
+ name: "Subscribers",
1471
+ description: "With a bar towards a goal. YouTube rounds the number down to three digits.",
1472
+ category,
1473
+ icon: "users",
1474
+ slots: slots2,
1475
+ display: true,
1476
+ settings: { goal },
1477
+ look: (s, slot) => countLook(slot, {
1478
+ icon: "lucide/users",
1479
+ path: subscriberCount.key,
1480
+ unit: "subscribers",
1481
+ goal: s.goal
1482
+ })
1483
+ });
1484
+ var likes2 = plugin.action({
1485
+ id: "likes",
1486
+ name: "Likes",
1487
+ description: "Of the stream that is live, with a bar towards a goal.",
1488
+ category,
1489
+ icon: "thumbs-up",
1490
+ slots: slots2,
1491
+ display: true,
1492
+ settings: { goal },
1493
+ look: (s, slot) => countLook(slot, {
1494
+ icon: "lucide/thumbs-up",
1495
+ path: likes.key,
1496
+ unit: "likes",
1497
+ goal: s.goal
1498
+ })
1499
+ });
1500
+ var VIDEO = {
1501
+ views: { icon: "lucide/square-play", path: videoViews.key },
1502
+ likes: { icon: "lucide/thumbs-up", path: videoLikes.key },
1503
+ comments: { icon: "lucide/message-circle", path: videoComments.key }
1504
+ };
1505
+ var newestVideo2 = plugin.action({
1506
+ id: "video",
1507
+ name: "Newest video",
1508
+ description: "How the last video you published does: its views, likes or comments.",
1509
+ category,
1510
+ icon: "square-play",
1511
+ slots: slots2,
1512
+ display: true,
1513
+ settings: {
1514
+ show: setting3.select("Show", { views: "Views", likes: "Likes", comments: "Comments" }),
1515
+ goal
1516
+ },
1517
+ look: (s, slot) => countLook(slot, { ...VIDEO[s.show], unit: s.show, goal: s.goal })
1518
+ });
1519
+ var streamHealth = plugin.action({
1520
+ id: "health",
1521
+ name: "Stream health",
1522
+ description: "How well YouTube receives your video. The window also shows what is wrong.",
1523
+ category,
1524
+ icon: "activity",
1525
+ slots: slots2,
1526
+ display: true,
1527
+ look: (_, slot) => {
1528
+ const name = healthName.key;
1529
+ const problem = `!!${healthProblem.key}`;
1530
+ const good = `(${name} == "Good" || ${name} == "OK")`;
1531
+ const bad = `${name} == "Bad"`;
1532
+ const colors = [
1533
+ ["good", "#2ba640", good],
1534
+ ["bad", RED, bad],
1535
+ ["none", MUTED, `!${good} && !(${bad})`]
1536
+ ];
1537
+ const wide = slot === "window";
1538
+ return {
1539
+ background: surface(BACKGROUND),
1540
+ layers: [
1541
+ ...colors.map(([id, color, visible]) => iconLayer(id, "lucide/activity", {
1542
+ color,
1543
+ visible,
1544
+ size: iconSize(true),
1545
+ ...wide && { frame: { x: 5, y: 20, width: 17, height: 60 } }
1546
+ })),
1547
+ ...wide ? [
1548
+ textLayer("label", healthName.template, {
1549
+ size: 22,
1550
+ align: "left",
1551
+ frame: { x: 28, y: 20, width: 68, height: 60 },
1552
+ visible: `!${problem}`
1553
+ }),
1554
+ textLayer("label-small", healthName.template, {
1555
+ size: 18,
1556
+ align: "left",
1557
+ frame: { x: 28, y: 10, width: 68, height: 42 },
1558
+ visible: problem
1559
+ }),
1560
+ textLayer("problem", healthProblem.template, {
1561
+ size: 12,
1562
+ color: MUTED,
1563
+ align: "left",
1564
+ frame: { x: 28, y: 54, width: 68, height: 34 },
1565
+ visible: problem
1566
+ })
1567
+ ] : [captionLayer("label", healthName.template)]
1568
+ ]
1569
+ };
1570
+ }
1571
+ });
1572
+ var displays = [status, subscribers2, likes2, newestVideo2, streamHealth];
1573
+
1574
+ // src/triggers.ts
1575
+ import { setting as setting4 } from "@sdeck/plugin";
1576
+ var on = (type, then) => chat.listen((event) => {
1577
+ if (event.type === type)
1578
+ then(CHAT[type](event.item));
1579
+ });
1580
+ function onLive(wanted, then) {
1581
+ let before = stream.shared.last;
1582
+ return stream.shared.listen((now) => {
1583
+ if (!now)
1584
+ return;
1585
+ const was = before;
1586
+ before = now;
1587
+ if (!was || was.live === now.live || now.live !== wanted)
1588
+ return;
1589
+ const { title, id } = now.live ? now : was;
1590
+ then({ title, url: `https://youtu.be/${id}` });
1591
+ });
1592
+ }
1593
+ function onNew(shared, then) {
1594
+ let known = shared.last && new Set(shared.last.map(({ id }) => id));
1595
+ return shared.listen((items) => {
1596
+ if (!items)
1597
+ return;
1598
+ const fresh = known ? newAtTop(items, known) : [];
1599
+ known ??= new Set;
1600
+ for (const { id } of items)
1601
+ known.add(id);
1602
+ for (const item of fresh)
1603
+ then(item);
1604
+ });
1605
+ }
1606
+ var online = plugin.trigger({
1607
+ id: "online",
1608
+ name: "When you go live",
1609
+ description: "Within a minute. Gives event.title and url.",
1610
+ subscribe: ({ fire }) => onLive(true, fire)
1611
+ });
1612
+ var offline = plugin.trigger({
1613
+ id: "offline",
1614
+ name: "When your stream ends",
1615
+ description: "Gives event.title and url.",
1616
+ subscribe: ({ fire }) => onLive(false, fire)
1617
+ });
1618
+ var subscribe = plugin.trigger({
1619
+ id: "subscribe",
1620
+ name: "When someone subscribes",
1621
+ description: "Within a few minutes, and only for people who show their subscriptions to everyone. Gives event.user and channelId.",
1622
+ subscribe: ({ fire }) => onNew(subscribers.shared, ({ user, channelId }) => fire({ user, channelId }))
1623
+ });
1624
+ var comment = plugin.trigger({
1625
+ id: "comment",
1626
+ name: "When someone comments on a video",
1627
+ description: "Within a few minutes. Gives event.user, text and url.",
1628
+ subscribe: ({ fire }) => onNew(comments.shared, fire)
1629
+ });
1630
+ var superChat = plugin.trigger({
1631
+ id: "super-chat",
1632
+ name: "When someone sends a Super Chat",
1633
+ description: "Gives event.user, amount, currency, amountText (such as $5.00) and message.",
1634
+ settings: {
1635
+ min: setting4.number("At least this much", {
1636
+ default: 0,
1637
+ min: 0,
1638
+ description: "In the currency it was sent in."
1639
+ }),
1640
+ stickers: setting4.boolean("Also for Super Stickers", { default: true })
1641
+ },
1642
+ subscribe: ({ settings, fire }) => {
1643
+ const check = (event) => {
1644
+ if (event.amount >= settings.min && (settings.stickers || !event.sticker))
1645
+ fire(event);
1646
+ };
1647
+ const stops = [on("superChatEvent", check), on("superStickerEvent", check)];
1648
+ return () => {
1649
+ for (const stop of stops)
1650
+ stop();
1651
+ };
1652
+ }
1653
+ });
1654
+ var gift = plugin.trigger({
1655
+ id: "gift",
1656
+ name: "When someone sends a gift with Jewels",
1657
+ description: "Gives event.user, gift, jewels and combo.",
1658
+ settings: { min: setting4.number("At least this many Jewels", { default: 1, min: 0 }) },
1659
+ subscribe: ({ settings, fire }) => on("giftEvent", (event) => {
1660
+ if (event.jewels >= settings.min)
1661
+ fire(event);
1662
+ })
1663
+ });
1664
+ var member = plugin.trigger({
1665
+ id: "member",
1666
+ name: "When someone becomes a member",
1667
+ description: "While you are live. Gives event.user, level and upgrade.",
1668
+ settings: { upgrades: setting4.boolean("Also when one changes to a higher level") },
1669
+ subscribe: ({ settings, fire }) => on("newSponsorEvent", (event) => {
1670
+ if (settings.upgrades || !event.upgrade)
1671
+ fire(event);
1672
+ })
1673
+ });
1674
+ var milestone = plugin.trigger({
1675
+ id: "milestone",
1676
+ name: "When a member shares a milestone",
1677
+ description: "Gives event.user, months, level and message.",
1678
+ subscribe: ({ fire }) => on("memberMilestoneChatEvent", fire)
1679
+ });
1680
+ var memberGift = plugin.trigger({
1681
+ id: "member-gift",
1682
+ name: "When someone gives memberships",
1683
+ description: "Gives event.user, total and level.",
1684
+ settings: { min: setting4.number("At least this many", { default: 1, min: 1 }) },
1685
+ subscribe: ({ settings, fire }) => on("membershipGiftingEvent", (event) => {
1686
+ if (event.total >= settings.min)
1687
+ fire(event);
1688
+ })
1689
+ });
1690
+ var pollEnded = plugin.trigger({
1691
+ id: "poll-ended",
1692
+ name: "When a chat poll ends",
1693
+ description: "Gives event.question, winner (empty for a draw) and votes.",
1694
+ subscribe: ({ fire }) => on("pollEvent", ({ closed, ...poll }) => {
1695
+ if (closed)
1696
+ fire(poll);
1697
+ })
1698
+ });
1699
+ var command = plugin.trigger({
1700
+ id: "command",
1701
+ name: "When someone writes a chat command",
1702
+ description: "Gives event.user, channelId, messageId, message, and text: what follows the command.",
1703
+ settings: {
1704
+ command: setting4.text("Command", { default: "!deck", required: true }),
1705
+ who: setting4.select("Who can use it", {
1706
+ everyone: "Everyone",
1707
+ member: "Members and above",
1708
+ moderator: "Moderators and you",
1709
+ owner: "Only you"
1710
+ }, { default: "moderator" })
1711
+ },
1712
+ subscribe: ({ settings, fire }) => on("textMessageEvent", (event) => {
1713
+ const text = commandWords(event.message, settings.command);
1714
+ if (text !== undefined && hasRole(event.role, settings.who))
1715
+ fire({ ...event, text });
1716
+ })
1717
+ });
1718
+ var triggers = [
1719
+ online,
1720
+ offline,
1721
+ subscribe,
1722
+ comment,
1723
+ superChat,
1724
+ gift,
1725
+ member,
1726
+ milestone,
1727
+ memberGift,
1728
+ pollEnded,
1729
+ command
1730
+ ];
1731
+
1732
+ // src/index.tsx
1733
+ var src_default = plugin.define({
1734
+ actions: [...displays, ...controls],
1735
+ state,
1736
+ triggers,
1737
+ sources: [broadcasts],
1738
+ commands: [signIn, signOut],
1739
+ activate: (context) => {
1740
+ if (!isSignedIn())
1741
+ context.status("Sign in to YouTube", "info");
1742
+ return stopAll;
1743
+ },
1744
+ onboarding: {
1745
+ steps: [
1746
+ {
1747
+ id: "app",
1748
+ title: "Use an app of your own",
1749
+ optional: true,
1750
+ body: [
1751
+ "YouTube limits what each app may do in a day, and everyone who signs in through sdeck's shares one limit. For long streams, or chat triggers, make an app of your own. It is free.",
1752
+ "In the Google Cloud console, create a project and enable the **YouTube Data API v3** for it. Set up the consent screen for **External** users and press **Publish app**: while an app is only being tested, Google ends your sign-in every week.",
1753
+ "Then create a client of the type **Desktop app**, and copy its **Client ID** and **Client secret** here.",
1754
+ "When you sign in, Google warns that it has not verified the app. It is your own: press **Advanced**, and go on."
1755
+ ].join(`
1756
+
1757
+ `),
1758
+ link: {
1759
+ label: "Google Cloud console",
1760
+ url: "https://console.cloud.google.com/apis/library/youtube.googleapis.com"
1761
+ },
1762
+ settings: ["clientId", "clientSecret"]
1763
+ },
1764
+ {
1765
+ id: "sign-in",
1766
+ title: "Sign in",
1767
+ body: "Allow access in the browser that opens, with the channel you stream from.",
1768
+ command: "sign-in",
1769
+ done: isSignedIn
1770
+ }
1771
+ ],
1772
+ starterPage: {
1773
+ name: "YouTube",
1774
+ keys: {
1775
+ 0: { action: "status" },
1776
+ 1: { action: "go-live" },
1777
+ 2: { action: "marker", settings: { back: 15 } },
1778
+ 3: { action: "health" },
1779
+ 4: { action: "subscribers" },
1780
+ 5: { action: "likes" },
1781
+ 6: { action: "video" },
1782
+ 7: { action: "end-poll" }
1783
+ },
1784
+ window: { action: "status" }
1785
+ }
1786
+ }
1787
+ });
1788
+ export {
1789
+ src_default as default
1790
+ };
1791
+
1792
+ //# debugId=574EAE774C93ACFE64756E2164756E21