From b1a6badf12b7e99b94db9c9f32e9a1d43df9435c Mon Sep 17 00:00:00 2001 From: nex Date: Tue, 19 Sep 2023 09:49:01 +0100 Subject: [PATCH] Update timetable code --- .idea/dataSources.local.xml | 2 +- .idea/misc.xml | 3 + cogs/other.py | 1 + cogs/timetable.py | 52 +++++++++--- utils/timetable.json | 162 +++++++++++++++--------------------- 5 files changed, 111 insertions(+), 109 deletions(-) diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml index 93731ca..98285dd 100644 --- a/.idea/dataSources.local.xml +++ b/.idea/dataSources.local.xml @@ -1,6 +1,6 @@ - + " diff --git a/.idea/misc.xml b/.idea/misc.xml index 5fe7701..657e23f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,7 @@ + + \ No newline at end of file diff --git a/cogs/other.py b/cogs/other.py index add4dfd..934b96a 100644 --- a/cogs/other.py +++ b/cogs/other.py @@ -1372,6 +1372,7 @@ class OtherCog(commands.Cog): discord.SlashCommandOptionType.attachment, description="Image to perform OCR on", ) + ): """OCRs an image""" await ctx.defer() diff --git a/cogs/timetable.py b/cogs/timetable.py index 36b28d8..de5b0ce 100644 --- a/cogs/timetable.py +++ b/cogs/timetable.py @@ -152,6 +152,10 @@ class TimeTableCog(commands.Cog): next_lesson = self.next_lesson(date) if not next_lesson: next_lesson = self.absolute_next_lesson() + next_lesson.setdefault("name", "unknown") + next_lesson.setdefault("tutor", "unknown") + next_lesson.setdefault("room", "unknown") + next_lesson.setdefault("start_datetime", discord.utils.utcnow()) text = ( "[tt] No more lessons today!\n" f"[tt] Next Lesson: {next_lesson['name']!r} with {next_lesson['tutor']} in " @@ -160,20 +164,46 @@ class TimeTableCog(commands.Cog): ) else: - text = ( - f"[tt] Next Lesson: {next_lesson['name']!r} with {next_lesson['tutor']} in " - f"{next_lesson['room']} - Starts {discord.utils.format_dt(next_lesson['start_datetime'], 'R')}" + next_lesson.setdefault("name", "unknown") + next_lesson.setdefault("tutor", "unknown") + next_lesson.setdefault("room", "unknown") + next_lesson.setdefault("start_datetime", discord.utils.utcnow()) + text = "[tt] Next Lesson: {0[name]!r} with {0[tutor]} in {0[room]} - Starts {1}".format( + lesson, + discord.utils.format_dt(next_lesson['start_datetime'], 'R') ) else: - text = ( - f"[tt] Current Lesson: {lesson['name']!r} with {lesson['tutor']} in {lesson['room']} - " - f"ends {discord.utils.format_dt(lesson['end_datetime'], 'R')}" - ) + lesson.setdefault("name", "unknown") + lesson.setdefault("tutor", "unknown") + lesson.setdefault("room", "unknown") + lesson.setdefault("start_datetime", discord.utils.utcnow()) + if lesson["name"].lower() != "lunch": + text = "[tt] Current Lesson: {0['name']!r} with {0['tutor']} in {0['room']} - ends {1}".format( + lesson, + discord.utils.format_dt(lesson['end_datetime'], 'R') + ) + else: + text = "[tt] \U0001f37d\U0000fe0f Lunch! {0}-{1}, ends in {2}".format( + discord.utils.format_dt(lesson['start_datetime'], 't'), + discord.utils.format_dt(lesson['end_datetime'], 't'), + discord.utils.format_dt(lesson['end_datetime'], 'R') + ) next_lesson = self.next_lesson(date) if next_lesson: - text += "\n[tt] Next lesson: {0[name]!r} with {0[tutor]} in {0[room]} - starts {1}".format( - next_lesson, discord.utils.format_dt(next_lesson["start_datetime"], "R") - ) + next_lesson = self.absolute_next_lesson() + next_lesson.setdefault("name", "unknown") + next_lesson.setdefault("tutor", "unknown") + next_lesson.setdefault("room", "unknown") + next_lesson.setdefault("start_datetime", discord.utils.utcnow()) + if lesson["name"].lower() != "lunch": + text += "\n[tt] Next lesson: {0[name]!r} with {0[tutor]} in {0[room]} - starts {1}".format( + next_lesson, discord.utils.format_dt(next_lesson["start_datetime"], "R") + ) + else: + text = "[tt] \U0001f37d\U0000fe0f Lunch! {0}-{1}.".format( + discord.utils.format_dt(lesson['start_datetime'], 't'), + discord.utils.format_dt(lesson['end_datetime'], 't'), + ) if no_prefix: text = text.replace("[tt] ", "") @@ -225,7 +255,7 @@ class TimeTableCog(commands.Cog): await ctx.defer() await self.update_timetable_message(ctx, date, no_prefix=True) if random.randint(1, 10) == 1: - end_date = datetime(2023, 7, 13, 0, 0, 0, tzinfo=timezone.utc) + end_date = datetime(2024, 7, 13, 0, 0, 0, tzinfo=timezone.utc) days_left = (end_date - discord.utils.utcnow()).days await ctx.respond("There are only {:,} days left of this academic year.".format(days_left)) diff --git a/utils/timetable.json b/utils/timetable.json index 7825837..e02a942 100644 --- a/utils/timetable.json +++ b/utils/timetable.json @@ -1,7 +1,7 @@ { "monday": [ { - "name": "???", + "name": "Digital Security", "start": [ 9, 0 @@ -10,11 +10,11 @@ 10, 15 ], - "tutor": "Other", - "room": "A145" + "tutor": "Raphael", + "room": "A132" }, { - "name": "???", + "name": "Digital Security", "start": [ 10, 30 @@ -23,26 +23,13 @@ 11, 45 ], - "tutor": "Other", - "room": "A145" + "tutor": "Raphael", + "room": "A132" } ], "tuesday": [ { - "name": "???", - "start": [ - 9, - 0 - ], - "end": [ - 10, - 15 - ], - "tutor": "Other", - "room": "A144" - }, - { - "name": "???", + "name": "Managing Infrastructure", "start": [ 10, 30 @@ -51,11 +38,11 @@ 11, 45 ], - "tutor": "Other", - "room": "A047" + "tutor": "Rebecca", + "room": "A132" }, { - "name": "???", + "name": "Digital Security", "start": [ 11, 45 @@ -64,11 +51,22 @@ 13, 0 ], - "tutor": "Other", - "room": "A145" + "tutor": "Raphael", + "room": "A132" }, { - "name": "???", + "name": "Lunch", + "start": [ + 13, + 0 + ], + "end": [ + 14, + 0 + ] + }, + { + "name": "Digital Security", "start": [ 14, 0 @@ -77,39 +75,26 @@ 15, 15 ], - "tutor": "Other", - "room": "A047" + "tutor": "Raphael", + "room": "A132" } ], "wednesday": [ { - "name": "???", + "name": "Managing Infrastructure", "start": [ 9, 0 ], - "end": [ - 10, - 15 - ], - "tutor": "Other", - "room": "A145" - }, - { - "name": "???", - "start": [ - 10, - 30 - ], "end": [ 11, 45 ], - "tutor": "Other", - "room": "A145" + "tutor": "Rebecca", + "room": "A132" }, { - "name": "???", + "name": "Digital Security", "start": [ 11, 45 @@ -118,11 +103,22 @@ 13, 0 ], - "tutor": "Other", - "room": "A145" + "tutor": "Raphael", + "room": "A132" }, { - "name": "???", + "name": "Lunch", + "start": [ + 13, + 0 + ], + "end": [ + 14, + 0 + ] + }, + { + "name": "Digital Security", "start": [ 14, 0 @@ -131,62 +127,47 @@ 15, 15 ], - "tutor": "Other", - "room": "A145" - }, - { - "name": "???", - "start": [ - 15, - 30 - ], - "end": [ - 16, - 45 - ], - "tutor": "Other", - "room": "A145" + "tutor": "Raphael", + "room": "A132" } ], "thursday": [ { - "name": "???", + "name": "Research & Evaluation", "start": [ 9, 0 ], - "end": [ - 10, - 15 - ], - "tutor": "Other", - "room": "A145" - }, - { - "name": "???", - "start": [ - 10, - 30 - ], "end": [ 11, 45 ], - "tutor": "Other", - "room": "A145" + "tutor": "Zach", + "room": "A132" }, { - "name": "???", + "name": "Lunch", "start": [ 11, 45 ], "end": [ - 13, + 12, + 45 + ] + }, + { + "name": "Research & Evaluation", + "start": [ + 12, + 45 + ], + "end": [ + 14, 0 ], - "tutor": "Other", - "room": "A145" + "tutor": "Zach", + "room": "A132" }, { "name": "Fundamentals", @@ -199,20 +180,7 @@ 15 ], "tutor": "Steven", - "room": "A145" - }, - { - "name": "Fundamentals", - "start": [ - 15, - 30 - ], - "end": [ - 16, - 45 - ], - "tutor": "Steven", - "room": "A145" + "room": "A132" } ], "friday": [],