'Can the user send a message?
Args:
user_id: The user sending a message.
time_now_s: The time now.
msg_rate_hz: The long term number of messages a user can send in a
second.
burst_count: How many messages the user can send before being
limited.
update (bool): Whether to update the message rates or not. This is
useful to check if a message would be allowed to be sent before
its ready to be actually sent.
Returns:
A pair of a bool indicating if they can send a message now and a
time in seconds of when they can next send a message.'

def send_message(self, user_id, time_now_s, msg_rate_hz, burst_count, update=True):

    self.prune_message_counts(time_now_s)
    (message_count, time_start, _ignored) = self.message_counts.get(user_id, (0.0, time_now_s, None))
    time_delta = (time_now_s - time_start)
    sent_count = (message_count - (time_delta * msg_rate_hz))
    if (sent_count < 0):
        allowed = True
        time_start = time_now_s
        message_count = 1.0
    elif (sent_count > (burst_count - 1.0)):
        allowed = False
    else:
        allowed = True
        message_count += 1
    if update:
        self.message_counts[user_id] = (message_count, time_start, msg_rate_hz)
    if (msg_rate_hz > 0):
        time_allowed = (time_start + (((message_count - burst_count) + 1) / msg_rate_hz))
        if (time_allowed < time_now_s):
            time_allowed = time_now_s
    else:
        time_allowed = (-1)
    return (allowed, time_allowed)
