From 6c8dd0ed9666d159b362557520109b4652947f2e Mon Sep 17 00:00:00 2001 From: Jackson Egan Date: Tue, 26 May 2020 13:02:32 -0400 Subject: [PATCH 1/2] Add time command to show datetime and timezone that the cron command will use. --- docker-compose.yml | 1 + modules/cron.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 0aac0f7..ee49d83 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,7 @@ services: - JOIN_ON_INVITE - BOT_OWNERS - DEBUG + - TZ volumes: - ${PWD}/config/:/bot/config - ${PWD}/credentials.json:/bot/credentials.json diff --git a/modules/cron.py b/modules/cron.py index fb68f83..3564327 100644 --- a/modules/cron.py +++ b/modules/cron.py @@ -1,4 +1,5 @@ import shlex +import os from datetime import datetime from .common.module import BotModule @@ -30,6 +31,8 @@ class MatrixModule(BotModule): self.daily_commands.pop(room.room_id, None) bot.save_settings() await bot.send_text(room, 'Cleared commands on this room.') + elif args[0] == 'time': + await bot.send_text(room, '{datetime} {timezone}'.format(datetime=datetime.now(), timezone=os.environ.get('TZ'))) def help(self): return ('Runs scheduled commands') From 6fe9839c66e8c9595109809bd7b4be054c51f026 Mon Sep 17 00:00:00 2001 From: Jackson Egan Date: Tue, 26 May 2020 13:12:13 -0400 Subject: [PATCH 2/2] Add time command and TZ variable explanation to README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index fc1680d..a07a3f2 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ Commands: * !cron daily [hour] [command] - Run command on start of hour (Must be done as room admin) * !cron list - List commands in this room * !cron clear - Clear command s in this room (Must be done as room admin) +* !cron time - Print the current datetime and time zone that the cron command will use (time zone set using the `TZ` environment variable) Examples: @@ -379,6 +380,7 @@ MATRIX_SERVER=https://matrix.org JOIN_ON_INVITE=True BOT_OWNERS=@user1:matrix.org,@user2:matrix.org DEBUG=False +TZ=America/New_York ``` Note: without quotes! @@ -406,6 +408,8 @@ __*ATTENTION:*__ Don't include bot itself in `BOT_OWNERS` if cron or any other m To enable debugging for the root logger set `DEBUG=True`. +`TZ` takes any valid [TZ database name](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) value and sets the bot server to the appropriate zone. + ## Module API Just write a python file with desired command name and place it in modules. See current modules for