@tixyel/streamelements 6.3.0 → 6.4.0

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.es.js CHANGED
@@ -6237,161 +6237,514 @@ class at {
6237
6237
  }
6238
6238
  }
6239
6239
  }
6240
- var q;
6241
- ((l) => {
6242
- l.generate = {
6243
- session: {
6244
- types: {
6245
- name: { type: "string", options: A.names.filter((t) => t.length) },
6246
- tier: { type: "string", options: A.tiers.filter((t) => t.length) },
6247
- message: { type: "string", options: A.messages.filter((t) => t.length) },
6248
- item: { type: "array", options: A.items },
6249
- avatar: { type: "string", options: A.avatars.filter((t) => t.length) }
6250
- },
6251
- available() {
6252
- const t = this.types;
6253
- return {
6254
- follower: {
6255
- latest: { name: t.name },
6256
- session: { count: { type: "int", min: 50, max: 200 } },
6257
- week: { count: { type: "int", min: 200, max: 1e3 } },
6258
- month: { count: { type: "int", min: 1e3, max: 3e3 } },
6259
- goal: { amount: { type: "int", min: 3e3, max: 7e3 } },
6260
- total: { count: { type: "int", min: 7e3, max: 1e4 } },
6261
- recent: {
6262
- type: "recent",
6263
- amount: 25,
6264
- value: { name: t.name, createdAt: { type: "date", range: 400 } }
6240
+ const et = [];
6241
+ class St extends X {
6242
+ constructor(e = {}) {
6243
+ super(), this.SE_API = null, this.id = "widget communications", this.loaded = !1, this.history = [], this.detected = /* @__PURE__ */ new Set(), this.id = e.id || this.id, et.push(this), ct?.then(async (t) => {
6244
+ this.loaded = !0, this.SE_API = t, Promise.all([
6245
+ async () => {
6246
+ const a = await t.store.get(this.id);
6247
+ a && (this.history = a.slice(-10));
6248
+ },
6249
+ async () => {
6250
+ const a = await t.store.get(this.id + "_detected");
6251
+ a && (this.detected = new Set(a));
6252
+ }
6253
+ ]);
6254
+ });
6255
+ }
6256
+ async send(e, t) {
6257
+ if (this.SE_API) {
6258
+ const a = {
6259
+ nonce: Math.random().toString(36).substring(2),
6260
+ key: e,
6261
+ value: t,
6262
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
6263
+ };
6264
+ this.history.push(a), this.SE_API.store.set(this.id, this.history), this.SE_API.store.set(this.id + "_detected", Array.from(this.detected));
6265
+ }
6266
+ }
6267
+ update(e) {
6268
+ if (!e.length)
6269
+ return;
6270
+ this.history = e, e.filter((a) => !this.detected.has(a.nonce)).forEach((a) => {
6271
+ this.detected.add(a.nonce), this.emit("message", a.key, a.value);
6272
+ });
6273
+ }
6274
+ on(e, t) {
6275
+ return e === "load" && this.loaded ? (t.apply(this), this) : (super.on(e, t), this);
6276
+ }
6277
+ }
6278
+ typeof window !== void 0 && (window.addEventListener("onWidgetLoad", async (l) => {
6279
+ const { detail: e } = l;
6280
+ if (window.client instanceof G) {
6281
+ const t = window.client;
6282
+ if (t.fields = e.fieldData, t.session = e.session.data, t.details = {
6283
+ ...t.details,
6284
+ user: e.channel,
6285
+ currency: e.currency,
6286
+ overlay: e.overlay
6287
+ }, e.channel.id && !e.emulated ? await fetch(`https://api.streamelements.com/kappa/v2/channels/${e.channel.id}/`).then((a) => a.json()).then((a) => {
6288
+ if (a.provider)
6289
+ return t.details.provider = a.provider, a.provider;
6290
+ t.details.provider = "local";
6291
+ }).catch(() => {
6292
+ t.details.provider = "local";
6293
+ }) : t.details.provider = "local", t.emit("load", e), t.debug) {
6294
+ N.received("Widget loaded!", l.detail);
6295
+ const a = l.detail.fieldData;
6296
+ Object.keys(a).length && N.received("Field data:", a);
6297
+ }
6298
+ t.loaded = !0, t.storage.on("load", (a) => {
6299
+ if (t.debug && a ? N.debug(
6300
+ "[Client]",
6301
+ "Storage loaded for client",
6302
+ `"${t.id}";`,
6303
+ `Provider: "${t.details.provider}";`,
6304
+ a
6305
+ ) : t.debug && N.debug(
6306
+ "[Client]",
6307
+ "Storage loaded for client",
6308
+ `"${t.id}";`,
6309
+ `Provider: "${t.details.provider}";`,
6310
+ "No data found."
6311
+ ), a) {
6312
+ const i = (b) => {
6313
+ const p = Date.now(), o = {};
6314
+ for (const h in b)
6315
+ if (b.hasOwnProperty(h)) {
6316
+ const f = b[h];
6317
+ f.expire && f.expire > p && (o[h] = f);
6265
6318
  }
6266
- },
6267
- subscriber: {
6268
- latest: {
6269
- name: t.name,
6270
- amount: { type: "int", min: 10, max: 30 },
6271
- tier: t.tier,
6272
- message: t.message
6273
- },
6274
- "new-latest": {
6275
- name: t.name,
6276
- amount: { type: "int", min: 10, max: 30 },
6277
- message: t.message
6278
- },
6279
- "resub-latest": {
6280
- name: t.name,
6281
- amount: { type: "int", min: 10, max: 30 },
6282
- message: t.message
6283
- },
6284
- "gifted-latest": {
6285
- name: t.name,
6286
- amount: { type: "int", min: 10, max: 30 },
6287
- message: t.message,
6288
- tier: t.tier,
6289
- sender: t.name
6290
- },
6291
- session: { count: { type: "int", min: 10, max: 40 } },
6292
- "new-session": { count: { type: "int", min: 10, max: 40 } },
6293
- "resub-session": { count: { type: "int", min: 10, max: 40 } },
6294
- "gifted-session": { count: { type: "int", min: 10, max: 40 } },
6295
- week: { count: { type: "int", min: 40, max: 100 } },
6296
- month: { count: { type: "int", min: 100, max: 200 } },
6297
- goal: { amount: { type: "int", min: 200, max: 300 } },
6298
- total: { count: { type: "int", min: 300, max: 400 } },
6299
- points: { amount: { type: "int", min: 100, max: 400 } },
6300
- "alltime-gifter": { name: t.name, amount: { type: "int", min: 300, max: 400 } },
6301
- recent: {
6302
- type: "recent",
6303
- amount: 25,
6304
- value: {
6305
- name: t.name,
6306
- amount: { type: "int", min: 10, max: 30 },
6307
- tier: t.tier,
6308
- createdAt: { type: "date", range: 400 }
6319
+ return o;
6320
+ }, s = i(a.user || {}), n = i(a.avatar || {}), m = i(a.pronoun || {}), c = i(a.emote || {});
6321
+ t.storage.update({
6322
+ user: s,
6323
+ avatar: n,
6324
+ pronoun: m,
6325
+ emote: c
6326
+ });
6327
+ }
6328
+ e.channel.providerId.length && t.storage.add(`avatar.${e.channel.providerId.toLowerCase()}`, {
6329
+ value: e.channel.avatar,
6330
+ timestamp: Date.now(),
6331
+ expire: Date.now() + t.cache.avatar * 60 * 1e3
6332
+ });
6333
+ });
6334
+ }
6335
+ }), window.addEventListener("onSessionUpdate", (l) => {
6336
+ const { detail: e } = l;
6337
+ if (window.client instanceof G) {
6338
+ const t = window.client;
6339
+ t.session = e.session, t.emit("session", e.session), t.debug && N.debug("[Client]", "Session updated", e.session);
6340
+ }
6341
+ }), window.addEventListener("onEventReceived", ({ detail: l }) => {
6342
+ if (window.client instanceof G) {
6343
+ const t = w.event.parseProvider(l);
6344
+ switch (t.provider) {
6345
+ case "streamelements": {
6346
+ const i = t.data;
6347
+ switch (i.listener) {
6348
+ case "tip-latest": {
6349
+ i.event;
6350
+ break;
6351
+ }
6352
+ case "event:skip": {
6353
+ i.event;
6354
+ break;
6355
+ }
6356
+ case "event:test": {
6357
+ switch (i.event.listener) {
6358
+ case "widget-button": {
6359
+ const s = i.event;
6360
+ at.execute(s.field, s.value);
6361
+ break;
6309
6362
  }
6310
- }
6311
- },
6312
- host: {
6313
- latest: { name: t.name, amount: { type: "int", min: 1, max: 10 } },
6314
- recent: {
6315
- type: "recent",
6316
- amount: 25,
6317
- value: {
6318
- name: t.name,
6319
- amount: { type: "int", min: 1, max: 10 },
6320
- createdAt: { type: "date", range: 400 }
6363
+ case "subscriber-latest": {
6364
+ i.event;
6365
+ break;
6321
6366
  }
6322
6367
  }
6323
- },
6324
- raid: {
6325
- latest: { name: t.name, amount: { type: "int", min: 0, max: 100 } },
6326
- recent: {
6327
- type: "recent",
6328
- amount: 25,
6329
- value: {
6330
- name: t.name,
6331
- amount: { type: "int", min: 0, max: 100 },
6332
- createdAt: { type: "date", range: 400 }
6333
- }
6368
+ break;
6369
+ }
6370
+ case "kvstore:update": {
6371
+ const s = i.event;
6372
+ if (tt.length) {
6373
+ var e = tt.find(
6374
+ (n) => n.id === s.data.key.replace("customWidget.", "") || n.id === s.data.key
6375
+ );
6376
+ e && e.update(s.data.value);
6334
6377
  }
6335
- },
6336
- charityCampaignDonation: {
6337
- latest: { name: t.name, amount: { type: "int", min: 50, max: 150 } },
6338
- "session-top-donation": {
6339
- name: t.name,
6340
- amount: { type: "int", min: 50, max: 200 }
6341
- },
6342
- "weekly-top-donation": {
6343
- name: t.name,
6344
- amount: { type: "int", min: 200, max: 500 }
6345
- },
6346
- "monthly-top-donation": {
6347
- name: t.name,
6348
- amount: { type: "int", min: 500, max: 800 }
6349
- },
6350
- "alltime-top-donation": {
6351
- name: t.name,
6352
- amount: { type: "int", min: 800, max: 1e3 }
6353
- },
6354
- "session-top-donator": { name: t.name, amount: { type: "int", min: 50, max: 200 } },
6355
- "weekly-top-donator": { name: t.name, amount: { type: "int", min: 200, max: 500 } },
6356
- "monthly-top-donator": {
6357
- name: t.name,
6358
- amount: { type: "int", min: 500, max: 800 }
6359
- },
6360
- "alltime-top-donator": {
6361
- name: t.name,
6362
- amount: { type: "int", min: 800, max: 1e3 }
6363
- },
6364
- recent: {
6365
- type: "recent",
6366
- amount: 25,
6367
- value: {
6368
- name: t.name,
6369
- amount: { type: "int", min: 50, max: 150 },
6370
- createdAt: { type: "date", range: 400 }
6371
- }
6378
+ if (et.length) {
6379
+ const n = et.find(
6380
+ (m) => m.id === s.data.key.replace("customWidget.", "") || m.id === s.data.key
6381
+ );
6382
+ n && n.update(s.data.value);
6383
+ }
6384
+ break;
6385
+ }
6386
+ case "bot:counter": {
6387
+ i.event;
6388
+ break;
6389
+ }
6390
+ case "alertService:toggleSound": {
6391
+ const s = i.event;
6392
+ client.details.overlay.muted = !!s.muted;
6393
+ break;
6394
+ }
6395
+ }
6396
+ window.client.emit("event", "streamelements", t.data);
6397
+ break;
6398
+ }
6399
+ case "twitch": {
6400
+ const i = t.data;
6401
+ switch (i.listener) {
6402
+ case "delete-message": {
6403
+ i.event;
6404
+ break;
6405
+ }
6406
+ case "delete-messages": {
6407
+ i.event;
6408
+ break;
6409
+ }
6410
+ case "message": {
6411
+ i.event, Z.execute({ provider: "twitch", data: i });
6412
+ break;
6413
+ }
6414
+ case "follower-latest": {
6415
+ i.event;
6416
+ break;
6417
+ }
6418
+ case "cheer-latest": {
6419
+ i.event;
6420
+ break;
6421
+ }
6422
+ case "subscriber-latest": {
6423
+ (!i.event.gifted && !i.event.bulkGifted && !i.event.isCommunityGift || i.event.gifted && !i.event.bulkGifted && !i.event.isCommunityGift || i.event.gifted && !i.event.bulkGifted && i.event.isCommunityGift || !i.event.gifted && i.event.bulkGifted && !i.event.isCommunityGift) && i.event;
6424
+ break;
6425
+ }
6426
+ case "raid-latest": {
6427
+ i.event;
6428
+ break;
6429
+ }
6430
+ }
6431
+ window.client.emit("event", "twitch", t.data);
6432
+ break;
6433
+ }
6434
+ case "youtube": {
6435
+ const i = t.data;
6436
+ switch (i.listener) {
6437
+ case "message": {
6438
+ i.event, Z.execute({ provider: "youtube", data: i });
6439
+ break;
6440
+ }
6441
+ case "subscriber-latest": {
6442
+ i.event;
6443
+ break;
6444
+ }
6445
+ case "sponsor-latest": {
6446
+ i.event, (!i.event.gifted && !i.event.bulkGifted && !i.event.isCommunityGift || i.event.gifted && !i.event.bulkGifted && !i.event.isCommunityGift || i.event.gifted && !i.event.bulkGifted && i.event.isCommunityGift || !i.event.gifted && i.event.bulkGifted && !i.event.isCommunityGift) && i.event;
6447
+ break;
6448
+ }
6449
+ case "superchat-latest": {
6450
+ i.event;
6451
+ break;
6452
+ }
6453
+ }
6454
+ window.client.emit("event", "youtube", t.data);
6455
+ break;
6456
+ }
6457
+ case "kick": {
6458
+ t.data, window.client.emit("event", "kick", t.data);
6459
+ break;
6460
+ }
6461
+ case "facebook": {
6462
+ t.data, window.client.emit("event", "facebook", t.data);
6463
+ break;
6464
+ }
6465
+ }
6466
+ const a = [
6467
+ "bot:counter",
6468
+ "alertService:toggleSound",
6469
+ "event",
6470
+ "event:skip",
6471
+ "event:test",
6472
+ "kvstore:update"
6473
+ ];
6474
+ client.debug && !a.some((i) => i === t.data.listener) && N.received(
6475
+ "[Client]",
6476
+ `Event ${t.data.listener} received from ${t.provider}`,
6477
+ t.data.event
6478
+ );
6479
+ }
6480
+ }));
6481
+ class gt extends X {
6482
+ constructor(e) {
6483
+ if (super(), this.queue = [], this.priorityQueue = [], this.history = [], this.timeouts = [], this.running = !1, this.duration = void 0, this.loaded = !1, this.clientWaitRetryDelay = 50, !e.processor || typeof e.processor != "function")
6484
+ throw new Error("A valid processor function must be provided to useQueue.");
6485
+ this.processor = e.processor, e.duration !== "client" && (this.duration = e.duration ?? 0), this.waitForClientAndBindLoad(e.duration);
6486
+ }
6487
+ waitForClientAndBindLoad(e = this.duration, t) {
6488
+ if (!(window?.client instanceof G)) {
6489
+ setTimeout(
6490
+ () => this.waitForClientAndBindLoad(e, t),
6491
+ this.clientWaitRetryDelay
6492
+ );
6493
+ return;
6494
+ }
6495
+ window.client.on("load", () => {
6496
+ e === "client" && (this.duration = window.client.fields?.widgetDuration ?? 0), this.emit("load"), this.loaded = !0, t && t();
6497
+ });
6498
+ }
6499
+ enqueue(e, t = {}) {
6500
+ const a = this.hasItems(), i = Array.isArray(e) ? e.map((s) => ({ value: s.value, options: s.options ?? {} })) : [{ value: e, options: t }];
6501
+ for (const s of i) {
6502
+ const n = {
6503
+ isoDate: (/* @__PURE__ */ new Date()).toISOString(),
6504
+ isLoop: s.options?.isLoop ?? !1,
6505
+ isPriority: s.options?.isPriority ?? !1,
6506
+ isImmediate: s.options?.isImmediate ?? !1,
6507
+ value: s.value
6508
+ };
6509
+ n.isPriority && n.isImmediate ? (this.cancel(), this.priorityQueue.unshift(n)) : (n.isPriority ? this.priorityQueue : this.queue).push(n);
6510
+ }
6511
+ return this.running === !1 && a === !1 && this.run(), this.emit("update", this.queue, this.priorityQueue, this.history, this.timeouts), this;
6512
+ }
6513
+ async run() {
6514
+ if (!this.hasItems()) {
6515
+ this.running = !1;
6516
+ return;
6517
+ }
6518
+ this.running = !0, await this.next(), typeof this.duration == "number" && this.duration > 0 ? this.timeouts.push(setTimeout(() => this.run(), this.duration)) : (this.duration === 0 || this.duration !== -1 && this.duration !== !1) && this.run();
6519
+ }
6520
+ async next() {
6521
+ const e = this.priorityQueue.length > 0 ? this.priorityQueue.shift() : this.queue.shift();
6522
+ if (!e) {
6523
+ this.running = !1;
6524
+ return;
6525
+ }
6526
+ try {
6527
+ await this.processor.apply(this, [e.value, this]), this.emit("process", e, this);
6528
+ } catch (a) {
6529
+ N.error(
6530
+ `Error during item processing: ${a instanceof Error ? a.message : String(a)}`
6531
+ );
6532
+ }
6533
+ this.history.push(e);
6534
+ const t = e.isPriority ? this.priorityQueue : this.queue;
6535
+ e.isLoop && t.push(e);
6536
+ }
6537
+ /**
6538
+ * Resume processing the queue if it is paused. If the queue is already running, it will be restarted, which can be useful if new items have been added or if you want to reset the processing timer.
6539
+ * If the queue was empty before, it will start processing immediately.
6540
+ * @returns - The instance of the queue for chaining.
6541
+ * @example
6542
+ * ```javascript
6543
+ * myQueue.resume();
6544
+ * ```
6545
+ */
6546
+ resume() {
6547
+ return this.running && this.cancel(), this.hasItems() && this.run(), this;
6548
+ }
6549
+ /**
6550
+ * Update the queue's state with new values. This can be used to replace the current queue, priority queue, history, or timeouts with new data. If the queue is not currently running and there are items in the queue after the update, it will start processing immediately.
6551
+ * @param save - An object containing the new state for the queue, priority queue, history, and timeouts. Each property is optional, and if not provided, the current state will be retained.
6552
+ * @returns - The instance of the queue for chaining.
6553
+ * @example
6554
+ * ```javascript
6555
+ * myQueue.update({
6556
+ * queue: newQueueItems,
6557
+ * priorityQueue: newPriorityItems,
6558
+ * history: newHistory,
6559
+ * });
6560
+ * ```
6561
+ */
6562
+ update(e) {
6563
+ return this.queue = e.queue ?? this.queue, this.priorityQueue = e.priorityQueue ?? this.priorityQueue, this.history = e.history ?? this.history, this.hasItems() && this.running === !1 && window.client?.on("load", () => this.run()), this;
6564
+ }
6565
+ /**
6566
+ * Cancel all pending timeouts and stop the queue from processing further items. This will clear any scheduled processing and prevent any new items from being processed until `resume()` is called again. The current state of the queue, priority queue, and history will be retained, allowing you to resume processing later without losing any data.
6567
+ */
6568
+ cancel() {
6569
+ this.running && (this.timeouts.forEach((e) => clearTimeout(e)), this.timeouts = [], this.running = !1, this.emit("cancel"));
6570
+ }
6571
+ /**
6572
+ * Check if there are any items in the queue or priority queue. This method returns `true` if there are items waiting to be processed in either the main queue or the priority queue, and `false` if both queues are empty.
6573
+ * @returns - A boolean indicating whether there are items in the queue or priority queue.
6574
+ */
6575
+ hasItems() {
6576
+ return this.queue.length > 0 || this.priorityQueue.length > 0;
6577
+ }
6578
+ on(e, t) {
6579
+ return e === "load" && this.loaded ? (t.apply(this), this) : (super.on(e, t), this);
6580
+ }
6581
+ }
6582
+ var q;
6583
+ ((l) => {
6584
+ l.queue = new gt({
6585
+ duration: "client",
6586
+ processor: async function(a) {
6587
+ if (window.dispatchEvent(new CustomEvent(a.listener, { detail: a.data })), a.listener === "onEventReceived" && a.session) {
6588
+ const i = await l.generate.event.onSessionUpdate(
6589
+ client.session,
6590
+ w.event.parseProvider(a.data)
6591
+ );
6592
+ window.dispatchEvent(new CustomEvent("onSessionUpdate", { detail: i }));
6593
+ }
6594
+ }
6595
+ }), l.generate = {
6596
+ session: {
6597
+ types: {
6598
+ name: { type: "string", options: A.names.filter((t) => t.length) },
6599
+ tier: { type: "string", options: A.tiers.filter((t) => t.length) },
6600
+ message: { type: "string", options: A.messages.filter((t) => t.length) },
6601
+ item: { type: "array", options: A.items },
6602
+ avatar: { type: "string", options: A.avatars.filter((t) => t.length) }
6603
+ },
6604
+ available() {
6605
+ const t = this.types;
6606
+ return {
6607
+ follower: {
6608
+ latest: { name: t.name },
6609
+ session: { count: { type: "int", min: 50, max: 200 } },
6610
+ week: { count: { type: "int", min: 200, max: 1e3 } },
6611
+ month: { count: { type: "int", min: 1e3, max: 3e3 } },
6612
+ goal: { amount: { type: "int", min: 3e3, max: 7e3 } },
6613
+ total: { count: { type: "int", min: 7e3, max: 1e4 } },
6614
+ recent: {
6615
+ type: "recent",
6616
+ amount: 25,
6617
+ value: { name: t.name, createdAt: { type: "date", range: 400 } }
6372
6618
  }
6373
6619
  },
6374
- cheer: {
6620
+ subscriber: {
6375
6621
  latest: {
6376
6622
  name: t.name,
6377
- amount: { type: "int", min: 200, max: 800 },
6623
+ amount: { type: "int", min: 10, max: 30 },
6624
+ tier: t.tier,
6378
6625
  message: t.message
6379
6626
  },
6380
- "session-top-donation": {
6381
- name: t.name,
6382
- amount: { type: "int", min: 200, max: 1e3 }
6383
- },
6384
- "weekly-top-donation": {
6627
+ "new-latest": {
6385
6628
  name: t.name,
6386
- amount: { type: "int", min: 1e3, max: 5e3 }
6629
+ amount: { type: "int", min: 10, max: 30 },
6630
+ message: t.message
6387
6631
  },
6388
- "monthly-top-donation": {
6632
+ "resub-latest": {
6389
6633
  name: t.name,
6390
- amount: { type: "int", min: 5e3, max: 12e3 }
6634
+ amount: { type: "int", min: 10, max: 30 },
6635
+ message: t.message
6391
6636
  },
6392
- "alltime-top-donation": {
6637
+ "gifted-latest": {
6393
6638
  name: t.name,
6394
- amount: { type: "int", min: 12e3, max: 2e4 }
6639
+ amount: { type: "int", min: 10, max: 30 },
6640
+ message: t.message,
6641
+ tier: t.tier,
6642
+ sender: t.name
6643
+ },
6644
+ session: { count: { type: "int", min: 10, max: 40 } },
6645
+ "new-session": { count: { type: "int", min: 10, max: 40 } },
6646
+ "resub-session": { count: { type: "int", min: 10, max: 40 } },
6647
+ "gifted-session": { count: { type: "int", min: 10, max: 40 } },
6648
+ week: { count: { type: "int", min: 40, max: 100 } },
6649
+ month: { count: { type: "int", min: 100, max: 200 } },
6650
+ goal: { amount: { type: "int", min: 200, max: 300 } },
6651
+ total: { count: { type: "int", min: 300, max: 400 } },
6652
+ points: { amount: { type: "int", min: 100, max: 400 } },
6653
+ "alltime-gifter": { name: t.name, amount: { type: "int", min: 300, max: 400 } },
6654
+ recent: {
6655
+ type: "recent",
6656
+ amount: 25,
6657
+ value: {
6658
+ name: t.name,
6659
+ amount: { type: "int", min: 10, max: 30 },
6660
+ tier: t.tier,
6661
+ createdAt: { type: "date", range: 400 }
6662
+ }
6663
+ }
6664
+ },
6665
+ host: {
6666
+ latest: { name: t.name, amount: { type: "int", min: 1, max: 10 } },
6667
+ recent: {
6668
+ type: "recent",
6669
+ amount: 25,
6670
+ value: {
6671
+ name: t.name,
6672
+ amount: { type: "int", min: 1, max: 10 },
6673
+ createdAt: { type: "date", range: 400 }
6674
+ }
6675
+ }
6676
+ },
6677
+ raid: {
6678
+ latest: { name: t.name, amount: { type: "int", min: 0, max: 100 } },
6679
+ recent: {
6680
+ type: "recent",
6681
+ amount: 25,
6682
+ value: {
6683
+ name: t.name,
6684
+ amount: { type: "int", min: 0, max: 100 },
6685
+ createdAt: { type: "date", range: 400 }
6686
+ }
6687
+ }
6688
+ },
6689
+ charityCampaignDonation: {
6690
+ latest: { name: t.name, amount: { type: "int", min: 50, max: 150 } },
6691
+ "session-top-donation": {
6692
+ name: t.name,
6693
+ amount: { type: "int", min: 50, max: 200 }
6694
+ },
6695
+ "weekly-top-donation": {
6696
+ name: t.name,
6697
+ amount: { type: "int", min: 200, max: 500 }
6698
+ },
6699
+ "monthly-top-donation": {
6700
+ name: t.name,
6701
+ amount: { type: "int", min: 500, max: 800 }
6702
+ },
6703
+ "alltime-top-donation": {
6704
+ name: t.name,
6705
+ amount: { type: "int", min: 800, max: 1e3 }
6706
+ },
6707
+ "session-top-donator": { name: t.name, amount: { type: "int", min: 50, max: 200 } },
6708
+ "weekly-top-donator": { name: t.name, amount: { type: "int", min: 200, max: 500 } },
6709
+ "monthly-top-donator": {
6710
+ name: t.name,
6711
+ amount: { type: "int", min: 500, max: 800 }
6712
+ },
6713
+ "alltime-top-donator": {
6714
+ name: t.name,
6715
+ amount: { type: "int", min: 800, max: 1e3 }
6716
+ },
6717
+ recent: {
6718
+ type: "recent",
6719
+ amount: 25,
6720
+ value: {
6721
+ name: t.name,
6722
+ amount: { type: "int", min: 50, max: 150 },
6723
+ createdAt: { type: "date", range: 400 }
6724
+ }
6725
+ }
6726
+ },
6727
+ cheer: {
6728
+ latest: {
6729
+ name: t.name,
6730
+ amount: { type: "int", min: 200, max: 800 },
6731
+ message: t.message
6732
+ },
6733
+ "session-top-donation": {
6734
+ name: t.name,
6735
+ amount: { type: "int", min: 200, max: 1e3 }
6736
+ },
6737
+ "weekly-top-donation": {
6738
+ name: t.name,
6739
+ amount: { type: "int", min: 1e3, max: 5e3 }
6740
+ },
6741
+ "monthly-top-donation": {
6742
+ name: t.name,
6743
+ amount: { type: "int", min: 5e3, max: 12e3 }
6744
+ },
6745
+ "alltime-top-donation": {
6746
+ name: t.name,
6747
+ amount: { type: "int", min: 12e3, max: 2e4 }
6395
6748
  },
6396
6749
  "session-top-donator": {
6397
6750
  name: t.name,
@@ -7260,581 +7613,229 @@ var q;
7260
7613
  sender: D,
7261
7614
  gifted: !0
7262
7615
  },
7263
- community: {
7264
- message: b,
7265
- sender: D,
7266
- bulkGifted: !0
7267
- },
7268
- spam: {
7269
- sender: D,
7270
- gifted: !0,
7271
- isCommunityGift: !0
7272
- }
7273
- }, _ = ["default", "gift", "community", "spam"], j = i?.subType ?? w.random.array(_)[0];
7274
- return j = _.includes(j) ? j : "default", {
7275
- listener: "sponsor-latest",
7276
- event: {
7277
- amount: C,
7278
- name: c.toLowerCase(),
7279
- displayName: c,
7280
- providerId: "",
7281
- ...M.default,
7282
- ...M[j],
7283
- _id: w.random.uuid(),
7284
- sessionTop: !1,
7285
- type: "sponsor",
7286
- originalEventName: "sponsor-latest",
7287
- provider: t
7288
- },
7289
- // @ts-ignore
7290
- emulated: !0
7291
- };
7292
- }
7293
- }
7294
- }
7295
- }
7296
- }
7297
- }, l.emulate = {
7298
- twitch: {
7299
- message(t = {}) {
7300
- l.generate.event.onEventReceived(
7301
- "twitch",
7302
- "message",
7303
- t
7304
- ).then((a) => {
7305
- a && l.emulate.send("onEventReceived", a);
7306
- });
7307
- },
7308
- deleteMessage(t) {
7309
- if (!t || typeof t != "string") return;
7310
- const a = {
7311
- listener: "delete-message",
7312
- event: {
7313
- msgId: t
7314
- }
7315
- };
7316
- l.emulate.send("onEventReceived", a);
7317
- },
7318
- deleteMessages(t) {
7319
- if (!t || typeof t != "string") return;
7320
- const a = {
7321
- listener: "delete-messages",
7322
- event: {
7323
- userId: t
7324
- }
7325
- };
7326
- l.emulate.send("onEventReceived", a);
7327
- },
7328
- follower(t = {}) {
7329
- l.generate.event.onEventReceived(
7330
- "twitch",
7331
- "follower-latest",
7332
- t
7333
- ).then((a) => {
7334
- a && l.emulate.send("onEventReceived", a);
7335
- });
7336
- },
7337
- raid(t = {}) {
7338
- l.generate.event.onEventReceived(
7339
- "twitch",
7340
- "raid-latest",
7341
- t
7342
- ).then((a) => {
7343
- a && l.emulate.send("onEventReceived", a);
7344
- });
7345
- },
7346
- cheer(t = {}) {
7347
- l.generate.event.onEventReceived(
7348
- "twitch",
7349
- "cheer-latest",
7350
- t
7351
- ).then((a) => {
7352
- a && l.emulate.send("onEventReceived", a);
7353
- });
7354
- },
7355
- subscriber(t = {}) {
7356
- l.generate.event.onEventReceived(
7357
- "twitch",
7358
- "subscriber-latest",
7359
- t
7360
- ).then((a) => {
7361
- a && l.emulate.send("onEventReceived", a);
7362
- });
7363
- }
7364
- },
7365
- streamelements: {
7366
- tip(t = {}) {
7367
- l.generate.event.onEventReceived(
7368
- "streamelements",
7369
- "tip-latest",
7370
- t
7371
- ).then((a) => {
7372
- a && l.emulate.send("onEventReceived", a);
7373
- });
7374
- }
7375
- },
7376
- youtube: {
7377
- message(t = {}) {
7378
- l.generate.event.onEventReceived(
7379
- "youtube",
7380
- "message",
7381
- t
7382
- ).then((a) => {
7383
- a && l.emulate.send("onEventReceived", a);
7384
- });
7385
- },
7386
- subscriber(t = {}) {
7387
- l.generate.event.onEventReceived(
7388
- "youtube",
7389
- "subscriber-latest",
7390
- t
7391
- ).then((a) => {
7392
- a && l.emulate.send("onEventReceived", a);
7393
- });
7394
- },
7395
- superchat(t = {}) {
7396
- l.generate.event.onEventReceived(
7397
- "youtube",
7398
- "superchat-latest",
7399
- t
7400
- ).then((a) => {
7401
- a && l.emulate.send("onEventReceived", a);
7402
- });
7403
- },
7404
- sponsor(t = {}) {
7405
- l.generate.event.onEventReceived(
7406
- "youtube",
7407
- "sponsor-latest",
7408
- t
7409
- ).then((a) => {
7410
- a && l.emulate.send("onEventReceived", a);
7411
- });
7412
- }
7413
- },
7414
- kick: {},
7415
- facebook: {},
7416
- send(t, a) {
7417
- if (!l.queue) {
7418
- N.warn("Local queue is not initialized."), window.dispatchEvent(new CustomEvent(t, { detail: a }));
7419
- return;
7420
- }
7421
- switch (t) {
7422
- case "onEventReceived": {
7423
- l.queue.enqueue({
7424
- listener: t,
7425
- data: a,
7426
- session: t === "onEventReceived" ? !0 : void 0
7427
- });
7428
- break;
7429
- }
7430
- case "onSessionUpdate": {
7431
- l.queue.enqueue({
7432
- listener: t,
7433
- data: a
7434
- });
7435
- break;
7436
- }
7437
- case "onWidgetLoad": {
7438
- l.queue.enqueue({
7439
- listener: t,
7440
- data: a
7441
- });
7442
- break;
7443
- }
7444
- }
7445
- }
7446
- };
7447
- async function e(t = ["fields.json", "cf.json", "field.json", "customfields.json"], a = ["data.json", "fielddata.json", "fd.json", "DATA.json"], i) {
7448
- const s = {
7449
- fields: t.find((m) => {
7450
- try {
7451
- return new URL("./" + m, window.location.href), !0;
7452
- } catch {
7453
- return !1;
7454
- }
7455
- }),
7456
- data: a.find((m) => {
7457
- try {
7458
- return new URL("./" + m, window.location.href), !0;
7459
- } catch {
7460
- return !1;
7461
- }
7462
- })
7463
- }, n = await fetch(
7464
- "./" + (s.data ?? "data.json"),
7465
- {
7466
- cache: "no-store"
7467
- }
7468
- ).then((m) => m.json()).catch(() => ({}));
7469
- await fetch("./" + (s.fields ?? "fields.json"), {
7470
- cache: "no-store"
7471
- }).then((m) => m.json()).then(async (m) => {
7472
- const c = Object.entries(m).filter(([p, { value: o }]) => o != null).reduce(
7473
- (p, [o, { value: h }]) => (n && n[o] !== void 0 && (h = n[o]), p[o] = h, p),
7474
- {
7475
- ...n
7476
- }
7477
- ), b = await l.generate.event.onWidgetLoad(
7478
- c,
7479
- await l.generate.session.get(i)
7480
- );
7481
- window.dispatchEvent(new CustomEvent("onWidgetLoad", { detail: b }));
7482
- });
7483
- }
7484
- l.start = e;
7485
- })(q || (q = {}));
7486
- class gt extends X {
7487
- constructor(e) {
7488
- if (super(), this.queue = [], this.priorityQueue = [], this.history = [], this.timeouts = [], this.running = !1, this.duration = void 0, this.loaded = !1, this.clientWaitRetryDelay = 50, !e.processor || typeof e.processor != "function")
7489
- throw new Error("A valid processor function must be provided to useQueue.");
7490
- this.processor = e.processor, e.duration !== "client" && (this.duration = e.duration ?? 0), this.waitForClientAndBindLoad(e.duration);
7491
- }
7492
- waitForClientAndBindLoad(e = this.duration) {
7493
- if (!(window?.client instanceof G)) {
7494
- setTimeout(() => this.waitForClientAndBindLoad(e), this.clientWaitRetryDelay);
7495
- return;
7496
- }
7497
- window.client.on("load", () => {
7498
- e === "client" && (this.duration = window.client.fields?.widgetDuration ?? 0), this.emit("load"), this.loaded = !0;
7499
- });
7500
- }
7501
- enqueue(e, t = {}) {
7502
- const a = this.hasItems(), i = Array.isArray(e) ? e.map((s) => ({ value: s.value, options: s.options ?? {} })) : [{ value: e, options: t }];
7503
- for (const s of i) {
7504
- const n = {
7505
- isoDate: (/* @__PURE__ */ new Date()).toISOString(),
7506
- isLoop: s.options?.isLoop ?? !1,
7507
- isPriority: s.options?.isPriority ?? !1,
7508
- isImmediate: s.options?.isImmediate ?? !1,
7509
- value: s.value
7510
- };
7511
- n.isPriority && n.isImmediate ? (this.cancel(), this.priorityQueue.unshift(n)) : (n.isPriority ? this.priorityQueue : this.queue).push(n);
7512
- }
7513
- return this.running === !1 && a === !1 && this.run(), this.emit("update", this.queue, this.priorityQueue, this.history, this.timeouts), this;
7514
- }
7515
- async run() {
7516
- if (!this.hasItems()) {
7517
- this.running = !1;
7518
- return;
7519
- }
7520
- this.running = !0, await this.next(), typeof this.duration == "number" && this.duration > 0 ? this.timeouts.push(setTimeout(() => this.run(), this.duration)) : (this.duration === 0 || this.duration !== -1 && this.duration !== !1) && this.run();
7521
- }
7522
- async next() {
7523
- const e = this.priorityQueue.length > 0 ? this.priorityQueue.shift() : this.queue.shift();
7524
- if (!e) {
7525
- this.running = !1;
7526
- return;
7527
- }
7528
- try {
7529
- await this.processor.apply(this, [e.value, this]), this.emit("process", e, this);
7530
- } catch (a) {
7531
- N.error(
7532
- `Error during item processing: ${a instanceof Error ? a.message : String(a)}`
7533
- );
7534
- }
7535
- this.history.push(e);
7536
- const t = e.isPriority ? this.priorityQueue : this.queue;
7537
- e.isLoop && t.push(e);
7538
- }
7539
- /**
7540
- * Resume processing the queue if it is paused. If the queue is already running, it will be restarted, which can be useful if new items have been added or if you want to reset the processing timer.
7541
- * If the queue was empty before, it will start processing immediately.
7542
- * @returns - The instance of the queue for chaining.
7543
- * @example
7544
- * ```javascript
7545
- * myQueue.resume();
7546
- * ```
7547
- */
7548
- resume() {
7549
- return this.running && this.cancel(), this.hasItems() && this.run(), this;
7550
- }
7551
- /**
7552
- * Update the queue's state with new values. This can be used to replace the current queue, priority queue, history, or timeouts with new data. If the queue is not currently running and there are items in the queue after the update, it will start processing immediately.
7553
- * @param save - An object containing the new state for the queue, priority queue, history, and timeouts. Each property is optional, and if not provided, the current state will be retained.
7554
- * @returns - The instance of the queue for chaining.
7555
- * @example
7556
- * ```javascript
7557
- * myQueue.update({
7558
- * queue: newQueueItems,
7559
- * priorityQueue: newPriorityItems,
7560
- * history: newHistory,
7561
- * });
7562
- * ```
7563
- */
7564
- update(e) {
7565
- return this.queue = e.queue ?? this.queue, this.priorityQueue = e.priorityQueue ?? this.priorityQueue, this.history = e.history ?? this.history, this.hasItems() && this.running === !1 && window.client?.on("load", () => this.run()), this;
7566
- }
7567
- /**
7568
- * Cancel all pending timeouts and stop the queue from processing further items. This will clear any scheduled processing and prevent any new items from being processed until `resume()` is called again. The current state of the queue, priority queue, and history will be retained, allowing you to resume processing later without losing any data.
7569
- */
7570
- cancel() {
7571
- this.running && (this.timeouts.forEach((e) => clearTimeout(e)), this.timeouts = [], this.running = !1, this.emit("cancel"));
7572
- }
7573
- /**
7574
- * Check if there are any items in the queue or priority queue. This method returns `true` if there are items waiting to be processed in either the main queue or the priority queue, and `false` if both queues are empty.
7575
- * @returns - A boolean indicating whether there are items in the queue or priority queue.
7576
- */
7577
- hasItems() {
7578
- return this.queue.length > 0 || this.priorityQueue.length > 0;
7579
- }
7580
- on(e, t) {
7581
- return e === "load" && this.loaded ? (t.apply(this), this) : (super.on(e, t), this);
7582
- }
7583
- }
7584
- const et = [];
7585
- class St extends X {
7586
- constructor(e = {}) {
7587
- super(), this.SE_API = null, this.id = "widget communications", this.loaded = !1, this.history = [], this.detected = /* @__PURE__ */ new Set(), this.id = e.id || this.id, et.push(this), ct?.then(async (t) => {
7588
- this.loaded = !0, this.SE_API = t, Promise.all([
7589
- async () => {
7590
- const a = await t.store.get(this.id);
7591
- a && (this.history = a.slice(-10));
7592
- },
7593
- async () => {
7594
- const a = await t.store.get(this.id + "_detected");
7595
- a && (this.detected = new Set(a));
7596
- }
7597
- ]);
7598
- });
7599
- }
7600
- async send(e, t) {
7601
- if (this.SE_API) {
7602
- const a = {
7603
- nonce: Math.random().toString(36).substring(2),
7604
- key: e,
7605
- value: t,
7606
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
7607
- };
7608
- this.history.push(a), this.SE_API.store.set(this.id, this.history), this.SE_API.store.set(this.id + "_detected", Array.from(this.detected));
7609
- }
7610
- }
7611
- update(e) {
7612
- if (!e.length)
7613
- return;
7614
- this.history = e, e.filter((a) => !this.detected.has(a.nonce)).forEach((a) => {
7615
- this.detected.add(a.nonce), this.emit("message", a.key, a.value);
7616
- });
7617
- }
7618
- on(e, t) {
7619
- return e === "load" && this.loaded ? (t.apply(this), this) : (super.on(e, t), this);
7620
- }
7621
- }
7622
- typeof window !== void 0 && (window.addEventListener("load", () => {
7623
- window.client instanceof G && (q.queue = new gt({
7624
- duration: "client",
7625
- processor: async function(e) {
7626
- if (window.dispatchEvent(new CustomEvent(e.listener, { detail: e.data })), e.listener === "onEventReceived" && e.session) {
7627
- const t = await q.generate.event.onSessionUpdate(
7628
- client.session,
7629
- w.event.parseProvider(e.data)
7630
- );
7631
- window.dispatchEvent(new CustomEvent("onSessionUpdate", { detail: t }));
7632
- }
7633
- }
7634
- }));
7635
- }), window.addEventListener("onWidgetLoad", async (l) => {
7636
- const { detail: e } = l;
7637
- if (window.client instanceof G) {
7638
- const t = window.client;
7639
- if (t.fields = e.fieldData, t.session = e.session.data, t.details = {
7640
- ...t.details,
7641
- user: e.channel,
7642
- currency: e.currency,
7643
- overlay: e.overlay
7644
- }, e.channel.id && !e.emulated ? await fetch(`https://api.streamelements.com/kappa/v2/channels/${e.channel.id}/`).then((a) => a.json()).then((a) => {
7645
- if (a.provider)
7646
- return t.details.provider = a.provider, a.provider;
7647
- t.details.provider = "local";
7648
- }).catch(() => {
7649
- t.details.provider = "local";
7650
- }) : t.details.provider = "local", t.emit("load", e), t.debug) {
7651
- N.received("Widget loaded!", l.detail);
7652
- const a = l.detail.fieldData;
7653
- Object.keys(a).length && N.received("Field data:", a);
7654
- }
7655
- t.loaded = !0, t.storage.on("load", (a) => {
7656
- if (t.debug && a ? N.debug(
7657
- "[Client]",
7658
- "Storage loaded for client",
7659
- `"${t.id}";`,
7660
- `Provider: "${t.details.provider}";`,
7661
- a
7662
- ) : t.debug && N.debug(
7663
- "[Client]",
7664
- "Storage loaded for client",
7665
- `"${t.id}";`,
7666
- `Provider: "${t.details.provider}";`,
7667
- "No data found."
7668
- ), a) {
7669
- const i = (b) => {
7670
- const p = Date.now(), o = {};
7671
- for (const h in b)
7672
- if (b.hasOwnProperty(h)) {
7673
- const f = b[h];
7674
- f.expire && f.expire > p && (o[h] = f);
7675
- }
7676
- return o;
7677
- }, s = i(a.user || {}), n = i(a.avatar || {}), m = i(a.pronoun || {}), c = i(a.emote || {});
7678
- t.storage.update({
7679
- user: s,
7680
- avatar: n,
7681
- pronoun: m,
7682
- emote: c
7683
- });
7684
- }
7685
- e.channel.providerId.length && t.storage.add(`avatar.${e.channel.providerId.toLowerCase()}`, {
7686
- value: e.channel.avatar,
7687
- timestamp: Date.now(),
7688
- expire: Date.now() + t.cache.avatar * 60 * 1e3
7689
- });
7690
- });
7691
- }
7692
- }), window.addEventListener("onSessionUpdate", (l) => {
7693
- const { detail: e } = l;
7694
- if (window.client instanceof G) {
7695
- const t = window.client;
7696
- t.session = e.session, t.emit("session", e.session), t.debug && N.debug("[Client]", "Session updated", e.session);
7697
- }
7698
- }), window.addEventListener("onEventReceived", ({ detail: l }) => {
7699
- if (window.client instanceof G) {
7700
- const t = w.event.parseProvider(l);
7701
- switch (t.provider) {
7702
- case "streamelements": {
7703
- const i = t.data;
7704
- switch (i.listener) {
7705
- case "tip-latest": {
7706
- i.event;
7707
- break;
7708
- }
7709
- case "event:skip": {
7710
- i.event;
7711
- break;
7712
- }
7713
- case "event:test": {
7714
- switch (i.event.listener) {
7715
- case "widget-button": {
7716
- const s = i.event;
7717
- at.execute(s.field, s.value);
7718
- break;
7719
- }
7720
- case "subscriber-latest": {
7721
- i.event;
7722
- break;
7723
- }
7724
- }
7725
- break;
7726
- }
7727
- case "kvstore:update": {
7728
- const s = i.event;
7729
- if (tt.length) {
7730
- var e = tt.find(
7731
- (n) => n.id === s.data.key.replace("customWidget.", "") || n.id === s.data.key
7732
- );
7733
- e && e.update(s.data.value);
7734
- }
7735
- if (et.length) {
7736
- const n = et.find(
7737
- (m) => m.id === s.data.key.replace("customWidget.", "") || m.id === s.data.key
7738
- );
7739
- n && n.update(s.data.value);
7740
- }
7741
- break;
7742
- }
7743
- case "bot:counter": {
7744
- i.event;
7745
- break;
7746
- }
7747
- case "alertService:toggleSound": {
7748
- const s = i.event;
7749
- client.details.overlay.muted = !!s.muted;
7750
- break;
7751
- }
7752
- }
7753
- window.client.emit("event", "streamelements", t.data);
7754
- break;
7755
- }
7756
- case "twitch": {
7757
- const i = t.data;
7758
- switch (i.listener) {
7759
- case "delete-message": {
7760
- i.event;
7761
- break;
7762
- }
7763
- case "delete-messages": {
7764
- i.event;
7765
- break;
7766
- }
7767
- case "message": {
7768
- i.event, Z.execute({ provider: "twitch", data: i });
7769
- break;
7770
- }
7771
- case "follower-latest": {
7772
- i.event;
7773
- break;
7774
- }
7775
- case "cheer-latest": {
7776
- i.event;
7777
- break;
7778
- }
7779
- case "subscriber-latest": {
7780
- (!i.event.gifted && !i.event.bulkGifted && !i.event.isCommunityGift || i.event.gifted && !i.event.bulkGifted && !i.event.isCommunityGift || i.event.gifted && !i.event.bulkGifted && i.event.isCommunityGift || !i.event.gifted && i.event.bulkGifted && !i.event.isCommunityGift) && i.event;
7781
- break;
7782
- }
7783
- case "raid-latest": {
7784
- i.event;
7785
- break;
7786
- }
7616
+ community: {
7617
+ message: b,
7618
+ sender: D,
7619
+ bulkGifted: !0
7620
+ },
7621
+ spam: {
7622
+ sender: D,
7623
+ gifted: !0,
7624
+ isCommunityGift: !0
7625
+ }
7626
+ }, _ = ["default", "gift", "community", "spam"], j = i?.subType ?? w.random.array(_)[0];
7627
+ return j = _.includes(j) ? j : "default", {
7628
+ listener: "sponsor-latest",
7629
+ event: {
7630
+ amount: C,
7631
+ name: c.toLowerCase(),
7632
+ displayName: c,
7633
+ providerId: "",
7634
+ ...M.default,
7635
+ ...M[j],
7636
+ _id: w.random.uuid(),
7637
+ sessionTop: !1,
7638
+ type: "sponsor",
7639
+ originalEventName: "sponsor-latest",
7640
+ provider: t
7641
+ },
7642
+ // @ts-ignore
7643
+ emulated: !0
7644
+ };
7645
+ }
7646
+ }
7787
7647
  }
7788
- window.client.emit("event", "twitch", t.data);
7789
- break;
7790
7648
  }
7791
- case "youtube": {
7792
- const i = t.data;
7793
- switch (i.listener) {
7794
- case "message": {
7795
- i.event, Z.execute({ provider: "youtube", data: i });
7796
- break;
7797
- }
7798
- case "subscriber-latest": {
7799
- i.event;
7800
- break;
7801
- }
7802
- case "sponsor-latest": {
7803
- i.event, (!i.event.gifted && !i.event.bulkGifted && !i.event.isCommunityGift || i.event.gifted && !i.event.bulkGifted && !i.event.isCommunityGift || i.event.gifted && !i.event.bulkGifted && i.event.isCommunityGift || !i.event.gifted && i.event.bulkGifted && !i.event.isCommunityGift) && i.event;
7804
- break;
7649
+ }
7650
+ }, l.emulate = {
7651
+ twitch: {
7652
+ message(t = {}) {
7653
+ l.generate.event.onEventReceived(
7654
+ "twitch",
7655
+ "message",
7656
+ t
7657
+ ).then((a) => {
7658
+ a && l.emulate.send("onEventReceived", a);
7659
+ });
7660
+ },
7661
+ deleteMessage(t) {
7662
+ if (!t || typeof t != "string") return;
7663
+ const a = {
7664
+ listener: "delete-message",
7665
+ event: {
7666
+ msgId: t
7805
7667
  }
7806
- case "superchat-latest": {
7807
- i.event;
7808
- break;
7668
+ };
7669
+ l.emulate.send("onEventReceived", a);
7670
+ },
7671
+ deleteMessages(t) {
7672
+ if (!t || typeof t != "string") return;
7673
+ const a = {
7674
+ listener: "delete-messages",
7675
+ event: {
7676
+ userId: t
7809
7677
  }
7810
- }
7811
- window.client.emit("event", "youtube", t.data);
7812
- break;
7678
+ };
7679
+ l.emulate.send("onEventReceived", a);
7680
+ },
7681
+ follower(t = {}) {
7682
+ l.generate.event.onEventReceived(
7683
+ "twitch",
7684
+ "follower-latest",
7685
+ t
7686
+ ).then((a) => {
7687
+ a && l.emulate.send("onEventReceived", a);
7688
+ });
7689
+ },
7690
+ raid(t = {}) {
7691
+ l.generate.event.onEventReceived(
7692
+ "twitch",
7693
+ "raid-latest",
7694
+ t
7695
+ ).then((a) => {
7696
+ a && l.emulate.send("onEventReceived", a);
7697
+ });
7698
+ },
7699
+ cheer(t = {}) {
7700
+ l.generate.event.onEventReceived(
7701
+ "twitch",
7702
+ "cheer-latest",
7703
+ t
7704
+ ).then((a) => {
7705
+ a && l.emulate.send("onEventReceived", a);
7706
+ });
7707
+ },
7708
+ subscriber(t = {}) {
7709
+ l.generate.event.onEventReceived(
7710
+ "twitch",
7711
+ "subscriber-latest",
7712
+ t
7713
+ ).then((a) => {
7714
+ a && l.emulate.send("onEventReceived", a);
7715
+ });
7813
7716
  }
7814
- case "kick": {
7815
- t.data, window.client.emit("event", "kick", t.data);
7816
- break;
7717
+ },
7718
+ streamelements: {
7719
+ tip(t = {}) {
7720
+ l.generate.event.onEventReceived(
7721
+ "streamelements",
7722
+ "tip-latest",
7723
+ t
7724
+ ).then((a) => {
7725
+ a && l.emulate.send("onEventReceived", a);
7726
+ });
7817
7727
  }
7818
- case "facebook": {
7819
- t.data, window.client.emit("event", "facebook", t.data);
7820
- break;
7728
+ },
7729
+ youtube: {
7730
+ message(t = {}) {
7731
+ l.generate.event.onEventReceived(
7732
+ "youtube",
7733
+ "message",
7734
+ t
7735
+ ).then((a) => {
7736
+ a && l.emulate.send("onEventReceived", a);
7737
+ });
7738
+ },
7739
+ subscriber(t = {}) {
7740
+ l.generate.event.onEventReceived(
7741
+ "youtube",
7742
+ "subscriber-latest",
7743
+ t
7744
+ ).then((a) => {
7745
+ a && l.emulate.send("onEventReceived", a);
7746
+ });
7747
+ },
7748
+ superchat(t = {}) {
7749
+ l.generate.event.onEventReceived(
7750
+ "youtube",
7751
+ "superchat-latest",
7752
+ t
7753
+ ).then((a) => {
7754
+ a && l.emulate.send("onEventReceived", a);
7755
+ });
7756
+ },
7757
+ sponsor(t = {}) {
7758
+ l.generate.event.onEventReceived(
7759
+ "youtube",
7760
+ "sponsor-latest",
7761
+ t
7762
+ ).then((a) => {
7763
+ a && l.emulate.send("onEventReceived", a);
7764
+ });
7765
+ }
7766
+ },
7767
+ kick: {},
7768
+ facebook: {},
7769
+ send(t, a) {
7770
+ if (!l.queue) {
7771
+ N.warn("Local queue is not initialized."), window.dispatchEvent(new CustomEvent(t, { detail: a }));
7772
+ return;
7773
+ }
7774
+ switch (t) {
7775
+ case "onEventReceived": {
7776
+ l.queue.enqueue({
7777
+ listener: t,
7778
+ data: a,
7779
+ session: t === "onEventReceived" ? !0 : void 0
7780
+ });
7781
+ break;
7782
+ }
7783
+ case "onSessionUpdate": {
7784
+ l.queue.enqueue({
7785
+ listener: t,
7786
+ data: a
7787
+ });
7788
+ break;
7789
+ }
7790
+ case "onWidgetLoad": {
7791
+ l.queue.enqueue({
7792
+ listener: t,
7793
+ data: a
7794
+ });
7795
+ break;
7796
+ }
7821
7797
  }
7822
7798
  }
7823
- const a = [
7824
- "bot:counter",
7825
- "alertService:toggleSound",
7826
- "event",
7827
- "event:skip",
7828
- "event:test",
7829
- "kvstore:update"
7830
- ];
7831
- client.debug && !a.some((i) => i === t.data.listener) && N.received(
7832
- "[Client]",
7833
- `Event ${t.data.listener} received from ${t.provider}`,
7834
- t.data.event
7835
- );
7799
+ };
7800
+ async function e(t = ["fields.json", "cf.json", "field.json", "customfields.json"], a = ["data.json", "fielddata.json", "fd.json", "DATA.json"], i) {
7801
+ const s = {
7802
+ fields: t.find((m) => {
7803
+ try {
7804
+ return new URL("./" + m, window.location.href), !0;
7805
+ } catch {
7806
+ return !1;
7807
+ }
7808
+ }),
7809
+ data: a.find((m) => {
7810
+ try {
7811
+ return new URL("./" + m, window.location.href), !0;
7812
+ } catch {
7813
+ return !1;
7814
+ }
7815
+ })
7816
+ }, n = await fetch(
7817
+ "./" + (s.data ?? "data.json"),
7818
+ {
7819
+ cache: "no-store"
7820
+ }
7821
+ ).then((m) => m.json()).catch(() => ({}));
7822
+ await fetch("./" + (s.fields ?? "fields.json"), {
7823
+ cache: "no-store"
7824
+ }).then((m) => m.json()).then(async (m) => {
7825
+ const c = Object.entries(m).filter(([p, { value: o }]) => o != null).reduce(
7826
+ (p, [o, { value: h }]) => (n && n[o] !== void 0 && (h = n[o]), p[o] = h, p),
7827
+ {
7828
+ ...n
7829
+ }
7830
+ ), b = await l.generate.event.onWidgetLoad(
7831
+ c,
7832
+ await l.generate.session.get(i)
7833
+ );
7834
+ window.dispatchEvent(new CustomEvent("onWidgetLoad", { detail: b }));
7835
+ });
7836
7836
  }
7837
- }));
7837
+ l.start = e;
7838
+ })(q || (q = {}));
7838
7839
  const rt = {
7839
7840
  getOverlayStatus: () => ({
7840
7841
  isEditorMode: !1,