From 685dd0beb5f4ba88e040bd5a21bab6967b7d0f71 Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Fri, 7 Oct 2016 16:29:03 -0500 Subject: [PATCH] Corrected how to search for the latest motd --- cogs/core.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/cogs/core.py b/cogs/core.py index 1dfc499..7cf413f 100644 --- a/cogs/core.py +++ b/cogs/core.py @@ -26,9 +26,18 @@ class Core: if date is None: motd = await config.get_content('motd') try: - date = motd['date'] - motd = motd['motd'] - # This one will be hit if we return None for that day + # Lets set this to the first one in the list first + latest_motd = motd[0] + for entry in motd: + d = pendulum.parse(entry['date']) + + # Check if the date for this entry is newer than our currently saved latest entry + if d > latest_motd['date']: + latest_motd = entry + + date = latest_motd['date'] + motd = latest_motd['motd'] + # This will be hit if we do not have any entries for motd except TypeError: await self.bot.say("No message of the day!") else: @@ -38,8 +47,8 @@ class Core: try: r_filter = pendulum.parse(date) motd = await config.get_content('motd', r_filter) - date = motd['date'] - motd = motd['motd'] + date = motd[0]['date'] + motd = motd[0]['motd'] fmt = "Message of the day for {}:\n\n{}".format(date, motd) await self.bot.say(fmt) # This one will be hit if we return None for that day