diff --git a/src/backend/variables/builtin/twitch/chat/message/chat-message-text-only.ts b/src/backend/variables/builtin/twitch/chat/message/chat-message-text-only.ts new file mode 100644 index 000000000..3bc8e6548 --- /dev/null +++ b/src/backend/variables/builtin/twitch/chat/message/chat-message-text-only.ts @@ -0,0 +1,36 @@ +import { ReplaceVariable } from "../../../../../../types/variables"; +import { EffectTrigger } from "../../../../../../shared/effect-constants"; +import { OutputDataType, VariableCategory } from "../../../../../../shared/variable-constants"; + +const triggers = {}; +triggers[EffectTrigger.MANUAL] = true; +triggers[EffectTrigger.COMMAND] = true; +triggers[EffectTrigger.EVENT] = [ + "twitch:chat-message", + "twitch:first-time-chat", + "firebot:highlight-message", + "twitch:viewer-arrived" +]; + +const model: ReplaceVariable = { + definition: { + handle: "chatMessageTextOnly", + description: "Outputs the chat message from the associated command or event, with any emotes or URLs trimmed out", + triggers: triggers, + categories: [VariableCategory.COMMON, VariableCategory.TRIGGER], + possibleDataOutput: [OutputDataType.TEXT] + }, + evaluator: (trigger) => { + let messageParts = []; + if (trigger.type === EffectTrigger.COMMAND) { + messageParts = trigger.metadata.chatMessage.parts; + } else if (trigger.type === EffectTrigger.EVENT) { + messageParts = trigger.metadata.eventData.chatMessage.parts; + } + + const textParts = messageParts.filter(p => p.type === "text").map(p => p.text); + return textParts.join(" ").trim(); + } +}; + +export default model; \ No newline at end of file diff --git a/src/backend/variables/builtin/twitch/chat/message/index.ts b/src/backend/variables/builtin/twitch/chat/message/index.ts index 6e6b25350..24861e263 100644 --- a/src/backend/variables/builtin/twitch/chat/message/index.ts +++ b/src/backend/variables/builtin/twitch/chat/message/index.ts @@ -1,6 +1,7 @@ import chatMessageAnimatedEmoteUrls from './chat-message-animated-emote-urls'; import chatMessageEmoteNames from './chat-message-emote-names'; import chatMessageEmoteUrls from './chat-message-emote-urls'; +import chatMessageTextOnly from './chat-message-text-only'; import chatMessage from './chat-message'; import chatColor from './chat-user-color'; @@ -13,6 +14,7 @@ export default [ chatMessageAnimatedEmoteUrls, chatMessageEmoteNames, chatMessageEmoteUrls, + chatMessageTextOnly, chatMessage, chatColor,