Skip to content

Commit

Permalink
Merge pull request #8 from sopel-irc/plugin-reply-message
Browse files Browse the repository at this point in the history
plugin: display full reminder datetime
  • Loading branch information
Exirel authored Aug 12, 2023
2 parents b08453b + e187c21 commit f535a28
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
6 changes: 4 additions & 2 deletions sopel_remind/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ def get_reminder_timezone(
:return: the appropriate timezone for ``reminder``
"""
return pytz.timezone(tools.time.get_timezone(
bot.db,
db=bot.db,
config=bot.settings,
nick=reminder.nick,
channel=reminder.destination,
) or 'UTC')
Expand Down Expand Up @@ -326,7 +327,8 @@ def command(bot, trigger):
return pytz.utc

return pytz.timezone(tools.time.get_timezone(
bot.db,
db=bot.db,
config=bot.settings,
nick=nickname,
channel=channel,
) or 'UTC')
Expand Down
29 changes: 21 additions & 8 deletions sopel_remind/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from sopel.bot import Sopel, SopelWrapper # type: ignore
from sopel.config import Config # type: ignore
from sopel.config.types import BooleanAttribute # type: ignore
from sopel.tools.time import format_time # type: ignore
from sopel.trigger import Trigger # type: ignore

from . import backend, config
Expand Down Expand Up @@ -158,10 +159,16 @@ def remind_in(bot: SopelWrapper, trigger: Trigger):
with LOCK:
backend.store(bot, reminder)

when = datetime.fromtimestamp(
reminder.timestamp, pytz.utc
).astimezone(backend.get_reminder_timezone(bot, reminder))
bot.reply('I will remind you that at %s' % (when.strftime('%H:%M:%S')))
when = datetime.fromtimestamp(reminder.timestamp, pytz.utc)
display_timezone = backend.get_reminder_timezone(bot, reminder)
display_when = format_time(
db=bot.db,
config=bot.settings,
channel=reminder.destination,
zone=display_timezone.zone or 'UTC',
time=when,
)
bot.reply('I will remind you that at %s' % display_when)


@plugin.command('at')
Expand Down Expand Up @@ -203,7 +210,13 @@ def remind_at(bot: SopelWrapper, trigger: Trigger):
with LOCK:
backend.store(bot, reminder)

when = datetime.fromtimestamp(
reminder.timestamp, pytz.utc
).astimezone(backend.get_reminder_timezone(bot, reminder))
bot.reply('I will remind you that at %s' % (when.strftime('%H:%M:%S')))
when = datetime.fromtimestamp(reminder.timestamp, pytz.utc)
display_timezone = backend.get_reminder_timezone(bot, reminder)
display_when = format_time(
db=bot.db,
config=bot.settings,
channel=reminder.destination,
zone=display_timezone.zone or 'UTC',
time=when,
)
bot.reply('I will remind you that at %s' % display_when)
30 changes: 25 additions & 5 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ def test_get_reminder_timezone(mockbot, mockreminder):
result = backend.get_reminder_timezone(mockbot, mockreminder)

mock_get_timezone.assert_called_once_with(
mockbot.db, nick='Test', channel='#channel')
db=mockbot.db,
config=mockbot.settings,
nick='Test',
channel='#channel',
)
assert result.zone == 'Europe/Paris'


Expand All @@ -189,7 +193,11 @@ def test_get_reminder_timezone_no_info(mockbot, mockreminder):
result = backend.get_reminder_timezone(mockbot, mockreminder)

mock_get_timezone.assert_called_once_with(
mockbot.db, nick='Test', channel='#channel')
db=mockbot.db,
config=mockbot.settings,
nick='Test',
channel='#channel',
)
assert result.zone == 'UTC'


Expand All @@ -203,7 +211,11 @@ def test_get_user_timezone(mockbot, triggerfactory):
mockbot, trigger.nick, trigger.sender)

mock_get_timezone.assert_called_once_with(
mockbot.db, nick='Test', channel='#channel')
db=mockbot.db,
config=mockbot.settings,
nick='Test',
channel='#channel',
)
assert result.zone == 'Europe/Paris'


Expand All @@ -217,7 +229,11 @@ def test_get_user_timezone_pm(mockbot, triggerfactory):
mockbot, trigger.nick, trigger.sender)

mock_get_timezone.assert_called_once_with(
mockbot.db, nick='Test', channel=None)
db=mockbot.db,
config=mockbot.settings,
nick='Test',
channel=None,
)
assert result.zone == 'Europe/Paris'


Expand All @@ -231,7 +247,11 @@ def test_get_user_timezone_edge_case(mockbot, triggerfactory):
mockbot, trigger.nick, trigger.sender)

mock_get_timezone.assert_called_once_with(
mockbot.db, nick=None, channel='#test')
db=mockbot.db,
config=mockbot.settings,
nick=None,
channel='#test',
)
assert result.zone == 'Europe/Paris'


Expand Down
12 changes: 8 additions & 4 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sopel.tests import rawlist

from sopel_remind.backend import (MEMORY_KEY, Reminder, get_reminder_filename,
load_reminders)
get_reminder_timezone, load_reminders)
from sopel_remind.plugin import configure, reminder_job

TMP_CONFIG = """
Expand Down Expand Up @@ -134,17 +134,21 @@ def test_configure_migration_no_reminders(tmpconfig, monkeypatch):


def test_remind_in(irc, user):
irc.bot.db.set_channel_value('#channel', 'timezone', 'Europe/Paris')
irc.say(user, '#channel', '.in 1s this is my reminder')

assert len(irc.bot.backend.message_sent) == 1
assert len(irc.bot.memory[MEMORY_KEY]) == 1

reminder = irc.bot.memory[MEMORY_KEY][0]
when = datetime.fromtimestamp(reminder.timestamp, pytz.utc)
timezone = get_reminder_timezone(irc.bot, reminder)
when = datetime.fromtimestamp(
reminder.timestamp, pytz.utc
).astimezone(timezone)

assert irc.bot.backend.message_sent == rawlist(
"PRIVMSG #channel :TestUser: I will remind you that at %s"
% when.strftime('%H:%M:%S'),
% when.strftime('%Y-%m-%d - %T%Z'),
)


Expand Down Expand Up @@ -182,7 +186,7 @@ def test_remind_at(irc, user):

assert irc.bot.backend.message_sent == rawlist(
"PRIVMSG #channel :TestUser: I will remind you that at %s"
% when.strftime('%H:%M:%S'),
% when.strftime('%Y-%m-%d - %T%Z'),
)


Expand Down

0 comments on commit f535a28

Please sign in to comment.