From 659dae9ce6f0e4b6ef6e05c1a2905c20ad3e6e05 Mon Sep 17 00:00:00 2001 From: dece Date: Thu, 7 Jul 2022 19:07:50 +0200 Subject: [PATCH] taxref: tell family name as well --- edmond/plugins/taxref.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/edmond/plugins/taxref.py b/edmond/plugins/taxref.py index 02a2d96..2c6a02d 100644 --- a/edmond/plugins/taxref.py +++ b/edmond/plugins/taxref.py @@ -150,17 +150,27 @@ class TaxrefPlugin(Plugin): if len(items) == 1: # Only one result: use it. - reply = items[0].get("scientificName") + reply = TaxrefPlugin.item_to_full_name(items[0]) else: # More than one result? For simplicity sake, use the shrlok plugin # if available or just show an ambiguous response. if (shrlok := self.bot.get_plugin("shrlok")): text = "\n".join( - f"{i['frenchVernacularName']} → {i['scientificName']}" - for i in items + ( + item['frenchVernacularName'] + + " → " + + TaxrefPlugin.item_to_full_name(item) + ) + for item in items ) + "\n" reply = shrlok.post_text(text) else: reply = self.get_ambiguous_reply(items) self.bot.say(target, reply) + + @staticmethod + def item_to_full_name(item): + family_name = item.get("familyName") + sci_name = item.get("scientificName") + return f"{family_name} {sci_name}"