Skip to content

Commit 3c0fd48

Browse files
committed
v0.761 - reminders
1 parent 3483c4e commit 3c0fd48

File tree

9 files changed

+1325
-107
lines changed

9 files changed

+1325
-107
lines changed

.catgitinclude

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ src/modules.py
88
src/text_message_handler.py
99
src/utils.py
1010
config/config.ini
11+
src/reminder_handler.py

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ chat.log
2626
bot.log
2727
*.log
2828

29+
# databases
30+
logs/*.db
31+
*.db
32+
2933
# Python cache files
3034
**/__pycache__/
3135
__pycache__/
@@ -59,4 +63,4 @@ audio/
5963
# Ignore virtual environments
6064
venv/
6165
env/
62-
.env
66+
.env

config/config.ini

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# config/config.ini
2+
13
[DEFAULT]
24
# Settings for TG bot
35
# https://github.com/FlyingFathead/TelegramBot-OpenAI-API/
@@ -50,7 +52,7 @@ BotOwnerID = 0
5052
IsBotDisabled = False
5153

5254
# Message to send to the user if the bot is disabled.
53-
BotDisabledMsg = "This bot is currently taking a break! Sorry!"
55+
BotDisabledMsg = "I'm currently taking a break! Sorry! 😐👍"
5456

5557
# ~~~~~~~~~~~
5658
# Local setup
@@ -181,6 +183,19 @@ ELASTICSEARCH_PASSWORD =
181183
[HolidaySettings]
182184
EnableHolidayNotification = true
183185

186+
# ~~~~~~~~~~~~~~~~~~~~~~~~~
187+
# User-assignable reminders
188+
# ~~~~~~~~~~~~~~~~~~~~~~~~~
189+
[Reminders]
190+
# Enable or disable the reminder/alert functionality
191+
EnableReminders = True
192+
193+
# Maximum number of pending reminders per user
194+
MaxAlertsPerUser = 30
195+
196+
# How often (in seconds) the bot checks for due reminders
197+
PollingIntervalSeconds = 5
198+
184199
# ~~~~~~~~~~~~~~~
185200
# Perplexity API
186201
# ~~~~~~~~~~~~~~~
@@ -217,7 +232,7 @@ NwsOnlyEligibleCountries = True
217232
# XW: International Waters (this isn't an official ISO code but could be used as a placeholder for maritime areas under U.S. influence or international jurisdictions)
218233
# ZZ: Unknown or undefined region (could be used as a placeholder for situations where precise location data isn't available or relevant)
219234
NwsEligibleCountries = US, PR, GU, AS, VI, MP, CA, MX, AQ, UM, XW, ZZ
220-
# Fetch NWS foreacsts and/or alerts (true/false)
235+
# Fetch NWS forecasts and/or alerts (true/false)
221236
# Note that the service can be slow and unreliable at times.
222237
# I recommand getting the alerts to supplement i.e. OpenWeatherMap.
223238
# The alerts usually work, but sadly their open API forecasts are often broken.

src/custom_functions.py

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,24 @@
55
# you can add your own custom bot functionalities via OpenAI's API function calls with this.
66

77
import logging
8+
import configparser
9+
from config_paths import CONFIG_PATH
810

911
# from api_get_openrouteservice import get_route, get_directions_from_addresses
1012
# from elasticsearch_handler import search_es # Import the Elasticsearch search function
1113

14+
# init logger
15+
logger = logging.getLogger(__name__)
16+
17+
# Read the config for enabled/disabled function calls
18+
config = configparser.ConfigParser()
19+
config.read(CONFIG_PATH)
20+
try: # Use try-except for safety
21+
enable_reminders = config.getboolean('Reminders', 'EnableReminders', fallback=False)
22+
except (configparser.NoSectionError, configparser.NoOptionError):
23+
enable_reminders = False
24+
25+
# silently observe the chat
1226
async def observe_chat():
1327
# Log observation or perform any silent monitoring if needed
1428
logging.info("Bot is currently observing the chat.")
@@ -149,6 +163,149 @@ async def observe_chat():
149163
}
150164
})
151165

