0

当我们的 errbot 看到正确的票证模式时,它会提供指向 JIRA 票证的链接。不幸的是,在 slack 中,用户编辑他们的帖子是很常见的,如果两个编辑都包含 JIRA 票证模式,errbot 会提供两次链接,这很烦人。

我可以检测消息何时是编辑而不是原始消息吗?

4

3 回答 3

1

现在您可以了,因为从消息的 .extra 参数中,您可以从 slack 中获取消息 ID。

于 2017-07-04T14:28:32.373 回答
0

目前这是不可能的(在任何后端),不。对于允许编辑消息的聊天网络,errbot 当前将编辑的消息作为新消息注入。

如果您需要此功能,请在 errbot 的问题跟踪器上打开一个问题,以便我们就如何可能引入此功能进行头脑风暴。

于 2016-10-28T18:04:33.547 回答
0

我的机器人也会监视并扩展对 Jira 问题的引用;我所做的其中一件事是跟踪在频道中看到了多少条消息,以及我最后一次回复任何给定问题的时间。在最后 N 条(我使用 10 条)消息中展开的问题将被忽略。这样,如果他们编辑问题密钥本身,他们通常会得到一个新的扩展,但如果他们编辑消息的其他部分则不会。

def activate(self):
    self.messages_seen={} # room: messages seen
    self.last_shown={} # issue_key : { room : message number last shown }
    super().activate()

def callback_message(self, msg):
    if msg.is_group:
        try:
            self.messages_seen[msg.to.id] += 1
        except KeyError:
            self.messages_seen[msg.to.id] = 1

def record_expanded(self, msg, key, orig_key=None):
    if msg.is_group:
        channel=msg.to.id
        keys = [ key, orig_key ] if orig_key and orig_key != key else [ key ]
        for k in keys:
            if k in self.last_shown:
                self.last_shown[ k ][ channel ] = self.messages_seen[ channel ]
            else:
                self.last_shown[ k ] = { channel : self.messages_seen[ channel ] }

def should_expand(self, msg, key):
    expand=False
    if msg.body.split()[0] == 'jira':
        # User said 'jira <key>', so always expand
        expand=True
    if msg.is_group:
        channel=msg.to.id
        message_number=self.messages_seen.get(channel, 1)

        expanded_in = self.last_shown.get(key, {})
        if expanded_in:
            if channel not in expanded_in: # key has been expanded, but not in this channel
                expand=True
            else:
                expanded_last_here = message_number - expanded_in[channel]
                if expanded_last_here >= self.bot_config.JIRA_EXPAND_ONLY_EVERY: # not recently enough
                    expand=True
                else:
                    self.log.debug("not expanding '%s' because expanded %d messages ago" % (key, expanded_last_here))
        else:
            # this key has not been seen anywhere before
            expand=True
    else:
        # direct IM - always expand
        expand=True
    if not expand:
        self.log.debug("Recently expanded %s, suppressing" % key)
    return expand
于 2018-11-30T16:46:20.627 回答