-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add $chatMessageTextOnly variable
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/backend/variables/builtin/twitch/chat/message/chat-message-text-only.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters