【问题标题】:Nightbot command夜间机器人命令
【发布时间】:2020-12-04 18:25:48
【问题描述】:

我不知道我发帖的地方是否正确,但我想知道是否有人可以帮助我完成我想做的 Nightbot 命令。
我有 !uptime 命令和 !rage 命令,它只检索一个值。现在我想将这两者组合成一个命令,该命令将检索 5 或 6 个不同的值(这种情况下的愤怒阶段),具体取决于 !uptime 将检索的值。所以基本上,如果我已经流了一个小时!愤怒会说最低限度,但如果持续 5 小时,它会说关键或其他东西。

这怎么可能?有人请帮忙

【问题讨论】:

    标签: command twitch


    【解决方案1】:

    TL:DR;最后的命令

    您可以使用它来实现您想要的(消息作为示例,您可以自定义):

    @$(channel) is $(eval let messages=["a-ok","irritated","wrathful","furious","in a fit of rage"],hrs=(Date.now()-new Date("$(twitch $(channel) "{{uptimeAt}}")").getTime())/3600000,toIndex=(d,l,u,c)=>d<l?0:d>=u?c-1:Math.floor((c-2)*(d-l)/(u-l))+1;messages[toIndex(hrs,1,5,5)])
    

    它产生以下消息:

    @streamer is a-ok               (during the first hour)
    @streamer is irritated          (during the second hour)
    @streamer is wrathful           (during the third hour)
    @streamer is furious            (during the fourth hour)
    @streamer is in a fit of rage   (after the start of the fifth hour)
    

    您可以通过更改toIndex(hrs,1,5,5) 中的数字来调整这些“愤怒阶段”的开始和结束。第二个数字是您正常/正常的小时数(可以是小数)。第三个数字是多少小时(也可以是小数),直到您完全倾斜。最后一个数字是您使用了多少个“愤怒阶段”(必须是整数,并且应该与messages 的长度匹配)。

    通过对此进行调整,您可以在 24 小时的视频流中传播足够多的消息,以表明您的疲劳程度。


    命令分解

    变量

    Nightbot 支持您可以在命令中使用的number of variables。要实现您想要的,您将需要以下变量:

    • $(command) 替换为频道的用户名。 (docs)
    • $(twitch $(channel)) 被替换为有关此 Twitch 频道的信息(关注次数、正常运行时间等)(docs) - 我们将使用它来获取流正常运行时间。
    • $(eval javascript) 替换为给定 JavaScript 代码的结果。 (docs)

    如何使用

    要获取流的开始时间,您可以使用 uptimeAt$(twitch)

    $(twitch $(channel) "{{uptimeAt}}") --> "Mon Dec 07 2015 22:10:56 GMT-0500 (EST)"
    

    您可以通过将其转换为 JavaScript Date 对象并将其转换为流式传输的小时数,然后使用以下方法返回数字时间:

    @$(channel) has been live for $(eval let hoursStreamed = (Date.now() - new Date("$(twitch $(channel) "{{uptimeAt}}")").getTime())/3600000; Math.round(hoursStreamed * 10) / 10) hours.
    

    接下来,我们需要定义“愤怒的等级”:

    @$(channel) is $(eval let messages = ["a-ok", "irritated", "wrathful", "furious", "in a fit of rage"]; messages[0]).
    

    一旦我们获得了流式传输的小时数,我们需要将其转换为可用于选择消息的索引。

    在这部分,我使用了一些变量来计算合适的指标,这就是他们的意思:

    • duration: 直播的小时数
    • lowerBound: 愤怒等级超过默认值之前的最短持续时间
    • upperBound:狂暴等级达到最极端进入前的最长持续时间
    • entryCount: 可选择的条目数
    // converts the given duration value into an index for an array of size entryCount
    function toIndex(duration, lowerBound, upperBound, entryCount) {
      if (duration < lowerBound) {
        // default rage level
        return 0;
      }
    
      if (duration >= upperBound) {
        // maximum rage level
        return entryCount - 1; // the last valid index
      }
    
      // the progress between the lowerBound and upperBound
      // progress will be a float between 0 and 1
      const progress = (duration - lowerBound) / (upperBound - lowerBound);
    
      // this is the number of entries to be spread out between the bounds
      const entriesBetweenBounds = entryCount - 2;
    
      // map progress to an index
      return Math.floor(progress * entriesBetweenBounds) + 1;
    }
    

    使用三元运算符,可以将其压缩为:

    function toIndex(duration, lowerBound, upperBound, entryCount) {
      return duration < lowerBound ? 0 : (
        duration >= upperBound ? entryCount - 1 : (
          Math.floor((entryCount - 2) * (duration - lowerBound)/(upperBound - lowerBound)) + 1
        )
      );
    }
    

    并且可以缩小到:

    let toIndex=(d,l,u,c)=>d<l?0:d>=u?c-1:Math.floor((c-2)*(d-l)/(u-l))+1;
    

    要使用toIndex 播放小时数,在开始后 1 小时内您是正常的,在 5 小时内主要是倾斜的,并且有 5 个愤怒阶段,您可以使用:

    toIndex(hoursStreamed, 1 /* hours you are normal */, 5 /* hours until full-tilt */, 5 /* number of rage stages */)
    

    然后你可以像这样把它们放在一起:

    @$(channel) is $(eval
      let messages=["a-ok","irritated","wrathful","furious","in a fit of rage"],
      hrs=(Date.now()-new Date("$(twitch $(channel) "{{uptimeAt}}")").getTime())/3600000,
      toIndex=(d,l,u,c)=>d<l?0:d>=u?c-1:Math.floor((c-2)*(d-l)/(u-l))+1;
      messages[toIndex(hrs,1,5,5)]
    )
    

    要使用它,您需要通过删除所有空格将其展平为一行:

    @$(channel) is $(eval let messages=["a-ok","irritated","wrathful","furious","in a fit of rage"],hrs=(Date.now()-new Date("$(twitch $(channel) "{{uptimeAt}}")").getTime())/3600000,toIndex=(d,l,u,c)=>d<l?0:d>=u?c-1:Math.floor((c-2)*(d-l)/(u-l))+1;messages[toIndex(hrs,1,5,5)])
    

    【讨论】:

      猜你喜欢
      • 2020-08-21
      • 2017-07-08
      • 2021-06-02
      • 2021-06-02
      • 2018-05-06
      • 2021-10-06
      • 2018-08-05
      • 2021-08-14
      • 2020-07-09
      相关资源
      最近更新 更多