Skip to content

Commit

Permalink
Feat: Add $chatMessageTextOnly variable
Browse files Browse the repository at this point in the history
  • Loading branch information
SReject authored Jun 29, 2024
2 parents e792184 + 4a22639 commit 3990d3a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions src/backend/variables/builtin/twitch/chat/message/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,6 +14,7 @@ export default [
chatMessageAnimatedEmoteUrls,
chatMessageEmoteNames,
chatMessageEmoteUrls,
chatMessageTextOnly,
chatMessage,

chatColor,
Expand Down

0 comments on commit 3990d3a

Please sign in to comment.