Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bot: round rate limit time_left value up, eliminate microseconds #2653

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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+)?")
dgw marked this conversation as resolved.
Show resolved Hide resolved
br"time_left=\d+:\d+:\d+ "
br"time_left_sec=\d+")
assert re.match(patt, mockbot.backend.message_sent[0])


Expand Down