diff --git a/src/overlays/chat.ts b/src/overlays/chat.ts index 4e8f8295f7d..79c34e7bf4e 100644 --- a/src/overlays/chat.ts +++ b/src/overlays/chat.ts @@ -9,6 +9,20 @@ import { ioServer } from '~/helpers/panel.js'; import { parseTextWithEmotes } from '~/helpers/parseTextWithEmotes.js'; import { adminEndpoint } from '~/helpers/socket.js'; +export const getBadgeImagesFromBadgeSet = (badgesMap: Map) => { + const badgeImages: {url: string }[] = []; + for (const messageBadgeId of badgesMap.keys()) { + const badge = badgesCache.find(o => o.id === messageBadgeId); + if (badge) { + const badgeImage = badge.getVersion(badgesMap.get(messageBadgeId) as string)?.getImageUrl(4); + if (badgeImage) { + badgeImages.push({ url: badgeImage }); + } + } + } + return badgeImages; +}; + class Chat extends Overlay { showInUI = false; @@ -23,16 +37,6 @@ class Chat extends Overlay { if (!message.sender) { return; } - const badgeImages: {url: string }[] = []; - for (const messageBadgeId of message.sender.badges.keys()) { - const badge = badgesCache.find(o => o.id === messageBadgeId); - if (badge) { - const badgeImage = badge.getVersion(message.sender.badges.get(messageBadgeId) as string)?.getImageUrl(4); - if (badgeImage) { - badgeImages.push({ url: badgeImage }); - } - } - } ioServer?.of('/overlays/chat').emit('message', { id: randomUUID(), timestamp: message.timestamp, @@ -40,7 +44,7 @@ class Chat extends Overlay { userName: message.sender.userName, message: data, show: false, - badges: badgeImages, + badges: getBadgeImagesFromBadgeSet(message.sender.badges), color: message.sender.color, service: 'twitch', }); diff --git a/src/services/twitch/chat.ts b/src/services/twitch/chat.ts index 4fa67303ed8..57a331e9da9 100644 --- a/src/services/twitch/chat.ts +++ b/src/services/twitch/chat.ts @@ -1,3 +1,4 @@ +import { randomUUID } from 'node:crypto'; import util from 'util'; import type { EmitData } from '@entity/overlay.js'; @@ -33,6 +34,7 @@ import { warning } from '~/helpers/log.js'; import { chatIn, debug, error, info, resub, subcommunitygift, subgift, whisperIn, } from '~/helpers/log.js'; +import { ioServer } from '~/helpers/panel.js'; import { linesParsedIncrement, setStatus } from '~/helpers/parser.js'; import { tmiEmitter } from '~/helpers/tmi/index.js'; import * as changelog from '~/helpers/user/changelog.js'; @@ -40,6 +42,7 @@ import getNameById from '~/helpers/user/getNameById.js'; import { isOwner } from '~/helpers/user/index.js'; import { isBot, isBotId } from '~/helpers/user/isBot.js'; import { isIgnored, isIgnoredSafe } from '~/helpers/user/isIgnored.js'; +import { getBadgeImagesFromBadgeSet } from '~/overlays/chat.js'; import eventlist from '~/overlays/eventlist.js'; import { Parser } from '~/parser.js'; import alerts from '~/registries/alerts.js'; @@ -353,6 +356,19 @@ class Chat { client.onMessage(async (_channel, user, message, msg) => { const userstate = msg.userInfo; if (isBotId(userstate.userId)) { + // send to dashboard and ignore + ioServer?.of('/widgets/chat').emit('bot-message', { + id: randomUUID(), + timestamp: Date.now(), + displayName: msg.userInfo.displayName.toLowerCase() === msg.userInfo.userName ? msg.userInfo.displayName : `${msg.userInfo.displayName} (${msg.userInfo.userName})`, + userName: msg.userInfo.userName, + message: message, + show: false, + badges: getBadgeImagesFromBadgeSet(msg.userInfo.badges), + color: msg.userInfo.color, + service: 'twitch', + isBot: true, + }); return; }