From 1324f83f1785b6750771e2b6a66804cee20cdec6 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Mon, 20 Oct 2025 12:07:22 -0700 Subject: [PATCH] enhance schedule allow basic Joke and Weather messages with out extra config # value can also be joke (everyXmin) or weather (hour) for special scheduled messages # custom for module/scheduler.py custom schedule examples --- README.md | 4 +++- config.template | 4 +++- modules/scheduler.py | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d2e3776..3e097e4 100644 --- a/README.md +++ b/README.md @@ -522,7 +522,9 @@ enabled = False # enable or disable the scheduler module interface = 1 # channel to send the message to channel = 2 message = "MeshBot says Hello! DM for more info." -value = # value can be min,hour,day,mon,tue,wed,thu,fri,sat,sun +value = # value can be min,hour,day,mon,tue,wed,thu,fri,sat,sun. +# value can also be joke (everyXmin) or weather (hour) for special scheduled messages +# custom for module/scheduler.py custom schedule examples interval = # interval to use when time is not set (e.g. every 2 days) time = # time of day in 24:00 hour format when value is 'day' and interval is not set ``` diff --git a/config.template b/config.template index 250a45e..61be17a 100644 --- a/config.template +++ b/config.template @@ -277,7 +277,9 @@ channel = 2 message = "MeshBot says Hello! DM for more info." # enable overides the above and uses the motd as the message schedulerMotd = False -# value can be min,hour,day,mon,tue,wed,thu,fri,sat,sun. or custom for module/scheduler.py +# value can be min,hour,day,mon,tue,wed,thu,fri,sat,sun. +# value can also be joke (everyXmin) or weather (hour) for special scheduled messages +# custom for module/scheduler.py custom schedule examples value = # interval to use when time is not set (e.g. every 2 days) interval = diff --git a/modules/scheduler.py b/modules/scheduler.py index 8ae6d8e..29c079a 100644 --- a/modules/scheduler.py +++ b/modules/scheduler.py @@ -24,7 +24,8 @@ async def setup_scheduler( scheduler_message = schedulerMessage # Basic Scheduler Options - if 'custom' not in schedulerValue: + basicOptions = ['day', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun', 'hour', 'min'] + if any(option.lower() in schedulerValue.lower() for option in basicOptions): # Basic scheduler job to run the schedule see examples below for custom schedules if schedulerValue.lower() == 'day': if schedulerTime != '': @@ -50,8 +51,16 @@ async def setup_scheduler( elif 'min' in schedulerValue.lower(): schedule.every(int(schedulerInterval)).minutes.do(lambda: send_message(scheduler_message, schedulerChannel, 0, schedulerInterface)) logger.debug(f"System: Starting the basic scheduler to send '{scheduler_message}' on schedule '{schedulerValue}' every {schedulerInterval} interval at time '{schedulerTime}' on Device:{schedulerInterface} Channel:{schedulerChannel}") - else: - # Default schedule if no valid configuration is provided + elif 'joke' in schedulerValue.lower(): + # Schedule to send a joke every specified interval + schedule.every(int(schedulerInterval)).minutes.do(lambda: send_message(tell_joke(), schedulerChannel, 0, schedulerInterface)) + logger.debug(f"System: Starting the joke scheduler to send a joke every {schedulerInterval} minutes on Device:{schedulerInterface} Channel:{schedulerChannel}") + elif 'weather' in schedulerValue.lower(): + # Schedule to send weather updates every specified interval + schedule.every(int(schedulerInterval)).hours.do(lambda: send_message(handle_wxc(0, schedulerInterface, 'wx'), schedulerChannel, 0, schedulerInterface)) + logger.debug(f"System: Starting the weather scheduler to send weather updates every {schedulerInterval} hours on Device:{schedulerInterface} Channel:{schedulerChannel}") + elif 'custom' in schedulerValue.lower(): + # Custom scheduler job to run the schedule see examples below # custom scheduler job to run the schedule see examples below logger.debug(f"System: Starting the custom scheduler default to send reminder every Monday at noon on Device:{schedulerInterface} Channel:{schedulerChannel}")