diff --git a/edmond/plugins/taxref.py b/edmond/plugins/taxref.py index b8bc055..cfca36c 100644 --- a/edmond/plugins/taxref.py +++ b/edmond/plugins/taxref.py @@ -1,3 +1,4 @@ +import random import urllib.parse import requests @@ -71,3 +72,23 @@ class TaxrefPlugin(Plugin): cd_ref=item_to_use["referenceId"], ) self.bot.say(target, reply) + + # If there are media available, show one! + m_url = item_to_use.get("_links", {}) .get("media", {}) .get("href") + if not m_url: + return + + response = requests.get(m_url) + if response.status_code != 200: + self.signal_failure(target) + return + media_data = response.json() + items = media_data.get("_embedded", {}).get("media", []) + if not items: + return + + random_item = random.choice(items) + media_href = random_item.get("_links", {}).get("file", {}).get("href") + if not media_href: + return + self.bot.say(target, "📷 " + media_href)