Skip to content

Commit

Permalink
Merge pull request #2653 from sopel-irc/rate-left-microseconds
Browse files Browse the repository at this point in the history
bot: round rate limit `time_left` value up, eliminate microseconds
  • Loading branch information
dgw authored Feb 1, 2025
2 parents cac7b5c + 00d1343 commit 44bc866
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
from __future__ import annotations

from ast import literal_eval
from datetime import timedelta
import inspect
import itertools
import logging
import math
import re
import threading
import time
Expand Down Expand Up @@ -631,7 +633,11 @@ def rate_limit_info(
return False, None

next_time = metrics.last_time + rate_limit
time_left = next_time - at_time
time_left = timedelta(
seconds=math.ceil(
(next_time - at_time).total_seconds()
)
)

message: Optional[str] = None

Expand Down
4 changes: 2 additions & 2 deletions test/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,8 @@ def testrule(bot, trigger):
# assert there is now a NOTICE which contains templated time left information
assert mockbot.backend.message_sent
patt = (br"NOTICE Test :"
br"time_left=\d+:\d+:\d+(\.\d+)? "
br"time_left_sec=\d+(\.\d+)?")
br"time_left=\d+:\d+:\d+ "
br"time_left_sec=\d+")
assert re.match(patt, mockbot.backend.message_sent[0])


Expand Down

0 comments on commit 44bc866

Please sign in to comment.