From ac183a3e7f10816b93cc9891b67f21522626d35f Mon Sep 17 00:00:00 2001
From: 0x5c <dev@0x5c.io>
Date: Mon, 18 Jan 2021 00:28:16 -0500
Subject: [PATCH] Fixed ?greyline caching (set date url param)

Fixed #318
---
 CHANGELOG.md  | 2 ++
 exts/image.py | 8 ++++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d5c680e..71a4f04 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Moved great circle distance and bearing calculation from `?ungrid` to `?griddistance`.
 - `?ungrid` to `?latlong`.
 - Renamed `?cond` to `?solar`.
+### Fixed
+- Weird image caching situation for `?greyline` on Discord's side.
 ### Deprecated
 - `?ungrid`.
 - Deprecated old `?solar` aliases (`?cond`, etc).
diff --git a/exts/image.py b/exts/image.py
index 9a834dc..c76d2c4 100644
--- a/exts/image.py
+++ b/exts/image.py
@@ -9,6 +9,7 @@ the GNU General Public License, version 2.
 
 
 import aiohttp
+from datetime import datetime
 
 import discord
 import discord.ext.commands as commands
@@ -17,7 +18,7 @@ import common as cmn
 
 
 class ImageCog(commands.Cog):
-    gl_url = "https://www.fourmilab.ch/cgi-bin/uncgi/Earth?img=ETOPO1_day-m.evif&dynimg=y&opt=-p"
+    gl_baseurl = "https://www.fourmilab.ch/cgi-bin/uncgi/Earth?img=ETOPO1_day-m.evif&dynimg=y&opt=-p"
 
     def __init__(self, bot: commands.Bot):
         self.bot = bot
@@ -85,9 +86,8 @@ class ImageCog(commands.Cog):
         embed = cmn.embed_factory(ctx)
         embed.title = "Current Greyline Conditions"
         embed.colour = cmn.colours.good
-        # Generate a nonce to force discord to recache this
-        cachenonce = (ctx.message.id >> 22) // 1000 // 600  # nonce will stay the same for ~10min
-        embed.set_image(url=self.gl_url + f"&cachenonce={cachenonce}")
+        date_params = f"&date=1&utc={datetime.utcnow():%Y-%m-%d+%H:%M:%S}"
+        embed.set_image(url=self.gl_baseurl + date_params)
         await ctx.send(embed=embed)