2025-11-16 16:34:52 +00:00
|
|
|
import logging
|
|
|
|
|
import peewee
|
2025-11-16 17:58:34 +00:00
|
|
|
import datetime
|
2025-11-16 16:34:52 +00:00
|
|
|
|
2025-11-16 17:58:34 +00:00
|
|
|
from db.queries import skip_day_put, skip_day_delete, skip_days_upcoming
|
2025-11-16 16:34:52 +00:00
|
|
|
from .telegram import TelegramCommand
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
class SkipDayAddCommand(TelegramCommand):
|
|
|
|
|
command_text = "/skip_day"
|
|
|
|
|
|
|
|
|
|
async def exec_inner(self, text, update, session, forResponse=None, reply=None):
|
|
|
|
|
try:
|
|
|
|
|
yield "Please enter a skip day"
|
|
|
|
|
|
|
|
|
|
response = await forResponse()
|
|
|
|
|
|
2025-11-16 17:58:34 +00:00
|
|
|
skip_day = datetime.date.fromisoformat(response)
|
|
|
|
|
skip_day_put(skip_day)
|
|
|
|
|
|
|
|
|
|
yield f"Skip day {response} has been added"
|
|
|
|
|
except ValueError:
|
|
|
|
|
yield "That date was not valid"
|
2025-11-16 16:34:52 +00:00
|
|
|
except peewee.IntegrityError:
|
|
|
|
|
yield "That day has already been added"
|
|
|
|
|
|
2025-11-16 17:58:34 +00:00
|
|
|
class SkipDayDeleteCommand(TelegramCommand):
|
|
|
|
|
command_text = "/skip_day_delete"
|
|
|
|
|
|
|
|
|
|
async def exec_inner(self, text, update, session, forResponse=None, reply=None):
|
|
|
|
|
try:
|
|
|
|
|
yield "Please enter a skip day to delete"
|
|
|
|
|
|
|
|
|
|
response = await forResponse()
|
|
|
|
|
|
|
|
|
|
skip_day = datetime.date.fromisoformat(response)
|
|
|
|
|
rows = skip_day_delete(skip_day)
|
|
|
|
|
|
|
|
|
|
if rows > 0:
|
|
|
|
|
yield f"Skip day {skip_day} has been deleted"
|
|
|
|
|
else:
|
|
|
|
|
yield f"Skip day {skip_day} does not exist"
|
|
|
|
|
except ValueError:
|
|
|
|
|
yield "That date was not valid"
|
|
|
|
|
|
|
|
|
|
class SkipDaysCommand(TelegramCommand):
|
|
|
|
|
command_text = "/skip_days"
|
|
|
|
|
|
|
|
|
|
async def exec_inner(self, text, update, session, forResponse=None, reply=None):
|
|
|
|
|
dates = skip_days_upcoming()
|
|
|
|
|
yield ("Upcoming skip days -\n" +
|
|
|
|
|
"\n".join([d.date.isoformat() for d in dates]))
|
|
|
|
|
|
2025-11-16 16:34:52 +00:00
|
|
|
commands = [
|
2025-11-16 17:58:34 +00:00
|
|
|
SkipDayAddCommand(),
|
|
|
|
|
SkipDayDeleteCommand(),
|
|
|
|
|
SkipDaysCommand()
|
2025-11-16 16:34:52 +00:00
|
|
|
]
|