@sdeck/twitch 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/README.md +27 -2
- package/dist/actions.d.ts +4 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/api.d.ts +60 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/events.d.ts +22 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1391 -0
- package/dist/index.js.map +17 -0
- package/dist/model.d.ts +117 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/plugin.d.ts +44 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/state.d.ts +18 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/triggers.d.ts +2 -0
- package/dist/triggers.d.ts.map +1 -0
- package/package.json +64 -4
- package/src/actions.ts +597 -0
- package/src/api.ts +307 -0
- package/src/events.ts +170 -0
- package/src/index.tsx +52 -0
- package/src/model.ts +195 -0
- package/src/plugin.ts +193 -0
- package/src/state.ts +75 -0
- package/src/triggers.ts +140 -0
package/src/actions.ts
ADDED
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
import { setting } from "@sdeck/plugin";
|
|
2
|
+
import {
|
|
3
|
+
captionLayer,
|
|
4
|
+
iconLayer,
|
|
5
|
+
iconLook,
|
|
6
|
+
iconSize,
|
|
7
|
+
type Look,
|
|
8
|
+
rectLayer,
|
|
9
|
+
surface,
|
|
10
|
+
switchLook,
|
|
11
|
+
textLayer,
|
|
12
|
+
} from "@sdeck/schema";
|
|
13
|
+
import { SignedOut, TwitchError, type User } from "./api.ts";
|
|
14
|
+
import { CHAT_MODES, type ChatMode, channelLogin, chatModeBody } from "./model.ts";
|
|
15
|
+
import {
|
|
16
|
+
ads,
|
|
17
|
+
change,
|
|
18
|
+
channel,
|
|
19
|
+
chat,
|
|
20
|
+
plugin,
|
|
21
|
+
readChannel,
|
|
22
|
+
readChat,
|
|
23
|
+
readShield,
|
|
24
|
+
shield,
|
|
25
|
+
twitch,
|
|
26
|
+
} from "./plugin.ts";
|
|
27
|
+
import * as values from "./state.ts";
|
|
28
|
+
|
|
29
|
+
const category = "Twitch";
|
|
30
|
+
const slots = ["key", "sensor"] as const;
|
|
31
|
+
|
|
32
|
+
// -- Looks --------------------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
const BACKGROUND = "#18181b";
|
|
35
|
+
const PURPLE = "#9146ff";
|
|
36
|
+
/** Purple that stands out on a dark key. */
|
|
37
|
+
const LILAC = "#bf94ff";
|
|
38
|
+
const RED = "#eb0400";
|
|
39
|
+
const MUTED = "#adadb8";
|
|
40
|
+
|
|
41
|
+
const key = (icon: string, caption = "") =>
|
|
42
|
+
iconLook({ icon, caption, background: BACKGROUND, color: LILAC });
|
|
43
|
+
|
|
44
|
+
// -- Switches -----------------------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
const operation = setting.select("When pressed", {
|
|
47
|
+
toggle: "Turn on or off",
|
|
48
|
+
on: "Turn on",
|
|
49
|
+
off: "Turn off",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/** Switches something, and tells how to put it back if that changed it. */
|
|
53
|
+
async function flip(
|
|
54
|
+
name: string,
|
|
55
|
+
wanted: "toggle" | "on" | "off",
|
|
56
|
+
before: boolean,
|
|
57
|
+
set: (on: boolean) => Promise<unknown>,
|
|
58
|
+
undo: () => Promise<unknown> = () => set(before),
|
|
59
|
+
) {
|
|
60
|
+
const on = wanted === "toggle" ? !before : wanted === "on";
|
|
61
|
+
const outcome = { result: on, label: `${name} ${on ? "on" : "off"}` };
|
|
62
|
+
if (on === before) return outcome;
|
|
63
|
+
await set(on);
|
|
64
|
+
return { ...outcome, undo };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const MODE_ICONS: Record<ChatMode, string> = {
|
|
68
|
+
emote_mode: "lucide/smile",
|
|
69
|
+
subscriber_mode: "lucide/star",
|
|
70
|
+
follower_mode: "lucide/heart",
|
|
71
|
+
slow_mode: "lucide/snail",
|
|
72
|
+
unique_chat_mode: "lucide/fingerprint",
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const chatMode = plugin.action({
|
|
76
|
+
id: "chat-mode",
|
|
77
|
+
name: "Chat mode",
|
|
78
|
+
description: "Emotes, subscribers or followers only, slow mode, or no repeated messages.",
|
|
79
|
+
category,
|
|
80
|
+
icon: "messages-square",
|
|
81
|
+
slots,
|
|
82
|
+
settings: {
|
|
83
|
+
mode: setting.select("Mode", CHAT_MODES),
|
|
84
|
+
seconds: setting.number("Seconds between messages", {
|
|
85
|
+
default: 30,
|
|
86
|
+
min: 3,
|
|
87
|
+
max: 120,
|
|
88
|
+
visibleIf: { mode: "slow_mode" },
|
|
89
|
+
}),
|
|
90
|
+
minutes: setting.number("Minutes of following first", {
|
|
91
|
+
default: 0,
|
|
92
|
+
min: 0,
|
|
93
|
+
max: 129_600,
|
|
94
|
+
visibleIf: { mode: "follower_mode" },
|
|
95
|
+
}),
|
|
96
|
+
operation,
|
|
97
|
+
},
|
|
98
|
+
run: async ({ settings }) => {
|
|
99
|
+
const { mode } = settings;
|
|
100
|
+
const before = await readChat(await twitch.user());
|
|
101
|
+
const set = async (on: boolean, slowSeconds: number, followMinutes: number) => {
|
|
102
|
+
const body = chatModeBody(mode, on, { slowSeconds, followMinutes });
|
|
103
|
+
await change("PATCH", "/chat/settings", body);
|
|
104
|
+
chat.refresh();
|
|
105
|
+
};
|
|
106
|
+
return flip(
|
|
107
|
+
CHAT_MODES[mode],
|
|
108
|
+
settings.operation,
|
|
109
|
+
before[mode],
|
|
110
|
+
(on) => set(on, settings.seconds, settings.minutes),
|
|
111
|
+
// With the times it had.
|
|
112
|
+
() => set(before[mode], before.slowSeconds, before.followMinutes),
|
|
113
|
+
);
|
|
114
|
+
},
|
|
115
|
+
look: (s) =>
|
|
116
|
+
switchLook({
|
|
117
|
+
icon: MODE_ICONS[s.mode],
|
|
118
|
+
on: values.chatModes[s.mode].key,
|
|
119
|
+
color: PURPLE,
|
|
120
|
+
background: BACKGROUND,
|
|
121
|
+
}),
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const shieldMode = plugin.action({
|
|
125
|
+
id: "shield",
|
|
126
|
+
name: "Shield Mode",
|
|
127
|
+
description: "Twitch's panic switch against harassment, with the limits you set up there.",
|
|
128
|
+
category,
|
|
129
|
+
icon: "shield",
|
|
130
|
+
slots,
|
|
131
|
+
settings: { operation },
|
|
132
|
+
run: async ({ settings }) => {
|
|
133
|
+
const before = await readShield(await twitch.user());
|
|
134
|
+
return flip("Shield Mode", settings.operation, before, async (on) => {
|
|
135
|
+
await change("PUT", "/moderation/shield_mode", { is_active: on });
|
|
136
|
+
shield.refresh();
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
look: () =>
|
|
140
|
+
switchLook({
|
|
141
|
+
icon: "lucide/shield",
|
|
142
|
+
on: values.shieldOn.key,
|
|
143
|
+
color: RED,
|
|
144
|
+
background: BACKGROUND,
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// -- Chat ---------------------------------------------------------------------------------------
|
|
149
|
+
|
|
150
|
+
const atMost = (length: number) => (text: string) =>
|
|
151
|
+
[...text].length > length ? `cannot be longer than ${length} letters` : undefined;
|
|
152
|
+
|
|
153
|
+
const chatText = setting.text("Message", {
|
|
154
|
+
multiline: true,
|
|
155
|
+
required: true,
|
|
156
|
+
validate: atMost(500),
|
|
157
|
+
});
|
|
158
|
+
const caption = setting.text("Caption", { appearance: true });
|
|
159
|
+
|
|
160
|
+
const message = plugin.action({
|
|
161
|
+
id: "message",
|
|
162
|
+
name: "Send a chat message",
|
|
163
|
+
category,
|
|
164
|
+
icon: "message-square",
|
|
165
|
+
slots,
|
|
166
|
+
settings: { text: chatText, caption },
|
|
167
|
+
run: async ({ settings }) => {
|
|
168
|
+
const { id } = await twitch.user();
|
|
169
|
+
const [sent] = await twitch.request<{
|
|
170
|
+
is_sent?: boolean;
|
|
171
|
+
drop_reason?: { message?: string } | null;
|
|
172
|
+
}>(
|
|
173
|
+
"POST",
|
|
174
|
+
"/chat/messages",
|
|
175
|
+
{},
|
|
176
|
+
{ broadcaster_id: id, sender_id: id, message: settings.text.trim() },
|
|
177
|
+
);
|
|
178
|
+
if (!sent?.is_sent) throw new Error(sent?.drop_reason?.message ?? "Twitch did not send it");
|
|
179
|
+
return { label: "Chat message" };
|
|
180
|
+
},
|
|
181
|
+
look: (s) => key("lucide/message-square", s.caption),
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const announcement = plugin.action({
|
|
185
|
+
id: "announcement",
|
|
186
|
+
name: "Announce in chat",
|
|
187
|
+
description: "A highlighted message.",
|
|
188
|
+
category,
|
|
189
|
+
icon: "megaphone",
|
|
190
|
+
slots,
|
|
191
|
+
settings: {
|
|
192
|
+
text: chatText,
|
|
193
|
+
color: setting.select("Colour", {
|
|
194
|
+
primary: "The channel's",
|
|
195
|
+
blue: "Blue",
|
|
196
|
+
green: "Green",
|
|
197
|
+
orange: "Orange",
|
|
198
|
+
purple: "Purple",
|
|
199
|
+
}),
|
|
200
|
+
caption,
|
|
201
|
+
},
|
|
202
|
+
run: async ({ settings }) => {
|
|
203
|
+
const body = { message: settings.text.trim(), color: settings.color };
|
|
204
|
+
await change("POST", "/chat/announcements", body);
|
|
205
|
+
return { label: "Announcement" };
|
|
206
|
+
},
|
|
207
|
+
look: (s) => key("lucide/megaphone", s.caption),
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const clearChat = plugin.action({
|
|
211
|
+
id: "clear-chat",
|
|
212
|
+
name: "Clear chat",
|
|
213
|
+
description: "Removes every message. This cannot be undone.",
|
|
214
|
+
category,
|
|
215
|
+
icon: "eraser",
|
|
216
|
+
slots,
|
|
217
|
+
run: async () => {
|
|
218
|
+
await change("DELETE", "/moderation/chat");
|
|
219
|
+
return { label: "Clear chat" };
|
|
220
|
+
},
|
|
221
|
+
look: () => key("lucide/eraser"),
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// -- The stream ---------------------------------------------------------------------------------
|
|
225
|
+
|
|
226
|
+
/** Says in words what Twitch calls "not found". */
|
|
227
|
+
async function whileLive<T>(request: Promise<T>): Promise<T> {
|
|
228
|
+
try {
|
|
229
|
+
return await request;
|
|
230
|
+
} catch (error) {
|
|
231
|
+
if (error instanceof TwitchError && error.status === 404) {
|
|
232
|
+
throw new Error("this only works while you are live");
|
|
233
|
+
}
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const clip = plugin.action({
|
|
239
|
+
id: "clip",
|
|
240
|
+
name: "Create a clip",
|
|
241
|
+
description: "Of the last moments of your stream. Its result is the link to edit it.",
|
|
242
|
+
category,
|
|
243
|
+
icon: "clapperboard",
|
|
244
|
+
slots,
|
|
245
|
+
run: async () => {
|
|
246
|
+
const { id } = await twitch.user();
|
|
247
|
+
const [made] = await whileLive(
|
|
248
|
+
twitch.request<{ edit_url?: string }>("POST", "/clips", { broadcaster_id: id }),
|
|
249
|
+
);
|
|
250
|
+
return { result: made?.edit_url, label: "Clip" };
|
|
251
|
+
},
|
|
252
|
+
look: () => key("lucide/clapperboard"),
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
const marker = plugin.action({
|
|
256
|
+
id: "marker",
|
|
257
|
+
name: "Add a stream marker",
|
|
258
|
+
description: "Marks this moment, for editing the recording later.",
|
|
259
|
+
category,
|
|
260
|
+
icon: "bookmark",
|
|
261
|
+
slots,
|
|
262
|
+
settings: {
|
|
263
|
+
text: setting.text("Description", { placeholder: "Optional", validate: atMost(140) }),
|
|
264
|
+
},
|
|
265
|
+
run: async ({ settings }) => {
|
|
266
|
+
const { id } = await twitch.user();
|
|
267
|
+
const description = settings.text.trim();
|
|
268
|
+
const body = { user_id: id, ...(description && { description }) };
|
|
269
|
+
const [made] = await whileLive(
|
|
270
|
+
twitch.request<{ position_seconds?: number }>("POST", "/streams/markers", {}, body),
|
|
271
|
+
);
|
|
272
|
+
return { result: made?.position_seconds, label: "Stream marker" };
|
|
273
|
+
},
|
|
274
|
+
look: () => key("lucide/bookmark"),
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
const ad = plugin.action({
|
|
278
|
+
id: "ad",
|
|
279
|
+
name: "Play an ad",
|
|
280
|
+
category,
|
|
281
|
+
icon: "badge-dollar-sign",
|
|
282
|
+
slots,
|
|
283
|
+
settings: {
|
|
284
|
+
// A list: an object would put numbers in its own order.
|
|
285
|
+
length: setting.select("Length", [
|
|
286
|
+
{ value: "30", label: "30 seconds" },
|
|
287
|
+
{ value: "60", label: "1 minute" },
|
|
288
|
+
{ value: "90", label: "1½ minutes" },
|
|
289
|
+
{ value: "120", label: "2 minutes" },
|
|
290
|
+
{ value: "150", label: "2½ minutes" },
|
|
291
|
+
{ value: "180", label: "3 minutes" },
|
|
292
|
+
]),
|
|
293
|
+
},
|
|
294
|
+
run: async ({ settings }) => {
|
|
295
|
+
const { id } = await twitch.user();
|
|
296
|
+
const body = { broadcaster_id: id, length: Number(settings.length) };
|
|
297
|
+
await twitch.request("POST", "/channels/commercial", {}, body);
|
|
298
|
+
ads.refresh();
|
|
299
|
+
return { label: `Ad, ${settings.length} s` };
|
|
300
|
+
},
|
|
301
|
+
look: (s) => key("lucide/badge-dollar-sign", `${s.length} s`),
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const snoozeAd = plugin.action({
|
|
305
|
+
id: "snooze-ad",
|
|
306
|
+
name: "Snooze the next ad",
|
|
307
|
+
description: "Puts it off by 5 minutes. Shows how long it is until the next one.",
|
|
308
|
+
category,
|
|
309
|
+
icon: "alarm-clock",
|
|
310
|
+
slots,
|
|
311
|
+
run: async () => {
|
|
312
|
+
const { id } = await twitch.user();
|
|
313
|
+
await twitch.request("POST", "/channels/ads/schedule/snooze", { broadcaster_id: id });
|
|
314
|
+
ads.refresh();
|
|
315
|
+
return { label: "Snooze ad" };
|
|
316
|
+
},
|
|
317
|
+
look: () => key("lucide/alarm-clock", values.nextAd.template),
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
async function categoryId(name: string): Promise<string> {
|
|
321
|
+
const found = await twitch.request<{ id: string; name: string }>("GET", "/search/categories", {
|
|
322
|
+
query: name,
|
|
323
|
+
first: "50",
|
|
324
|
+
});
|
|
325
|
+
const exact = found.find((c) => c.name.toLowerCase() === name.toLowerCase());
|
|
326
|
+
if (exact) return exact.id;
|
|
327
|
+
const near = found.slice(0, 3).map((c) => c.name);
|
|
328
|
+
const hint = near.length > 0 ? ` (did you mean ${near.join(", ")}?)` : "";
|
|
329
|
+
throw new Error(`Twitch has no category "${name}"${hint}`);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const update = plugin.action({
|
|
333
|
+
id: "update",
|
|
334
|
+
name: "Change title or category",
|
|
335
|
+
category,
|
|
336
|
+
icon: "pencil",
|
|
337
|
+
slots,
|
|
338
|
+
settings: {
|
|
339
|
+
title: setting.text("Title", {
|
|
340
|
+
placeholder: "Leave it as it is",
|
|
341
|
+
validate: atMost(140),
|
|
342
|
+
}),
|
|
343
|
+
category: setting.text("Category", {
|
|
344
|
+
placeholder: "Leave it as it is",
|
|
345
|
+
description: "As Twitch names it, such as Just Chatting.",
|
|
346
|
+
}),
|
|
347
|
+
caption,
|
|
348
|
+
},
|
|
349
|
+
run: async ({ settings }) => {
|
|
350
|
+
const title = settings.title.trim();
|
|
351
|
+
const name = settings.category.trim();
|
|
352
|
+
if (!title && !name) throw new Error("enter a title or a category");
|
|
353
|
+
const gameId = name && (await categoryId(name));
|
|
354
|
+
const user = await twitch.user();
|
|
355
|
+
const before = await readChannel(user);
|
|
356
|
+
const set = async (to: { title: string; categoryId: string }) => {
|
|
357
|
+
const body = { ...(title && { title: to.title }), ...(name && { game_id: to.categoryId }) };
|
|
358
|
+
await twitch.request("PATCH", "/channels", { broadcaster_id: user.id }, body);
|
|
359
|
+
channel.refresh();
|
|
360
|
+
};
|
|
361
|
+
await set({ title, categoryId: gameId });
|
|
362
|
+
return { label: name || title, undo: () => set(before) };
|
|
363
|
+
},
|
|
364
|
+
look: (s) => key("lucide/pencil", s.caption || s.category),
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// -- Other channels -----------------------------------------------------------------------------
|
|
368
|
+
|
|
369
|
+
async function find(input: string): Promise<User & { name: string }> {
|
|
370
|
+
const login = channelLogin(input);
|
|
371
|
+
if (!login) throw new Error(`"${input}" is not a channel's name`);
|
|
372
|
+
const [user] = await twitch.request<{ id: string; login: string; display_name: string }>(
|
|
373
|
+
"GET",
|
|
374
|
+
"/users",
|
|
375
|
+
{ login },
|
|
376
|
+
);
|
|
377
|
+
if (!user) throw new Error(`there is no channel "${login}"`);
|
|
378
|
+
return { id: user.id, login: user.login, name: user.display_name };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const otherChannel = (description: string) =>
|
|
382
|
+
setting.text("Channel", {
|
|
383
|
+
required: true,
|
|
384
|
+
placeholder: "Name or link",
|
|
385
|
+
description,
|
|
386
|
+
validate: (text) => (channelLogin(text) ? undefined : "should be a channel's name or link"),
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
const shoutout = plugin.action({
|
|
390
|
+
id: "shoutout",
|
|
391
|
+
name: "Shout out a channel",
|
|
392
|
+
category,
|
|
393
|
+
icon: "volume-2",
|
|
394
|
+
slots,
|
|
395
|
+
settings: { channel: otherChannel("In a workflow that a raid starts: {{event.login}}.") },
|
|
396
|
+
run: async ({ settings }) => {
|
|
397
|
+
const me = await twitch.user();
|
|
398
|
+
const to = await find(settings.channel);
|
|
399
|
+
await twitch.request("POST", "/chat/shoutouts", {
|
|
400
|
+
from_broadcaster_id: me.id,
|
|
401
|
+
to_broadcaster_id: to.id,
|
|
402
|
+
moderator_id: me.id,
|
|
403
|
+
});
|
|
404
|
+
return { label: `Shout out ${to.name}` };
|
|
405
|
+
},
|
|
406
|
+
look: (s) => key("lucide/volume-2", s.channel),
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
const raid = plugin.action({
|
|
410
|
+
id: "raid",
|
|
411
|
+
name: "Raid a channel",
|
|
412
|
+
description: "Starts the countdown. Undoing it before it ends calls the raid off.",
|
|
413
|
+
category,
|
|
414
|
+
icon: "swords",
|
|
415
|
+
slots,
|
|
416
|
+
settings: { channel: otherChannel("Where your viewers go.") },
|
|
417
|
+
run: async ({ settings }) => {
|
|
418
|
+
const me = await twitch.user();
|
|
419
|
+
const to = await find(settings.channel);
|
|
420
|
+
await twitch.request("POST", "/raids", {
|
|
421
|
+
from_broadcaster_id: me.id,
|
|
422
|
+
to_broadcaster_id: to.id,
|
|
423
|
+
});
|
|
424
|
+
return {
|
|
425
|
+
label: `Raid ${to.name}`,
|
|
426
|
+
undo: () => twitch.request("DELETE", "/raids", { broadcaster_id: me.id }),
|
|
427
|
+
};
|
|
428
|
+
},
|
|
429
|
+
look: (s) => key("lucide/swords", s.channel),
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// -- Showing things -----------------------------------------------------------------------------
|
|
433
|
+
|
|
434
|
+
/** An expression for a count as people write it: `12,345`. Nothing until it is known. */
|
|
435
|
+
const grouped = (path: string) => `${path} == null ? "" : fmt(${path}, 0, ",")`;
|
|
436
|
+
|
|
437
|
+
/** The viewers, shortened to `123.5K` where the full number would not fit. */
|
|
438
|
+
const viewers = `{{${values.viewers.key} >= 100000 ? fmt(${values.viewers.key} / 1000, 1) + "K" : (${grouped(values.viewers.key)})}}`;
|
|
439
|
+
|
|
440
|
+
/** The window is wide and low: a line about the stream, over what is being streamed. */
|
|
441
|
+
function statusWindow(): Look {
|
|
442
|
+
const on = values.live.key;
|
|
443
|
+
const off = `!${on}`;
|
|
444
|
+
const pill = { x: 4, y: 14, width: 19, height: 36 };
|
|
445
|
+
const followers = values.followerCount.key;
|
|
446
|
+
return {
|
|
447
|
+
background: surface(BACKGROUND),
|
|
448
|
+
layers: [
|
|
449
|
+
rectLayer("badge", { frame: pill, fill: RED, radius: 6, visible: on }),
|
|
450
|
+
textLayer("live", "LIVE", { size: 13, frame: pill, visible: on }),
|
|
451
|
+
iconLayer("eye", "lucide/eye", {
|
|
452
|
+
color: LILAC,
|
|
453
|
+
frame: { x: 27, y: 15, width: 9, height: 34 },
|
|
454
|
+
visible: on,
|
|
455
|
+
}),
|
|
456
|
+
textLayer("viewers", viewers, {
|
|
457
|
+
size: 21,
|
|
458
|
+
align: "left",
|
|
459
|
+
frame: { x: 37.5, y: 10, width: 32, height: 44 },
|
|
460
|
+
visible: on,
|
|
461
|
+
}),
|
|
462
|
+
textLayer("uptime", values.uptime.template, {
|
|
463
|
+
size: 15,
|
|
464
|
+
color: MUTED,
|
|
465
|
+
align: "right",
|
|
466
|
+
frame: { x: 69, y: 10, width: 27, height: 44 },
|
|
467
|
+
visible: on,
|
|
468
|
+
}),
|
|
469
|
+
textLayer("category", values.category.template, {
|
|
470
|
+
size: 13,
|
|
471
|
+
color: MUTED,
|
|
472
|
+
align: "left",
|
|
473
|
+
frame: { x: 4, y: 58, width: 92, height: 32 },
|
|
474
|
+
visible: on,
|
|
475
|
+
}),
|
|
476
|
+
iconLayer("logo", "si/SiTwitch", {
|
|
477
|
+
color: LILAC,
|
|
478
|
+
frame: { x: 21, y: 20, width: 15, height: 60 },
|
|
479
|
+
visible: off,
|
|
480
|
+
}),
|
|
481
|
+
textLayer("offline", "Offline", {
|
|
482
|
+
size: 20,
|
|
483
|
+
align: "left",
|
|
484
|
+
frame: { x: 41, y: 12, width: 55, height: 44 },
|
|
485
|
+
visible: `${off} && ${followers} != null`,
|
|
486
|
+
}),
|
|
487
|
+
textLayer("offline-alone", "Offline", {
|
|
488
|
+
size: 20,
|
|
489
|
+
align: "left",
|
|
490
|
+
frame: { x: 41, y: 20, width: 55, height: 60 },
|
|
491
|
+
visible: `${off} && ${followers} == null`,
|
|
492
|
+
}),
|
|
493
|
+
textLayer("followers", `{{${grouped(followers)}}} followers`, {
|
|
494
|
+
size: 13,
|
|
495
|
+
color: MUTED,
|
|
496
|
+
align: "left",
|
|
497
|
+
frame: { x: 41, y: 54, width: 55, height: 32 },
|
|
498
|
+
visible: `${off} && ${followers} != null`,
|
|
499
|
+
}),
|
|
500
|
+
],
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const status = plugin.action({
|
|
505
|
+
id: "status",
|
|
506
|
+
name: "Stream status",
|
|
507
|
+
description: "Whether you are live, with viewers and the time since it started.",
|
|
508
|
+
category,
|
|
509
|
+
icon: "radio",
|
|
510
|
+
slots: ["key", "window"],
|
|
511
|
+
display: true,
|
|
512
|
+
look: (_, slot): Look => {
|
|
513
|
+
if (slot === "window") return statusWindow();
|
|
514
|
+
const on = values.live.key;
|
|
515
|
+
const off = `!${on}`;
|
|
516
|
+
const pill = { x: 22, y: 13, width: 56, height: 22 };
|
|
517
|
+
return {
|
|
518
|
+
background: surface(BACKGROUND),
|
|
519
|
+
layers: [
|
|
520
|
+
rectLayer("badge", { frame: pill, fill: RED, radius: 6, visible: on }),
|
|
521
|
+
textLayer("live", "LIVE", { size: 13, frame: pill, visible: on }),
|
|
522
|
+
textLayer("viewers", viewers, {
|
|
523
|
+
size: 25,
|
|
524
|
+
frame: { x: 0, y: 38, width: 100, height: 30 },
|
|
525
|
+
visible: on,
|
|
526
|
+
}),
|
|
527
|
+
textLayer("uptime", values.uptime.template, {
|
|
528
|
+
size: 13,
|
|
529
|
+
color: MUTED,
|
|
530
|
+
frame: { x: 0, y: 69, width: 100, height: 20 },
|
|
531
|
+
visible: on,
|
|
532
|
+
}),
|
|
533
|
+
iconLayer("logo", "si/SiTwitch", { color: MUTED, size: iconSize(true), visible: off }),
|
|
534
|
+
captionLayer("offline", "Offline", { color: MUTED, visible: off }),
|
|
535
|
+
],
|
|
536
|
+
};
|
|
537
|
+
},
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
const followers = plugin.action({
|
|
541
|
+
id: "followers",
|
|
542
|
+
name: "Followers",
|
|
543
|
+
category,
|
|
544
|
+
icon: "users",
|
|
545
|
+
slots: ["key", "window"],
|
|
546
|
+
display: true,
|
|
547
|
+
look: (_, slot): Look => {
|
|
548
|
+
const count = textLayer("label", `{{${grouped(values.followerCount.key)}}}`, {
|
|
549
|
+
size: slot === "window" ? 26 : 18,
|
|
550
|
+
row: slot === "window" ? "line" : "",
|
|
551
|
+
});
|
|
552
|
+
if (slot !== "window") {
|
|
553
|
+
const icon = iconLayer("icon", "lucide/users", { color: LILAC, size: 44 });
|
|
554
|
+
return { background: surface(BACKGROUND), layers: [icon, count] };
|
|
555
|
+
}
|
|
556
|
+
return {
|
|
557
|
+
background: surface(BACKGROUND),
|
|
558
|
+
layers: [
|
|
559
|
+
iconLayer("icon", "lucide/users", { color: LILAC, size: 50, row: "line" }),
|
|
560
|
+
count,
|
|
561
|
+
textLayer("unit", "followers", { color: MUTED, size: 14, row: "line" }),
|
|
562
|
+
],
|
|
563
|
+
};
|
|
564
|
+
},
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
export const actions = [
|
|
568
|
+
status,
|
|
569
|
+
clip,
|
|
570
|
+
marker,
|
|
571
|
+
chatMode,
|
|
572
|
+
shieldMode,
|
|
573
|
+
message,
|
|
574
|
+
announcement,
|
|
575
|
+
clearChat,
|
|
576
|
+
ad,
|
|
577
|
+
snoozeAd,
|
|
578
|
+
update,
|
|
579
|
+
shoutout,
|
|
580
|
+
raid,
|
|
581
|
+
followers,
|
|
582
|
+
];
|
|
583
|
+
|
|
584
|
+
/** Titles of the channel's rewards, for the trigger. */
|
|
585
|
+
export const rewards = plugin.source("rewards", async () => {
|
|
586
|
+
try {
|
|
587
|
+
const { id } = await twitch.user();
|
|
588
|
+
const found = await twitch.request<{ title: string }>("GET", "/channel_points/custom_rewards", {
|
|
589
|
+
broadcaster_id: id,
|
|
590
|
+
});
|
|
591
|
+
return found.map(({ title }) => ({ value: title, label: title }));
|
|
592
|
+
} catch (error) {
|
|
593
|
+
// Channels that are not affiliates have none, and any name can still be typed.
|
|
594
|
+
if (error instanceof SignedOut || error instanceof TwitchError) return [];
|
|
595
|
+
throw error;
|
|
596
|
+
}
|
|
597
|
+
});
|