166+
# ~~~~~~~~~~~~~~~~~~~~~~
167+
# reminders (if enabled)
168+
# ~~~~~~~~~~~~~~~~~~~~~~
169+
170+
if enable_reminders:
171+
manage_reminder_function = {
172+
'name': 'manage_reminder',
173+
'description': """Manages user reminders (alerts). Specify the action: 'add' to create, 'view' to list pending, 'delete' to remove by ID, or 'edit' to modify by ID.
174+
- For 'add': requires 'reminder_text' and exact 'due_time_utc' (ISO 8601 format, e.g., '2025-04-04T10:00:00Z'). Calculate UTC from user input based on current system UTC time.
175+
- For 'view': no other parameters needed.
176+
- For 'delete': requires 'reminder_id'.
177+
- For 'edit': requires 'reminder_id' and at least one of 'reminder_text' or 'due_time_utc'.""",
178+
'parameters': {
179+
'type': 'object',
180+
'properties': {
181+
'action': {
182+
'type': 'string',
183+
'enum': ['add', 'view', 'delete', 'edit'],
184+
'description': "The operation: 'add', 'view', 'delete', or 'edit'."
185+
},
186+
'reminder_text': {
187+
'type': 'string',
188+
'description': "Text of the reminder. Required for 'add', optional for 'edit'."
189+
},
190+
'due_time_utc': {
191+
'type': 'string',
192+
'description': "Due time in UTC ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ). Required for 'add', optional for 'edit'."
193+
},
194+
'reminder_id': {
195+
'type': 'integer',
196+
'description': "ID of the reminder. Required for 'delete' and 'edit'."
197+
}
198+
},
199+
'required': ['action']
200+
}
201+
}
202+
custom_functions.append(manage_reminder_function) # Directly append if enabled
203+
logger.info("Reminder function 'manage_reminder' appended to custom_functions list.")
204+
else:
205+
logger.info("Reminders disabled in config.ini => 'manage_reminder' function not added.")
206+
207+
# # original reminder method (tryout)
208+
# if enable_reminders:
209+
# # 1) Add a reminder
210+
# custom_functions.append({
211+
# 'name': 'add_reminder',
212+
# 'description': (
213+
# "[Use if the user wants to set a reminder for a future time.] "
214+
# "Accept user text and a date/time in UTC (YYYY-MM-DDTHH:MM:SSZ). "
215+
# "If user says 'in 5 minutes', parse that to a UTC time. "
216+
# "Return success/failure, and the ID of the reminder if successful."
217+
# ),
218+
# 'parameters': {
219+
# 'type': 'object',
220+
# 'properties': {
221+
# 'due_time_utc': {
222+
# 'type': 'string',
223+
# 'description': (
224+
# "The date/time in UTC, e.g. 2025-01-02T13:00:00Z. "
225+
# "If user says something like 'in 5 minutes', parse into UTC. "
226+
# "If date/time is missing, ask user for clarification."
227+
# )
228+
# },
229+
# 'reminder_text': {
230+
# 'type': 'string',
231+
# 'description': (
232+
# "What does the user want to be reminded of? E.g. 'Take out the trash'."
233+
# )
234+
# }
235+
# },
236+
# 'required': ['due_time_utc', 'reminder_text']
237+
# }
238+
# })
239+
240+
# # 2) View all pending reminders
241+
# custom_functions.append({
242+
# 'name': 'view_reminders',
243+
# 'description': (
244+
# "[Use if the user wants to see their current/pending reminders.] "
245+
# "No arguments needed."
246+
# ),
247+
# 'parameters': {
248+
# 'type': 'object',
249+
# 'properties': {},
250+
# 'required': []
251+
# }
252+
# })
253+
254+
# # 3) Delete a reminder
255+
# custom_functions.append({
256+
# 'name': 'delete_reminder',
257+
# 'description': (
258+
# "[Use if the user wants to delete/cancel an existing reminder by ID.] "
259+
# "Reminders are typically identified by an integer ID."
260+
# ),
261+
# 'parameters': {
262+
# 'type': 'object',
263+
# 'properties': {
264+
# 'reminder_id': {
265+
# 'type': 'integer',
266+
# 'description': (
267+
# "The ID number of the reminder to delete. "
268+
# "If user doesn't know the ID, prompt them to /viewreminders first or if they ask for you to show them their reminders."
269+
# )
270+
# }
271+
# },
272+
# 'required': ['reminder_id']
273+
# }
274+
# })
275+
276+
# # 4) Edit a reminder (optional)
277+
# custom_functions.append({
278+
# 'name': 'edit_reminder',
279+
# 'description': (
280+
# "[Use if user wants to update an existing reminder. Provide the ID plus new text/time.] "
281+
# "Either 'due_time_utc' or 'reminder_text' or both can be changed."
282+
# ),
283+
# 'parameters': {
284+
# 'type': 'object',
285+
# 'properties': {
286+
# 'reminder_id': {
287+
# 'type': 'integer',
288+
# 'description': "The ID of the reminder to edit."
289+
# },
290+
# 'due_time_utc': {
291+
# 'type': 'string',
292+
# 'description': (
293+
# "The new date/time in UTC, e.g. 2025-01-02T13:00:00Z. "
294+
# "If user says 'tomorrow 10am', parse that into a UTC string."
295+
# )
296+
# },
297+
# 'reminder_text': {
298+
# 'type': 'string',
299+
# 'description': "The updated reminder text."
300+
# }
301+
# },
302+
# 'required': ['reminder_id']
303+
# }
304+
# })
305+
306+
# else:
307+
# logging.info("Reminders are disabled in config.ini => not adding reminder functions.")
308+
152309
# # jul 26 / 2024
153310
# custom_functions.append({
154311
# 'name': 'get_rss_feed',

0 commit comments

Comments
 (0)