StreamElements Twitch !shoutout命令@符号处理方案求助
StreamElements !shoutout命令处理@符号的优化方案
我正在为Twitch频道配置StreamElements的!shoutout(可缩写为!so)命令,当前使用的命令内容为:Check out ${1}, they are playing ${game ${1}} at https://twitch.tv/${1}!
现有正常功能示例:
- 输入:
!so Test123 - 输出:
Check out Test123, they are playing Some_Game_Here at https://twitch.tv/Test123!
但输入带@的用户名时,@符号会被保留,导致Twitch链接无效,具体情况:
- 输入:
!so @Test123 - 当前输出:
Check out @Test123, they are playing Some_Game_Here at https://twitch.tv/@Test123! - 期望输出:
Check out Test123, they are playing Some_Game_Here at https://twitch.tv/Test123!
之前在Nightbot中曾用以下代码实现@符号替换:
$(eval decodeURIComponent(`$(querystring)`).split(` `)[0].replace(/@/g,``)||`$(user)`)
但StreamElements命令内无法直接使用这类解析逻辑,以下是可行的解决方法:
方法1:使用管道符直接替换
利用StreamElements内置的管道过滤功能,对参数中的@符号进行替换,优化后的命令内容如下:Check out ${args.1 | replace("@", "")}, they are playing ${game ${args.1 | replace("@", "")}} at https://twitch.tv/${args.1 | replace("@", "")}!
方法2:使用自定义变量复用处理结果
如果觉得重复写替换逻辑麻烦,可以先定义一个处理好的自定义变量,再复用该变量,命令内容如下:
${set cleanedUser= ${replace ${1} "@" ""}} Check out ${cleanedUser}, they are playing ${game ${cleanedUser}} at https://twitch.tv/${cleanedUser}!
两种方法都能自动去除输入中的@符号,不管用户输入!so Test123还是!so @Test123,都会输出符合预期的内容,同时保证Twitch链接有效。
内容的提问来源于stack exchange,提问作者5Reaper5
相关产品推荐
相关产品推荐

